Skip to content

Commit 842eeb1

Browse files
authored
✨ Groups Templates (and Services!) by Shared with (ITISFoundation#3665)
1 parent 414292d commit 842eeb1

File tree

9 files changed

+137
-64
lines changed

9 files changed

+137
-64
lines changed

services/static-webserver/client/source/class/osparc/component/permissions/ShareWith.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ qx.Class.define("osparc.component.permissions.ShareWith", {
3535
const store = osparc.store.Store.getInstance();
3636
Promise.all([
3737
store.getGroupsMe(),
38-
store.getGroupsAll()
38+
store.getGroupEveryone()
3939
])
4040
.then(values => {
4141
const groupMe = values[0];
42-
const groupAll = values[1];
42+
const groupEveryone = values[1];
4343
this.__rbManager.getChildren().forEach(rb => {
4444
if (rb.contextId === this.self().SharingOpts["me"].contextId) {
4545
rb.gid = groupMe["gid"];
4646
}
4747
if (rb.contextId === this.self().SharingOpts["all"].contextId) {
48-
rb.gid = groupAll["gid"];
48+
rb.gid = groupEveryone["gid"];
4949
}
5050
});
5151
});

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,19 +217,19 @@ qx.Class.define("osparc.dashboard.GridButtonItem", {
217217

218218
const store = osparc.store.Store.getInstance();
219219
Promise.all([
220-
store.getGroupsAll(),
220+
store.getGroupEveryone(),
221221
store.getVisibleMembers(),
222222
store.getGroupsOrganizations()
223223
])
224224
.then(values => {
225-
const all = values[0];
225+
const everyone = values[0];
226226
const orgMembs = [];
227227
const orgMembers = values[1];
228228
for (const gid of Object.keys(orgMembers)) {
229229
orgMembs.push(orgMembers[gid]);
230230
}
231231
const orgs = values.length === 3 ? values[2] : [];
232-
const groups = [orgMembs, orgs, [all]];
232+
const groups = [orgMembs, orgs, [everyone]];
233233
this.__setSharedIcon(sharedIcon, value, groups);
234234
});
235235

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ qx.Class.define("osparc.dashboard.GroupedToggleButtonContainer", {
8989
allowGrowX: false,
9090
backgroundColor: "background-main-1"
9191
});
92+
control.getChildControl("icon").set({
93+
scale: true,
94+
allowGrowX: true,
95+
allowGrowY: true,
96+
allowShrinkX: true,
97+
allowShrinkY: true,
98+
maxWidth: 32,
99+
maxHeight: 32
100+
});
92101
control.getContentElement().setStyles({
93102
"border-top-left-radius": "4px",
94103
"border-top-right-radius": "4px"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,19 @@ qx.Class.define("osparc.dashboard.ListButtonItem", {
209209

210210
const store = osparc.store.Store.getInstance();
211211
Promise.all([
212-
store.getGroupsAll(),
212+
store.getGroupEveryone(),
213213
store.getVisibleMembers(),
214214
store.getGroupsOrganizations()
215215
])
216216
.then(values => {
217-
const all = values[0];
217+
const everyone = values[0];
218218
const orgMembs = [];
219219
const orgMembers = values[1];
220220
for (const gid of Object.keys(orgMembers)) {
221221
orgMembs.push(orgMembers[gid]);
222222
}
223223
const orgs = values.length === 3 ? values[2] : [];
224-
const groups = [orgMembs, orgs, [all]];
224+
const groups = [orgMembs, orgs, [everyone]];
225225
this.__setSharedIcon(sharedIcon, value, groups);
226226
});
227227

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,38 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
161161
this._reloadCards();
162162
},
163163

164+
_addGroupByButton: function() {
165+
const groupByMenu = new qx.ui.menu.Menu().set({
166+
font: "text-14"
167+
});
168+
const groupByButton = new qx.ui.form.MenuButton(this.tr("Group"), "@FontAwesome5Solid/chevron-down/10", groupByMenu);
169+
osparc.utils.Utils.setIdToWidget(groupByButton, "groupByButton");
170+
171+
const dontGroup = new qx.ui.menu.RadioButton(this.tr("None"));
172+
osparc.utils.Utils.setIdToWidget(dontGroup, "groupByNone");
173+
dontGroup.addListener("execute", () => this._groupByChanged(null));
174+
const tagByGroup = new qx.ui.menu.RadioButton(this.tr("Tags"));
175+
tagByGroup.addListener("execute", () => this._groupByChanged("tags"));
176+
const groupByShared = new qx.ui.menu.RadioButton(this.tr("Shared with"));
177+
groupByShared.addListener("execute", () => this._groupByChanged("shared"));
178+
179+
const groupOptions = new qx.ui.form.RadioGroup();
180+
[
181+
dontGroup,
182+
tagByGroup,
183+
groupByShared
184+
].forEach(btn => {
185+
groupByMenu.add(btn);
186+
groupOptions.add(btn);
187+
});
188+
189+
if (osparc.utils.Utils.isProduct("s4llite")) {
190+
tagByGroup.execute();
191+
}
192+
193+
this._secondaryBar.add(groupByButton);
194+
},
195+
164196
_addViewModeButton: function() {
165197
const viewByMenu = this.__viewMenuButton.getMenu();
166198

@@ -177,6 +209,8 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
177209
viewByMenu.add(btn);
178210
groupOptions.add(btn);
179211
});
212+
213+
this._secondaryBar.add(this.__viewMenuButton);
180214
},
181215

182216
/**

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
4747
},
4848

4949
groupBy: {
50-
check: [null, "tags"],
50+
check: [null, "tags", "shared"],
5151
init: null,
5252
nullable: true
5353
}
@@ -127,11 +127,11 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
127127
return this.__flatList;
128128
},
129129

130-
__createGroupContainer: function(groupId, headerLabel, headerColor) {
130+
__createGroupContainer: function(groupId, headerLabel, headerColor = "text") {
131131
const groupContainer = new osparc.dashboard.GroupedToggleButtonContainer().set({
132132
groupId: groupId.toString(),
133133
headerLabel,
134-
headerIcon: "@FontAwesome5Solid/tag/24",
134+
headerIcon: "",
135135
headerColor,
136136
visibility: "excluded"
137137
});
@@ -215,7 +215,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
215215

216216
reloadCards: function(listId) {
217217
this.__cleanAll();
218-
if (this.getGroupBy() === "tags") {
218+
if (this.getGroupBy()) {
219219
const noGroupContainer = this.__createEmptyGroupContainer();
220220
this._add(noGroupContainer);
221221
} else {
@@ -269,8 +269,56 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
269269
let groupContainer = this.__getGroupContainer(tag.id);
270270
if (groupContainer === null) {
271271
groupContainer = this.__createGroupContainer(tag.id, tag.name, tag.color);
272-
const noGroupContainer = this.__getGroupContainer("no-group");
273-
const idx = this._getChildren().findIndex(grpContainer => grpContainer === noGroupContainer);
272+
groupContainer.setHedaerIcon("@FontAwesome5Solid/tag/24");
273+
const idx = this._getChildren().findIndex(grpContainer => grpContainer === this.__getGroupContainer("no-group"));
274+
this._addAt(groupContainer, idx);
275+
}
276+
const card = this.__createCard(resourceData, tags);
277+
groupContainer.add(card);
278+
this.self().sortList(groupContainer.getContentContainer());
279+
cards.push(card);
280+
});
281+
}
282+
} else if (this.getGroupBy() === "shared") {
283+
let orgIds = [];
284+
if ("accessRights" in resourceData) {
285+
// study or templates
286+
orgIds = Object.keys(resourceData["accessRights"]);
287+
} else if ("access_rights" in resourceData) {
288+
// services
289+
orgIds = Object.keys(resourceData["access_rights"]);
290+
}
291+
if (orgIds.length === 0) {
292+
let noGroupContainer = this.__getGroupContainer("no-group");
293+
const card = this.__createCard(resourceData, tags);
294+
noGroupContainer.add(card);
295+
this.self().sortList(noGroupContainer.getContentContainer());
296+
cards.push(card);
297+
} else {
298+
orgIds.forEach(orgId => {
299+
let groupContainer = this.__getGroupContainer(orgId);
300+
if (groupContainer === null) {
301+
groupContainer = this.__createGroupContainer(orgId, "loading-label");
302+
osparc.store.Store.getInstance().getOrganization(orgId)
303+
.then(org => {
304+
if (org) {
305+
let icon = "";
306+
if (org.thumbnail) {
307+
icon = org.thumbnail;
308+
} else if (org["groupType"] === 0) {
309+
icon = "@FontAwesome5Solid/globe/24";
310+
} else if (org["groupType"] === 1) {
311+
icon = "@FontAwesome5Solid/users/24";
312+
} else if (org["groupType"] === 2) {
313+
icon = "@FontAwesome5Solid/user/24";
314+
}
315+
groupContainer.set({
316+
headerIcon: icon,
317+
headerLabel: org.label
318+
});
319+
}
320+
});
321+
const idx = this._getChildren().findIndex(grpContainer => grpContainer === this.__getGroupContainer("no-group"));
274322
this._addAt(groupContainer, idx);
275323
}
276324
const card = this.__createCard(resourceData, tags);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
156156
flex: 1
157157
});
158158
this.__addSortingButtons();
159+
this._addGroupByButton();
159160
this._addViewModeButton();
160161

161162
return this._resourcesContainer;

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -135,42 +135,11 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
135135
this._secondaryBar.add(new qx.ui.core.Spacer(), {
136136
flex: 1
137137
});
138-
const groupByButton = this.__createGroupByButton();
139-
this._secondaryBar.add(groupByButton);
140-
138+
this._addGroupByButton();
141139
this._addViewModeButton();
142140

143141
return this._resourcesContainer;
144142
},
145-
146-
__createGroupByButton: function() {
147-
const groupByMenu = new qx.ui.menu.Menu().set({
148-
font: "text-14"
149-
});
150-
const groupByButton = new qx.ui.form.MenuButton(this.tr("Group"), "@FontAwesome5Solid/chevron-down/10", groupByMenu);
151-
osparc.utils.Utils.setIdToWidget(groupByButton, "groupByButton");
152-
153-
const dontGroup = new qx.ui.menu.RadioButton(this.tr("None"));
154-
osparc.utils.Utils.setIdToWidget(dontGroup, "groupByNone");
155-
dontGroup.addListener("execute", () => this._groupByChanged(null));
156-
const tagByGroup = new qx.ui.menu.RadioButton(this.tr("Tags"));
157-
tagByGroup.addListener("execute", () => this._groupByChanged("tags"));
158-
159-
const groupOptions = new qx.ui.form.RadioGroup();
160-
[
161-
dontGroup,
162-
tagByGroup
163-
].forEach(btn => {
164-
groupByMenu.add(btn);
165-
groupOptions.add(btn);
166-
});
167-
168-
if (osparc.utils.Utils.isProduct("s4llite")) {
169-
tagByGroup.execute();
170-
}
171-
172-
return groupByButton;
173-
},
174143
// LAYOUT //
175144

176145
// MENU //

services/static-webserver/client/source/class/osparc/store/Store.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,12 @@ qx.Class.define("osparc.store.Store", {
369369
},
370370

371371
__getGroups: function(group) {
372-
return new Promise((resolve, reject) => {
372+
return new Promise(resolve => {
373373
osparc.data.Resources.getOne("profile")
374374
.then(profile => {
375375
resolve(profile["groups"][group]);
376376
})
377-
.catch(err => {
378-
console.error(err);
379-
});
377+
.catch(err => console.error(err));
380378
});
381379
},
382380

@@ -388,33 +386,47 @@ qx.Class.define("osparc.store.Store", {
388386
return this.__getGroups("organizations");
389387
},
390388

391-
getGroupsAll: function() {
389+
getGroupEveryone: function() {
392390
return this.__getGroups("all");
393391
},
394392

395-
getGroups: function(withMySelf = true) {
396-
return new Promise((resolve, reject) => {
393+
__getAllGroups: function() {
394+
return new Promise(resolve => {
397395
const promises = [];
396+
promises.push(this.getGroupsMe());
398397
promises.push(this.getGroupsOrganizations());
399-
promises.push(this.getGroupsAll());
400-
if (withMySelf) {
401-
promises.push(this.getGroupsMe());
402-
}
398+
promises.push(this.getGroupEveryone());
403399
Promise.all(promises)
404400
.then(values => {
405401
const groups = [];
406-
values[0].forEach(value => {
407-
groups.push(value);
402+
const groupMe = values[0];
403+
groupMe["groupType"] = 2;
404+
groups.push(groupMe);
405+
values[1].forEach(org => {
406+
org["groupType"] = 1;
407+
groups.push(org);
408408
});
409-
groups.push(values[1]);
410-
if (withMySelf) {
411-
groups.push(values[2]);
412-
}
409+
const groupEveryone = values[2];
410+
groupEveryone["groupType"] = 0;
411+
groups.push(groupEveryone);
413412
resolve(groups);
414413
});
415414
});
416415
},
417416

417+
getOrganization: function(orgId) {
418+
return new Promise(resolve => {
419+
this.__getAllGroups()
420+
.then(orgs => {
421+
const idx = orgs.findIndex(org => org.gid === parseInt(orgId));
422+
if (idx > -1) {
423+
resolve(orgs[idx]);
424+
}
425+
resolve(null);
426+
});
427+
});
428+
},
429+
418430
getVisibleMembers: function(reload = false) {
419431
return new Promise((resolve, reject) => {
420432
const reachableMembers = this.getReachableMembers();

0 commit comments

Comments
 (0)