Fix file rename bug

This commit is contained in:
mike cullerton 2022-11-16 11:12:08 -05:00
parent e4031b69bf
commit 1f86fede35
2 changed files with 20 additions and 9 deletions

View File

@ -68,7 +68,7 @@
<button mat-menu-item (click)="diagram.saveXML()"><mat-icon>code</mat-icon> Download XML File</button> <button mat-menu-item (click)="diagram.saveXML()"><mat-icon>code</mat-icon> Download XML File</button>
</mat-menu> </mat-menu>
<button mat-button *ngIf="diagramFile" (click)="editFileMeta()"> <button mat-button *ngIf="!hasChanged()" (click)="editFileMeta()">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
{{getFileName()}} {{getFileName()}}
</button> </button>

View File

@ -327,7 +327,11 @@ export class ModelerComponent implements AfterViewInit {
dialogRef.afterClosed().subscribe((data: FileMetaDialogData) => { dialogRef.afterClosed().subscribe((data: FileMetaDialogData) => {
if (data && data.fileName) { if (data && data.fileName) {
this._upsertFileMeta(data); if (this.diagramFileMeta) {
this._updateFileFilename(data);
} else {
this._upsertFileMeta(data);
}
} }
}); });
} }
@ -379,6 +383,17 @@ export class ModelerComponent implements AfterViewInit {
}); });
} }
private _updateFileFilename(data: FileMetaDialogData) {
// If it's the first time, we don't have this.fileMetaName
if ((!this.fileMetaName) || ((data.fileName) && (this.fileMetaName !== data.fileName))) {
this.api.updateSpecFileFilename(this.workflowSpec, this.diagramFileMeta, data.fileName).subscribe(newFileMeta => {
this.diagramFileMeta = newFileMeta;
this.router.navigate(['/modeler', this.workflowSpec.id, 'file', data.fileName]);
this.snackBar.open(`Renamed file to ${this.diagramFileMeta.name}.`, 'Ok', {duration: 5000});
});
}
}
private _upsertFileMeta(data: FileMetaDialogData) { private _upsertFileMeta(data: FileMetaDialogData) {
if (data.fileName) { if (data.fileName) {
this.xml = this.draftXml; this.xml = this.draftXml;
@ -391,7 +406,7 @@ export class ModelerComponent implements AfterViewInit {
}; };
this.diagramFile = new File([this.xml], data.fileName, {type: 'text/xml'}); this.diagramFile = new File([this.xml], data.fileName, {type: 'text/xml'});
if (this.bpmnFiles.find(x => x.name === data.fileName)) { if (this.bpmnFiles.find(x => x.name === data.fileName)) {
// Update the existing file meta // Update the existing file meta
this.api.updateSpecFileData(this.workflowSpec, this.diagramFileMeta, this.diagramFile).subscribe(() => { this.api.updateSpecFileData(this.workflowSpec, this.diagramFileMeta, this.diagramFile).subscribe(() => {
this.api.updateSpecFileMeta(this.workflowSpec, this.diagramFileMeta, false).subscribe(() => { this.api.updateSpecFileMeta(this.workflowSpec, this.diagramFileMeta, false).subscribe(() => {
@ -400,13 +415,9 @@ export class ModelerComponent implements AfterViewInit {
}); });
}); });
} else { } else {
// If the filename has changed, delete the old version // The filename has changed
if (this.fileMetaName !== data.fileName && this.fileMetaName !== null) { if (this.fileMetaName !== data.fileName && this.fileMetaName !== null) {
this.api.deleteSpecFileMeta(this.workflowSpec, this.fileMetaName).subscribe(() => { this._updateFileFilename(data);
this.api.getSpecFileMetas(this.workflowSpec.id).subscribe(fms => {
this.bpmnFiles = fms.sort((a, b) => (a.name > b.name) ? 1 : -1);
});
});
} }
this.api.addSpecFile(this.workflowSpec, this.diagramFileMeta, this.diagramFile).subscribe(fileMeta => { this.api.addSpecFile(this.workflowSpec, this.diagramFileMeta, this.diagramFile).subscribe(fileMeta => {
this.router.navigate(['/modeler', this.workflowSpec.id, 'file', fileMeta.name]); this.router.navigate(['/modeler', this.workflowSpec.id, 'file', fileMeta.name]);