Skip to content

Commit 67beca2

Browse files
authored
TI: New Study -> New Plan (ITISFoundation#3197)
1 parent 5ead5b0 commit 67beca2

File tree

9 files changed

+140
-33
lines changed

9 files changed

+140
-33
lines changed

services/web/client/source/class/osparc/dashboard/Dashboard.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ qx.Class.define("osparc.dashboard.Dashboard", {
8989
const tabs = [{
9090
label: this.tr("STUDIES"),
9191
buildLayout: this.__createStudyBrowser
92-
}, {
93-
label: this.tr("TEMPLATES"),
94-
buildLayout: this.__createTemplateBrowser
95-
}, {
96-
label: this.tr("SERVICES"),
97-
buildLayout: this.__createServiceBrowser
9892
}];
93+
if (!osparc.utils.Utils.isProduct("tis")) {
94+
tabs.push({
95+
label: this.tr("TEMPLATES"),
96+
buildLayout: this.__createTemplateBrowser
97+
});
98+
}
99+
if (!osparc.utils.Utils.isProduct("tis")) {
100+
tabs.push({
101+
label: this.tr("SERVICES"),
102+
buildLayout: this.__createServiceBrowser
103+
});
104+
}
99105
if (!osparc.utils.Utils.isProduct("s4l")) {
100106
tabs.push({
101107
label: this.tr("DATA"),

services/web/client/source/class/osparc/dashboard/GridButtonNew.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ qx.Class.define("osparc.dashboard.GridButtonNew", {
3030
construct: function() {
3131
this.base(arguments);
3232

33-
this.__buildLayout();
33+
this._buildLayout();
3434
},
3535

3636
members: {
37-
__buildLayout: function() {
37+
_buildLayout: function() {
3838
const title = this.getChildControl("title");
3939
title.setValue(this.tr("Empty Study"));
4040

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2022 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.dashboard.GridButtonNewPlan", {
19+
extend: osparc.dashboard.GridButtonNew,
20+
21+
members: {
22+
_buildLayout: function() {
23+
const title = this.getChildControl("title");
24+
title.setValue(this.tr("New Plan"));
25+
26+
const desc = this.getChildControl("subtitle-text");
27+
desc.setValue(this.tr("Start a new plan").toString());
28+
29+
this.setIcon(osparc.dashboard.CardBase.NEW_ICON);
30+
}
31+
}
32+
});

services/web/client/source/class/osparc/dashboard/ListButtonNew.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ qx.Class.define("osparc.dashboard.ListButtonNew", {
2727
construct: function() {
2828
this.base(arguments);
2929

30-
this.__buildLayout();
30+
this._buildLayout();
3131
},
3232

3333
members: {
34-
__buildLayout: function() {
34+
_buildLayout: function() {
3535
const title = this.getChildControl("title");
3636
title.setValue(this.tr("Empty Study"));
3737

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2022 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.dashboard.ListButtonNewPlan", {
19+
extend: osparc.dashboard.ListButtonNew,
20+
21+
members: {
22+
_buildLayout: function() {
23+
const title = this.getChildControl("title");
24+
title.setValue(this.tr("New Plan"));
25+
26+
const desc = this.getChildControl("description");
27+
desc.setValue(this.tr("Start a new plan").toString());
28+
29+
this.setIcon(osparc.dashboard.CardBase.NEW_ICON);
30+
}
31+
}
32+
});

services/web/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
118118
osparc.data.Resources.fetch("studies", "getActive", params)
119119
.then(studyData => {
120120
if (studyData) {
121-
this._startStudy(studyData);
121+
this.__startStudy(studyData);
122122
} else {
123123
osparc.store.Store.getInstance().setCurrentStudyId(null);
124124
}
@@ -129,13 +129,39 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
129129
},
130130

131131
__createNewStudyButton: function(mode = "grid") {
132-
const newStudyBtn = this.__newStudyBtn = (mode === "grid") ? new osparc.dashboard.GridButtonNew() : new osparc.dashboard.ListButtonNew();
132+
const newStudyBtn = (mode === "grid") ? new osparc.dashboard.GridButtonNew() : new osparc.dashboard.ListButtonNew();
133133
newStudyBtn.subscribeToFilterGroup("searchBarFilter");
134134
osparc.utils.Utils.setIdToWidget(newStudyBtn, "newStudyBtn");
135-
newStudyBtn.addListener("execute", () => this.__createStudyBtnClkd());
135+
newStudyBtn.addListener("execute", () => this.__newStudyBtnClicked());
136+
if (this._resourcesContainer.getMode() === "list") {
137+
const width = this._resourcesContainer.getBounds().width - 15;
138+
newStudyBtn.setWidth(width);
139+
}
140+
if (osparc.utils.Utils.isProduct("tis")) {
141+
this.__replaceNewStudyWithNewPlanButton(mode);
142+
}
136143
return newStudyBtn;
137144
},
138145

146+
__replaceNewStudyWithNewPlanButton: function(mode = "grid") {
147+
osparc.data.Resources.get("templates")
148+
.then(templates => {
149+
// replace if a "TI Planning Tool" template exists
150+
const templateData = templates.find(t => t.name === "TI Planning Tool");
151+
if (templateData) {
152+
this._resourcesContainer.remove(this.__newStudyBtn);
153+
const newPlanButton = (mode === "grid") ? new osparc.dashboard.GridButtonNewPlan() : new osparc.dashboard.ListButtonNewPlan();
154+
newPlanButton.addListener("execute", () => this.__newPlanBtnClicked(templateData));
155+
this.__newStudyBtn = newPlanButton;
156+
if (this._resourcesContainer.getMode() === "list") {
157+
const width = this._resourcesContainer.getBounds().width - 15;
158+
newPlanButton.setWidth(width);
159+
}
160+
this._resourcesContainer.addAt(newPlanButton, 0);
161+
}
162+
});
163+
},
164+
139165
_createLayout: function() {
140166
this._createResourcesLayout("study");
141167

@@ -159,7 +185,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
159185

160186
osparc.utils.Utils.setIdToWidget(this._resourcesContainer, "studiesList");
161187

162-
const newStudyButton = this.__createNewStudyButton();
188+
const newStudyButton = this.__newStudyBtn = this.__createNewStudyButton();
163189
this._resourcesContainer.add(newStudyButton);
164190

165191
const loadingStudiesBtn = this._createLoadMoreButton("studiesLoading");
@@ -184,16 +210,12 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
184210
this._resetResourcesList();
185211

186212
const studyItems = this._resourcesContainer.getChildren();
187-
studyItems.forEach((studyItem, i) => {
213+
studyItems.forEach(studyItem => {
188214
if (!osparc.dashboard.ResourceBrowserBase.isCardButtonItem(studyItem)) {
189215
if (studyItem === this.__newStudyBtn) {
190216
this._resourcesContainer.remove(studyItem);
191-
const newBtn = this.__createNewStudyButton(this._resourcesContainer.getMode());
192-
this._resourcesContainer.addAt(newBtn, i);
193-
if (this._resourcesContainer.getMode() === "list") {
194-
const width = this._resourcesContainer.getBounds().width - 15;
195-
newBtn.setWidth(width);
196-
}
217+
const newBtn = this.__newStudyBtn = this.__createNewStudyButton(this._resourcesContainer.getMode());
218+
this._resourcesContainer.addAt(newBtn, 0);
197219
}
198220

199221
if (studyItem === this._loadingResourcesBtn) {
@@ -293,7 +315,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
293315
};
294316
osparc.data.Resources.getOne("studies", params)
295317
.then(studyData => {
296-
this._startStudy(studyData);
318+
this.__startStudy(studyData);
297319
})
298320
.catch(() => {
299321
const msg = this.tr("Study unavailable or inaccessible");
@@ -343,7 +365,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
343365
}, this);
344366
},
345367

346-
__createStudyBtnClkd: function() {
368+
__newStudyBtnClicked: function() {
347369
this.__newStudyBtn.setValue(false);
348370
const minStudyData = osparc.data.model.Study.createMyNewStudyObject();
349371
let title = minStudyData.name;
@@ -360,6 +382,20 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
360382
this.__createStudy(minStudyData, null);
361383
},
362384

385+
__newPlanBtnClicked: function(templateData) {
386+
this._showLoadingPage(this.tr("Creating ") + (templateData.name || this.tr("Study")));
387+
osparc.utils.Study.createStudyFromTemplate(templateData)
388+
.then(studyId => {
389+
this._hideLoadingPage();
390+
this.__getStudyAndStart(studyId);
391+
})
392+
.catch(err => {
393+
this._hideLoadingPage();
394+
osparc.component.message.FlashMessenger.getInstance().logAs(err.message, "ERROR");
395+
console.error(err);
396+
});
397+
},
398+
363399
__createStudy: function(minStudyData) {
364400
this._showLoadingPage(this.tr("Creating ") + (minStudyData.name || this.tr("Study")));
365401

@@ -369,14 +405,14 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
369405
osparc.data.Resources.fetch("studies", "post", params)
370406
.then(studyData => {
371407
this._hideLoadingPage();
372-
this._startStudy(studyData);
408+
this.__startStudy(studyData);
373409
})
374410
.catch(err => {
375411
console.error(err);
376412
});
377413
},
378414

379-
_startStudy: function(studyData, pageContext) {
415+
__startStudy: function(studyData, pageContext) {
380416
if (pageContext === undefined) {
381417
pageContext = osparc.data.model.Study.getUiMode(studyData) || "workbench";
382418
}
@@ -595,7 +631,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
595631

596632
if (!item.isMultiSelectionMode()) {
597633
const studyData = this.__getStudyData(item.getUuid(), false);
598-
this._startStudy(studyData);
634+
this.__startStudy(studyData);
599635
}
600636
},
601637

services/web/client/source/class/osparc/desktop/MainPage.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,12 @@ qx.Class.define("osparc.desktop.MainPage", {
183183
templateBrowser,
184184
serviceBrowser
185185
].forEach(browser => {
186-
browser.addListener("startStudy", e => {
187-
const startStudyData = e.getData();
188-
this.__startStudy(startStudyData);
189-
}, this);
186+
if (browser) {
187+
browser.addListener("startStudy", e => {
188+
const startStudyData = e.getData();
189+
this.__startStudy(startStudyData);
190+
}, this);
191+
}
190192
});
191193

192194
studyBrowser.addListener("updateTemplates", () => templateBrowser.reloadResources(), this);

services/web/client/source/class/osparc/navigation/BreadcrumbsSlideshow.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ qx.Class.define("osparc.navigation.BreadcrumbsSlideshow", {
8888
converter: output => osparc.utils.StatusUI.getIconSource(output),
8989
onUpdate: (source, target) => {
9090
const elem = target.getContentElement();
91-
const state = source.get(check);
92-
if (["busy", "starting", "pulling", "pending", "connecting"].includes(state)) {
91+
if (target.getSource() && target.getSource().includes("circle-notch")) {
9392
osparc.ui.basic.NodeStatusUI.addClass(elem, "rotate");
9493
} else {
9594
osparc.ui.basic.NodeStatusUI.removeClass(elem, "rotate");

services/web/client/source/class/osparc/ui/basic/NodeStatusUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ qx.Class.define("osparc.ui.basic.NodeStatusUI", {
141141
onUpdate: (source, target) => {
142142
const props = qx.util.PropertyUtil.getProperties(osparc.data.model.NodeStatus);
143143
const state = source.getInteractive();
144-
if (["starting", "pulling", "pending", "connecting"].includes(state)) {
144+
if (target.getSource() && target.getSource().includes("circle-notch")) {
145145
this.self().addClass(this.__icon.getContentElement(), "rotate");
146146
} else {
147147
this.self().removeClass(this.__icon.getContentElement(), "rotate");

0 commit comments

Comments
 (0)