Skip to content

Commit cb0094b

Browse files
authored
Shared project concurrency (frontend) (#1591)
- Study cards show lock and tooltip when study is being used somewhere else - Optimized backend calls for getting Orgs and orgMembers
1 parent bb0788f commit cb0094b

File tree

10 files changed

+309
-95
lines changed

10 files changed

+309
-95
lines changed

services/web/client/source/class/osparc/component/export/Permissions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ qx.Class.define("osparc.component.export.Permissions", {
3333
construct: function(studyData) {
3434
this.base(arguments);
3535

36-
this.__studyData = osparc.utils.Utils.deepCloneObject(studyData);
36+
this.__studyData = osparc.data.model.Study.deepCloneStudyObject(studyData);
3737

3838
this._setLayout(new qx.ui.layout.VBox(15));
3939

services/web/client/source/class/osparc/component/export/SaveAsTemplate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ qx.Class.define("osparc.component.export.SaveAsTemplate", {
3434
this._setLayout(new qx.ui.layout.VBox(5));
3535

3636
this.__studyId = studyId;
37-
this.__formData = osparc.utils.Utils.deepCloneObject(studyData);
37+
this.__formData = osparc.data.model.Study.deepCloneStudyObject(studyData);
3838

3939
this.__buildLayout();
4040

services/web/client/source/class/osparc/dashboard/ExploreBrowser.js

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
130130
__initResources: function() {
131131
this.__showLoadingPage(this.tr("Discovering Templates and Apps"));
132132

133+
this.__templateStudies = [];
134+
this.__services = [];
133135
const servicesTags = this.__getTags();
134136
const store = osparc.store.Store.getInstance();
135137
const servicesPromise = store.getServicesDAGs(true);

services/web/client/source/class/osparc/dashboard/StudyBrowser.js

+41-39
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
9090
}
9191
},
9292

93-
__reloadUserStudy: function(studyId) {
94-
const params = {
95-
url: {
96-
projectId: studyId
97-
}
98-
};
99-
osparc.data.Resources.getOne("studies", params)
93+
__reloadUserStudy: function(studyId, reload) {
94+
osparc.store.Store.getInstance().getStudyWState(studyId, reload)
10095
.then(studyData => {
10196
this.__resetStudyItem(studyData);
10297
})
@@ -111,7 +106,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
111106
*/
112107
reloadUserStudies: function() {
113108
if (osparc.data.Permissions.getInstance().canDo("studies.user.read")) {
114-
osparc.data.Resources.get("studies")
109+
osparc.store.Store.getInstance().getStudiesWState()
115110
.then(studies => {
116111
this.__resetStudyList(studies);
117112
this.resetSelection();
@@ -127,14 +122,15 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
127122
__initResources: function() {
128123
this.__showLoadingPage(this.tr("Loading Studies"));
129124

130-
const servicesTags = this.__getTags();
125+
this.__userStudies = [];
126+
const resourcePromises = [];
131127
const store = osparc.store.Store.getInstance();
132-
const servicesPromise = store.getServicesDAGs(true);
133-
134-
Promise.all([
135-
servicesTags,
136-
servicesPromise
137-
])
128+
resourcePromises.push(store.getVisibleMembers());
129+
resourcePromises.push(store.getServicesDAGs(true));
130+
if (osparc.data.Permissions.getInstance().canDo("study.tag")) {
131+
resourcePromises.push(osparc.data.Resources.get("tags"));
132+
}
133+
Promise.all(resourcePromises)
138134
.then(() => {
139135
this.__hideLoadingPage();
140136
this.__createStudiesLayout();
@@ -144,7 +140,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
144140
if (loadStudyId) {
145141
this.__getStudyAndStart(loadStudyId);
146142
}
147-
});
143+
})
144+
.catch(console.error);
148145
},
149146

150147
__reloadResources: function() {
@@ -171,18 +168,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
171168
});
172169
},
173170

174-
__getTags: function() {
175-
return new Promise((resolve, reject) => {
176-
if (osparc.data.Permissions.getInstance().canDo("study.tag")) {
177-
osparc.data.Resources.get("tags")
178-
.catch(console.error)
179-
.finally(() => resolve());
180-
} else {
181-
resolve();
182-
}
183-
});
184-
},
185-
186171
__createStudiesLayout: function() {
187172
const studyFilters = this.__studyFilters = new osparc.component.filter.group.StudyFilterGroup("studyBrowser").set({
188173
paddingTop: 5
@@ -244,12 +229,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
244229
},
245230

246231
__getStudyAndStart: function(loadStudyId) {
247-
const params = {
248-
url: {
249-
projectId: loadStudyId
250-
}
251-
};
252-
osparc.data.Resources.getOne("studies", params)
232+
osparc.store.Store.getStudyWState(loadStudyId, true)
253233
.then(studyData => {
254234
this.__startStudy(studyData);
255235
})
@@ -282,6 +262,23 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
282262
},
283263

284264
__attachEventHandlers: function() {
265+
// Listen to socket
266+
const socket = osparc.wrapper.WebSocket.getInstance();
267+
// callback for incoming logs
268+
const slotName = "projectStateUpdated";
269+
socket.removeSlot(slotName);
270+
socket.on(slotName, function(jsonString) {
271+
const data = JSON.parse(jsonString);
272+
if (data) {
273+
const studyId = data["project_uuid"];
274+
const state = ("data" in data) ? data["data"] : {};
275+
const studyItem = this.__userStudyContainer.getChildren().find(card => (card instanceof osparc.dashboard.StudyBrowserButtonItem) && (card.getUuid() === studyId));
276+
if (studyItem) {
277+
studyItem.setState(state);
278+
}
279+
}
280+
}, this);
281+
285282
const textfield = this.__studyFilters.getTextFilter().getChildControl("textfield");
286283
textfield.addListener("appear", () => {
287284
textfield.focus();
@@ -347,10 +344,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
347344
__resetStudyItem: function(studyData) {
348345
const userStudyList = this.__userStudies;
349346
const index = userStudyList.findIndex(userStudy => userStudy["uuid"] === studyData["uuid"]);
350-
if (index !== -1) {
351-
this.__userStudies[index] = studyData;
352-
this.__resetStudyList(userStudyList);
347+
if (index === -1) {
348+
userStudyList.push(studyData);
349+
} else {
350+
userStudyList[index] = studyData;
353351
}
352+
this.__resetStudyList(userStudyList);
354353
},
355354

356355
__resetStudyList: function(userStudyList) {
@@ -400,13 +399,16 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
400399
accessRights: study.accessRights ? study.accessRights : null,
401400
lastChangeDate: study.lastChangeDate ? new Date(study.lastChangeDate) : null,
402401
icon: study.thumbnail || defaultThumbnail,
402+
state: study.state ? study.state : {},
403403
tags
404404
});
405405
const menu = this.__getStudyItemMenu(item, study);
406406
item.setMenu(menu);
407407
item.subscribeToFilterGroup("studyBrowser");
408408
item.addListener("execute", () => {
409-
this.__itemClicked(item);
409+
if (!item.isLocked()) {
410+
this.__itemClicked(item);
411+
}
410412
}, this);
411413

412414
return item;
@@ -469,7 +471,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
469471
const permissionsView = new osparc.component.export.Permissions(studyData);
470472
permissionsView.addListener("updateStudy", e => {
471473
const studyId = e.getData();
472-
this.__reloadUserStudy(studyId);
474+
this.__reloadUserStudy(studyId, true);
473475
}, this);
474476
const window = permissionsView.createWindow();
475477
permissionsView.addListener("finished", e => {

0 commit comments

Comments
 (0)