Breaks out add new vs modifying existing workflow spec.

This commit is contained in:
Aaron Louie 2020-01-14 14:13:22 -05:00
parent 7d1121365e
commit 9adb103f18
2 changed files with 31 additions and 11 deletions

View File

@ -29,12 +29,19 @@ export class ApiService {
.pipe(catchError(this._handleError)); .pipe(catchError(this._handleError));
} }
upsertWorkflowSpecification(specId: string, newSpec: WorkflowSpec): Observable<WorkflowSpec> { addWorkflowSpecification(newSpec: WorkflowSpec): Observable<WorkflowSpec> {
const url = this.apiUrl + '/workflow-specification'; const url = this.apiUrl + '/workflow-specification';
const params = new HttpParams().set('spec_id', specId);
return this.httpClient return this.httpClient
.post<WorkflowSpec>(url, newSpec, {params: params}) .post<WorkflowSpec>(url, newSpec)
.pipe(catchError(this._handleError));
}
updateWorkflowSpecification(specId: string, newSpec: WorkflowSpec): Observable<WorkflowSpec> {
const url = this.apiUrl + '/workflow-specification/' + specId;
return this.httpClient
.post<WorkflowSpec>(url, newSpec)
.pipe(catchError(this._handleError)); .pipe(catchError(this._handleError));
} }
@ -55,7 +62,7 @@ export class ApiService {
.pipe(catchError(this._handleError)); .pipe(catchError(this._handleError));
} }
upsertFileMeta(specId: string, fileMeta: FileMeta): Observable<FileMeta> { addFileMeta(specId: string, fileMeta: FileMeta): Observable<FileMeta> {
const url = this.apiUrl + '/file'; const url = this.apiUrl + '/file';
const params = new HttpParams().set('spec_id', specId); const params = new HttpParams().set('spec_id', specId);
const formData = new FormData(); const formData = new FormData();

View File

@ -179,6 +179,9 @@ export class AppComponent implements AfterViewInit {
dialogRef.afterClosed().subscribe((data: NewFileDialogData) => { dialogRef.afterClosed().subscribe((data: NewFileDialogData) => {
console.log('dialog afterClosed result', data); console.log('dialog afterClosed result', data);
if (data && data.fileName && data.workflowSpecId) {
this._upsertSpecAndFileMeta(data);
}
this._upsertSpecAndFileMeta(data); this._upsertSpecAndFileMeta(data);
}); });
} }
@ -188,7 +191,7 @@ export class AppComponent implements AfterViewInit {
this.xml = this.draftXml; this.xml = this.draftXml;
// Save old workflow spec id, if user wants to change it // 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 = { this.workflowSpec = {
id: data.workflowSpecId, id: data.workflowSpecId,
@ -210,13 +213,23 @@ export class AppComponent implements AfterViewInit {
description: data.description, description: data.description,
}; };
// New workflow spec if (specId) {
this.api.upsertWorkflowSpecification(specId, newSpec).subscribe(spec => { // Update existing workflow spec and file
this.api.upsertFileMeta(specId, this.diagramFileMeta).subscribe(fileMeta => { this.api.updateWorkflowSpecification(specId, newSpec).subscribe(spec => {
this.loadFilesFromDb(); this.api.updateFileMeta(this.diagramFileMeta).subscribe(fileMeta => {
this.snackBar.open('Saved changes to new workflow spec and file.', 'Ok', {duration: 5000}); 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});
});
});
}
} }
} }