|
| 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 | + |
| 19 | +qx.Class.define("osparc.info.FunctionLarge", { |
| 20 | + extend: osparc.info.CardLarge, |
| 21 | + |
| 22 | + /** |
| 23 | + * @param func {osparc.data.model.Function} Function model |
| 24 | + */ |
| 25 | + construct: function(func) { |
| 26 | + this.base(arguments); |
| 27 | + |
| 28 | + this.setFunction(func); |
| 29 | + |
| 30 | + this.setOpenOptions(false); |
| 31 | + |
| 32 | + this._attachHandlers(); |
| 33 | + }, |
| 34 | + |
| 35 | + events: { |
| 36 | + "updateFunction": "qx.event.type.Data", |
| 37 | + }, |
| 38 | + |
| 39 | + properties: { |
| 40 | + function: { |
| 41 | + check: "osparc.data.model.Function", |
| 42 | + init: null, |
| 43 | + nullable: false |
| 44 | + } |
| 45 | + }, |
| 46 | + |
| 47 | + members: { |
| 48 | + __canIWrite: function() { |
| 49 | + // return osparc.data.model.Function.canIWrite(this.getFunction().getAccessRights()); |
| 50 | + return true; |
| 51 | + }, |
| 52 | + |
| 53 | + _rebuildLayout: function() { |
| 54 | + this._removeAll(); |
| 55 | + |
| 56 | + const vBox = new qx.ui.container.Composite(new qx.ui.layout.VBox(10)); |
| 57 | + |
| 58 | + const infoElements = this.__infoElements(); |
| 59 | + const isStudy = true; |
| 60 | + const infoLayout = osparc.info.Utils.infoElementsToLayout(infoElements, isStudy); |
| 61 | + vBox.add(infoLayout); |
| 62 | + |
| 63 | + // Copy Id button |
| 64 | + const text = "Function Id"; |
| 65 | + const copyIdButton = new qx.ui.form.Button(null, "@FontAwesome5Solid/copy/12").set({ |
| 66 | + label: text, |
| 67 | + toolTipText: "Copy " + text, |
| 68 | + marginTop: 15, |
| 69 | + allowGrowX: false |
| 70 | + }); |
| 71 | + copyIdButton.addListener("execute", () => osparc.utils.Utils.copyTextToClipboard(this.getFunction().getUuid())); |
| 72 | + vBox.add(copyIdButton); |
| 73 | + |
| 74 | + // All in a scroll container |
| 75 | + const scrollContainer = new qx.ui.container.Scroll(); |
| 76 | + scrollContainer.add(vBox); |
| 77 | + |
| 78 | + this._add(scrollContainer, { |
| 79 | + flex: 1 |
| 80 | + }); |
| 81 | + }, |
| 82 | + |
| 83 | + __infoElements: function() { |
| 84 | + const canIWrite = this.__canIWrite(); |
| 85 | + |
| 86 | + const infoLayout = { |
| 87 | + "TITLE": { |
| 88 | + view: osparc.info.StudyUtils.createTitle(this.getFunction()), |
| 89 | + action: { |
| 90 | + button: osparc.utils.Utils.getEditButton(canIWrite), |
| 91 | + callback: canIWrite ? this.__openTitleEditor : null, |
| 92 | + ctx: this |
| 93 | + } |
| 94 | + }, |
| 95 | + "THUMBNAIL": { |
| 96 | + view: this.__createThumbnail(), |
| 97 | + action: null |
| 98 | + }, |
| 99 | + "DESCRIPTION": { |
| 100 | + view: osparc.info.StudyUtils.createDescription(this.getFunction()), |
| 101 | + action: { |
| 102 | + button: osparc.utils.Utils.getEditButton(canIWrite), |
| 103 | + callback: canIWrite ? this.__openDescriptionEditor : null, |
| 104 | + ctx: this |
| 105 | + } |
| 106 | + }, |
| 107 | + /* |
| 108 | + "AUTHOR": { |
| 109 | + label: this.tr("Author"), |
| 110 | + view: osparc.info.StudyUtils.createOwner(this.getFunction()), |
| 111 | + action: null |
| 112 | + }, |
| 113 | + */ |
| 114 | + "ACCESS_RIGHTS": { |
| 115 | + label: this.tr("Access"), |
| 116 | + view: osparc.info.StudyUtils.createAccessRights(this.getFunction()), |
| 117 | + action: { |
| 118 | + button: osparc.utils.Utils.getLinkButton(canIWrite), |
| 119 | + callback: this.isOpenOptions() ? this.__openAccessRights : "openAccessRights", |
| 120 | + ctx: this |
| 121 | + } |
| 122 | + }, |
| 123 | + "CREATED": { |
| 124 | + label: this.tr("Created"), |
| 125 | + view: osparc.info.StudyUtils.createCreationDate(this.getFunction()), |
| 126 | + action: null |
| 127 | + }, |
| 128 | + "MODIFIED": { |
| 129 | + label: this.tr("Modified"), |
| 130 | + view: osparc.info.StudyUtils.createLastChangeDate(this.getFunction()), |
| 131 | + action: null |
| 132 | + }, |
| 133 | + }; |
| 134 | + return infoLayout; |
| 135 | + }, |
| 136 | + |
| 137 | + __createThumbnail: function() { |
| 138 | + const maxWidth = 190; |
| 139 | + const maxHeight = 220; |
| 140 | + const thumb = osparc.info.StudyUtils.createThumbnail(this.getFunction(), maxWidth, maxHeight); |
| 141 | + thumb.set({ |
| 142 | + maxWidth: 120, |
| 143 | + maxHeight: 139 |
| 144 | + }); |
| 145 | + thumb.getChildControl("image").set({ |
| 146 | + width: 120, |
| 147 | + height: 139, |
| 148 | + scale: true, |
| 149 | + }); |
| 150 | + |
| 151 | + return thumb; |
| 152 | + }, |
| 153 | + |
| 154 | + __openTitleEditor: function() { |
| 155 | + const title = this.tr("Edit Title"); |
| 156 | + const titleEditor = new osparc.widget.Renamer(this.getFunction().getName(), null, title); |
| 157 | + titleEditor.addListener("labelChanged", e => { |
| 158 | + titleEditor.close(); |
| 159 | + const newLabel = e.getData()["newLabel"]; |
| 160 | + this.__patchFunction("name", newLabel); |
| 161 | + }, this); |
| 162 | + titleEditor.center(); |
| 163 | + titleEditor.open(); |
| 164 | + }, |
| 165 | + |
| 166 | + __openDescriptionEditor: function() { |
| 167 | + const title = this.tr("Edit Description"); |
| 168 | + const textEditor = new osparc.editor.MarkdownEditor(this.getStudy().getDescription()); |
| 169 | + textEditor.setMaxHeight(570); |
| 170 | + const win = osparc.ui.window.Window.popUpInWindow(textEditor, title, 400, 300); |
| 171 | + textEditor.addListener("textChanged", e => { |
| 172 | + win.close(); |
| 173 | + const newDescription = e.getData(); |
| 174 | + this.__patchFunction("description", newDescription); |
| 175 | + }, this); |
| 176 | + textEditor.addListener("cancel", () => { |
| 177 | + win.close(); |
| 178 | + }, this); |
| 179 | + }, |
| 180 | + |
| 181 | + __patchFunction: function(fieldKey, value) { |
| 182 | + this.getStudy().patchStudy({[fieldKey]: value}) |
| 183 | + .then(studyData => { |
| 184 | + studyData["resourceType"] = this.getStudy().getTemplateType() ? "template" : "study"; |
| 185 | + this.fireDataEvent("updateStudy", studyData); |
| 186 | + qx.event.message.Bus.getInstance().dispatchByName("updateStudy", studyData); |
| 187 | + }) |
| 188 | + .catch(err => { |
| 189 | + const msg = this.tr("An issue occurred while updating the information."); |
| 190 | + osparc.FlashMessenger.logError(err, msg); |
| 191 | + }); |
| 192 | + } |
| 193 | + } |
| 194 | +}); |
0 commit comments