Skip to content

Commit

Permalink
✨ Expose message templates to POs (#4943)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Oct 27, 2023
1 parent b3b42a5 commit 6bccd73
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2023 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

qx.Class.define("osparc.editor.HtmlEditor", {
extend: qx.ui.core.Widget,

/**
* @param initText {String} Initialization text
*/
construct: function(initText = "") {
this.base(arguments);

this._setLayout(new qx.ui.layout.VBox(2));

this.getChildControl("text-area");
this.getChildControl("preview");
if (initText) {
this.setText(initText);
}

this.__addButtons();
},

events: {
"textChanged": "qx.event.type.Data",
"cancel": "qx.event.type.Event"
},

properties: {
text: {
check: "String",
event: "changeText",
init: "",
nullable: true
}
},

members: {
_createChildControlImpl: function(id) {
let control;
switch (id) {
case "tabs":
control = new qx.ui.tabview.TabView().set({
contentPadding: 0,
barPosition: "top"
});
this._add(control, {
flex: 1
});
break;
case "text-area": {
control = new qx.ui.form.TextArea().set({
allowGrowX: true
});
control.addListener("appear", () => {
if (control.getValue()) {
control.setTextSelection(0, control.getValue().length);
}
}, this);
this.bind("text", control, "value");
const tabs = this.getChildControl("tabs");
const writePage = new qx.ui.tabview.Page(this.tr("Write")).set({
layout: new qx.ui.layout.VBox(5)
});
writePage.getChildControl("button").getChildControl("label").set({
font: "text-13"
});
writePage.add(control, {
flex: 1
});
const subtitle = this.getChildControl("subtitle").set({
value: this.tr("Supports HTML")
});
writePage.add(subtitle);
tabs.add(writePage);
break;
}
case "preview": {
control = new qx.ui.embed.Html();
const textArea = this.getChildControl("text-area");
textArea.bind("value", control, "html");
const tabs = this.getChildControl("tabs");
const previewPage = new qx.ui.tabview.Page(this.tr("Preview")).set({
layout: new qx.ui.layout.VBox(5)
});
previewPage.getChildControl("button").getChildControl("label").set({
font: "text-13"
});
const scrollContainer = new qx.ui.container.Scroll();
scrollContainer.add(control);
previewPage.add(scrollContainer, {
flex: 1
});
tabs.add(previewPage);
break;
}
case "subtitle":
control = new qx.ui.basic.Label().set({
font: "text-12"
});
this._add(control);
break;
case "buttons":
control = new qx.ui.container.Composite(new qx.ui.layout.HBox(5).set({
alignX: "right"
}));
this._add(control);
break;
case "cancel-button": {
const buttons = this.getChildControl("buttons");
control = new qx.ui.form.Button(this.tr("Cancel"));
control.addListener("execute", () => {
this.fireDataEvent("cancel");
}, this);
buttons.add(control);
break;
}
case "accept-button": {
const buttons = this.getChildControl("buttons");
control = new qx.ui.form.Button(this.tr("Save"));
control.addListener("execute", () => {
const newText = this.getChildControl("text-area").getValue();
this.fireDataEvent("textChanged", newText);
}, this);
buttons.add(control);
break;
}
}
return control || this.base(arguments, id);
},

__addButtons: function() {
this.getChildControl("cancel-button");
this.getChildControl("accept-button");
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* It can be used to dit a longer texts
*/

qx.Class.define("osparc.editor.TextEditor", {
qx.Class.define("osparc.editor.MarkdownEditor", {
extend: qx.ui.core.Widget,

/**
Expand All @@ -31,7 +31,7 @@ qx.Class.define("osparc.editor.TextEditor", {

this._setLayout(new qx.ui.layout.VBox(2));

this.__textArea = this.getChildControl("text-area");
this.getChildControl("text-area");
this.getChildControl("preview");
if (initText) {
this.setText(initText);
Expand All @@ -55,8 +55,6 @@ qx.Class.define("osparc.editor.TextEditor", {
},

members: {
__textArea: null,

_createChildControlImpl: function(id) {
let control;
switch (id) {
Expand Down Expand Up @@ -143,7 +141,7 @@ qx.Class.define("osparc.editor.TextEditor", {
const buttons = this.getChildControl("buttons");
control = new qx.ui.form.Button(this.tr("Save"));
control.addListener("execute", () => {
const newText = this.__textArea.getValue();
const newText = this.getChildControl("text-area").getValue();
this.fireDataEvent("textChanged", newText);
}, this);
buttons.add(control);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ qx.Class.define("osparc.info.CommentAdd", {
break;
}
case "comment-field": {
control = new osparc.editor.TextEditor();
control = new osparc.editor.MarkdownEditor();
control.getChildControl("buttons").exclude();
const layout = this.getChildControl("add-comment-layout");
layout.add(control, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ qx.Class.define("osparc.info.MergedLarge", {

__openDescriptionEditor: function() {
const title = this.tr("Edit Description");
const textEditor = new osparc.editor.TextEditor(this.getStudy().getDescription());
const textEditor = new osparc.editor.MarkdownEditor(this.getStudy().getDescription());
const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 400, 300);
textEditor.addListener("textChanged", e => {
win.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ qx.Class.define("osparc.info.ServiceLarge", {

__openDescriptionEditor: function() {
const title = this.tr("Edit Description");
const textEditor = new osparc.editor.TextEditor(this.getService()["description"]);
const textEditor = new osparc.editor.MarkdownEditor(this.getService()["description"]);
const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 400, 300);
textEditor.addListener("textChanged", e => {
win.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ qx.Class.define("osparc.info.StudyLarge", {

__openDescriptionEditor: function() {
const title = this.tr("Edit Description");
const textEditor = new osparc.editor.TextEditor(this.getStudy().getDescription());
const textEditor = new osparc.editor.MarkdownEditor(this.getStudy().getDescription());
const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 400, 300);
textEditor.addListener("textChanged", e => {
win.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ qx.Class.define("osparc.metadata.QualityEditor", {
const button = osparc.utils.Utils.getEditButton();
button.addListener("execute", () => {
const title = this.tr("Edit References");
const textEditor = new osparc.editor.TextEditor(currentRule.references);
const textEditor = new osparc.editor.MarkdownEditor(currentRule.references);
textEditor.getChildControl("accept-button").setLabel(this.tr("Accept"));
const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 400, 300);
textEditor.addListener("textChanged", e => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/* ************************************************************************
osparc - the simcore frontend
https://osparc.io
Copyright:
2023 IT'IS Foundation, https://itis.swiss
License:
MIT: https://opensource.org/licenses/MIT
Authors:
* Odei Maiz (odeimaiz)
************************************************************************ */

qx.Class.define("osparc.po.MessageTemplates", {
extend: qx.ui.core.Widget,

construct: function() {
this.base(arguments);

this._setLayout(new qx.ui.layout.VBox(10));

this.__fetchInfo();
},

members: {
__messageTemplates: null,

__fetchInfo: function() {
const params = {
url: {
productName: osparc.product.Utils.getProductName()
}
};
osparc.data.Resources.fetch("productMetadata", "get", params)
.then(respData => {
this.__messageTemplates = respData["templates"];
this.__buildLayout();
});
},

__buildLayout: function() {
this._removeAll();

const templatesSB = new qx.ui.form.SelectBox().set({
allowGrowX: false
});
this._add(templatesSB);

const htmlViewer = this.__htmlViewer = new osparc.editor.HtmlEditor().set({
minHeight: 400
});
htmlViewer.getChildControl("cancel-button").exclude();
const container = new qx.ui.container.Scroll();
container.add(htmlViewer, {
flex: 1
});
this._add(container, {
flex: 1
});

templatesSB.addListener("changeSelection", e => {
const templateId = e.getData()[0].getModel();
this.__populateMessage(templateId);
}, this);
this.__messageTemplates.forEach(template => {
const lItem = new qx.ui.form.ListItem(template.id, null, template.id);
templatesSB.add(lItem);
});
htmlViewer.addListener("textChanged", e => {
const newTemplate = e.getData();
const templateId = templatesSB.getSelection()[0].getModel();
this.__saveTemplate(templateId, newTemplate);
});
},

__populateMessage: function(templateId) {
const found = this.__messageTemplates.find(template => template.id === templateId);
if (found) {
this.__htmlViewer.setText(found.content);
}
},

__saveTemplate: function(templateId, newTemplate) {
const productName = osparc.product.Utils.getProductName();
const params = {
url: {
productName,
templateId
},
data: {
content: newTemplate
}
};
osparc.data.Resources.fetch("productMetadata", "updateEmailTemplate", params)
.then(() => osparc.FlashMessenger.logAs(this.tr("Template updated"), "INFO"))
.catch(err => {
console.error(err);
osparc.FlashMessenger.logAs(err.message, "ERROR");
})
.finally(() => this.__fetchInfo());
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ qx.Class.define("osparc.po.POCenter", {
const productPage = this.__getProductPage();
tabViews.add(productPage);

const msgTemplatesPage = this.__getMsgTemplatesPage();
tabViews.add(msgTemplatesPage);

this._add(tabViews);
},

Expand Down Expand Up @@ -70,6 +73,19 @@ qx.Class.define("osparc.po.POCenter", {
});
page.add(productInfo);
return page;
},

__getMsgTemplatesPage: function() {
const title = this.tr("Message Templates");
const iconSrc = "@FontAwesome5Solid/envelope-open/22";
const page = new osparc.desktop.preferences.pages.BasePage(title, iconSrc);
page.showLabelOnTab();
const productInfo = new osparc.po.MessageTemplates();
productInfo.set({
margin: 10
});
page.add(productInfo);
return page;
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ qx.Class.define("osparc.po.ProductInfo", {
};
osparc.data.Resources.fetch("productMetadata", "get", params)
.then(respData => {
// "templates" has its own section
delete respData["templates"];
const invitationRespViewer = new osparc.ui.basic.JsonTreeWidget(respData, "product-metadata");
const container = new qx.ui.container.Scroll().set({
maxHeight: 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ qx.Class.define("osparc.widget.NodeSlideTreeItem", {

__editText: function() {
const title = this.tr("Edit Instructions");
const textEditor = new osparc.editor.TextEditor(this.getInstructions());
const textEditor = new osparc.editor.MarkdownEditor(this.getInstructions());
textEditor.getChildControl("accept-button").setLabel(this.tr("Save"));
const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 500, 300);
textEditor.addListener("textChanged", e => {
Expand Down

0 comments on commit 6bccd73

Please sign in to comment.