From e2dfbfa2e8c1331a2d8dc291581f3c3f4f4aa87a Mon Sep 17 00:00:00 2001 From: Adarshdeep Cheema Date: Tue, 5 Jul 2022 14:57:44 -0400 Subject: [PATCH 1/3] adding a SaveAs Option in the Menu Signed-off-by: Adarshdeep Cheema --- .../src/app/core/menu-bar/menu-bar.component.ts | 12 ++++++++++++ .../src/app/core/menu-bar/menu-bar.config.ts | 7 +++++++ .../editor/code-editor/monaco/monaco.service.ts | 17 ++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/webClient/src/app/core/menu-bar/menu-bar.component.ts b/webClient/src/app/core/menu-bar/menu-bar.component.ts index 0d4daec9..9ad77914 100644 --- a/webClient/src/app/core/menu-bar/menu-bar.component.ts +++ b/webClient/src/app/core/menu-bar/menu-bar.component.ts @@ -423,6 +423,8 @@ export class MenuBarComponent implements OnInit, OnDestroy { this.closeAll(); } else if (event.which === KeyCode.KEY_R && event.shiftKey) { this.refreshFile(); + } else if (event.which === KeyCode.KEY_S && event.shiftKey) { + this.saveAsFile(); } // else if (event.which === KeyCode.KEY_S && event.ctrlKey) { TODO // this.saveAll(); @@ -629,6 +631,16 @@ export class MenuBarComponent implements OnInit, OnDestroy { } } + saveAsFile() { + let fileContext = this.editorControl.fetchActiveFile(); + let directory = fileContext.model.path || this.editorControl.activeDirectory; + if (!fileContext) { + this.snackBar.open('Warning: Cannot save, no content found', 'Dismiss', {duration: MessageDuration.Medium, panelClass: 'center'}); + } else { + let sub = this.monacoService.saveFile(fileContext, directory, true).subscribe(() => { sub.unsubscribe(); }); + } + } + //saveAll() { // this.editorControl.saveAllFile.emit(); //} diff --git a/webClient/src/app/core/menu-bar/menu-bar.config.ts b/webClient/src/app/core/menu-bar/menu-bar.config.ts index c4f8a28a..9a3d91fa 100644 --- a/webClient/src/app/core/menu-bar/menu-bar.config.ts +++ b/webClient/src/app/core/menu-bar/menu-bar.config.ts @@ -183,6 +183,13 @@ export const MENU = [ internalName: 'saveFile' }, keyMap: 'Ctrl+S' + }, + { + name: 'Save As', + action: { + internalName: 'saveAsFile' + }, + keyMap: 'Alt+S+Shift' }, { name: 'group-end' diff --git a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts index 3d573b9b..2a8a1986 100644 --- a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts +++ b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts @@ -404,7 +404,7 @@ export class MonacoService implements OnDestroy { return canBeISO; } - saveFile(fileContext: ProjectContext, fileDirectory?: string): Observable { + saveFile(fileContext: ProjectContext, fileDirectory?: string, saveAs?: any): Observable { return new Observable((obs) => { if (fileContext.model.isDataset) { this.editorControl.saveBuffer(fileContext, null).subscribe(() => obs.next('Save')); @@ -414,7 +414,7 @@ export class MonacoService implements OnDestroy { * perhaps this should be done in real * time as an enhancement. */ - if (fileContext.temp) { + if (fileContext.temp || saveAs) { let x = this.preSaveCheck(fileContext); /* Open up a dialog with the standard, * "save as" format. @@ -426,7 +426,18 @@ export class MonacoService implements OnDestroy { }); saveRef.afterClosed().subscribe(result => { if (result) { - this.editorControl.saveBuffer(fileContext, result).subscribe(() => obs.next('Save')); + this.editorControl.getFileMetadata(result.directory + '/' + result.fileName).subscribe(r => { + this.snackBar.open(`File ${result.directory}/${result.fileName} already exists.` , + 'Close', { duration: MessageDuration.Medium, panelClass: 'center' }); + }, error => { + if(error.status === 404){ + this.editorControl.saveBuffer(fileContext, result).subscribe(() => obs.next('Save')); + } else{ + this.snackBar.open(`Problem verifying if ${result.directory}/${result.fileName} already exists.` , + 'Close', { duration: MessageDuration.Medium, panelClass: 'center' }); + } + } + ); } else { obs.next('Cancel'); } From 02006fe3e12b46ae9d2865b98760c7c5d33f9c81 Mon Sep 17 00:00:00 2001 From: Adarshdeep Cheema Date: Tue, 5 Jul 2022 16:09:40 -0400 Subject: [PATCH 2/3] adding a SaveAs Option in the Menu Signed-off-by: Adarshdeep Cheema --- .../code-editor/monaco/monaco.service.ts | 8 +-- .../editor-control/editor-control.service.ts | 71 ++++++++++--------- 2 files changed, 42 insertions(+), 37 deletions(-) diff --git a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts index 2a8a1986..43ed01a0 100644 --- a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts +++ b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts @@ -407,7 +407,7 @@ export class MonacoService implements OnDestroy { saveFile(fileContext: ProjectContext, fileDirectory?: string, saveAs?: any): Observable { return new Observable((obs) => { if (fileContext.model.isDataset) { - this.editorControl.saveBuffer(fileContext, null).subscribe(() => obs.next('Save')); + this.editorControl.saveBuffer(fileContext, null, saveAs).subscribe(() => obs.next('Save')); } else { /* Issue a presave check to see if the * file can be saved as ISO-8859-1, @@ -431,7 +431,7 @@ export class MonacoService implements OnDestroy { 'Close', { duration: MessageDuration.Medium, panelClass: 'center' }); }, error => { if(error.status === 404){ - this.editorControl.saveBuffer(fileContext, result).subscribe(() => obs.next('Save')); + this.editorControl.saveBuffer(fileContext, result, saveAs).subscribe(() => obs.next('Save')); } else{ this.snackBar.open(`Problem verifying if ${result.directory}/${result.fileName} already exists.` , 'Close', { duration: MessageDuration.Medium, panelClass: 'center' }); @@ -454,7 +454,7 @@ export class MonacoService implements OnDestroy { this.editorControl.getFileMetadata(fileContext.model.path + '/' + fileContext.model.name).subscribe(r => { fileContext.model.encoding = r.ccsid; if (r.ccsid && r.ccsid != 0) { - this.editorControl.saveBuffer(fileContext, null).subscribe(() => obs.next('Save')); + this.editorControl.saveBuffer(fileContext, null, saveAs).subscribe(() => obs.next('Save')); } /* The file was never tagged, so we should * ask the user if they would like to tag it. @@ -468,7 +468,7 @@ export class MonacoService implements OnDestroy { }); saveRef.afterClosed().subscribe(result => { if (result) { - this.editorControl.saveBuffer(fileContext, result).subscribe(() => obs.next('Save')); + this.editorControl.saveBuffer(fileContext, result, saveAs).subscribe(() => obs.next('Save')); } else { obs.next('Cancel'); } diff --git a/webClient/src/app/shared/editor-control/editor-control.service.ts b/webClient/src/app/shared/editor-control/editor-control.service.ts index 6ed40df6..fd8e9945 100644 --- a/webClient/src/app/shared/editor-control/editor-control.service.ts +++ b/webClient/src/app/shared/editor-control/editor-control.service.ts @@ -539,7 +539,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff } doSaving(context: ProjectContext, requestUrl: string, _activeFile: ProjectContext, results: any, isUntagged: boolean, - _observer: Observer, _observable: Observable) { + _observer: Observer, _observable: Observable, saveAs?: boolean) { /* We must BASE64 encode the contents * of the file before it is sent * to the server. @@ -550,36 +550,41 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff * to save the file. */ this.http.put(requestUrl, encodedFileContents).subscribe(r => { - + // if we are doing SaveAs then do not update the openedFileList + if(saveAs){ + this.snackBar.open(`${results.fileName} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' }); + this.openDirectory.next(results.directory); + } /* It was a new file, we * can set the new fileName. */ - if (results && !isUntagged) { - _activeFile.name = results.fileName; - _activeFile.model.name = results.fileName; - _activeFile.model.fileName = results.fileName; - _activeFile.model.encoding = this.getIntEncoding(results.encoding); - _activeFile.model.path = results.directory; - _activeFile.temp = false; - } - /* This will probably need to be changed - * for the sake of accessibility. - */ - this.snackBar.open(`${_activeFile.name} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' }); - - /* Send buffer saved event */ - this.bufferSaved.next({ buffer: _activeFile.model.contents, file: _activeFile.model.name }); - let fileList = this.openFileList.getValue() - .map(file => { - if (file.id === context.id) { - file.changed = false; - } - return file; - }); - this.openFileList.next(fileList); - if (results) { - this.openDirectory.next(results.directory); + else{ + if (results && !isUntagged) { + _activeFile.name = results.fileName; + _activeFile.model.name = results.fileName; + _activeFile.model.fileName = results.fileName; + _activeFile.model.encoding = this.getIntEncoding(results.encoding); + _activeFile.model.path = results.directory; + _activeFile.temp = false; + } + /* This will probably need to be changed + * for the sake of accessibility. + */ + this.snackBar.open(`${_activeFile.name} has been saved!`, 'Close', { duration: MessageDuration.Short, panelClass: 'center' }); + /* Send buffer saved event */ + this.bufferSaved.next({ buffer: _activeFile.model.contents, file: _activeFile.model.name }); + let fileList = this.openFileList.getValue() + .map(file => { + if (file.id === context.id) { + file.changed = false; + } + return file; + }); + this.openFileList.next(fileList); + if (results) { + this.openDirectory.next(results.directory); + } + if (_observer != null) { _observer.next(null); } } - if (_observer != null) { _observer.next(null); } }, e => { let error = e.error.error; @@ -758,7 +763,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff }) } - saveFileHandler(context?: ProjectContext, results?: any): Observable { + saveFileHandler(context?: ProjectContext, results?: any, saveAs?: boolean): Observable { const _openFile = this.openFileList.getValue(); let _activeFile: ProjectContext; let _observer: Observer; @@ -832,7 +837,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff { sessionID, forceOverwrite, lastChunk: true }); - this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable); + this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable, saveAs); /** Update the new encoding value, in opeFileList Models */ let index = this._openFileList.value.findIndex(item => item.id === _activeFile.id); this._openFileList.value[index].model.encoding = this.getIntEncoding(targetEncoding); @@ -872,7 +877,7 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff { forceOverwrite: true, sessionID, lastChunk: true }); - this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable); + this.doSaving(context, requestUrl, _activeFile, results, isUntagged, _observer, _observable, saveAs); /** Update the new encoding value, in opeFileList Models */ let index = this._openFileList.value.findIndex(item => item.id === _activeFile.id); this._openFileList.value[index].model.encoding = this.getIntEncoding(targetEncoding); @@ -1082,12 +1087,12 @@ export class EditorControlService implements ZLUX.IEditor, ZLUX.IEditorMultiBuff * @param path The path of the file into which the buffer should be saved, or null if the buffer is already associated with a file * @returns An observable that pushes when the file has been saved */ - saveBuffer(buffer: ZLUX.EditorBufferHandle, path: string | null): Observable { + saveBuffer(buffer: ZLUX.EditorBufferHandle, path: string | null, saveAs?: boolean): Observable { this.saveFile.emit(buffer); if (buffer.model.isDataset) { return this.saveDatasetHandler(buffer, path); } else { - return this.saveFileHandler(buffer, path); + return this.saveFileHandler(buffer, path, saveAs); } } /** From cdfc24920d9f41d4150de97a69c69fd1d03dc088 Mon Sep 17 00:00:00 2001 From: Adarshdeep Cheema Date: Wed, 6 Jul 2022 08:59:38 -0400 Subject: [PATCH 3/3] changing the parameter dataType Signed-off-by: Adarshdeep Cheema --- webClient/src/app/editor/code-editor/monaco/monaco.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts index 43ed01a0..c193ee96 100644 --- a/webClient/src/app/editor/code-editor/monaco/monaco.service.ts +++ b/webClient/src/app/editor/code-editor/monaco/monaco.service.ts @@ -404,7 +404,7 @@ export class MonacoService implements OnDestroy { return canBeISO; } - saveFile(fileContext: ProjectContext, fileDirectory?: string, saveAs?: any): Observable { + saveFile(fileContext: ProjectContext, fileDirectory?: string, saveAs?: boolean): Observable { return new Observable((obs) => { if (fileContext.model.isDataset) { this.editorControl.saveBuffer(fileContext, null, saveAs).subscribe(() => obs.next('Save'));