Adding contract creation

This commit is contained in:
2023-03-06 17:05:49 +01:00
parent d8c8ebdc48
commit 576b5970a5
5 changed files with 210 additions and 16 deletions

View File

@@ -3,6 +3,9 @@ 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 { formatDate } from "@angular/common";
export class BaseDraftsComponent {
@@ -86,7 +89,69 @@ export class DraftsNewComponent extends BaseDraftsComponent implements OnInit {
}
@Component({
templateUrl: '../base-view/templates/card.template.html'
template: `
<base-card
[resource]="this.resource"
[schema]="this.schema">
</base-card>
<a class="btn btn-link" href="http://localhost/api/v1/contract/print/preview/{{this.resource_id}}">Preview</a>
<formly-form [fields]="newContractFormfields" [form]="newContractForm" [model]="newContractModel"></formly-form>
<button class="btn btn-success" (click)="publish()">Publish</button>
`
})
export class DraftsCardComponent extends BaseDraftsComponent {
export class DraftsCardComponent extends BaseDraftsComponent implements OnInit {
resource_id: string | null = null;templateModel: {} = {};
newContractFormfields: FormlyFieldConfig[] = [];
newContractForm: FormGroup = new FormGroup({});
newContractModel: any = {
date: formatDate(new Date(),'YYYY-MM-dd', 'EN_US', 'CET'),
location: "Los Santos, SA",
draft_id: null
}
fieldJson = {
type: "object",
properties: {
date: {
type: "string",
format: "date",
title: "Date"
},
location: {
type: "string",
title: "Location"
},
draft_id: {
type: "string",
title: "Contract Draft",
hidden: true
},
},
}
constructor(
private route: ActivatedRoute,
private formlyJsonschema: CrudFormlyJsonschemaService,
private crudService: CrudService
) {
super();
}
ngOnInit(): void {
if (this.resource_id === null) {
this.route.paramMap.subscribe((params: ParamMap) => {
this.resource_id = params.get('id')
})
}
this.newContractModel.draft_id = this.resource_id;
// @ts-ignore
this.newContractFormfields = [this.formlyJsonschema.toFieldConfig(this.fieldJson)];
}
publish() {
this.crudService.create('contract', this.newContractModel).subscribe((templateModel) => {
console.log(templateModel)
});
}
}