Skip to content

Commit 118b972

Browse files
committed
unique names
1 parent 1a1ae8e commit 118b972

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
11691169
__newStudyBtnClicked: function(button) {
11701170
button.setValue(false);
11711171
const minStudyData = osparc.data.model.Study.createMinStudyObject();
1172-
const title = osparc.utils.Utils.getUniqueName(minStudyData.name, this._resourcesList);
1172+
const existingNames = this._resourcesList.map(study => study["name"]);
1173+
const title = osparc.utils.Utils.getUniqueName(minStudyData.name, existingNames);
11731174
minStudyData["name"] = title;
11741175
minStudyData["workspaceId"] = this.getCurrentWorkspaceId();
11751176
minStudyData["folderId"] = this.getCurrentFolderId();
@@ -1189,7 +1190,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
11891190
__newPlanBtnClicked: function(templateData, newStudyName) {
11901191
// do not override cached template data
11911192
const templateCopyData = osparc.utils.Utils.deepCloneObject(templateData);
1192-
const title = osparc.utils.Utils.getUniqueName(newStudyName, this._resourcesList);
1193+
const existingNames = this._resourcesList.map(study => study["name"]);
1194+
const title = osparc.utils.Utils.getUniqueName(newStudyName, existingNames);
11931195
templateCopyData.name = title;
11941196
this._showLoadingPage(this.tr("Creating ") + (newStudyName || osparc.product.Utils.getStudyAlias()));
11951197
const contextProps = {

services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationDetails.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,8 @@ qx.Class.define("osparc.desktop.organizations.OrganizationDetails", {
9494

9595
__openEditOrganization: function() {
9696
const org = this.__orgModel;
97-
98-
const newOrg = false;
99-
const orgEditor = new osparc.editor.OrganizationEditor(newOrg);
100-
org.bind("gid", orgEditor, "gid");
101-
org.bind("label", orgEditor, "label");
102-
org.bind("description", orgEditor, "description");
103-
org.bind("thumbnail", orgEditor, "thumbnail", {
104-
converter: val => val ? val : ""
105-
});
10697
const title = this.tr("Organization Details Editor");
98+
const orgEditor = new osparc.editor.OrganizationEditor(org);
10799
const win = osparc.ui.window.Window.popUpInWindow(orgEditor, title, 400, 200);
108100
orgEditor.addListener("updateOrg", () => {
109101
this.__updateOrganization(win, orgEditor.getChildControl("save"), orgEditor);

services/static-webserver/client/source/class/osparc/desktop/organizations/OrganizationsList.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", {
9999
allowGrowX: false
100100
});
101101
createOrgBtn.addListener("execute", function() {
102-
const newOrg = true;
103-
const orgEditor = new osparc.editor.OrganizationEditor(newOrg);
104102
const title = this.tr("New Organization");
103+
const orgEditor = new osparc.editor.OrganizationEditor();
105104
const win = osparc.ui.window.Window.popUpInWindow(orgEditor, title, 400, 200);
106105
orgEditor.addListener("createOrg", () => {
107106
this.__createOrganization(win, orgEditor.getChildControl("create"), orgEditor);
@@ -211,15 +210,8 @@ qx.Class.define("osparc.desktop.organizations.OrganizationsList", {
211210
return;
212211
}
213212

214-
const newOrg = false;
215-
const orgEditor = new osparc.editor.OrganizationEditor(newOrg);
216-
org.bind("gid", orgEditor, "gid");
217-
org.bind("label", orgEditor, "label");
218-
org.bind("description", orgEditor, "description");
219-
org.bind("thumbnail", orgEditor, "thumbnail", {
220-
converter: val => val ? val : ""
221-
});
222213
const title = this.tr("Organization Details Editor");
214+
const orgEditor = new osparc.editor.OrganizationEditor(org);
223215
const win = osparc.ui.window.Window.popUpInWindow(orgEditor, title, 400, 200);
224216
orgEditor.addListener("updateOrg", () => {
225217
this.__updateOrganization(win, orgEditor.getChildControl("save"), orgEditor);

services/static-webserver/client/source/class/osparc/editor/OrganizationEditor.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
qx.Class.define("osparc.editor.OrganizationEditor", {
1919
extend: qx.ui.core.Widget,
2020

21-
construct: function(newOrg = true) {
21+
construct: function(organization) {
2222
this.base(arguments);
2323

2424
this._setLayout(new qx.ui.layout.VBox(8));
@@ -29,7 +29,27 @@ qx.Class.define("osparc.editor.OrganizationEditor", {
2929
manager.add(title);
3030
this.getChildControl("description");
3131
this.getChildControl("thumbnail");
32-
newOrg ? this.getChildControl("create") : this.getChildControl("save");
32+
organization ? this.getChildControl("save") : this.getChildControl("create");
33+
34+
if (organization) {
35+
organization.bind("gid", this, "gid");
36+
organization.bind("label", this, "label");
37+
organization.bind("description", this, "description");
38+
organization.bind("thumbnail", this, "thumbnail", {
39+
converter: val => val ? val : ""
40+
});
41+
} else {
42+
osparc.store.Store.getInstance().getGroupsOrganizations()
43+
.then(orgs => {
44+
const existingNames = orgs.map(org => org["label"]);
45+
const defaultName = osparc.utils.Utils.getUniqueName("New Organization", existingNames)
46+
title.setValue(defaultName);
47+
})
48+
.catch(err => {
49+
console.error(err);
50+
title.setValue("New Organization");
51+
});
52+
}
3353

3454
this.addListener("appear", () => {
3555
title.focus();

services/static-webserver/client/source/class/osparc/editor/WorkspaceEditor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,16 @@ qx.Class.define("osparc.editor.WorkspaceEditor", {
197197
},
198198

199199
__createWorkspace: function() {
200+
const workspaceStore = osparc.store.Workspaces.getInstance();
201+
const workspaces = workspaceStore.getWorkspaces();
202+
const existingNames = workspaces.map(workspace => workspace.getName());
203+
const defaultName = osparc.utils.Utils.getUniqueName("New Workspace", existingNames)
200204
const newWorkspaceData = {
201-
name: this.getLabel() || "New Workspace",
205+
name: this.getLabel() || defaultName,
202206
description: this.getDescription(),
203207
thumbnail: this.getThumbnail(),
204208
};
205-
return osparc.store.Workspaces.getInstance().postWorkspace(newWorkspaceData)
209+
return workspaceStore.postWorkspace(newWorkspaceData)
206210
},
207211

208212
__saveWorkspace: function(editButton) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ qx.Class.define("osparc.store.Workspaces", {
197197
return this.workspacesCached.find(w => w.getWorkspaceId() === workspaceId);
198198
},
199199

200+
getWorkspaces: function() {
201+
return this.workspacesCached;
202+
},
203+
200204
__addToCache: function(workspace) {
201205
const found = this.workspacesCached.find(w => w.getWorkspaceId() === workspace.getWorkspaceId());
202206
if (!found) {

services/static-webserver/client/source/class/osparc/study/Utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ qx.Class.define("osparc.study.Utils", {
116116
newStudyLabel = metadata["name"];
117117
}
118118
if (existingStudies) {
119-
const title = osparc.utils.Utils.getUniqueName(newStudyLabel, existingStudies);
119+
const existingNames = existingStudies.map(study => study["name"]);
120+
const title = osparc.utils.Utils.getUniqueName(newStudyLabel, existingNames);
120121
minStudyData["name"] = title;
121122
} else {
122123
minStudyData["name"] = newStudyLabel;

services/static-webserver/client/source/class/osparc/utils/Utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,11 @@ qx.Class.define("osparc.utils.Utils", {
277277
return reloadButton;
278278
},
279279

280-
getUniqueName: function(preferredName, list, key = "name") {
280+
getUniqueName: function(preferredName, existingNames) {
281281
let title = preferredName;
282-
const existingTitles = list.map(study => study[key]);
283-
if (existingTitles.includes(title)) {
282+
if (existingNames.includes(title)) {
284283
let cont = 1;
285-
while (existingTitles.includes(`${title} (${cont})`)) {
284+
while (existingNames.includes(`${title} (${cont})`)) {
286285
cont++;
287286
}
288287
title += ` (${cont})`;

0 commit comments

Comments
 (0)