Skip to content

Commit c6dcd3b

Browse files
committed
[skip ci] refactor
1 parent 0c22a60 commit c6dcd3b

File tree

1 file changed

+50
-30
lines changed

1 file changed

+50
-30
lines changed

services/static-webserver/client/source/class/osparc/file/FileLabelWithActions.js

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
4545
this.getChildControl("selected-label");
4646

4747
const downloadBtn = this.getChildControl("download-button");
48-
downloadBtn.addListener("execute", () => this.__retrieveURLAndDownload(), this);
48+
downloadBtn.addListener("execute", () => this.__retrieveURLAndDownloadSelected(), this);
4949

5050
const deleteBtn = this.getChildControl("delete-button");
51-
deleteBtn.addListener("execute", () => this.__deleteFile(), this);
51+
deleteBtn.addListener("execute", () => this.__deleteSelected(), this);
5252
},
5353

5454
events: {
@@ -129,11 +129,24 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
129129
},
130130

131131
setMultiItemSelected: function(multiSelectionData) {
132-
console.log("multiSelectionData", multiSelectionData);
132+
this.__multiSelection = multiSelectionData;
133+
if (multiSelectionData && multiSelectionData.length) {
134+
if (multiSelectionData.length === 1) {
135+
this.setItemSelected(multiSelectionData[0].entry);
136+
} else {
137+
const selectedLabel = this.getChildControl("selected-label");
138+
selectedLabel.set({
139+
value: multiSelectionData.length + " files"
140+
});
141+
}
142+
} else {
143+
this.resetItemSelected();
144+
}
133145
},
134146

135147
resetItemSelected: function() {
136148
this.__selection = null;
149+
this.__multiSelection = [];
137150
this.getChildControl("download-button").setEnabled(false);
138151
this.getChildControl("delete-button").setEnabled(false);
139152
this.getChildControl("selected-label").resetValue();
@@ -147,40 +160,47 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
147160
return null;
148161
},
149162

150-
// Request to the server and download
151-
__retrieveURLAndDownload: function() {
163+
__retrieveURLAndDownloadSelected: function() {
152164
let selection = this.getItemSelected();
153165
if (selection) {
154-
const fileId = selection.getFileId();
155-
const locationId = selection.getLocation();
156-
osparc.utils.Utils.retrieveURLAndDownload(locationId, fileId)
157-
.then(data => {
158-
if (data) {
159-
osparc.DownloadLinkTracker.getInstance().downloadLinkUnattended(data.link, data.fileName);
160-
}
161-
});
166+
this.__retrieveURLAndDownloadFile(selection);
162167
}
163168
},
164169

165-
__deleteFile: function() {
166-
let selection = this.getItemSelected();
170+
__deleteSelected: function() {
171+
const selection = this.getItemSelected();
167172
if (selection) {
168-
console.log("Delete ", selection);
169-
const fileId = selection.getFileId();
170-
const locationId = selection.getLocation();
171-
if (locationId !== 0 && locationId !== "0") {
172-
osparc.FlashMessenger.getInstance().logAs(this.tr("Only files in simcore.s3 can be deleted"));
173-
return false;
174-
}
175-
const dataStore = osparc.store.Data.getInstance();
176-
dataStore.addListenerOnce("deleteFile", e => {
177-
if (e) {
178-
this.fireDataEvent("fileDeleted", e.getData());
179-
}
180-
}, this);
181-
return dataStore.deleteFile(locationId, fileId);
173+
return this.__deleteFile(selection);
182174
}
183175
return false;
184-
}
176+
},
177+
178+
__retrieveURLAndDownloadFile: function(file) {
179+
const fileId = file.getFileId();
180+
const locationId = file.getLocation();
181+
osparc.utils.Utils.retrieveURLAndDownload(locationId, fileId)
182+
.then(data => {
183+
if (data) {
184+
osparc.DownloadLinkTracker.getInstance().downloadLinkUnattended(data.link, data.fileName);
185+
}
186+
});
187+
},
188+
189+
__deleteFile: function(file) {
190+
console.log("Delete ", file);
191+
const fileId = file.getFileId();
192+
const locationId = file.getLocation();
193+
if (locationId !== 0 && locationId !== "0") {
194+
osparc.FlashMessenger.getInstance().logAs(this.tr("Only files in simcore.s3 can be deleted"));
195+
return false;
196+
}
197+
const dataStore = osparc.store.Data.getInstance();
198+
dataStore.addListenerOnce("deleteFile", e => {
199+
if (e) {
200+
this.fireDataEvent("fileDeleted", e.getData());
201+
}
202+
}, this);
203+
return dataStore.deleteFile(locationId, fileId);
204+
},
185205
}
186206
});

0 commit comments

Comments
 (0)