Skip to content

Commit e85ab50

Browse files
committed
LicensedItemResource
1 parent 34221c4 commit e85ab50

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2025 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.data.model.LicensedItemResource", {
19+
extend: qx.core.Object,
20+
21+
/**
22+
* @param licensedItemResourceData {Object} Object containing the serialized LicensedItem Data
23+
*/
24+
construct: function(licensedItemResourceData) {
25+
this.base(arguments);
26+
27+
let description = licensedItemResourceData["description"] || "";
28+
let title = "";
29+
let subtitle = null;
30+
description = description.replace(/SPEAG/g, " "); // remove SPEAG substring
31+
const delimiter = " - ";
32+
let titleAndSubtitle = description.split(delimiter);
33+
if (titleAndSubtitle.length > 0) {
34+
title = titleAndSubtitle[0];
35+
titleAndSubtitle.shift();
36+
}
37+
if (titleAndSubtitle.length > 0) {
38+
subtitle = titleAndSubtitle.join(delimiter);
39+
}
40+
41+
const manufacturerData = {};
42+
if (licensedItemResourceData["thumbnail"]) {
43+
if (licensedItemResourceData["thumbnail"].includes("itis.swiss")) {
44+
manufacturerData["label"] = "IT'IS Foundation";
45+
manufacturerData["link"] = "https://itis.swiss/virtual-population/";
46+
manufacturerData["icon"] = "https://media.licdn.com/dms/image/v2/C4D0BAQE_FGa66IyvrQ/company-logo_200_200/company-logo_200_200/0/1631341490431?e=2147483647&v=beta&t=7f_IK-ArGjPrz-1xuWolAT4S2NdaVH-e_qa8hsKRaAc";
47+
} else if (licensedItemResourceData["thumbnail"].includes("speag.swiss")) {
48+
manufacturerData["label"] = "Speag";
49+
manufacturerData["link"] = "https://speag.swiss/products/em-phantoms/overview-2/";
50+
manufacturerData["icon"] = "https://media.licdn.com/dms/image/v2/D4E0BAQG2CYG28KAKbA/company-logo_200_200/company-logo_200_200/0/1700045977122/schmid__partner_engineering_ag_logo?e=2147483647&v=beta&t=6CZb1jjg5TnnzQWkrZBS9R3ebRKesdflg-_xYi4dwD8";
51+
}
52+
}
53+
54+
this.set({
55+
description: description,
56+
title: title,
57+
subtitle: subtitle,
58+
thumbnail: licensedItemResourceData.thumbnail || "",
59+
features: licensedItemResourceData.features || {},
60+
doi: licensedItemResourceData.doi || null,
61+
termsOfUseUrl: licensedItemResourceData.termsOfUseUrl || null,
62+
manufacturerLabel: manufacturerData.label || null,
63+
manufacturerLink: manufacturerData.link || null,
64+
manufacturerIcon: manufacturerData.icon || null,
65+
});
66+
},
67+
68+
properties: {
69+
description: {
70+
check: "String",
71+
nullable: false,
72+
init: null,
73+
event: "changeDescription",
74+
},
75+
76+
title: {
77+
check: "String",
78+
nullable: false,
79+
init: null,
80+
event: "changeTitle",
81+
},
82+
83+
subtitle: {
84+
check: "String",
85+
nullable: true,
86+
init: null,
87+
event: "changeSubtitle",
88+
},
89+
90+
thumbnail: {
91+
check: "String",
92+
nullable: false,
93+
init: null,
94+
event: "changeThumbnail",
95+
},
96+
97+
features: {
98+
check: "Object",
99+
nullable: false,
100+
init: null,
101+
event: "changeFeatures",
102+
},
103+
104+
doi: {
105+
check: "String",
106+
nullable: true,
107+
init: null,
108+
event: "changeDoi",
109+
},
110+
111+
termsOfUseUrl: {
112+
check: "String",
113+
nullable: true,
114+
init: null,
115+
event: "changeTermsOfUseUrl",
116+
},
117+
118+
manufacturerLabel: {
119+
check: "String",
120+
nullable: true,
121+
init: null,
122+
event: "changeManufacturerLabel",
123+
},
124+
125+
manufacturerLink: {
126+
check: "String",
127+
nullable: true,
128+
init: null,
129+
event: "changeManufacturerLink",
130+
},
131+
132+
manufacturerIcon: {
133+
check: "String",
134+
nullable: true,
135+
init: null,
136+
event: "changeManufacturerIcon",
137+
},
138+
},
139+
140+
statics: {
141+
addSeatsFromPurchases: function(licensedItemResources, purchases) {
142+
// reset seats
143+
Object.values(licensedItemResources).forEach(licensedItemResource => licensedItemResource.setSeats([]));
144+
// populate seats
145+
purchases.forEach(purchase => {
146+
const {
147+
key,
148+
version,
149+
} = purchase;
150+
Object.values(licensedItemResources).forEach(licensedItemResource => {
151+
if (licensedItemResource.getKey() === key && licensedItemResource.getVersion() <= version) {
152+
licensedItemResource.getSeats().push({
153+
licensedItemResourceId: purchase["licensedItemResourceId"],
154+
licensedItemResourcePurchaseId: purchase["licensedItemResourcePurchaseId"],
155+
numOfSeats: purchase["numOfSeats"],
156+
expireAt: new Date(purchase["expireAt"]),
157+
});
158+
}
159+
});
160+
})
161+
},
162+
163+
licensedResourceTitle: function(licensedResource) {
164+
const name = licensedResource["features"]["name"] || osparc.data.model.LicensedItem.extractNameFromDescription(licensedResource);
165+
const version = licensedResource["features"]["version"] || "";
166+
const functionality = licensedResource["features"]["functionality"] || "Static";
167+
return `${name} ${version}, ${functionality}`;
168+
},
169+
170+
extractNameFromDescription: function(licensedResource) {
171+
const description = licensedResource["description"] || "";
172+
const delimiter = " - ";
173+
let typeAndName = description.split(delimiter);
174+
if (typeAndName.length > 1) {
175+
// drop the type
176+
typeAndName.shift();
177+
// join the name
178+
typeAndName = typeAndName.join(delimiter);
179+
return typeAndName;
180+
}
181+
return "";
182+
},
183+
},
184+
185+
members: {
186+
}
187+
});

0 commit comments

Comments
 (0)