diff --git a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js index 714123543cc..639407882ca 100644 --- a/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js +++ b/services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js @@ -178,8 +178,10 @@ qx.Class.define("osparc.dashboard.Dashboard", { }, this); const preResourcePromises = []; + const store = osparc.store.Store.getInstance(); + preResourcePromises.push(store.getAllGroupsAndMembers()); const groupsStore = osparc.store.Groups.getInstance(); - preResourcePromises.push(groupsStore.getAllGroupsAndMembers()); + preResourcePromises.push(groupsStore.fetchAll()); preResourcePromises.push(osparc.store.Services.getServicesLatest(false)); Promise.all(preResourcePromises) .then(() => { diff --git a/services/static-webserver/client/source/class/osparc/data/model/Group.js b/services/static-webserver/client/source/class/osparc/data/model/Group.js index 9277b18c84a..3e78a215de4 100644 --- a/services/static-webserver/client/source/class/osparc/data/model/Group.js +++ b/services/static-webserver/client/source/class/osparc/data/model/Group.js @@ -29,26 +29,15 @@ qx.Class.define("osparc.data.model.Group", { this.base(arguments); this.set({ - workspaceId: groupData.workspaceId, groupId: groupData.groupId, - parentGroupId: groupData.parentGroupId, - name: groupData.name, - myAccessRights: groupData.myAccessRights, - owner: groupData.owner, - createdAt: new Date(groupData.createdAt), - lastModified: new Date(groupData.modifiedAt), - trashedAt: groupData.trashedAt ? new Date(groupData.trashedAt) : this.getTrashedAt(), + label: groupData.label, + description: groupData.description, + accessRights: groupData.accessRights, + thumbnail: groupData.thumbnail, }); }, properties: { - workspaceId: { - check: "Number", - nullable: true, - init: null, - event: "changeWorkspaceId" - }, - groupId: { check: "Number", nullable: false, @@ -56,51 +45,36 @@ qx.Class.define("osparc.data.model.Group", { event: "changeGroupId" }, - parentGroupId: { - check: "Number", - nullable: true, - init: null, - event: "changeParentGroupId" - }, - - name: { + label: { check: "String", nullable: false, init: null, - event: "changeName" - }, - - myAccessRights: { - check: "Object", - nullable: false, - init: null, - event: "changeMyAccessRights" + event: "changeLabel" }, - owner: { - check: "Number", + description: { + check: "String", nullable: true, init: null, - event: "changeOwner" + event: "changeDescription" }, - createdAt: { - check: "Date", - nullable: true, + accessRights: { + check: "Object", + nullable: false, init: null, - event: "changeCreatedAt" + event: "changeAccessRights" }, - lastModified: { - check: "Date", + thumbnail: { + check: "String", nullable: true, - init: null, - event: "changeLastModified" + init: "" }, - trashedAt: { - check: "Date", - nullable: true, + groupType: { + check: ["me", "organization", "productEveryone", "everyone"], + nullable: false, init: null, }, }, diff --git a/services/static-webserver/client/source/class/osparc/store/Groups.js b/services/static-webserver/client/source/class/osparc/store/Groups.js index c5020fdc50e..5317fad8583 100644 --- a/services/static-webserver/client/source/class/osparc/store/Groups.js +++ b/services/static-webserver/client/source/class/osparc/store/Groups.js @@ -23,30 +23,36 @@ qx.Class.define("osparc.store.Groups", { this.base(arguments); this.groupsCached = []; + this.usersCached = []; }, properties: { - organizations: { - check: "Object", + everyoneGroup: { + check: "osparc.data.model.Group", init: {} }, - organizationMembers: { - check: "Object", + everyoneProductGroup: { + check: "osparc.data.model.Group", init: {} }, - reachableMembers: { - check: "Object", + organizations: { + check: "Array", + init: [] + }, + + meGroup: { + check: "osparc.data.model.Group", init: {} }, - everyoneProductGroup: { + organizationMembers: { check: "Object", init: {} }, - everyoneGroup: { + reachableMembers: { check: "Object", init: {} }, @@ -71,6 +77,7 @@ qx.Class.define("osparc.store.Groups", { members: { groupsCached: null, + usersCached: null, fetchGroups: function() { if (osparc.auth.Data.getInstance().isGuest()) { @@ -78,15 +85,58 @@ qx.Class.define("osparc.store.Groups", { resolve([]); }); } + const useCache = false; + return osparc.data.Resources.get("organizations", {}, useCache) + .then(resp => { + const everyoneGroup = new osparc.data.model.Group(resp["all"]).set({ + groupType: "everyone" + }); + const productEveryoneGroup = new osparc.data.model.Group(resp["product"]).set({ + groupType: "productEveryone" + }); + const meGroup = new osparc.data.model.Group(resp["me"]).set({ + groupType: "productEveryone" + }); + const orgs = []; + resp["organizations"].forEach(organization => { + const org = new osparc.data.model.Group(organization).set({ + groupType: "organization" + }); + orgs.push(org); + }); + this.setEveryoneGroup(everyoneGroup); + this.setEveryoneProductGroup(productEveryoneGroup); + this.setMeGroup(meGroup); + this.setOrganizations(orgs); + return orgs; + }); + }, - return osparc.data.Resources.getInstance().getAllPages("groups") - .then(groupsData => { - const groups = []; - groupsData.forEach(groupData => { - const group = this.__addToCache(groupData); - groups.push(group); + fetchAll: function() { + this.fetchGroups() + .then(orgs => { + const orgMembersPromises = []; + orgs.forEach(org => { + const params = { + url: { + gid: org.getGroupId() + } + }; + orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); }); - return groups; + Promise.all(orgMembersPromises) + .then(orgMemberss => { + const reachableMembers = this.getReachableMembers(); + orgMemberss.forEach(orgMembers => { + orgMembers.forEach(orgMember => { + orgMember["label"] = osparc.utils.Utils.firstsUp( + `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, + `${orgMember["last_name"] ? orgMember["last_name"] : ""}` + ); + reachableMembers[orgMember["gid"]] = orgMember; + }); + }); + }); }); }, @@ -167,40 +217,6 @@ qx.Class.define("osparc.store.Groups", { }); }, - getAllGroupsAndMembers: function() { - return new Promise(resolve => { - osparc.data.Resources.get("organizations") - .then(resp => { - this.setEveryoneGroup(resp["all"]); - this.setEveryoneProductGroup(resp["product"]); - const orgMembersPromises = []; - const orgs = resp["organizations"]; - orgs.forEach(org => { - const params = { - url: { - "gid": org["gid"] - } - }; - orgMembersPromises.push(osparc.data.Resources.get("organizationMembers", params)); - }); - Promise.all(orgMembersPromises) - .then(orgMemberss => { - const reachableMembers = this.getReachableMembers(); - orgMemberss.forEach(orgMembers => { - orgMembers.forEach(orgMember => { - orgMember["label"] = osparc.utils.Utils.firstsUp( - `${"first_name" in orgMember && orgMember["first_name"] != null ? orgMember["first_name"] : orgMember["login"]}`, - `${orgMember["last_name"] ? orgMember["last_name"] : ""}` - ); - reachableMembers[orgMember["gid"]] = orgMember; - }); - }); - resolve(); - }); - }); - }); - }, - getPotentialCollaborators: function(includeMe = false, includeProductEveryone = false) { return new Promise((resolve, reject) => { const promises = [];