From 9adb103f1815063a1a5a1549f7d63a8d62177aa3 Mon Sep 17 00:00:00 2001 From: Aaron Louie Date: Tue, 14 Jan 2020 14:13:22 -0500 Subject: [PATCH] Breaks out add new vs modifying existing workflow spec. --- src/app/_services/api.service.ts | 15 +++++++++++---- src/app/app.component.ts | 27 ++++++++++++++++++++------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/app/_services/api.service.ts b/src/app/_services/api.service.ts index e636a55..0d86e85 100644 --- a/src/app/_services/api.service.ts +++ b/src/app/_services/api.service.ts @@ -29,12 +29,19 @@ export class ApiService { .pipe(catchError(this._handleError)); } - upsertWorkflowSpecification(specId: string, newSpec: WorkflowSpec): Observable { + addWorkflowSpecification(newSpec: WorkflowSpec): Observable { const url = this.apiUrl + '/workflow-specification'; - const params = new HttpParams().set('spec_id', specId); return this.httpClient - .post(url, newSpec, {params: params}) + .post(url, newSpec) + .pipe(catchError(this._handleError)); + } + + updateWorkflowSpecification(specId: string, newSpec: WorkflowSpec): Observable { + const url = this.apiUrl + '/workflow-specification/' + specId; + + return this.httpClient + .post(url, newSpec) .pipe(catchError(this._handleError)); } @@ -55,7 +62,7 @@ export class ApiService { .pipe(catchError(this._handleError)); } - upsertFileMeta(specId: string, fileMeta: FileMeta): Observable { + addFileMeta(specId: string, fileMeta: FileMeta): Observable { const url = this.apiUrl + '/file'; const params = new HttpParams().set('spec_id', specId); const formData = new FormData(); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 76ce8bc..e18613f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -179,6 +179,9 @@ export class AppComponent implements AfterViewInit { dialogRef.afterClosed().subscribe((data: NewFileDialogData) => { console.log('dialog afterClosed result', data); + if (data && data.fileName && data.workflowSpecId) { + this._upsertSpecAndFileMeta(data); + } this._upsertSpecAndFileMeta(data); }); } @@ -188,7 +191,7 @@ export class AppComponent implements AfterViewInit { this.xml = this.draftXml; // Save old workflow spec id, if user wants to change it - const specId = this.workflowSpec ? this.workflowSpec.id : data.workflowSpecId; + const specId = this.workflowSpec ? this.workflowSpec.id : undefined; this.workflowSpec = { id: data.workflowSpecId, @@ -210,13 +213,23 @@ export class AppComponent implements AfterViewInit { description: data.description, }; - // New workflow spec - this.api.upsertWorkflowSpecification(specId, newSpec).subscribe(spec => { - this.api.upsertFileMeta(specId, this.diagramFileMeta).subscribe(fileMeta => { - this.loadFilesFromDb(); - this.snackBar.open('Saved changes to new workflow spec and file.', 'Ok', {duration: 5000}); + if (specId) { + // Update existing workflow spec and file + this.api.updateWorkflowSpecification(specId, newSpec).subscribe(spec => { + this.api.updateFileMeta(this.diagramFileMeta).subscribe(fileMeta => { + this.loadFilesFromDb(); + this.snackBar.open('Saved changes to workflow spec and file.', 'Ok', {duration: 5000}); + }); }); - }); + } else { + // Add new workflow spec and file + this.api.addWorkflowSpecification(newSpec).subscribe(spec => { + this.api.addFileMeta(newSpec.id, this.diagramFileMeta).subscribe(fileMeta => { + this.loadFilesFromDb(); + this.snackBar.open('Saved new workflow spec and file.', 'Ok', {duration: 5000}); + }); + }); + } } }