Skip to content

Commit f9ec3a8

Browse files
authored
✨ Frontend TIP Feature: Pop up window with available new Plans (#5784)
1 parent 1388d44 commit f9ec3a8

File tree

21 files changed

+412
-150
lines changed

21 files changed

+412
-150
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ qx.Class.define("osparc.dashboard.GridButtonBase", {
182182
case "title-row":
183183
control = new qx.ui.container.Composite(new qx.ui.layout.VBox(6)).set({
184184
anonymous: true,
185-
maxWidth: this.self().ITEM_WIDTH - 20
185+
maxWidth: this.self().ITEM_WIDTH - 2*this.self().PADDING
186186
});
187187
layout = this.getChildControl("header");
188188
layout.addAt(control, 1, {
@@ -193,8 +193,7 @@ qx.Class.define("osparc.dashboard.GridButtonBase", {
193193
control = new qx.ui.basic.Label().set({
194194
textColor: "contrasted-text-light",
195195
font: "text-14",
196-
maxWidth: this.self().ITEM_WIDTH,
197-
width: this.self().ITEM_WIDTH - 50,
196+
maxWidth: this.self().ITEM_WIDTH - 2*this.self().PADDING,
198197
maxHeight: this.self().TITLE_MAX_HEIGHT
199198
});
200199
layout = this.getChildControl("title-row");
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2024 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.NewStudies", {
19+
extend: qx.ui.core.Widget,
20+
21+
construct: function(newStudies) {
22+
this.base(arguments);
23+
24+
this.__newStudies = newStudies;
25+
26+
this._setLayout(new qx.ui.layout.VBox(10));
27+
28+
const flatList = this.__flatList = new osparc.dashboard.ToggleButtonContainer();
29+
[
30+
"changeSelection",
31+
"changeVisibility"
32+
].forEach(signalName => {
33+
flatList.addListener(signalName, e => this.fireDataEvent(signalName, e.getData()), this);
34+
});
35+
this._add(this.__flatList);
36+
37+
this.__groupedContainers = [];
38+
},
39+
40+
properties: {
41+
mode: {
42+
check: ["grid", "list"],
43+
init: "grid",
44+
nullable: false,
45+
event: "changeMode",
46+
apply: "reloadCards"
47+
},
48+
49+
groupBy: {
50+
check: [null, "category"],
51+
init: null,
52+
nullable: true
53+
}
54+
},
55+
56+
events: {
57+
"newStudyClicked": "qx.event.type.Data"
58+
},
59+
60+
members: {
61+
__newStudies: null,
62+
__flatList: null,
63+
__groupedContainers: null,
64+
65+
reloadCards: function(listId) {
66+
this.__cleanAll();
67+
68+
if (this.getGroupBy()) {
69+
const noGroupContainer = this.__createGroupContainer("no-group", "No Group", "transparent");
70+
this._add(noGroupContainer);
71+
72+
const categories = new Set([]);
73+
this.__newStudies.forEach(newStudy => newStudy.category && categories.add(newStudy.category));
74+
Array.from(categories).forEach(category => {
75+
const groupContainer = this.__createGroupContainer(category, qx.lang.String.firstUp(category), "transparent");
76+
this._add(groupContainer);
77+
});
78+
} else {
79+
const flatList = this.__flatList = new osparc.dashboard.ToggleButtonContainer();
80+
osparc.utils.Utils.setIdToWidget(flatList, listId);
81+
[
82+
"changeSelection",
83+
"changeVisibility"
84+
].forEach(signalName => {
85+
flatList.addListener(signalName, e => this.fireDataEvent(signalName, e.getData()), this);
86+
});
87+
const spacing = this.getMode() === "grid" ? osparc.dashboard.GridButtonBase.SPACING : osparc.dashboard.ListButtonBase.SPACING;
88+
this.__flatList.getLayout().set({
89+
spacingX: spacing,
90+
spacingY: spacing
91+
});
92+
this._add(this.__flatList);
93+
}
94+
95+
let cards = [];
96+
this.__newStudies.forEach(resourceData => {
97+
Array.prototype.push.apply(cards, this.__resourceToCards(resourceData));
98+
});
99+
return cards;
100+
},
101+
102+
__resourceToCards: function(resourceData) {
103+
const cards = [];
104+
if (this.getGroupBy() === "category") {
105+
this.__groupByCategory(cards, resourceData);
106+
} else {
107+
const card = this.__createCard(resourceData);
108+
cards.push(card);
109+
this.__flatList.add(card);
110+
}
111+
return cards;
112+
},
113+
114+
__groupByCategory: function(cards, resourceData) {
115+
const card = this.__createCard(resourceData);
116+
const groupContainer = this.__getGroupContainer(resourceData.category);
117+
if (groupContainer) {
118+
groupContainer.add(card);
119+
} else {
120+
let noGroupContainer = this.__getGroupContainer("no-group");
121+
noGroupContainer.add(card);
122+
}
123+
cards.push(card);
124+
},
125+
126+
__createGroupContainer: function(groupId, headerLabel, headerColor = "text") {
127+
const groupContainer = new osparc.dashboard.GroupedToggleButtonContainer().set({
128+
groupId: groupId.toString(),
129+
headerLabel,
130+
headerIcon: "",
131+
headerColor,
132+
visibility: "excluded"
133+
});
134+
const atom = groupContainer.getChildControl("header");
135+
atom.setFont("text-16");
136+
this.__groupedContainers.push(groupContainer);
137+
return groupContainer;
138+
},
139+
140+
__getGroupContainer: function(gid) {
141+
const idx = this.__groupedContainers.findIndex(groupContainer => groupContainer.getGroupId() === gid.toString());
142+
if (idx > -1) {
143+
return this.__groupedContainers[idx];
144+
}
145+
return null;
146+
},
147+
148+
__createCard: function(templateInfo) {
149+
const title = templateInfo.title;
150+
const desc = templateInfo.description;
151+
const mode = this.getMode();
152+
const newPlanButton = (mode === "grid") ? new osparc.dashboard.GridButtonNew(title, desc) : new osparc.dashboard.ListButtonNew(title, desc);
153+
newPlanButton.setCardKey(templateInfo.idToWidget);
154+
osparc.utils.Utils.setIdToWidget(newPlanButton, templateInfo.idToWidget);
155+
if (this.getMode() === "list") {
156+
const width = this.getBounds().width - 15;
157+
newPlanButton.setWidth(width);
158+
}
159+
newPlanButton.addListener("execute", () => this.fireDataEvent("newStudyClicked", templateInfo))
160+
return newPlanButton;
161+
},
162+
163+
__cleanAll: function() {
164+
if (this.__flatList) {
165+
this.__flatList.removeAll();
166+
this.__flatList = null;
167+
}
168+
this.__groupedContainers.forEach(groupedContainer => groupedContainer.getContentContainer().removeAll());
169+
this.__groupedContainers = [];
170+
this._removeAll();
171+
},
172+
173+
__moveNoGroupToLast: function() {
174+
const idx = this._getChildren().findIndex(grpContainer => grpContainer === this.__getGroupContainer("no-group"));
175+
if (idx > -1) {
176+
this._getChildren().push(this._getChildren().splice(idx, 1)[0]);
177+
}
178+
}
179+
}
180+
});

0 commit comments

Comments
 (0)