Skip to content

Commit e32e933

Browse files
authored
🎨 [Frontend] Filter and patch template types (#7690)
1 parent e888734 commit e32e933

File tree

25 files changed

+372
-240
lines changed

25 files changed

+372
-240
lines changed

.eslintignore

Lines changed: 0 additions & 7 deletions
This file was deleted.

eslint.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
ignores: [
3+
"services/static-webserver/client/source/resource/",
4+
"services/static-webserver/client/source-output/",
5+
]
6+
};

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ qx.Class.define("osparc.dashboard.AppBrowser", {
4545
this._resourcesList = [];
4646
Promise.all([
4747
osparc.store.Services.getServicesLatest(),
48-
osparc.store.Templates.getTemplatesHypertools(),
48+
osparc.store.Templates.getHypertools(),
4949
])
5050
.then(resps => {
5151
const services = resps[0];
@@ -67,9 +67,9 @@ qx.Class.define("osparc.dashboard.AppBrowser", {
6767
});
6868
},
6969

70-
reloadResources: function() {
70+
reloadResources: function(useCache = true) {
7171
this.__loadServices();
72-
this.__loadHypertools();
72+
this.__loadHypertools(useCache);
7373
},
7474

7575
__loadServices: function() {
@@ -83,8 +83,8 @@ qx.Class.define("osparc.dashboard.AppBrowser", {
8383
});
8484
},
8585

86-
__loadHypertools: function() {
87-
osparc.store.Templates.getTemplatesHypertools()
86+
__loadHypertools: function(useCache = true) {
87+
osparc.store.Templates.getHypertools(useCache)
8888
.then(hypertoolsList => {
8989
hypertoolsList.forEach(hypertool => hypertool["resourceType"] = "hypertool");
9090
this._resourcesList.push(...hypertoolsList.filter(hypertool => hypertool !== null));

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ qx.Class.define("osparc.dashboard.CardBase", {
162162
},
163163

164164
filterAppType: function(resourceType, metadata, appType) {
165-
if (appType && ["service", "hypertool"].includes(resourceType)) {
166-
if (metadata && metadata.type) {
167-
const matches = metadata.type === appType;
165+
if (appType) {
166+
if (resourceType === "service" && metadata && metadata.type) {
167+
const matches = (metadata.type === appType);
168+
return !matches;
169+
} else if (resourceType === "hypertool") {
170+
const matches = (resourceType === appType);
168171
return !matches;
169172
}
170173
return false;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
188188
},
189189

190190
__addHypertools: function() {
191-
osparc.store.Templates.getTemplatesHypertools()
191+
osparc.store.Templates.getHypertools()
192192
.then(hypertools => {
193193
if (hypertools.length) {
194194
const hypertoolsMenuButton = this.self().createMenuButton("@FontAwesome5Solid/star/16", this.tr("Hypertools"));
@@ -321,14 +321,14 @@ qx.Class.define("osparc.dashboard.NewPlusMenu", {
321321
},
322322

323323
__addFromTemplateButton: function(buttonConfig) {
324-
osparc.store.Templates.getTemplates()
325-
.then(templates => {
324+
osparc.store.Templates.getHypertools()
325+
.then(hypertools => {
326326
const menuButton = this.self().createMenuButton(null, buttonConfig["title"]);
327327
osparc.utils.Utils.setIdToWidget(menuButton, buttonConfig["idToWidget"]);
328328
// disable it until found in templates store
329329
menuButton.setEnabled(false);
330330

331-
let templateMetadata = templates.find(t => t.name === buttonConfig["expectedTemplateLabel"]);
331+
let templateMetadata = hypertools.find(t => t.name === buttonConfig["expectedTemplateLabel"]);
332332
if (templateMetadata) {
333333
menuButton.setEnabled(true);
334334
menuButton.addListener("tap", () => {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ qx.Class.define("osparc.dashboard.NewStudies", {
3636
});
3737
this._add(this.__flatList);
3838

39-
osparc.store.Templates.getTemplates()
40-
.then(templates => {
39+
osparc.store.Templates.getHypertools()
40+
.then(hypertools => {
4141
this.__newStudies = newButtonsInfo.filter(newButtonInfo => {
4242
if (newButtonInfo.showDisabled) {
4343
return true;
4444
}
45-
return templates.find(t => t.name === newButtonInfo.expectedTemplateLabel);
45+
return hypertools.find(t => t.name === newButtonInfo.expectedTemplateLabel);
4646
});
4747

4848
this.setGroupBy("category");

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

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,55 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
482482
}
483483
},
484484

485+
taskToTemplateReceived: function(task, studyName, templateType) {
486+
const toTemplateTaskUI = new osparc.task.ToTemplate(studyName);
487+
toTemplateTaskUI.setTask(task);
488+
489+
osparc.task.TasksContainer.getInstance().addTaskUI(toTemplateTaskUI);
490+
491+
const cardTitle = this.tr("Publishing ") + studyName;
492+
const toTemplateCard = this._addTaskCard(task, cardTitle, osparc.task.ToTemplate.ICON);
493+
if (toTemplateCard) {
494+
this.__attachToTemplateEventHandler(task, toTemplateCard, templateType);
495+
}
496+
},
497+
498+
__attachToTemplateEventHandler: function(task, toTemplateCard, templateType) {
499+
const finished = () => {
500+
this._resourcesContainer.removeNonResourceCard(toTemplateCard);
501+
};
502+
503+
task.addListener("updateReceived", e => {
504+
const updateData = e.getData();
505+
if ("task_progress" in updateData && toTemplateCard) {
506+
const taskProgress = updateData["task_progress"];
507+
toTemplateCard.getChildControl("progress-bar").set({
508+
value: osparc.data.PollTask.extractProgress(updateData) * 100
509+
});
510+
toTemplateCard.getChildControl("state-label").set({
511+
value: taskProgress["message"]
512+
});
513+
}
514+
}, this);
515+
task.addListener("resultReceived", e => {
516+
finished();
517+
this.reloadResources();
518+
const userFriendlyType = templateType.charAt(0).toUpperCase() + templateType.slice(1).toLowerCase();
519+
const msg = userFriendlyType + this.tr(" created");
520+
osparc.FlashMessenger.logAs(msg, "INFO");
521+
});
522+
task.addListener("taskAborted", () => {
523+
finished();
524+
const msg = this.tr("Study to Template cancelled");
525+
osparc.FlashMessenger.logAs(msg, "WARNING");
526+
});
527+
task.addListener("pollingError", e => {
528+
finished();
529+
const err = e.getData();
530+
osparc.FlashMessenger.logError(err);
531+
});
532+
},
533+
485534
_addTaskCard: function(task, cardTitle, cardIcon) {
486535
if (!this._resourcesContainer) {
487536
return null;
@@ -531,7 +580,12 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
531580
},
532581

533582
_updateTemplateData: function(templateData) {
534-
throw new Error("Abstract method called!");
583+
const templatesList = this._resourcesList;
584+
const index = templatesList.findIndex(template => template["uuid"] === templateData["uuid"]);
585+
if (index !== -1) {
586+
templatesList[index] = templateData;
587+
this._reloadCards();
588+
}
535589
},
536590

537591
_updateServiceData: function(serviceData) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ qx.Class.define("osparc.dashboard.ResourceContainerManager", {
224224
const tags = resourceData.tags ? osparc.store.Tags.getInstance().getTags().filter(tag => resourceData.tags.includes(tag.getTagId())) : [];
225225
const card = this.getMode() === "grid" ? new osparc.dashboard.GridButtonItem() : new osparc.dashboard.ListButtonItem();
226226
card.set({
227-
appearance: resourceData.type ? `pb-${resourceData.type}` : `pb-${resourceData.resourceType}`,
227+
appearance: resourceData.type ? `pb-${resourceData.type.toLowerCase()}` : `pb-${resourceData.resourceType}`,
228228
resourceData: resourceData,
229229
tags
230230
});

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,18 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
279279
if (["templates", "public"].includes(this.getCurrentContext())) {
280280
const templates = resp["data"];
281281
templates.forEach(template => template["resourceType"] = "template");
282-
this.__addResourcesToList(templates);
282+
// For now, filtered in the frontend
283+
const groupsStore = osparc.store.Groups.getInstance();
284+
const everyoneGid = groupsStore.getEveryoneGroup().getGroupId();
285+
const productEveryoneGid = groupsStore.getEveryoneProductGroup().getGroupId();
286+
const filteredTemplates = templates.filter(template => {
287+
const publicAccess = everyoneGid in template["accessRights"] || productEveryoneGid in template["accessRights"];
288+
if (this.getCurrentContext() === "public") {
289+
return publicAccess;
290+
}
291+
return !publicAccess;
292+
});
293+
this.__addResourcesToList(filteredTemplates);
283294
} else {
284295
const studies = resp["data"];
285296
studies.forEach(study => study["resourceType"] = "study");
@@ -724,7 +735,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
724735

725736
__didContextChange: function(reqParams) {
726737
// not needed for the comparison
727-
// delete reqParams["type"];
728738
delete reqParams["limit"];
729739
delete reqParams["offset"];
730740
delete reqParams["filters"];
@@ -762,6 +772,17 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
762772
const key = osparc.utils.Utils.snakeToCamel(snakeKey);
763773
urlParams[key] = value === "null" ? null : value;
764774
}
775+
776+
// keep this until the backend implements it
777+
switch (this.getCurrentContext()) {
778+
case "templates":
779+
urlParams.accessRights = "non-public";
780+
break;
781+
case "public":
782+
urlParams.accessRights = "public";
783+
break;
784+
}
785+
765786
const contextChanged = this.__didContextChange(urlParams);
766787
if (
767788
!contextChanged &&
@@ -789,9 +810,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
789810
break;
790811
case "templates":
791812
requestParams.type = "template";
813+
requestParams.templateType = osparc.data.model.StudyUI.TEMPLATE_TYPE;
814+
requestParams.accessRights = "non-public";
792815
break;
793816
case "public":
794817
requestParams.type = "template";
818+
requestParams.templateType = osparc.data.model.StudyUI.TEMPLATE_TYPE;
819+
requestParams.accessRights = "public";
795820
break;
796821
case "search": {
797822
// Use the ``search`` functionality only if the user types some text
@@ -838,7 +863,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
838863
request = osparc.data.Resources.fetch("studies", "getPageSearch", params, options);
839864
break;
840865
case "templates":
841-
request = osparc.store.Templates.fetchTemplatesPaginated(params, options);
866+
request = osparc.store.Templates.fetchTemplatesNonPublicPaginated(params, options);
842867
break;
843868
case "public":
844869
request = osparc.store.Templates.fetchTemplatesPublicPaginated(params, options);
@@ -938,9 +963,9 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
938963
newPlansBtn.setEnabled(true);
939964

940965
newPlansBtn.addListener("tap", () => {
941-
osparc.store.Templates.getTemplates()
942-
.then(templates => {
943-
if (templates) {
966+
osparc.store.Templates.getHypertools()
967+
.then(hypertools => {
968+
if (hypertools) {
944969
const newStudies = new osparc.dashboard.NewStudies(newStudiesConfig);
945970
const winTitle = this.tr("New Plan");
946971
const win = osparc.ui.window.Window.popUpInWindow(newStudies, winTitle, osparc.dashboard.NewStudies.WIDTH+40, 300).set({
@@ -950,7 +975,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
950975
newStudies.addListener("newStudyClicked", e => {
951976
win.close();
952977
const templateInfo = e.getData();
953-
const templateData = templates.find(t => t.name === templateInfo.expectedTemplateLabel);
978+
const templateData = hypertools.find(t => t.name === templateInfo.expectedTemplateLabel);
954979
if (templateData) {
955980
this.__newPlanBtnClicked(templateData, templateInfo.newStudyLabel);
956981
}
@@ -1504,6 +1529,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
15041529
this._reloadCards();
15051530
},
15061531

1532+
_updateTemplateData: function(templateData) {
1533+
templateData["resourceType"] = "template";
1534+
this.base(arguments, templateData);
1535+
},
1536+
15071537
__removeFromStudyList: function(studyId) {
15081538
const idx = this._resourcesList.findIndex(study => study["uuid"] === studyId);
15091539
if (idx > -1) {

0 commit comments

Comments
 (0)