Skip to content

Commit 52088bf

Browse files
Merge branch 'master' into fix-api-base-url-generation
2 parents c4ac547 + 5ff7809 commit 52088bf

File tree

3 files changed

+96
-27
lines changed

3 files changed

+96
-27
lines changed

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

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
341341
this.__getServicesBootOptionsPage,
342342
this.__getConversationsPage,
343343
this.__getPermissionsPage,
344-
this.__getSaveAsTemplatePage,
344+
this.__getPublishPage,
345+
this.__getCreateTemplatePage,
345346
this.__getCreateFunctionsPage,
346347
this.__getTagsPage,
347348
this.__getQualityPage,
@@ -738,17 +739,17 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
738739
return page;
739740
},
740741

741-
__getSaveAsTemplatePage: function() {
742+
__getPublishPage: function() {
742743
if (!osparc.utils.Resources.isStudy(this.__resourceData)) {
743744
return null;
744745
}
745746

746747
const canIWrite = osparc.data.model.Study.canIWrite(this.__resourceData["accessRights"]);
747748
const canCreateTemplate = osparc.data.Permissions.getInstance().canDo("studies.template.create");
748749
if (canIWrite && canCreateTemplate) {
749-
const id = "SaveAsTemplate";
750-
const iconSrc = "@FontAwesome5Solid/copy/22";
751-
const title = this.tr("Publish ") + osparc.product.Utils.getTemplateAlias({firstUpperCase: true});
750+
const id = "Publish";
751+
const iconSrc = "@FontAwesome5Solid/globe/22";
752+
const title = this.tr("Publish");
752753
const page = new osparc.dashboard.resources.pages.BasePage(title, iconSrc, id);
753754

754755
if (this.__resourceData["resourceType"] === "study") {
@@ -758,10 +759,11 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
758759
}
759760

760761
const lazyLoadContent = () => {
761-
const saveAsTemplate = new osparc.study.SaveAsTemplate(this.__resourceData);
762+
const makeItPublic = true;
763+
const saveAsTemplate = new osparc.study.SaveAsTemplate(this.__resourceData, makeItPublic);
762764
saveAsTemplate.addListener("publishTemplate", e => this.fireDataEvent("publishTemplate", e.getData()));
763765

764-
const publishTemplateButton = saveAsTemplate.getPublishTemplateButton();
766+
const publishTemplateButton = saveAsTemplate.getCreateTemplateButton();
765767
osparc.dashboard.resources.pages.BasePage.decorateHeaderButton(publishTemplateButton);
766768
const toolbar = this.self().createToolbar();
767769
toolbar.add(publishTemplateButton);
@@ -775,6 +777,44 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
775777
return null;
776778
},
777779

780+
__getCreateTemplatePage: function() {
781+
if (!osparc.utils.Resources.isStudy(this.__resourceData)) {
782+
return null;
783+
}
784+
785+
const canIWrite = osparc.data.model.Study.canIWrite(this.__resourceData["accessRights"]);
786+
const canCreateTemplate = osparc.data.Permissions.getInstance().canDo("studies.template.create");
787+
if (canIWrite && canCreateTemplate) {
788+
const id = "Template";
789+
const iconSrc = "@FontAwesome5Solid/copy/22";
790+
const title = this.tr("Template");
791+
const page = new osparc.dashboard.resources.pages.BasePage(title, iconSrc, id);
792+
793+
if (this.__resourceData["resourceType"] === "study") {
794+
const studyData = this.__resourceData;
795+
const canBeOpened = osparc.study.Utils.canBeDuplicated(studyData);
796+
page.setEnabled(canBeOpened);
797+
}
798+
799+
const lazyLoadContent = () => {
800+
const makeItPublic = false;
801+
const saveAsTemplate = new osparc.study.SaveAsTemplate(this.__resourceData, makeItPublic);
802+
saveAsTemplate.addListener("publishTemplate", e => this.fireDataEvent("publishTemplate", e.getData()));
803+
804+
const createTemplateButton = saveAsTemplate.getCreateTemplateButton();
805+
osparc.dashboard.resources.pages.BasePage.decorateHeaderButton(createTemplateButton);
806+
const toolbar = this.self().createToolbar();
807+
toolbar.add(createTemplateButton);
808+
page.addToHeader(toolbar);
809+
page.addToContent(saveAsTemplate);
810+
}
811+
page.addListenerOnce("appear", lazyLoadContent, this);
812+
813+
return page;
814+
}
815+
return null;
816+
},
817+
778818
__getCreateFunctionsPage: function() {
779819
if (!osparc.utils.Resources.isStudy(this.__resourceData)) {
780820
return null;

services/static-webserver/client/source/class/osparc/share/ShareTemplateWith.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ qx.Class.define("osparc.share.ShareTemplateWith", {
5050
this.__potentialTemplateData["resourceType"] = "template";
5151
const addCollaborators = new osparc.share.AddCollaborators(this.__potentialTemplateData, true);
5252
addCollaborators.getChildControl("intro-text").set({
53-
value: this.tr("Make the ") + osparc.product.Utils.getTemplateAlias() + this.tr(" also accessible to:"),
54-
font: "text-14"
53+
value: this.tr("Make the template accessible to:"),
54+
font: "text-14",
5555
});
56-
addCollaborators.getChildControl("share-with").setLabel(this.tr("Publish for..."));
56+
addCollaborators.getChildControl("share-with").setLabel(this.tr("Share with..."));
5757
this._add(addCollaborators);
5858

5959
this._add(this.__selectedCollabs);

services/static-webserver/client/source/class/osparc/study/SaveAsTemplate.js

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
2727
/**
2828
* @param studyData {Object} Object containing part or the entire serialized Study Data
2929
*/
30-
construct: function(studyData) {
30+
construct: function(studyData, makeItPublic = false) {
3131
this.base(arguments);
3232

3333
this._setLayout(new qx.ui.layout.VBox(20));
3434

3535
this.__studyDataClone = osparc.data.model.Study.deepCloneStudyObject(studyData);
36+
this.__makeItPublic = makeItPublic;
3637

3738
this.__buildLayout();
3839
},
@@ -43,10 +44,26 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
4344

4445
members: {
4546
__studyDataClone: null,
47+
__makeItPublic: null,
4648
__form: null,
47-
__publishTemplateBtn: null,
49+
__createTemplateBtn: null,
4850

4951
__buildLayout: function() {
52+
let introText = "";
53+
if (this.__makeItPublic) {
54+
introText += this.tr("This project will be published and accessible to everyone.");
55+
introText += "<br>";
56+
introText += this.tr("All users will see it and can copy it.");
57+
} else {
58+
introText += this.tr("This project will be saved as a template.");
59+
introText += "<br>";
60+
introText += this.tr("The users you select will be able to see it and copy it.");
61+
}
62+
this._add(new qx.ui.basic.Label(introText).set({
63+
font: "text-14",
64+
rich: true,
65+
}));
66+
5067
const form = this.__form = new qx.ui.form.Form();
5168
this._add(new qx.ui.form.renderer.Single(form));
5269

@@ -56,11 +73,14 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
5673
});
5774
form.add(publishWithData, this.tr("Publish with data"), null, "publishWithData");
5875

59-
if (osparc.product.Utils.isS4LProduct()) {
76+
if (osparc.data.Permissions.getInstance().isTester()) {
6077
const templateTypeSB = new qx.ui.form.SelectBox().set({
6178
allowGrowX: false,
6279
});
6380
const templateTypes = [{
81+
label: "Template",
82+
id: null,
83+
}, {
6484
label: "Tutorial",
6585
id: null,
6686
}, {
@@ -74,33 +94,42 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
7494
form.add(templateTypeSB, this.tr("Template Type"), null, "templateType");
7595
}
7696

77-
const shareWith = this.__shareWith = new osparc.share.ShareTemplateWith(this.__studyDataClone);
78-
this._add(shareWith);
97+
if (!this.__makeItPublic) {
98+
const shareWith = this.__shareWith = new osparc.share.ShareTemplateWith(this.__studyDataClone);
99+
this._add(shareWith);
100+
}
79101

80-
const publishTemplateBtn = this.__publishTemplateBtn = new qx.ui.form.Button().set({
102+
const createTemplateBtn = this.__createTemplateBtn = new qx.ui.form.Button().set({
81103
appearance: "strong-button",
82-
label: this.tr("Publish"),
104+
label: this.__makeItPublic ? this.tr("Publish") : this.tr("Create Template"),
83105
allowGrowX: false,
84106
alignX: "right"
85107
});
86-
publishTemplateBtn.addListener("execute", () => this.__publishTemplate(), this);
87-
this._add(publishTemplateBtn);
108+
createTemplateBtn.addListener("execute", () => this.__createTemplate(), this);
109+
this._add(createTemplateBtn);
88110
},
89111

90-
__publishTemplate: function() {
112+
__createTemplate: function() {
91113
const publishWithDataCB = this.__form.getItem("publishWithData");
92114
const templateTypeSB = this.__form.getItem("templateType");
93115
const templateType = templateTypeSB ? templateTypeSB.getSelection()[0].getModel() : null;
94116

95-
const readAccessRole = osparc.data.Roles.STUDY["read"];
96117
// AccessRights will be POSTed after the template is created.
97118
// No need to add myself, backend will automatically do it
98119
const accessRights = {};
99120
this.__studyDataClone["accessRights"] = {};
100-
const selectedGroupIDs = this.__shareWith.getSelectedGroups();
101-
selectedGroupIDs.forEach(gid => {
102-
accessRights[gid] = readAccessRole.accessRights;
103-
});
121+
if (this.__makeItPublic) {
122+
// share the template with the everyone group
123+
const groupsStore = osparc.store.Groups.getInstance();
124+
const groupProductEveryone = groupsStore.getEveryoneProductGroup();
125+
accessRights[groupProductEveryone.getGroupId()] = osparc.data.Roles.STUDY["read"].accessRights;
126+
} else {
127+
const selectedGroupIDs = this.__shareWith.getSelectedGroups();
128+
const readAccessRole = osparc.data.Roles.STUDY["read"];
129+
selectedGroupIDs.forEach(gid => {
130+
accessRights[gid] = readAccessRole.accessRights;
131+
});
132+
}
104133

105134
this.fireDataEvent("publishTemplate", {
106135
"studyData": this.__studyDataClone,
@@ -110,8 +139,8 @@ qx.Class.define("osparc.study.SaveAsTemplate", {
110139
});
111140
},
112141

113-
getPublishTemplateButton: function() {
114-
return this.__publishTemplateBtn;
142+
getCreateTemplateButton: function() {
143+
return this.__createTemplateBtn;
115144
}
116145
}
117146
});

0 commit comments

Comments
 (0)