Skip to content

Commit

Permalink
Clusters in frontend (#2517)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Sep 7, 2021
1 parent 7c8b806 commit 47e95fb
Show file tree
Hide file tree
Showing 19 changed files with 1,035 additions and 86 deletions.
6 changes: 6 additions & 0 deletions services/web/client/source/class/osparc/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,18 @@ qx.Class.define("osparc.Application", {
},

__loadMainPage: function() {
// Invalidate the entire cache
osparc.store.Store.getInstance().invalidate();

this.__connectWebSocket();
const mainPage = this.__mainPage = new osparc.desktop.MainPage();
this.__loadView(mainPage);
},

__loadNodeViewerPage: function(studyId, viewerNodeId) {
// Invalidate the entire cache
osparc.store.Store.getInstance().invalidate();

this.__connectWebSocket();
this.__loadView(new osparc.viewer.MainPage(studyId, viewerNodeId));
},
Expand Down
6 changes: 6 additions & 0 deletions services/web/client/source/class/osparc/auth/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ qx.Class.define("osparc.auth.Manager", {
osparc.auth.Data.getInstance().setOrgIds(orgIds);
}
osparc.data.Permissions.getInstance().setRole(profile.role);

this.__fetchStartUpResources();
},

__fetchStartUpResources: function() {
osparc.data.Resources.get("clusters");
},

__logoutUser: function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ qx.Class.define("osparc.component.filter.OrganizationsAndMembers", {
* @extends osparc.component.filter.TagsFilter
*/
construct: function(filterGroupId) {
this.base(arguments, this.tr("Members"), "organizationsAndMembers", filterGroupId);
this.base(arguments, this.tr("Organizations and Members"), "organizationsAndMembers", filterGroupId);

this.__visibleCollaborators = {};
},

members: {
__visibleCollaborators: null,
__collaboratorsToBeRemoved: null,

addOption: function(group) {
let name = "";
if ("first_name" in group) {
Expand All @@ -57,6 +62,58 @@ qx.Class.define("osparc.component.filter.OrganizationsAndMembers", {
selectedGIDs.push(activeMenuButton.gid);
});
return selectedGIDs;
},

reloadVisibleCollaborators: function(collaboratorsToBeRemoved = null) {
if (collaboratorsToBeRemoved) {
this.__collaboratorsToBeRemoved = collaboratorsToBeRemoved.map(collaboratorToBeRemoved => parseInt(collaboratorToBeRemoved));
}

osparc.store.Store.getInstance().getPotentialCollaborators()
.then(potentialCollaborators => {
this.__visibleCollaborators = potentialCollaborators;
this.__addOrgsAndMembers();
});
},

__addOrgsAndMembers: function() {
this.reset();

const visibleCollaborators = Object.values(this.__visibleCollaborators);

// sort them first
visibleCollaborators.sort((a, b) => {
if (a["collabType"] > b["collabType"]) {
return 1;
}
if (a["collabType"] < b["collabType"]) {
return -1;
}
if (a["label"] > b["label"]) {
return 1;
}
return -1;
});

visibleCollaborators.forEach(visibleCollaborator => {
if (this.__collaboratorsToBeRemoved && this.__collaboratorsToBeRemoved.includes(visibleCollaborator["gid"])) {
return;
}
const btn = this.addOption(visibleCollaborator);
let iconPath = null;
switch (visibleCollaborator["collabType"]) {
case 0:
iconPath = "@FontAwesome5Solid/globe/14";
break;
case 1:
iconPath = "@FontAwesome5Solid/users/14";
break;
case 2:
iconPath = "@FontAwesome5Solid/user/14";
break;
}
btn.setIcon(iconPath);
});
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ qx.Class.define("osparc.component.permissions.Permissions", {
__organizationsAndMembers: null,
__collaboratorsModel: null,
__collaborators: null,
__addCollaboratorBtn: null,

__buildLayout: function() {
const addCollaborator = this.__createAddCollaboratorSection();
Expand Down Expand Up @@ -100,7 +99,7 @@ qx.Class.define("osparc.component.permissions.Permissions", {
flex: 1
});

const addCollaboratorBtn = this.__addCollaboratorBtn = new qx.ui.form.Button(this.tr("Add")).set({
const addCollaboratorBtn = new qx.ui.form.Button(this.tr("Add")).set({
allowGrowY: false,
enabled: false
});
Expand All @@ -109,7 +108,7 @@ qx.Class.define("osparc.component.permissions.Permissions", {
}, this);
qx.event.message.Bus.getInstance().subscribe("OrgAndMembPermsFilter", () => {
const anySelected = Boolean(this.__organizationsAndMembers.getSelectedGIDs().length);
this.__addCollaboratorBtn.setEnabled(anySelected);
addCollaboratorBtn.setEnabled(anySelected);
}, this);

hBox.add(addCollaboratorBtn);
Expand All @@ -134,15 +133,15 @@ qx.Class.define("osparc.component.permissions.Permissions", {
const collaboratorsModel = this.__collaboratorsModel = new qx.data.Array();
const collaboratorsCtrl = new qx.data.controller.List(collaboratorsModel, collaboratorsUIList, "name");
collaboratorsCtrl.setDelegate({
createItem: () => new osparc.dashboard.CollaboratorListItem(),
createItem: () => new osparc.ui.list.CollaboratorListItem(),
bindItem: (ctrl, item, id) => {
ctrl.bindProperty("gid", "model", null, item, id);
ctrl.bindProperty("gid", "key", null, item, id);
ctrl.bindProperty("collabType", "collabType", null, item, id);
ctrl.bindProperty("thumbnail", "thumbnail", null, item, id);
ctrl.bindProperty("name", "title", null, item, id); // user
ctrl.bindProperty("label", "title", null, item, id); // organization
ctrl.bindProperty("login", "subtitle", null, item, id); // user
ctrl.bindProperty("login", "subtitleMD", null, item, id); // user
ctrl.bindProperty("description", "subtitle", null, item, id); // organization
ctrl.bindProperty("accessRights", "accessRights", null, item, id);
ctrl.bindProperty("showOptions", "showOptions", null, item, id);
Expand Down Expand Up @@ -211,23 +210,9 @@ qx.Class.define("osparc.component.permissions.Permissions", {
},

getCollaborators: function() {
const store = osparc.store.Store.getInstance();
const promises = [];
promises.push(store.getGroupsOrganizations());
promises.push(store.getVisibleMembers());
Promise.all(promises)
.then(values => {
const orgs = values[0]; // array
const orgMembers = values[1]; // object
orgs.forEach(org => {
org["collabType"] = 1;
this.__collaborators[org["gid"]] = org;
});
for (const gid of Object.keys(orgMembers)) {
const orgMember = orgMembers[gid];
orgMember["collabType"] = 2;
this.__collaborators[gid] = orgMember;
}
osparc.store.Store.getInstance().getPotentialCollaborators()
.then(potentialCollaborators => {
this.__collaborators = potentialCollaborators;
this.__reloadOrganizationsAndMembers();
this.__reloadCollaboratorsList();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ qx.Class.define("osparc.component.permissions.ShareWith", {
});
});
myOrgMembersHB.add(myOrgsSB);
const myOrgMembers = this.__myOrgMembers = new osparc.component.filter.OrganizationMembers("asdfasdf");
const myOrgMembers = this.__myOrgMembers = new osparc.component.filter.OrganizationMembers("shareWithOrganizationMembers");
myOrgMembersHB.add(myOrgMembers, {
flex: 1
});
Expand Down
131 changes: 131 additions & 0 deletions services/web/client/source/class/osparc/dashboard/ClusterEditor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2021 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

qx.Class.define("osparc.dashboard.ClusterEditor", {
extend: qx.ui.core.Widget,

construct: function(newCluster = true) {
this.base(arguments);

this._setLayout(new qx.ui.layout.VBox(8));

const manager = this.__validator = new qx.ui.form.validation.Manager();
const title = this.getChildControl("title");
title.setRequired(true);
manager.add(title);
this.getChildControl("description");
newCluster ? this.getChildControl("create") : this.getChildControl("save");
},

properties: {
cid: {
check: "Number",
init: 0,
nullable: false,
event: "changeCid"
},

label: {
check: "String",
init: "",
nullable: false,
event: "changeLabel"
},

description: {
check: "String",
init: "",
nullable: false,
event: "changeDescription"
}
},

events: {
"createCluster": "qx.event.type.Event",
"updateCluster": "qx.event.type.Event",
"cancel": "qx.event.type.Event"
},

members: {
_createChildControlImpl: function(id) {
let control;
switch (id) {
case "title": {
control = new qx.ui.form.TextField().set({
font: "title-14",
backgroundColor: "background-main",
placeholder: this.tr("Title"),
height: 35
});
this.bind("label", control, "value");
control.bind("value", this, "label");
this._add(control);
break;
}
case "description": {
control = new qx.ui.form.TextArea().set({
font: "text-14",
placeholder: this.tr("Description"),
autoSize: true,
minHeight: 70,
maxHeight: 140
});
this.bind("description", control, "value");
control.bind("value", this, "description");
this._add(control);
break;
}
case "create": {
const buttons = this.getChildControl("buttonsLayout");
control = new osparc.ui.form.FetchButton(this.tr("Create"));
control.addListener("execute", () => {
if (this.__validator.validate()) {
control.setFetching(true);
this.fireEvent("createCluster");
}
}, this);
buttons.addAt(control, 0);
break;
}
case "save": {
const buttons = this.getChildControl("buttonsLayout");
control = new osparc.ui.form.FetchButton(this.tr("Save"));
control.addListener("execute", () => {
if (this.__validator.validate()) {
control.setFetching(true);
this.fireEvent("updateCluster");
}
}, this);
buttons.addAt(control, 0);
break;
}
case "buttonsLayout": {
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(8).set({
alignX: "right"
}));
const cancelButton = new qx.ui.form.Button(this.tr("Cancel"));
cancelButton.addListener("execute", () => this.fireEvent("cancel"), this);
control.add(cancelButton);
this._add(control);
break;
}
}

return control || this.base(arguments, id);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ qx.Class.define("osparc.data.Permissions", {
"studies.template.create.all",
"services.all.read",
"user.role.update",
"user.clusters.create",
"study.service.update",
"study.snapshot.create",
"study.nodestree.uuid.read",
Expand Down
28 changes: 28 additions & 0 deletions services/web/client/source/class/osparc/data/Resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,34 @@ qx.Class.define("osparc.data.Resources", {
}
}
},
/*
* CLUSTERS
*/
"clusters": {
useCache: true,
endpoints: {
get: {
method: "GET",
url: statics.API + "/clusters"
},
post: {
method: "POST",
url: statics.API + "/clusters"
},
getOne: {
method: "GET",
url: statics.API + "/clusters/{cid}"
},
delete: {
method: "DELETE",
url: statics.API + "/clusters/{cid}"
},
patch: {
method: "PATCH",
url: statics.API + "/clusters/{cid}"
}
}
},
/*
* CLASSIFIERS
* Gets the json object containing sample classifiers
Expand Down
Loading

0 comments on commit 47e95fb

Please sign in to comment.