Better feedback on draft publication

This commit is contained in:
2023-03-10 17:27:14 +01:00
parent a52435d443
commit 1d3918db87
10 changed files with 198 additions and 73 deletions

View File

@@ -4,5 +4,6 @@
[schema]="this.schema"
(resourceUpdated)="this.flashService.success('Entity updated')"
(resourceDeleted)="this.flashService.success('Entity deleted')"
(resourceReceived)="this.onResourceReceived($event)"
(error)="this.flashService.error($event)">
</crud-card>

View File

@@ -1,26 +1,32 @@
import {Component, Input} from "@angular/core";
import {Component, EventEmitter, Input, Output} from "@angular/core";
import {ActivatedRoute, ParamMap} from "@angular/router";
import { FlashmessagesService } from "../../../layout/flashmessages/flashmessages.service";
@Component({
templateUrl: 'card.component.html',
selector: 'base-card',
templateUrl: 'card.component.html',
selector: 'base-card',
})
export class BaseCrudCardComponent {
@Input() resource: string | undefined;
@Input() resource_id: string | null = null;
@Input() schema: string | undefined;
@Input() resource: string | undefined;
@Input() resource_id: string | null = null;
@Input() schema: string | undefined;
constructor(
private route: ActivatedRoute,
public flashService: FlashmessagesService
) {}
@Output() resourceReceived: EventEmitter<any> = new EventEmitter();
ngOnInit(): void {
if (this.resource_id === null) {
this.route.paramMap.subscribe((params: ParamMap) => {
this.resource_id = params.get('id')
})
constructor(
private route: ActivatedRoute,
public flashService: FlashmessagesService
) {}
ngOnInit(): void {
if (this.resource_id === null) {
this.route.paramMap.subscribe((params: ParamMap) => {
this.resource_id = params.get('id')
})
}
}
}
}
onResourceReceived(model: any) {
this.resourceReceived.emit(model);
}
}

View File

@@ -25,35 +25,54 @@ export class ContractsNewComponent extends BaseContractsComponent {
@Component({
template:`
<label>Download Link:</label>
<div class="input-group mb-12">
<span class="input-group-text"><a href="{{ this.contractPrintLink! }}" target="_blank">{{ this.contractPrintLink! }}&nbsp;</a></span>
<button type="button" class="btn btn-light" [cdkCopyToClipboard]="this.contractPrintLink!"><i-bs name="text-paragraph"/></button>
</div>
<ng-container *ngIf="this.resourceReadyToPrint; else previewLink">
<label i18n>Download Link:</label>
<div class="input-group mb-12">
<span class="input-group-text"><a href="{{ this.contractPrintLink! }}" target="_blank">{{ this.contractPrintLink! }}</a></span>
<button type="button" class="btn btn-light" [cdkCopyToClipboard]="this.contractPrintLink!"><i-bs name="text-paragraph"/></button>
</div>
</ng-container>
<ng-template #previewLink>
<label i18n>Preview Link:</label>
<div class="input-group mb-12">
<span class="input-group-text"><a href="{{ this.contractPreviewLink! }}" target="_blank">{{ this.contractPreviewLink! }}</a></span>
<button type="button" class="btn btn-light" [cdkCopyToClipboard]="this.contractPreviewLink!"><i-bs name="text-paragraph"/></button>
</div>
</ng-template>
<base-card
[resource_id]="this.resource_id"
[resource]="this.resource"
[schema]="this.schema">
[schema]="this.schema"
(resourceReceived)="this.onResourceReceived($event)">
</base-card>
`,
})
export class ContractsCardComponent extends BaseContractsComponent{
resource_id: string | null = null;
resourceReadyToPrint = false;
contractPrintLink: string | null = null;
constructor(
private route: ActivatedRoute
) {
super()
}
contractPreviewLink: string | null = null;
constructor(
private route: ActivatedRoute
) {
super()
}
ngOnInit(): void {
if (this.resource_id === null) {
this.route.paramMap.subscribe((params: ParamMap) => {
this.resource_id = params.get('id')
this.contractPrintLink = `${location.origin}/api/v1/contract/print/pdf/${this.resource_id}`
})
}
}
onResourceReceived(model: any): void {
this.resourceReadyToPrint = model.status != "published";
this.contractPrintLink = `${location.origin}/api/v1/contract/print/pdf/${this.resource_id}`
this.contractPreviewLink = `${location.origin}/api/v1/contract/print/preview/${this.resource_id}`
}
}
@Component({
@@ -119,7 +138,7 @@ export class ContractsSignatureComponent implements OnInit {
}
getPreview() {
return this.sanitizer.bypassSecurityTrustResourceUrl("/api/v1/contract/print/preview/" + this.signature_id);
return this.sanitizer.bypassSecurityTrustResourceUrl("/api/v1/contract/print/preview/signature/" + this.signature_id);
}
postSignature(image: string) {

View File

@@ -3,7 +3,7 @@ import { FormlyFieldConfig } from "@ngx-formly/core";
import { FormGroup} from "@angular/forms";
import { CrudFormlyJsonschemaService } from "@common/crud/crud-formly-jsonschema.service";
import { CrudService } from "@common/crud/crud.service";
import {ActivatedRoute, ParamMap} from "@angular/router";
import { ActivatedRoute, ParamMap, Router } from "@angular/router";
import { formatDate } from "@angular/common";
@@ -92,15 +92,20 @@ export class DraftsNewComponent extends BaseDraftsComponent implements OnInit {
template: `
<base-card
[resource]="this.resource"
[schema]="this.schema">
[schema]="this.schema"
(resourceReceived)="this.onResourceReceived($event)"
>
</base-card>
<a class="btn btn-link" href="http://localhost/api/v1/contract/print/preview/draft/{{this.resource_id}}" target="_blank">Preview</a>
<formly-form [fields]="newContractFormfields" [form]="newContractForm" [model]="newContractModel"></formly-form>
<button class="btn btn-success" (click)="publish()">Publish</button>
<ng-container *ngIf="this.isReadyForPublication;">
<formly-form [fields]="newContractFormfields" [form]="newContractForm" [model]="newContractModel"></formly-form>
<button class="btn btn-success" (click)="publish()">Publish</button>
</ng-container>
`
})
export class DraftsCardComponent extends BaseDraftsComponent implements OnInit {
resource_id: string | null = null;templateModel: {} = {};
isReadyForPublication = false;
newContractFormfields: FormlyFieldConfig[] = [];
newContractForm: FormGroup = new FormGroup({});
newContractModel: any = {
@@ -132,7 +137,8 @@ export class DraftsCardComponent extends BaseDraftsComponent implements OnInit {
constructor(
private route: ActivatedRoute,
private formlyJsonschema: CrudFormlyJsonschemaService,
private crudService: CrudService
private crudService: CrudService,
private router: Router,
) {
super();
}
@@ -150,8 +156,12 @@ export class DraftsCardComponent extends BaseDraftsComponent implements OnInit {
}
publish() {
this.crudService.create('contract', this.newContractModel).subscribe((templateModel) => {
console.log(templateModel)
this.crudService.create('contract', this.newContractModel).subscribe((response: any) => {
this.router.navigate([`../../${response.id}`], {relativeTo: this.route});
});
}
onResourceReceived(model: any): void {
this.isReadyForPublication = model.status == "ready";
}
}

View File

@@ -37,7 +37,7 @@ export class CardComponent implements OnInit {
@Output() resourceUpdated: EventEmitter<string> = new EventEmitter();
@Output() resourceDeleted: EventEmitter<string> = new EventEmitter();
@Output() error: EventEmitter<string> = new EventEmitter();
@Output() resourceReceived: EventEmitter<any> = new EventEmitter();
form = new FormGroup({});
fields: FormlyFieldConfig[] = [];
@@ -78,6 +78,7 @@ export class CardComponent implements OnInit {
next :(model: any) => {
this.model = model;
this._modelLoading$.next(false);
this.resourceReceived.emit(model);
},
error: (err) => this.error.emit("Error loading the model:" + err)
});
@@ -96,27 +97,28 @@ export class CardComponent implements OnInit {
onSubmit(model: any) {
this._modelLoading$.next(true);
if (this.isCreateForm()) {
this.crudService.create(this.resource!, model).subscribe({
next: (response: any) => {
this._modelLoading$.next(false);
if (! this.is_modal) {
this.router.navigate([`../${response.id}`], {relativeTo: this.route});
} else {
this.resourceCreated.emit(response.id)
}
},
error: (err) => this.error.emit("Error creating the entity:" + err)
});
this.crudService.create(this.resource!, model).subscribe({
next: (response: any) => {
this._modelLoading$.next(false);
if (! this.is_modal) {
this.router.navigate([`../${response.id}`], {relativeTo: this.route});
} else {
this.resourceCreated.emit(response.id)
}
},
error: (err) => this.error.emit("Error creating the entity:" + err)
});
} else {
model._id = this.resource_id;
this.crudService.update(this.resource!, model).subscribe( {
next: (model: any) => {
this.model = model;
this._modelLoading$.next(false);
this.resourceUpdated.emit(model._id)
},
error: (err) => this.error.emit("Error updating the entity:" + err)
});
this.crudService.update(this.resource!, model).subscribe( {
next: (model: any) => {
this.model = model;
this._modelLoading$.next(false);
this.resourceUpdated.emit(model._id);
this.resourceReceived.emit(model);
},
error: (err) => this.error.emit("Error updating the entity:" + err)
});
}
}