Skip to content

Commit b2d2be4

Browse files
committed
__reloadFiles
1 parent a0064a3 commit b2d2be4

File tree

3 files changed

+54
-48
lines changed

3 files changed

+54
-48
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,33 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
427427
const filterData = this._searchBarFilter.getFilterData();
428428
const text = filterData.text ? encodeURIComponent(filterData.text) : "";
429429
const streamPromise = osparc.store.Data.getInstance().searchFiles(text);
430-
osparc.store.StreamTasks.getInstance().getStreamTask("files_search", text, streamPromise, 500)
431-
.then(stream => {
432-
// const stream = new osparc.data.StreamTask(streamData);
433-
stream.addListener("streamReceived", e => {
434-
const data = e.getData();
435-
if ("items" in data) {
436-
this.__setFilesToList(data["items"]);
437-
}
438-
}, this);
430+
let stream = null;
431+
const pollingInterval = 2000;
432+
osparc.store.StreamTasks.getInstance().getStreamTask("files_search", text, streamPromise, pollingInterval)
433+
.then(strm => {
434+
stream = strm;
435+
console.log("Streaming files search...", stream);
436+
return stream.fetchStream()
437+
})
438+
.then(streamData => {
439+
const items = streamData["data"]["items"] || [];
440+
if (items.length) {
441+
this.__setFilesToList(items);
442+
}
443+
const end = streamData["data"]["end"] || false;
444+
if (end === false && items.length === 0 && stream) {
445+
// nothing to stream yet, try again later
446+
setTimeout(() => this.__reloadFiles(), pollingInterval);
447+
}
439448
})
440449
.catch(err => console.log(err))
441450
.finally(() => {
442451
this._loadingResourcesBtn.setFetching(false);
443-
if (stream.isEnd() === false) {
452+
/*
453+
if (stream && stream.isEnd() === false) {
444454
setTimeout(() => this.__reloadFiles(), 500);
445455
}
456+
*/
446457
});
447458
},
448459

services/static-webserver/client/source/class/osparc/data/StreamTask.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,44 +61,39 @@ qx.Class.define("osparc.data.StreamTask", {
6161
},
6262

6363
fetchStream: function() {
64-
if (!this.isEnd()) {
65-
const streamPath = osparc.data.PollTask.extractPathname(this.getStreamHref());
66-
const url = `${streamPath}?limit=${this.getPageSize()}`;
67-
fetch(url)
68-
.then(resp => {
69-
if (resp.status === 200) {
70-
return resp.json();
71-
}
72-
const errMsg = qx.locale.Manager.tr("Unsuccessful streaming");
73-
const err = new Error(errMsg);
74-
this.fireDataEvent("pollingError", err);
75-
throw err;
76-
})
77-
.then(streamData => {
78-
if ("error" in streamData && streamData["error"]) {
79-
throw streamData["error"];
80-
}
81-
if ("data" in streamData && streamData["data"]) {
82-
const items = streamData["data"]["items"] || [];
83-
const end = streamData["data"]["end"] || false;
84-
if (items.length === 0 && end === false) {
85-
// nothing to stream yet, try again later
86-
setTimeout(() => this.fetchStream(), this.getPollInterval());
87-
return;
64+
return new Promise((resolve, reject) => {
65+
if (!this.isEnd()) {
66+
const streamPath = osparc.data.PollTask.extractPathname(this.getStreamHref());
67+
const url = `${streamPath}?limit=${this.getPageSize()}`;
68+
fetch(url)
69+
.then(resp => {
70+
if (resp.status === 200) {
71+
return resp.json();
72+
}
73+
const errMsg = qx.locale.Manager.tr("Unsuccessful streaming");
74+
const err = new Error(errMsg);
75+
this.fireDataEvent("pollingError", err);
76+
throw err;
77+
})
78+
.then(streamData => {
79+
if ("error" in streamData && streamData["error"]) {
80+
throw streamData["error"];
8881
}
89-
this.fireDataEvent("streamReceived", items);
82+
const end = streamData["data"]["end"] || false;
9083
if (end) {
9184
this.setEnd(true);
9285
}
93-
return;
94-
}
95-
throw new Error("Missing stream data");
96-
})
97-
.catch(err => {
98-
this.fireDataEvent("pollingError", err);
99-
throw err;
100-
});
101-
}
86+
if ("data" in streamData && streamData["data"]) {
87+
resolve(streamData);
88+
}
89+
throw new Error("Missing stream data");
90+
})
91+
.catch(err => {
92+
this.fireDataEvent("pollingError", err);
93+
reject(err);
94+
});
95+
}
96+
});
10297
},
10398
}
10499
});

services/static-webserver/client/source/class/osparc/data/model/File.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ qx.Class.define("osparc.data.model.File", {
3333
projectId: fileData.projectId || null,
3434
createdAt: new Date(fileData.createdAt),
3535
modifiedAt: new Date(fileData.modifiedAt),
36-
size: fileData.size,
37-
path: fileData.path || null,
36+
size: fileData.size || null,
37+
path: fileData.path,
3838
isDirectory: fileData.isDirectory || false,
3939
});
4040
},
@@ -49,7 +49,7 @@ qx.Class.define("osparc.data.model.File", {
4949

5050
projectId: {
5151
check: "String",
52-
nullable: null,
52+
nullable: true,
5353
init: null,
5454
event: "changeProjectId"
5555
},
@@ -77,7 +77,7 @@ qx.Class.define("osparc.data.model.File", {
7777

7878
path: {
7979
check: "String",
80-
nullable: true,
80+
nullable: false,
8181
init: null,
8282
event: "changePath"
8383
},

0 commit comments

Comments
 (0)