Skip to content

Commit 9459040

Browse files
committed
selectedCollaborators
1 parent 3e3a154 commit 9459040

File tree

2 files changed

+40
-23
lines changed

2 files changed

+40
-23
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ qx.Mixin.define("osparc.filter.MFilterable", {
2929
const msgName = osparc.utils.Utils.capitalize(filterGroupId, "filter");
3030
qx.event.message.Bus.getInstance().subscribe(msgName, this.__subscriber, this);
3131
},
32+
unsubscribeToFilterGroup: function(filterGroupId) {
33+
const msgName = osparc.utils.Utils.capitalize(filterGroupId, "filter");
34+
qx.event.message.Bus.getInstance().unsubscribe(msgName, this.__subscriber, this);
35+
},
3236
/**
3337
* Subscriber function for incoming messages. It implements the common filtering workflow of every
3438
* filterable GUI element: If the filter state is appropriate, compare it with the own state and act

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

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
99
extend: osparc.ui.window.SingletonWindow,
1010

1111
construct: function(resourceData, showOrganizations = true) {
12-
this.base(arguments, "collaboratorsManager", this.tr("New collaborators"));
12+
this.base(arguments, "newCollaboratorsManager", this.tr("New collaborators"));
1313

1414
this.set({
1515
layout: new qx.ui.layout.VBox(5),
@@ -29,7 +29,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
2929

3030
this.__renderLayout();
3131

32-
this.__selectedCollaborators = [];
32+
this.__selectedCollaborators = {};
3333
this.__potentialCollaborators = {};
3434
this.__reloadPotentialCollaborators();
3535

@@ -95,7 +95,7 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
9595
control = new qx.ui.container.Composite(new qx.ui.layout.VBox(2)).set({
9696
paddingLeft: 8,
9797
});
98-
const title = new qx.ui.basic.Label(this.tr("Give access:"));
98+
const title = new qx.ui.basic.Label(this.tr("Set following Role:"));
9999
control.add(title);
100100
this.add(control);
101101
break;
@@ -217,30 +217,35 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
217217
__reloadPotentialCollaborators: function() {
218218
const includeProductEveryone = this.__showProductEveryone();
219219
this.__potentialCollaborators = osparc.store.Groups.getInstance().getPotentialCollaborators(false, includeProductEveryone);
220-
const potentialCollaborators = Object.values(this.__potentialCollaborators);
221-
this.__addPotentialCollaborators(potentialCollaborators);
220+
this.__addPotentialCollaborators();
222221
},
223222

224-
__collaboratorButton: function(collaborator) {
223+
__collaboratorButton: function(collaborator, preSelected = false) {
225224
const collaboratorButton = new osparc.filter.CollaboratorToggleButton(collaborator);
226225
collaboratorButton.groupId = collaborator.getGroupId();
226+
collaboratorButton.setValue(preSelected);
227+
if (!preSelected) {
228+
collaboratorButton.subscribeToFilterGroup("collaboratorsManager");
229+
}
230+
227231
collaboratorButton.addListener("changeValue", e => {
228232
const selected = e.getData();
229233
if (selected) {
230-
this.__selectedCollaborators.push(collaborator.getGroupId());
231-
} else {
232-
const idx = this.__selectedCollaborators.indexOf(collaborator.getGroupId());
233-
if (idx > -1) {
234-
this.__selectedCollaborators.splice(idx, 1);
235-
}
234+
this.__selectedCollaborators[collaborator.getGroupId()] = collaborator;
235+
collaboratorButton.unsubscribeToFilterGroup("collaboratorsManager");
236+
} else if (collaborator.getGroupId() in this.__selectedCollaborators) {
237+
delete this.__selectedCollaborators[collaborator.getGroupId()];
238+
collaboratorButton.subscribeToFilterGroup("collaboratorsManager");
236239
}
237-
this.getChildControl("share-button").setEnabled(Boolean(this.__selectedCollaborators.length));
240+
this.getChildControl("share-button").setEnabled(Boolean(Object.keys(this.__selectedCollaborators).length));
238241
}, this);
239-
collaboratorButton.subscribeToFilterGroup("collaboratorsManager");
240242
return collaboratorButton;
241243
},
242244

243-
__addPotentialCollaborators: function(potentialCollaborators) {
245+
__addPotentialCollaborators: function(foundCollaborators = []) {
246+
const potentialCollaborators = Object.values(this.__potentialCollaborators).concat(foundCollaborators);
247+
const potentialCollaboratorList = this.getChildControl("potential-collaborators-list");
248+
244249
// sort them first
245250
potentialCollaborators.sort((a, b) => {
246251
if (a["collabType"] > b["collabType"]) {
@@ -275,32 +280,40 @@ qx.Class.define("osparc.share.NewCollaboratorsManager", {
275280
potentialCollaborators.forEach(potentialCollaborator => {
276281
// do not list the potentialCollaborators that are already collaborators
277282
if (existingCollaborators.includes(potentialCollaborator.getGroupId())) {
283+
console.log("already collaborator", potentialCollaborator.getLabel());
284+
return;
285+
}
286+
// do not list the potentialCollaborators that were selected
287+
console.log("selected?", potentialCollaborator.getGroupId(), this.__selectedCollaborators);
288+
if (potentialCollaborator.getGroupId() in this.__selectedCollaborators) {
289+
console.log("already selected", potentialCollaborator.getLabel());
278290
return;
279291
}
280-
// do not list those that were already listed
281-
if (this.getChildControl("potential-collaborators-list").getChildren().find(c => "groupId" in c && c["groupId"] === potentialCollaborator.getGroupId())) {
292+
// do not list the potentialCollaborators that were already listed
293+
if (potentialCollaboratorList.getChildren().find(c => "groupId" in c && c["groupId"] === potentialCollaborator.getGroupId())) {
294+
console.log("already listed", potentialCollaborator.getLabel());
282295
return;
283296
}
297+
// maybe, do not list the organizations
284298
if (this.__showOrganizations === false && potentialCollaborator["collabType"] !== 2) {
285299
return;
286300
}
287-
this.getChildControl("potential-collaborators-list").add(this.__collaboratorButton(potentialCollaborator));
301+
potentialCollaboratorList.add(this.__collaboratorButton(potentialCollaborator));
288302
});
289303

290304
// move it to last position
291305
const searching = this.getChildControl("searching-collaborators");
292-
this.getChildControl("potential-collaborators-list").remove(searching);
293-
this.getChildControl("potential-collaborators-list").add(searching);
306+
potentialCollaboratorList.remove(searching);
307+
potentialCollaboratorList.add(searching);
294308
},
295309

296310
__shareClicked: function() {
297311
this.getChildControl("potential-collaborators-list").setEnabled(false);
298312
this.getChildControl("share-button").setFetching(true);
299313

300-
if (this.__selectedCollaborators.length) {
301-
this.fireDataEvent("addCollaborators", this.__selectedCollaborators);
314+
if (Object.keys(this.__selectedCollaborators).length) {
315+
this.fireDataEvent("addCollaborators", Object.keys(this.__selectedCollaborators));
302316
}
303-
// The parent class will close the window
304317
}
305318
}
306319
});

0 commit comments

Comments
 (0)