From a2b99cad1aa5bb8e945dae5a7dcd5401bf642adf Mon Sep 17 00:00:00 2001 From: gpveronica Date: Tue, 17 Dec 2024 15:59:47 +0100 Subject: [PATCH 1/2] wc - WiP Delete files #TASK-7220 #TASK-7100 Signed-off-by: gpveronica --- src/webcomponents/file/file-data-manager.js | 53 +++++++- src/webcomponents/file/file-delete.js | 143 ++++++++++++++++++++ 2 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 src/webcomponents/file/file-delete.js diff --git a/src/webcomponents/file/file-data-manager.js b/src/webcomponents/file/file-data-manager.js index cf172b954..5b2adfea7 100644 --- a/src/webcomponents/file/file-data-manager.js +++ b/src/webcomponents/file/file-data-manager.js @@ -21,6 +21,7 @@ import GridCommons from "../commons/grid-commons"; import "../commons/data-list.js"; import "../loading-spinner.js"; import "./file-view.js"; +import "./file-delete.js"; import "./folder-create.js"; import "./file-create.js"; import "./file-fetch.js" @@ -114,6 +115,24 @@ export default class FileDataManager extends LitElement { icon: "fas fa-copy", render: () => this.renderFileCopy(), }, + /* + { + id: "file-execute", + title: "View", + icon: "", + modalTitle: "Execute", + modalId: `${this._prefix}FileExecuteModal`, + render: () => this.renderFileExecute(), + // permission: this.permissions["organization"](), + }, + */ + { + id: "file-delete", + title: "Delete", + icon: "far fa-trash-alt", + render: () => this.renderFileDelete(), + }, + ]; this.actions = { @@ -439,14 +458,23 @@ export default class FileDataManager extends LitElement { ModalUtils.show(this.currentAction["modalId"]); } - - onFileAction(e,id) { - ModalUtils.close(id); + #initOriginalObjects() { this.currentAction = {}; + this.fileId = ""; + this.file = {}; this.currentRoot.visited = false; this.route(this.currentRoot.file.id) } + onFileAction(e,id) { + ModalUtils.close(id); + this.#initOriginalObjects(); + } + + onCloseNotification() { + this.#initOriginalObjects(); + } + onCheckRow(e) {} renderFolderCreate() { @@ -500,7 +528,7 @@ export default class FileDataManager extends LitElement { modalSize: "modal-lg", }, render: () => { - debugger + // FIXME 20241217 Vero: unlink files for fetched files not working. Waiting for Pedro's feedback. return html` + + `; + } + addSearch(action, icon = "fa-search", placeholder = "Search ...", className = "", style = "") { return html`
@@ -734,6 +772,7 @@ export default class FileDataManager extends LitElement { width: "20", widthUnit: "%" }, + // CAUTION 20241217 Vero: Nacho, { title: "Format", field: "format", @@ -753,6 +792,12 @@ export default class FileDataManager extends LitElement { `; } }, + { + title: "Status", + field: "internal.status.id", + rowspan: 1, + colspan: 1, + }, { title: "Tags", field: "tags", diff --git a/src/webcomponents/file/file-delete.js b/src/webcomponents/file/file-delete.js new file mode 100644 index 000000000..c5378b085 --- /dev/null +++ b/src/webcomponents/file/file-delete.js @@ -0,0 +1,143 @@ +/** + * Copyright 2015-2024 OpenCB + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {html, LitElement} from "lit"; +import UtilsNew from "../../core/utils-new.js"; +import LitUtils from "../commons/utils/lit-utils.js"; +import NotificationUtils from "../commons/utils/notification-utils.js"; + +export default class FileDelete extends LitElement { + + constructor() { + super(); + + this.#init(); + } + + createRenderRoot() { + return this; + } + + static get properties() { + return { + fileId: { + type: String, + }, + opencgaSession: { + type: Object, + }, + }; + } + + #init() { + this.JOB_ID = "file-delete"; + this._file = null; + this._config = this.getDefaultConfig(); + } + + #setLoading(value) { + this.isLoading = value; + this.requestUpdate(); + } + + update(changedProperties) { + if (changedProperties.has("fileId") || changedProperties.has("opencgaSession")) { + this.fileIdObserver(); + } + super.update(changedProperties); + } + + fileIdObserver() { + if (this.opencgaSession && this.fileId) { + const params = { + study: this.opencgaSession.study.fqn + }; + this.opencgaSession.opencgaClient.files() + .info(this.fileId, params) + .then(response => { + this._file = UtilsNew.objectClone(response.responses[0].results[0]); + this.requestUpdate(); + }) + .catch(response => { + console.error(response); + }); + } + } + + onSubmit() { + const params = { + study: this.opencgaSession.study.fqn, + jobId: `${this.JOB_ID}-${UtilsNew.getDatetime()}`, + }; + + const endpoint = this._file.external ? + this.opencgaSession.opencgaClient.files().unlink(this._file.id, params) : + this.opencgaSession.opencgaClient.files().delete(this._file.id, params); + + // FIXME 20241217 VERO: When trying to delete a file fetched from an external source in the root path: + // - If delete is used, opencga returns error "Use unlink". This is happening because the field "external" in this case is set to true in opencga. + // - If unlink is used, opencga returns error "[...] Could not unlink [...] Could not delete file: No documents could be found to be updated". + // Bug created: https://app.clickup.com/t/36631768/TASK-7291 + this.#setLoading(true); + endpoint + .then(() => { + NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_SUCCESS, { + title: "Delete File: Job launched", + message: `Job ${params.jobId} has been launched successfully`, + }); + LitUtils.dispatchCustomEvent(this, "fileDelete", this._file.id, {}); + LitUtils.dispatchCustomEvent(this, "closeNotification", this._file.id, {}); + this._file = null; + }) + .catch(error => { + NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_RESPONSE, error); + }) + .finally(() => { + this.#setLoading(false); + }); + } + + render() { + debugger + if (this.isLoading) { + return html``; + } + if (this._file) { + // Caution 20241218 Vero: displaying a notification for now. Deleting is launching and endpoint, but + // we are not seeing the job parameters in the meta endpoint. Waiting for Pedro's feedback. + return NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_CONFIRMATION, { + title: `Delete File: File ${this._file.id} in organization ${this.opencgaSession.organization.id}`, + message: ` + Are you sure you want to delete the file ${this._file.id}? + `, + ok: () => { + this.onSubmit(); + }, + cancel: () => { + this._file = null; + LitUtils.dispatchCustomEvent(this, "closeNotification", null); + }, + }); + } + } + + getDefaultConfig() { + return {}; + } + +} + +customElements.define("file-delete", FileDelete); From c1a399f04e5819327c2a391b301c90ae26589348 Mon Sep 17 00:00:00 2001 From: gpveronica Date: Tue, 17 Dec 2024 16:00:06 +0100 Subject: [PATCH 2/2] wc - Tiny improvement in notification message #TASK-7220 #TASK-7100 Signed-off-by: gpveronica --- src/webcomponents/file/file-fetch.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webcomponents/file/file-fetch.js b/src/webcomponents/file/file-fetch.js index 169ccacb7..d75b2585b 100644 --- a/src/webcomponents/file/file-fetch.js +++ b/src/webcomponents/file/file-fetch.js @@ -114,8 +114,8 @@ export default class FileFetch extends LitElement { .then(() => { this.#initOriginalObjects(); NotificationUtils.dispatch(this, NotificationUtils.NOTIFY_SUCCESS, { - title: "Job launched", - message: `Job ${jobId} has been launched successfully`, + title: "Fetch File: Job launched", + message: `Job ${params.jobId} has been launched successfully`, }); LitUtils.dispatchCustomEvent(this, "fileFetch", data); })