Skip to content

Commit

Permalink
Merge branch 'TASK-7100' of github.com:opencb/jsorolla into TASK-7100
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjuanes committed Dec 17, 2024
2 parents a1820ef + 58217b9 commit 5b7fabc
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 6 deletions.
53 changes: 49 additions & 4 deletions src/webcomponents/file/file-data-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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`
<file-fetch
.path="${this.currentRoot.file.path}"
Expand Down Expand Up @@ -536,6 +564,16 @@ export default class FileDataManager extends LitElement {
UtilsNew.copyToClipboard(JSON.stringify(this.file, null, "\t"));
}

renderFileDelete() {
return html`
<file-delete
.opencgaSession="${this.opencgaSession}"
.fileId="${this.fileId}"
@closeNotification="${e => this.onCloseNotification(e)}">
</file-delete>
`;
}

addSearch(action, icon = "fa-search", placeholder = "Search ...", className = "", style = "") {
return html`
<div class="input-group ${className}" style="${style}">
Expand Down Expand Up @@ -734,6 +772,7 @@ export default class FileDataManager extends LitElement {
width: "20",
widthUnit: "%"
},
// CAUTION 20241217 Vero: Nacho,
{
title: "Format",
field: "format",
Expand All @@ -753,6 +792,12 @@ export default class FileDataManager extends LitElement {
`;
}
},
{
title: "Status",
field: "internal.status.id",
rowspan: 1,
colspan: 1,
},
{
title: "Tags",
field: "tags",
Expand Down
143 changes: 143 additions & 0 deletions src/webcomponents/file/file-delete.js
Original file line number Diff line number Diff line change
@@ -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`<loading-spinner></loading-spinner>`;
}
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 <b>${this._file.id}</b> 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);
4 changes: 2 additions & 2 deletions src/webcomponents/file/file-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})
Expand Down

0 comments on commit 5b7fabc

Please sign in to comment.