Skip to content

Commit 8670901

Browse files
authored
Large study card supports Study Model (#2127)
* Large refactored to support Study Model * Import: display webserver's error message * Export: display webserver's error message
1 parent 81ff349 commit 8670901

File tree

18 files changed

+372
-245
lines changed

18 files changed

+372
-245
lines changed

services/web/client/source/class/osparc/component/form/tag/TagManager.js

Lines changed: 102 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Copyright: 2020 IT'IS Foundation - https://itis.swiss
44
* License: MIT - https://opensource.org/licenses/MIT
55
* Authors: Ignacio Pascual (ignapas)
6+
* Odei Maiz (odeimaiz)
67
*/
78

89
/**
910
* Tag manager server to manage one resource's related tags.
1011
*/
1112
qx.Class.define("osparc.component.form.tag.TagManager", {
1213
extend: osparc.ui.window.SingletonWindow,
13-
construct: function(selectedTags, attachment, resourceName, resourceId) {
14+
construct: function(studyData, attachment, resourceName, resourceId) {
1415
this.base(arguments, "tagManager", this.tr("Apply Tags"));
1516
this.set({
1617
layout: new qx.ui.layout.VBox(),
@@ -28,25 +29,33 @@ qx.Class.define("osparc.component.form.tag.TagManager", {
2829
this.__attachment = attachment;
2930
this.__resourceName = resourceName;
3031
this.__resourceId = resourceId;
31-
this.__selectedTags = new qx.data.Array(selectedTags);
32+
this.__studyData = studyData;
33+
this.__selectedTags = new qx.data.Array(studyData["tags"]);
3234
this.__renderLayout();
3335
this.__attachEventHandlers();
3436
this.open();
3537
},
38+
3639
events: {
40+
"updateTags": "qx.event.type.Data",
3741
"changeSelected": "qx.event.type.Data"
3842
},
43+
3944
properties: {
4045
liveUpdate: {
4146
check: "Boolean",
47+
event: "changeLiveUpdate",
4248
init: true
4349
}
4450
},
51+
4552
members: {
53+
__studyData: null,
4654
__attachment: null,
4755
__resourceName: null,
4856
__resourceId: null,
4957
__selectedTags: null,
58+
5059
__renderLayout: function() {
5160
const filterBar = new qx.ui.toolbar.ToolBar();
5261
const filter = new osparc.component.filter.TextFilter("name", "studyBrowserTagManager").set({
@@ -57,6 +66,7 @@ qx.Class.define("osparc.component.form.tag.TagManager", {
5766
width: "100%"
5867
});
5968
this.add(filterBar);
69+
6070
const buttonContainer = new qx.ui.container.Composite(new qx.ui.layout.VBox());
6171
this.add(buttonContainer, {
6272
flex: 1
@@ -72,7 +82,22 @@ qx.Class.define("osparc.component.form.tag.TagManager", {
7282
textAlign: "center"
7383
}));
7484
}
85+
86+
const buttons = new qx.ui.container.Composite(new qx.ui.layout.HBox().set({
87+
alignX: "right"
88+
}));
89+
const saveButton = new osparc.ui.form.FetchButton(this.tr("Save"));
90+
osparc.utils.Utils.setIdToWidget(saveButton, "saveTagsBtn");
91+
saveButton.addListener("execute", e => {
92+
this.__save(saveButton);
93+
}, this);
94+
buttons.add(saveButton);
95+
this.bind("liveUpdate", buttons, "visibility", {
96+
converter: value => value ? "excluded" : "visible"
97+
});
98+
this.add(buttons);
7599
},
100+
76101
/**
77102
* If the attachment (element close to which the TagManager is being rendered) is already on the DOM,
78103
* this function calculates where the TagManager should render, taking into account the window edges.
@@ -98,44 +123,94 @@ qx.Class.define("osparc.component.form.tag.TagManager", {
98123
this.center();
99124
}
100125
},
126+
101127
__tagButton: function(tag) {
102-
const button = new osparc.component.form.tag.TagToggleButton(tag, this.__selectedTags.includes(tag.id));
103-
button.addListener("changeValue", evt => {
128+
const tagButton = new osparc.component.form.tag.TagToggleButton(tag, this.__selectedTags.includes(tag.id));
129+
tagButton.addListener("changeValue", evt => {
104130
const selected = evt.getData();
105131
if (this.isLiveUpdate()) {
106-
button.setFetching(true);
107-
const params = {
108-
url: {
109-
tagId: tag.id,
110-
studyUuid: this.__resourceId
111-
}
112-
};
132+
tagButton.setFetching(true);
113133
if (selected) {
114-
osparc.data.Resources.fetch("studies", "addTag", params)
115-
.then(() => this.__selectedTags.push(tag.id))
116-
.catch(err => {
117-
console.error(err);
118-
button.setValue(false);
119-
})
120-
.finally(() => button.setFetching(false));
134+
this.__saveAddTag(tag.id, tagButton);
121135
} else {
122-
osparc.data.Resources.fetch("studies", "removeTag", params)
123-
.then(() => this.__selectedTags.remove(tag.id))
124-
.catch(err => {
125-
console.error(err);
126-
button.setValue(true);
127-
})
128-
.finally(() => button.setFetching(false));
136+
this.__saveRemoveTag(tag.id, tagButton);
129137
}
130138
} else if (selected) {
131139
this.__selectedTags.push(tag.id);
132140
} else {
133141
this.__selectedTags.remove(tag.id);
134142
}
135143
}, this);
136-
button.subscribeToFilterGroup("studyBrowserTagManager");
137-
return button;
144+
tagButton.subscribeToFilterGroup("studyBrowserTagManager");
145+
return tagButton;
146+
},
147+
148+
__getAddTagPromise: function(tagId) {
149+
const params = {
150+
url: {
151+
tagId,
152+
studyUuid: this.__resourceId
153+
}
154+
};
155+
return osparc.data.Resources.fetch("studies", "addTag", params);
156+
},
157+
158+
__getRemoveTagPromise: function(tagId) {
159+
const params = {
160+
url: {
161+
tagId,
162+
studyUuid: this.__resourceId
163+
}
164+
};
165+
return osparc.data.Resources.fetch("studies", "removeTag", params);
166+
},
167+
168+
__saveAddTag: function(tagId, tagButton) {
169+
this.__getAddTagPromise(tagId)
170+
.then(() => this.__selectedTags.push(tagId))
171+
.catch(err => {
172+
console.error(err);
173+
tagButton.setValue(false);
174+
})
175+
.finally(() => tagButton.setFetching(false));
176+
},
177+
178+
__saveRemoveTag: function(tagId, tagButton) {
179+
this.__getRemoveTagPromise(tagId)
180+
.then(() => this.__selectedTags.remove(tagId))
181+
.catch(err => {
182+
console.error(err);
183+
tagButton.setValue(true);
184+
})
185+
.finally(() => tagButton.setFetching(false));
138186
},
187+
188+
__save: async function(saveButton) {
189+
saveButton.setFetching(true);
190+
191+
// call them sequentially
192+
let updatedStudy = null;
193+
for (let i=0; i<this.__selectedTags.length; i++) {
194+
const tagId = this.__selectedTags.getItem(i);
195+
if (!this.__studyData["tags"].includes(tagId)) {
196+
updatedStudy = await this.__getAddTagPromise(tagId)
197+
.then(updatedData => updatedData);
198+
}
199+
}
200+
for (let i=0; i<this.__studyData["tags"].length; i++) {
201+
const tagId = this.__studyData["tags"][i];
202+
if (!this.__selectedTags.includes(tagId)) {
203+
updatedStudy = await this.__getRemoveTagPromise(tagId)
204+
.then(updatedData => updatedData);
205+
}
206+
}
207+
208+
saveButton.setFetching(false);
209+
if (updatedStudy) {
210+
this.fireDataEvent("updateTags", updatedStudy);
211+
}
212+
},
213+
139214
__attachEventHandlers: function() {
140215
this.addListener("appear", () => {
141216
this.__updatePosition();

services/web/client/source/class/osparc/component/metadata/ClassifiersEditor.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ qx.Class.define("osparc.component.metadata.ClassifiersEditor", {
3333
},
3434

3535
events: {
36-
"updateResourceClassifiers": "qx.event.type.Data"
36+
"updateClassifiers": "qx.event.type.Data"
3737
},
3838

3939
members: {
@@ -153,10 +153,10 @@ qx.Class.define("osparc.component.metadata.ClassifiersEditor", {
153153
data: this.__studyData
154154
};
155155
osparc.data.Resources.fetch("studies", "put", params)
156-
.then(() => {
157-
this.fireDataEvent("updateResourceClassifiers", this.__studyData["uuid"]);
156+
.then(updatedStudy => {
158157
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Classifiers successfully edited"));
159158
saveBtn.setFetching(false);
159+
this.fireDataEvent("updateClassifiers", updatedStudy);
160160
})
161161
.catch(err => {
162162
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Something went wrong editing Classifiers"), "ERROR");
@@ -173,10 +173,10 @@ qx.Class.define("osparc.component.metadata.ClassifiersEditor", {
173173
}
174174
};
175175
osparc.data.Resources.fetch("services", "patch", params)
176-
.then(() => {
177-
this.fireDataEvent("updateResourceClassifiers", this.__studyData["key"]);
176+
.then(updatedService => {
178177
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Classifiers successfully edited"));
179178
saveBtn.setFetching(false);
179+
this.fireDataEvent("updateClassifiers", updatedService);
180180
})
181181
.catch(err => {
182182
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Something went wrong editing Classifiers"), "ERROR");

services/web/client/source/class/osparc/component/metadata/QualityEditor.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ qx.Class.define("osparc.component.metadata.QualityEditor", {
3737
},
3838

3939
events: {
40-
"updateStudy": "qx.event.type.Data",
41-
"updateTemplate": "qx.event.type.Data",
42-
"updateService": "qx.event.type.Data"
40+
"updateQuality": "qx.event.type.Data"
4341
},
4442

4543
properties: {
@@ -587,7 +585,7 @@ qx.Class.define("osparc.component.metadata.QualityEditor", {
587585
osparc.data.Resources.fetch("services", "patch", params)
588586
.then(serviceData => {
589587
this.__initResourceData(serviceData);
590-
this.fireDataEvent("updateService", serviceData);
588+
this.fireDataEvent("updateQuality", serviceData);
591589
})
592590
.catch(err => {
593591
console.error(err);
@@ -607,7 +605,7 @@ qx.Class.define("osparc.component.metadata.QualityEditor", {
607605
osparc.data.Resources.fetch(isTemplate ? "templates" : "studies", "put", params)
608606
.then(resourceData => {
609607
this.__initResourceData(resourceData);
610-
this.fireDataEvent(isTemplate ? "updateTemplate" : "updateStudy", resourceData);
608+
this.fireDataEvent("updateQuality", resourceData);
611609
})
612610
.catch(err => {
613611
console.error(err);

services/web/client/source/class/osparc/component/permissions/Study.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ qx.Class.define("osparc.component.permissions.Study", {
3737
},
3838

3939
events: {
40-
"updateStudy": "qx.event.type.Data"
40+
"updateAccessRights": "qx.event.type.Data"
4141
},
4242

4343
statics: {
@@ -112,8 +112,8 @@ qx.Class.define("osparc.component.permissions.Study", {
112112
data: this.__studyData
113113
};
114114
osparc.data.Resources.fetch("studies", "put", params)
115-
.then(() => {
116-
this.fireDataEvent("updateStudy", this.__studyData["uuid"]);
115+
.then(updatedData => {
116+
this.fireDataEvent("updateAccessRights", updatedData);
117117
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Collaborator(s) successfully added"));
118118
this.__reloadOrganizationsAndMembers();
119119
this.__reloadCollaboratorsList();
@@ -137,8 +137,8 @@ qx.Class.define("osparc.component.permissions.Study", {
137137
data: this.__studyData
138138
};
139139
osparc.data.Resources.fetch("studies", "put", params)
140-
.then(() => {
141-
this.fireDataEvent("updateStudy", this.__studyData["uuid"]);
140+
.then(updatedData => {
141+
this.fireDataEvent("updateAccessRights", updatedData);
142142
osparc.component.message.FlashMessenger.getInstance().logAs(this.tr("Collaborator successfully removed"));
143143
this.__reloadOrganizationsAndMembers();
144144
this.__reloadCollaboratorsList();
@@ -158,8 +158,8 @@ qx.Class.define("osparc.component.permissions.Study", {
158158
data: this.__studyData
159159
};
160160
osparc.data.Resources.fetch("studies", "put", params)
161-
.then(() => {
162-
this.fireDataEvent("updateStudy", this.__studyData["uuid"]);
161+
.then(updatedData => {
162+
this.fireDataEvent("updateAccessRights", updatedData);
163163
osparc.component.message.FlashMessenger.getInstance().logAs(successMsg);
164164
this.__reloadOrganizationsAndMembers();
165165
this.__reloadCollaboratorsList();

services/web/client/source/class/osparc/component/widget/NodesTree.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,7 @@ qx.Class.define("osparc.component.widget.NodesTree", {
316316
const params = {
317317
name: newLabel
318318
};
319-
study.updateStudy(params)
320-
.then(data => {
321-
selectedItem.setLabel(data.name);
322-
});
319+
study.updateStudy(params);
323320
} else if (osparc.data.Permissions.getInstance().canDo("study.node.rename", true)) {
324321
selectedItem.setLabel(newLabel);
325322
const node = study.getWorkbench().getNode(nodeId);

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,9 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
586586

587587
__openTemplatePermissions: function(studyData) {
588588
const permissionsView = osparc.studycard.Utils.openAccessRights(studyData);
589-
permissionsView.addListener("updateStudy", e => {
590-
const studyId = e.getData();
591-
console.log(studyId);
592-
this.reloadTemplates();
589+
permissionsView.addListener("updateAccessRights", e => {
590+
const updatedData = e.getData();
591+
this._resetTemplateItem(updatedData);
593592
});
594593
},
595594

@@ -598,20 +597,20 @@ qx.Class.define("osparc.dashboard.ExploreBrowser", {
598597
let classifiers = null;
599598
if (osparc.data.model.Study.isOwner(studyData)) {
600599
classifiers = new osparc.component.metadata.ClassifiersEditor(studyData);
601-
osparc.ui.window.Window.popUpInWindow(classifiers, title, 400, 400);
602-
classifiers.addListener("updateResourceClassifiers", e => {
600+
const win = osparc.ui.window.Window.popUpInWindow(classifiers, title, 400, 400);
601+
classifiers.addListener("updateClassifiers", e => {
602+
win.close();
603+
const updatedResource = e.getData();
603604
if (osparc.utils.Resources.isTemplate(studyData)) {
604-
const studyId = e.getData();
605-
this._reloadTemplate(studyId);
605+
this._resetTemplateItem(updatedResource);
606606
} else if (osparc.utils.Resources.isService(studyData)) {
607-
const serviceKey = e.getData();
608-
this.__reloadService(serviceKey, studyData.version);
607+
this._resetServiceItem(updatedResource);
609608
}
610609
}, this);
611610
} else {
612611
classifiers = new osparc.component.metadata.ClassifiersViewer(studyData);
612+
osparc.ui.window.Window.popUpInWindow(classifiers, title, 400, 400);
613613
}
614-
osparc.ui.window.Window.popUpInWindow(classifiers, title, 400, 400);
615614
},
616615

617616
__deleteTemplate: function(studyData) {

0 commit comments

Comments
 (0)