Skip to content

Commit 6c236d4

Browse files
odeimaizmrnicegyu11
authored andcommitted
🎨 [Frontend] UX: Reuse Add collaborators widget in Publish template (ITISFoundation#6058)
1 parent 2aecc2e commit 6c236d4

File tree

11 files changed

+183
-245
lines changed

11 files changed

+183
-245
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,9 @@ qx.Class.define("osparc.dashboard.CardBase", {
791791

792792
// groups -> [orgMembs, orgs, [productEveryone], [everyone]];
793793
__setIconAndTooltip: function(shareIcon, accessRights, groups) {
794+
shareIcon.setSource(osparc.dashboard.CardBase.SHARE_ICON);
794795
if (osparc.data.model.Study.canIWrite(accessRights)) {
795796
shareIcon.set({
796-
source: osparc.dashboard.CardBase.SHARE_ICON,
797797
toolTipText: this.tr("Share")
798798
});
799799
}
@@ -808,7 +808,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
808808
const gids = Object.keys(accessRights);
809809
for (let j=0; j<gids.length; j++) {
810810
const gid = parseInt(gids[j]);
811-
if (this.isResourceType("study") && (gid === myGroupId)) {
811+
if (gid === myGroupId) {
812812
continue;
813813
}
814814
const grp = groups[i].find(group => group["gid"] === gid);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
310310
this.__itemClicked(card, e.getNativeEvent().shiftKey);
311311
}
312312
}, this);
313-
card.addListener("publishTemplate", e => this.fireDataEvent("publishTemplate", e.getData()));
314313
this._populateCardMenu(card);
315314
});
316315
},

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ qx.Class.define("osparc.data.Roles", {
159159
text += "<br>";
160160
}
161161
});
162-
const infoHint = new osparc.ui.hint.InfoHint(text);
162+
const infoHint = new osparc.ui.hint.InfoHint(text).set({
163+
alignY: "middle"
164+
});
163165
rolesLayout.add(infoHint);
164166
return rolesLayout;
165167
},

‎services/static-webserver/client/source/class/osparc/filter/Organizations.js

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
/**
19+
* Widget that offers the "Share with..." button to add collaborators to a resource.
20+
* It also provides the "Check Organization..." direct access.
21+
* As output, once the user select n gid in the NewCollaboratorsManager pop up window,
22+
* an event is fired with the list of collaborators.
23+
*/
24+
25+
qx.Class.define("osparc.share.AddCollaborators", {
26+
extend: qx.ui.core.Widget,
27+
28+
/**
29+
* @param serializedDataCopy {Object} Object containing the Serialized Data
30+
*/
31+
construct: function(serializedDataCopy) {
32+
this.base(arguments);
33+
34+
this.setSerializedDataCopy(serializedDataCopy);
35+
36+
this._setLayout(new qx.ui.layout.VBox(5));
37+
38+
this.__buildLayout();
39+
},
40+
41+
events: {
42+
"addCollaborators": "qx.event.type.Data"
43+
},
44+
45+
members: {
46+
__serializedDataCopy: null,
47+
48+
_createChildControlImpl: function(id) {
49+
let control;
50+
switch (id) {
51+
case "intro-text":
52+
control = new qx.ui.basic.Label(this.tr("Select from the list below and click Share"));
53+
this._add(control);
54+
break;
55+
case "share-with":
56+
control = new qx.ui.form.Button(this.tr("Share with...")).set({
57+
appearance: "form-button",
58+
alignX: "left",
59+
allowGrowX: false
60+
});
61+
this._add(control);
62+
break;
63+
case "check-organizations":
64+
control = new qx.ui.form.Button(this.tr("Check Organizations...")).set({
65+
appearance: "form-button-outlined",
66+
allowGrowY: false,
67+
allowGrowX: false,
68+
icon: osparc.dashboard.CardBase.SHARED_ORGS
69+
});
70+
this._add(control);
71+
}
72+
return control || this.base(arguments, id);
73+
},
74+
75+
setSerializedDataCopy: function(serializedDataCopy) {
76+
this.__serializedDataCopy = serializedDataCopy;
77+
},
78+
79+
__buildLayout: function() {
80+
this.getChildControl("intro-text");
81+
82+
const addCollaboratorBtn = this.getChildControl("share-with");
83+
addCollaboratorBtn.addListener("execute", () => {
84+
const collaboratorsManager = new osparc.share.NewCollaboratorsManager(this.__serializedDataCopy);
85+
collaboratorsManager.addListener("addCollaborators", e => {
86+
collaboratorsManager.close();
87+
this.fireDataEvent("addCollaborators", e.getData());
88+
}, this);
89+
}, this);
90+
91+
const organizations = this.getChildControl("check-organizations");
92+
organizations.addListener("execute", () => osparc.desktop.organizations.OrganizationsWindow.openWindow(), this);
93+
}
94+
}
95+
});

‎services/static-webserver/client/source/class/osparc/share/Collaborators.js

Lines changed: 29 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ qx.Class.define("osparc.share.Collaborators", {
2727

2828
this._serializedDataCopy = serializedDataCopy;
2929

30-
this._setLayout(new qx.ui.layout.VBox(10));
30+
this._setLayout(new qx.ui.layout.VBox(15));
3131

3232
this.set({
3333
padding: 5
@@ -163,18 +163,6 @@ qx.Class.define("osparc.share.Collaborators", {
163163
control = this.__createAddCollaboratorSection();
164164
this._add(control);
165165
break;
166-
case "open-organizations-btn":
167-
control = new qx.ui.form.Button(this.tr("Organizations...")).set({
168-
appearance: "form-button-outlined",
169-
allowGrowY: false,
170-
allowGrowX: false,
171-
icon: osparc.dashboard.CardBase.SHARED_ORGS
172-
});
173-
control.addListener("execute", () => osparc.desktop.organizations.OrganizationsWindow.openWindow(), this);
174-
this._add(control, {
175-
flex: 1
176-
});
177-
break;
178166
case "collaborators-list":
179167
control = this.__createCollaboratorsListSection();
180168
this._add(control, {
@@ -197,56 +185,52 @@ qx.Class.define("osparc.share.Collaborators", {
197185
return control || this.base(arguments, id);
198186
},
199187

188+
__amIOwner: function() {
189+
let fullOptions = false;
190+
if (this._resourceType === "service") {
191+
// service
192+
fullOptions = osparc.service.Utils.canIWrite(this._serializedDataCopy["accessRights"]);
193+
} else {
194+
// study or template
195+
fullOptions = osparc.data.model.Study.canIDelete(this._serializedDataCopy["accessRights"]);
196+
}
197+
return fullOptions;
198+
},
199+
200200
__buildLayout: function() {
201-
this._createChildControlImpl("add-collaborator");
201+
if (this.__amIOwner()) {
202+
this._createChildControlImpl("add-collaborator");
203+
}
202204
this._createChildControlImpl("open-organizations-btn");
203205
this._createChildControlImpl("collaborators-list");
204206
this._createChildControlImpl("study-link");
205207
this._createChildControlImpl("template-link");
206208
},
207209

208210
__createAddCollaboratorSection: function() {
209-
const vBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
210-
if (this._resourceType === "service") {
211-
// service
212-
vBox.setVisibility(this._canIWrite() ? "visible" : "excluded");
213-
} else {
214-
// study or template
215-
vBox.setVisibility(this._canIDelete() ? "visible" : "excluded");
216-
}
217-
218-
const label = new qx.ui.basic.Label(this.tr("Select from the list below and click Share"));
219-
vBox.add(label);
220-
221-
const addCollaboratorBtn = new qx.ui.form.Button(this.tr("Share with...")).set({
222-
appearance: "form-button",
223-
alignX: "left",
224-
allowGrowX: false
225-
});
226-
addCollaboratorBtn.addListener("execute", () => {
227-
const collaboratorsManager = new osparc.share.NewCollaboratorsManager(this._serializedDataCopy);
228-
collaboratorsManager.addListener("addCollaborators", e => {
229-
const cb = () => collaboratorsManager.close();
230-
this._addEditors(e.getData(), cb);
231-
}, this);
232-
}, this);
233-
vBox.add(addCollaboratorBtn);
234-
235-
return vBox;
211+
const addCollaborators = new osparc.share.AddCollaborators(this._serializedDataCopy);
212+
addCollaborators.addListener("addCollaborators", e => this._addEditors(e.getData()), this);
213+
return addCollaborators;
236214
},
237215

238216
__createCollaboratorsListSection: function() {
239217
const vBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
240218

219+
const header = new qx.ui.container.Composite(new qx.ui.layout.HBox());
220+
241221
const label = new qx.ui.basic.Label(this.tr("Shared with"));
242-
vBox.add(label);
222+
label.set({allowGrowX: true});
223+
header.add(label, {
224+
flex: 1
225+
});
243226

244227
const rolesLayout = osparc.data.Roles.createRolesStudyResourceInfo();
245228
const leaveButton = this.__getLeaveStudyButton();
246229
if (leaveButton) {
247230
rolesLayout.addAt(leaveButton, 0);
248231
}
249-
vBox.add(rolesLayout);
232+
header.add(rolesLayout);
233+
vBox.add(header);
250234

251235
const collaboratorsUIList = new qx.ui.form.List().set({
252236
decorator: "no-border",
@@ -362,6 +346,7 @@ qx.Class.define("osparc.share.Collaborators", {
362346
];
363347
const accessRights = this._serializedDataCopy["accessRights"];
364348
const collaboratorsList = [];
349+
const showOptions = this.__amIOwner();
365350
Object.keys(accessRights).forEach(gid => {
366351
if (Object.prototype.hasOwnProperty.call(this.__collaborators, gid)) {
367352
const collab = this.__collaborators[gid];
@@ -383,7 +368,7 @@ qx.Class.define("osparc.share.Collaborators", {
383368
}
384369
}
385370
collaborator["accessRights"] = accessRights[gid];
386-
collaborator["showOptions"] = (this._resourceType === "service") ? this._canIWrite() : this._canIDelete();
371+
collaborator["showOptions"] = showOptions;
387372
collaborator["resourceType"] = this._resourceType;
388373
collaboratorsList.push(collaborator);
389374
}
@@ -392,14 +377,6 @@ qx.Class.define("osparc.share.Collaborators", {
392377
collaboratorsList.forEach(c => this.__collaboratorsModel.append(qx.data.marshal.Json.createModel(c)));
393378
},
394379

395-
_canIDelete: function() {
396-
throw new Error("Abstract method called!");
397-
},
398-
399-
_canIWrite: function() {
400-
throw new Error("Abstract method called!");
401-
},
402-
403380
_addEditors: function(gids) {
404381
throw new Error("Abstract method called!");
405382
},

‎services/static-webserver/client/source/class/osparc/share/CollaboratorsService.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ qx.Class.define("osparc.share.CollaboratorsService", {
8787
},
8888

8989
members: {
90-
_canIWrite: function() {
91-
return osparc.service.Utils.canIWrite(this._serializedDataCopy["accessRights"]);
92-
},
93-
94-
_addEditors: function(gids, cb) {
90+
_addEditors: function(gids) {
9591
if (gids.length === 0) {
9692
return;
9793
}
@@ -112,8 +108,7 @@ qx.Class.define("osparc.share.CollaboratorsService", {
112108
.catch(err => {
113109
console.error(err);
114110
osparc.FlashMessenger.getInstance().logAs(this.tr("Something went wrong adding editor(s)"), "ERROR");
115-
})
116-
.finally(() => cb());
111+
});
117112
},
118113

119114
_deleteMember: function(collaborator, item) {

‎services/static-webserver/client/source/class/osparc/share/CollaboratorsStudy.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
128128
},
129129

130130
members: {
131-
_canIDelete: function() {
132-
return osparc.data.model.Study.canIDelete(this._serializedDataCopy["accessRights"]);
133-
},
134-
135-
_canIWrite: function() {
136-
return osparc.data.model.Study.canIWrite(this._serializedDataCopy["accessRights"]);
137-
},
138-
139-
_addEditors: function(gids, cb) {
131+
_addEditors: function(gids) {
140132
if (gids.length === 0) {
141133
return;
142134
}
@@ -157,8 +149,7 @@ qx.Class.define("osparc.share.CollaboratorsStudy", {
157149
.catch(err => {
158150
console.error(err);
159151
osparc.FlashMessenger.getInstance().logAs(this.tr("Something went adding user(s)"), "ERROR");
160-
})
161-
.finally(() => cb());
152+
});
162153

163154
// push 'STUDY_SHARED'/'TEMPLATE_SHARED' notification
164155
osparc.store.Store.getInstance().getPotentialCollaborators()

‎services/static-webserver/client/source/class/osparc/share/NewCollaboratorsManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
8282
let includeProductEveryone = false;
8383
if (this.__showOrganizations === false) {
8484
includeProductEveryone = false;
85-
} else if (this.__resourceData && this.__resourceData["resourceType"] === "template") {
85+
} else if (this.__resourceData && this.__resourceData["resourceType"] === "study") {
8686
// studies can't be shared with ProductEveryone
8787
includeProductEveryone = false;
8888
} else if (this.__resourceData && this.__resourceData["resourceType"] === "template") {

0 commit comments

Comments
 (0)