Skip to content

Commit a0064a3

Browse files
committed
internalId
1 parent 3eecd9b commit a0064a3

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
118118
__filesList: null,
119119
__loadingWorkspaces: null,
120120
__loadingFolders: null,
121-
__loadingFiles: null,
122121
__lastUrlParams: null,
123122

124123
// overridden
@@ -428,21 +427,23 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
428427
const filterData = this._searchBarFilter.getFilterData();
429428
const text = filterData.text ? encodeURIComponent(filterData.text) : "";
430429
const streamPromise = osparc.store.Data.getInstance().searchFiles(text);
431-
osparc.store.StreamTasks.getInstance().createStreamTask(streamPromise, 500)
430+
osparc.store.StreamTasks.getInstance().getStreamTask("files_search", text, streamPromise, 500)
432431
.then(stream => {
433432
// const stream = new osparc.data.StreamTask(streamData);
434433
stream.addListener("streamReceived", e => {
435434
const data = e.getData();
436435
if ("items" in data) {
437436
this.__setFilesToList(data["items"]);
438437
}
439-
if (stream.isEnd() === false) {
440-
setTimeout(() => stream.fetchStream(), 2000);
441-
}
442438
}, this);
443439
})
444440
.catch(err => console.log(err))
445-
.finally(() => this.__loadingFiles = null);
441+
.finally(() => {
442+
this._loadingResourcesBtn.setFetching(false);
443+
if (stream.isEnd() === false) {
444+
setTimeout(() => this.__reloadFiles(), 500);
445+
}
446+
});
446447
},
447448

448449
__resetStudiesList: function() {

services/static-webserver/client/source/class/osparc/store/StreamTasks.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ qx.Class.define("osparc.store.StreamTasks", {
2828
},
2929

3030
members: {
31-
createStreamTask: function(streamPromise, interval) {
31+
getStreamTask: function(action, params, streamPromise, interval) {
32+
const internalId = action + "_" + JSON.stringify(params);
33+
const task = this.__getStreamTask(internalId);
34+
if (task) {
35+
return Promise.resolve(task);
36+
}
37+
return this.__createStreamTask(internalId, streamPromise, interval);
38+
},
39+
40+
__createStreamTask: function(internalId, streamPromise, interval) {
3241
return new Promise((resolve, reject) => {
3342
streamPromise
3443
.then(streamData => {
3544
if ("status_href" in streamData) {
36-
const task = this.__addTask(streamData, interval);
45+
const task = this.__addStreamTask(internalId, streamData, interval);
3746
resolve(task);
3847
} else {
3948
throw Error("Status missing");
@@ -43,32 +52,33 @@ qx.Class.define("osparc.store.StreamTasks", {
4352
});
4453
},
4554

46-
__removeTask: function(task) {
55+
__getStreamTask: function(internalId) {
4756
const tasks = this.getTasks();
48-
const index = tasks.findIndex(t => t.getTaskId() === task.getTaskId());
49-
if (index > -1) {
50-
tasks.splice(index, 1);
57+
if (internalId in tasks) {
58+
return tasks[internalId];
5159
}
60+
return null;
5261
},
5362

54-
__addTask: function(streamData, interval) {
55-
const tasks = this.getTasks();
56-
if (streamData["task_id"] in tasks) {
57-
return tasks[streamData["task_id"]];
63+
__addStreamTask: function(internalId, streamData, interval) {
64+
const task = this.__getStreamTask(internalId);
65+
if (task) {
66+
return task;
5867
}
5968

6069
const stream = new osparc.data.StreamTask(streamData, interval);
61-
stream.addListener("resultReceived", () => this.__removeTask(stream), this);
62-
stream.addListener("taskAborted", () => this.__removeTask(stream), this);
63-
tasks[stream.getTaskId()] = stream;
70+
stream.addListener("resultReceived", () => this.__removeStreamTask(stream), this);
71+
stream.addListener("taskAborted", () => this.__removeStreamTask(stream), this);
72+
const tasks = this.getTasks();
73+
tasks[internalId] = stream;
6474
return stream;
6575
},
6676

67-
fetchStream: function(taskId) {
77+
__removeStreamTask: function(stream) {
6878
const tasks = this.getTasks();
69-
if (taskId in tasks) {
70-
const task = tasks[taskId];
71-
task.fetchStream();
79+
const index = tasks.findIndex(t => t.getTaskId() === stream.getTaskId());
80+
if (index > -1) {
81+
tasks.splice(index, 1);
7282
}
7383
},
7484
}

0 commit comments

Comments
 (0)