Skip to content

Commit ba45277

Browse files
odeimaizgiancarloromeomergify[bot]
authored
🎨 [Frontend] Functions browser: connect FE to BE (ITISFoundation#8135)
Co-authored-by: Giancarlo Romeo <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 633f3c1 commit ba45277

File tree

12 files changed

+361
-213
lines changed

12 files changed

+361
-213
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ qx.Class.define("osparc.dashboard.CardBase", {
228228
this.addHintFromGids(shareIcon, gids);
229229
},
230230

231+
populateMyAccessRightsIcon: function(shareIcon, myAccessRights) {
232+
const canIWrite = Boolean(myAccessRights["write"]);
233+
shareIcon.set({
234+
source: canIWrite ? osparc.dashboard.CardBase.SHARE_ICON : osparc.dashboard.CardBase.SHARED_USER,
235+
toolTipText: canIWrite ? "" : qx.locale.Manager.tr("Shared"),
236+
});
237+
},
238+
231239
addHintFromGids: function(icon, gids) {
232240
const groupsStore = osparc.store.Groups.getInstance();
233241
const groupEveryone = groupsStore.getEveryoneGroup();
@@ -524,6 +532,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
524532

525533
__applyResourceData: function(resourceData) {
526534
let uuid = null;
535+
let title = "";
527536
let owner = null;
528537
let workbench = null;
529538
let defaultHits = null;
@@ -534,16 +543,19 @@ qx.Class.define("osparc.dashboard.CardBase", {
534543
case "tutorial":
535544
case "hypertool":
536545
uuid = resourceData.uuid ? resourceData.uuid : null;
546+
title = resourceData.name,
537547
owner = resourceData.prjOwner ? resourceData.prjOwner : "";
538548
workbench = resourceData.workbench ? resourceData.workbench : {};
539549
break;
540550
case "function":
541551
uuid = resourceData.uuid ? resourceData.uuid : null;
552+
title = resourceData.title,
542553
owner = "";
543554
workbench = resourceData.workbench ? resourceData.workbench : {};
544555
break;
545556
case "service":
546557
uuid = resourceData.key ? resourceData.key : null;
558+
title = resourceData.name,
547559
owner = resourceData.owner ? resourceData.owner : resourceData.contact;
548560
icon = resourceData["icon"] || osparc.dashboard.CardBase.PRODUCT_ICON;
549561
defaultHits = 0;
@@ -553,7 +565,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
553565
this.set({
554566
resourceType: resourceData.resourceType,
555567
uuid,
556-
title: resourceData.name,
568+
title,
557569
description: resourceData.description,
558570
owner,
559571
accessRights: resourceData.accessRights ? resourceData.accessRights : {},
@@ -593,7 +605,11 @@ qx.Class.define("osparc.dashboard.CardBase", {
593605
break;
594606
}
595607
case "function":
596-
this.setIcon(osparc.data.model.StudyUI.PIPELINE_ICON);
608+
if (resourceData["functionClass"] === osparc.data.model.Function.FUNCTION_CLASS.PROJECT) {
609+
this.setIcon(osparc.data.model.StudyUI.PIPELINE_ICON);
610+
} else {
611+
this.setIcon(osparc.dashboard.CardBase.PRODUCT_ICON);
612+
}
597613
break;
598614
}
599615
},

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,33 @@ qx.Class.define("osparc.dashboard.GridButtonItem", {
249249
// overridden
250250
_applyOwner: function(value, old) {
251251
const label = this.getChildControl("subtitle-text");
252-
const user = this.__createOwner(value);
253-
label.setValue(user);
254-
label.setVisibility(value ? "visible" : "excluded");
252+
if (osparc.utils.Resources.isFunction(this.getResourceData())) {
253+
const canIWrite = Boolean(this.getResourceData()["accessRights"]["write"]);
254+
label.setValue(canIWrite ? "My Function" : "Read Only");
255+
} else {
256+
const user = this.__createOwner(value);
257+
label.setValue(user);
258+
label.setVisibility(value ? "visible" : "excluded");
259+
}
255260
},
256261

257262
_applyAccessRights: function(value) {
258263
if (value && Object.keys(value).length) {
259264
const shareIcon = this.getChildControl("subtitle-icon");
260-
shareIcon.addListener("tap", e => {
261-
e.stopPropagation();
262-
this.openAccessRights();
263-
}, this);
264-
shareIcon.addListener("pointerdown", e => e.stopPropagation());
265-
osparc.dashboard.CardBase.populateShareIcon(shareIcon, value);
265+
if (this.isResourceType("function")) {
266+
// in case of functions, the access rights are actually myAccessRights
267+
osparc.dashboard.CardBase.populateMyAccessRightsIcon(shareIcon, value);
268+
} else {
269+
shareIcon.addListener("tap", e => {
270+
e.stopPropagation();
271+
this.openAccessRights();
272+
}, this);
273+
shareIcon.addListener("pointerdown", e => e.stopPropagation());
274+
osparc.dashboard.CardBase.populateShareIcon(shareIcon, value);
266275

267-
if (this.isResourceType("study")) {
268-
this._setStudyPermissions(value);
276+
if (this.isResourceType("study")) {
277+
this._setStudyPermissions(value);
278+
}
269279
}
270280
}
271281
},

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,34 @@ qx.Class.define("osparc.dashboard.ListButtonItem", {
243243

244244
_applyOwner: function(value, old) {
245245
const label = this.getChildControl("owner");
246-
const user = this.__createOwner(value);
247-
label.setValue(user);
246+
if (osparc.utils.Resources.isFunction(this.getResourceData())) {
247+
const canIWrite = Boolean(this.getResourceData()["accessRights"]["write"]);
248+
label.setValue(canIWrite ? "My Function" : "Read Only");
249+
} else {
250+
const user = this.__createOwner(value);
251+
label.setValue(user);
252+
}
248253

249254
this.__makeItemResponsive(label);
250255
},
251256

252257
_applyAccessRights: function(value) {
253258
if (value && Object.keys(value).length) {
254259
const shareIcon = this.getChildControl("shared-icon");
255-
shareIcon.addListener("tap", e => {
256-
e.stopPropagation();
257-
this.openAccessRights();
258-
}, this);
259-
shareIcon.addListener("pointerdown", e => e.stopPropagation());
260-
osparc.dashboard.CardBase.populateShareIcon(shareIcon, value);
260+
if (this.isResourceType("function")) {
261+
// in case of functions, the access rights are actually myAccessRights
262+
osparc.dashboard.CardBase.populateMyAccessRightsIcon(shareIcon, value);
263+
} else {
264+
shareIcon.addListener("tap", e => {
265+
e.stopPropagation();
266+
this.openAccessRights();
267+
}, this);
268+
shareIcon.addListener("pointerdown", e => e.stopPropagation());
269+
osparc.dashboard.CardBase.populateShareIcon(shareIcon, value);
261270

262-
if (this.isResourceType("study")) {
263-
this._setStudyPermissions(value);
271+
if (this.isResourceType("study")) {
272+
this._setStudyPermissions(value);
273+
}
264274
}
265275
}
266276
},

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
6666
const studyStore = osparc.store.Study.getInstance();
6767
this.__resourceData["debt"] = studyStore.getStudyDebt(this.__resourceData["uuid"]);
6868
}
69+
// prefetch project's services metadata
6970
osparc.store.Services.getStudyServicesMetadata(latestResourceData)
7071
.finally(() => {
7172
this.__resourceModel = new osparc.data.model.Study(latestResourceData);
@@ -75,15 +76,25 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
7576
});
7677
break;
7778
case "function": {
78-
// use function's underlying template info to fetch services metadata
79-
// osparc.store.Templates.fetchTemplate(resourceData["uuid"]);
80-
osparc.store.Services.getStudyServicesMetadata(latestResourceData)
81-
.finally(() => {
82-
this.__resourceModel = new osparc.data.model.Function(latestResourceData);
83-
this.__resourceModel["resourceType"] = resourceData["resourceType"];
84-
this.__resourceData["services"] = resourceData["services"];
85-
this.__addPages();
86-
});
79+
addPages = (functionData, templateData = null) => {
80+
this.__resourceModel = new osparc.data.model.Function(functionData, templateData);
81+
this.__resourceModel["resourceType"] = resourceData["resourceType"];
82+
this.__addPages();
83+
}
84+
if (resourceData["functionClass"] === osparc.data.model.Function.FUNCTION_CLASS.PROJECT) {
85+
// this is only required for functions that have a template linked
86+
osparc.store.Templates.fetchTemplate(resourceData["templateId"])
87+
.then(templateData => {
88+
// prefetch function's underlying template's services metadata
89+
osparc.store.Services.getStudyServicesMetadata(templateData)
90+
.finally(() => {
91+
this.__resourceData["services"] = resourceData["services"];
92+
addPages(latestResourceData, templateData);
93+
});
94+
});
95+
} else {
96+
addPages(latestResourceData);
97+
}
8798
break;
8899
}
89100
case "service": {
@@ -121,7 +132,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
121132

122133
popUpInWindow: function(resourceData) {
123134
const resourceDetails = new osparc.dashboard.ResourceDetails(resourceData);
124-
const title = resourceData.name;
135+
const title = resourceData.name || resourceData.title; // title is used by functions
125136
const window = osparc.ui.window.Window.popUpInWindow(resourceDetails, title, this.WIDTH, this.HEIGHT).set({
126137
layout: new qx.ui.layout.Grow(),
127138
...osparc.ui.window.TabbedWindow.DEFAULT_PROPS,
@@ -173,7 +184,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
173184
__addToolbarButtons: function(page) {
174185
const resourceData = this.__resourceData;
175186

176-
if (this.__resourceData["resourceType"] === "function") {
187+
if (osparc.utils.Resources.isFunction(this.__resourceData)) {
177188
return; // no toolbar buttons for functions
178189
}
179190

@@ -395,10 +406,11 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
395406
this.__addPreviewPage();
396407
this.fireEvent("pagesAdded");
397408
return;
398-
} else if (this.__resourceData["resourceType"] === "function") {
409+
} else if (osparc.utils.Resources.isFunction(this.__resourceData)) {
399410
this.__addInfoPage();
400-
// to build the preview page we need the underlying template data
401-
// this.__addPreviewPage();
411+
if (this.__resourceModel.getFunctionClass() === osparc.data.model.Function.FUNCTION_CLASS.PROJECT) {
412+
this.__addPreviewPage();
413+
}
402414
this.fireEvent("pagesAdded");
403415
return;
404416
}
@@ -575,12 +587,12 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
575587
const page = new osparc.dashboard.resources.pages.BasePage(title, iconSrc, id);
576588
this.__addToolbarButtons(page);
577589

578-
const studyData = this.__resourceData;
590+
const studyData = osparc.utils.Resources.isFunction(this.__resourceData) ? this.__resourceModel.getTemplate().serialize() : this.__resourceData;
579591
const enabled = osparc.study.Utils.canShowPreview(studyData);
580592
page.setEnabled(enabled);
581593

582594
const lazyLoadContent = () => {
583-
const resourceModel = this.__resourceModel;
595+
const resourceModel = osparc.utils.Resources.isFunction(this.__resourceData) ? this.__resourceModel.getTemplate() : this.__resourceData;
584596
const preview = new osparc.study.StudyPreview(resourceModel);
585597
page.addToContent(preview);
586598
this.__widgets.push(preview);

services/static-webserver/client/source/class/osparc/data/Permissions.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,6 @@ qx.Class.define("osparc.data.Permissions", {
310310
return false;
311311
}
312312

313-
// This needs to be provided by the backend
314-
if (action === "readFunctions") {
315-
return osparc.utils.Utils.isDevelopmentPlatform();
316-
}
317-
318313
if (
319314
this.__functionPermissions &&
320315
action in this.__functionPermissions

services/static-webserver/client/source/class/osparc/data/Resources.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,22 @@ qx.Class.define("osparc.data.Resources", {
628628
"functions": {
629629
useCache: false,
630630
endpoints: {
631-
create: {
632-
method: "POST",
633-
url: statics.API + "/functions"
634-
},
635631
getOne: {
636632
method: "GET",
637633
url: statics.API + "/functions/{functionId}?include_extras=true"
638634
},
639635
getPage: {
640636
method: "GET",
641-
url: statics.API + "/functions?include_extras=true"
642-
}
637+
url: statics.API + "/functions?include_extras=true&offset={offset}&limit={limit}"
638+
},
639+
create: {
640+
method: "POST",
641+
url: statics.API + "/functions"
642+
},
643+
patch: {
644+
method: "PATCH",
645+
url: statics.API + "/functions/{functionId}?include_extras=true"
646+
},
643647
}
644648
},
645649
/*

0 commit comments

Comments
 (0)