Skip to content

Commit 3839c4f

Browse files
committed
patchFunction
1 parent df12a5f commit 3839c4f

File tree

5 files changed

+145
-25
lines changed

5 files changed

+145
-25
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ qx.Class.define("osparc.data.Resources", {
640640
method: "POST",
641641
url: statics.API + "/functions"
642642
},
643+
patch: {
644+
method: "PATCH",
645+
url: statics.API + "/functions/{functionId}"
646+
},
643647
}
644648
},
645649
/*

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ qx.Class.define("osparc.data.model.Function", {
3232
this.set({
3333
uuid: functionData.uuid,
3434
functionClass: functionData.functionClass,
35-
name: functionData.title,
35+
title: functionData.title,
3636
description: functionData.description,
3737
inputSchema: functionData.inputSchema || this.getInputSchema(),
3838
outputSchema: functionData.outputSchema || this.getOutputSchema(),
@@ -64,11 +64,11 @@ qx.Class.define("osparc.data.model.Function", {
6464
init: null
6565
},
6666

67-
name: {
67+
title: {
6868
check: "String",
6969
nullable: false,
70-
event: "changeName",
71-
init: "New Study"
70+
event: "changeTitle",
71+
init: "Function"
7272
},
7373

7474
description: {
@@ -134,18 +134,27 @@ qx.Class.define("osparc.data.model.Function", {
134134
},
135135
},
136136

137+
statics: {
138+
getProperties: function() {
139+
return Object.keys(qx.util.PropertyUtil.getProperties(osparc.data.model.Function));
140+
}
141+
},
142+
137143
members: {
138-
serialize: function(clean = true) {
144+
serialize: function() {
139145
let jsonObject = {};
140146
const propertyKeys = this.self().getProperties();
141147
propertyKeys.forEach(key => {
148+
if (key === "template") {
149+
return; // template is not serialized
150+
}
142151
jsonObject[key] = this.get(key);
143152
});
144153
return jsonObject;
145154
},
146155

147156
patchFunction: function(functionChanges) {
148-
return osparc.store.Study.getInstance().patchStudy(this.getUuid(), functionChanges)
157+
return osparc.store.Functions.patchFunction(this.getUuid(), functionChanges)
149158
.then(() => {
150159
Object.keys(functionChanges).forEach(fieldKey => {
151160
const upKey = qx.lang.String.firstUp(fieldKey);
@@ -156,9 +165,8 @@ qx.Class.define("osparc.data.model.Function", {
156165
lastChangeDate: new Date()
157166
});
158167
const functionData = this.serialize();
159-
resolve(functionData);
160-
})
161-
.catch(err => reject(err));
168+
return functionData;
169+
});
162170
},
163171
}
164172
});

services/static-webserver/client/source/class/osparc/info/FunctionLarge.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ qx.Class.define("osparc.info.FunctionLarge", {
9999

100100
const infoLayout = {
101101
"TITLE": {
102-
view: osparc.info.StudyUtils.createTitle(this.getFunction()),
102+
view: osparc.info.FunctionUtils.createTitle(this.getFunction()),
103103
action: {
104104
button: osparc.utils.Utils.getEditButton(canIWrite),
105105
callback: canIWrite ? this.__openTitleEditor : null,
@@ -111,7 +111,7 @@ qx.Class.define("osparc.info.FunctionLarge", {
111111
action: null
112112
},
113113
"DESCRIPTION": {
114-
view: osparc.info.StudyUtils.createDescription(this.getFunction()),
114+
view: osparc.info.FunctionUtils.createDescription(this.getFunction()),
115115
action: {
116116
button: osparc.utils.Utils.getEditButton(canIWrite),
117117
callback: canIWrite ? this.__openDescriptionEditor : null,
@@ -120,17 +120,17 @@ qx.Class.define("osparc.info.FunctionLarge", {
120120
},
121121
"ACCESS_RIGHTS": {
122122
label: this.tr("Permissions"),
123-
view: new qx.ui.basic.Label(canIWrite ? "My Function" : "Read Only"),
123+
view: osparc.info.FunctionUtils.createOwner(this.getFunction()),
124124
action: null
125125
},
126126
"CREATED": {
127127
label: this.tr("Created"),
128-
view: osparc.info.StudyUtils.createCreationDate(this.getFunction()),
128+
view: osparc.info.FunctionUtils.createCreationDate(this.getFunction()),
129129
action: null
130130
},
131131
"MODIFIED": {
132132
label: this.tr("Modified"),
133-
view: osparc.info.StudyUtils.createLastChangeDate(this.getFunction()),
133+
view: osparc.info.FunctionUtils.createLastChangeDate(this.getFunction()),
134134
action: null
135135
},
136136
};
@@ -140,7 +140,7 @@ qx.Class.define("osparc.info.FunctionLarge", {
140140
__createThumbnail: function() {
141141
const maxWidth = 190;
142142
const maxHeight = 220;
143-
const thumb = osparc.info.StudyUtils.createThumbnail(this.getFunction(), maxWidth, maxHeight);
143+
const thumb = osparc.info.FunctionUtils.createThumbnail(this.getFunction(), maxWidth, maxHeight);
144144
thumb.set({
145145
maxWidth: 120,
146146
maxHeight: 139
@@ -156,11 +156,11 @@ qx.Class.define("osparc.info.FunctionLarge", {
156156

157157
__openTitleEditor: function() {
158158
const title = this.tr("Edit Title");
159-
const titleEditor = new osparc.widget.Renamer(this.getFunction().getName(), null, title);
159+
const titleEditor = new osparc.widget.Renamer(this.getFunction().getTitle(), null, title);
160160
titleEditor.addListener("labelChanged", e => {
161161
titleEditor.close();
162162
const newLabel = e.getData()["newLabel"];
163-
this.__patchFunction("name", newLabel);
163+
this.__patchFunction("title", newLabel);
164164
}, this);
165165
titleEditor.center();
166166
titleEditor.open();
@@ -187,10 +187,7 @@ qx.Class.define("osparc.info.FunctionLarge", {
187187
this.fireDataEvent("updateFunction", functionData);
188188
qx.event.message.Bus.getInstance().dispatchByName("updateFunction", functionData);
189189
})
190-
.catch(err => {
191-
const msg = this.tr("An issue occurred while updating the information.");
192-
osparc.FlashMessenger.logError(err, msg);
193-
});
190+
.catch(err => osparc.FlashMessenger.logError(err));
194191
}
195192
}
196193
});
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.FunctionUtils", {
20+
type: "static",
21+
22+
statics: {
23+
/**
24+
* @param func {osparc.data.model.Function} Function Model
25+
*/
26+
createTitle: function(func) {
27+
const title = osparc.info.Utils.createTitle();
28+
func.bind("title", title, "value");
29+
return title;
30+
},
31+
32+
/**
33+
* @param func {osparc.data.model.Function} Function Model
34+
* @param maxHeight {Number} description's maxHeight
35+
*/
36+
createDescription: function(func, maxHeight) {
37+
const description = new osparc.ui.markdown.Markdown();
38+
func.bind("description", description, "value", {
39+
converter: desc => desc ? desc : "No description"
40+
});
41+
const scrollContainer = new qx.ui.container.Scroll();
42+
if (maxHeight) {
43+
scrollContainer.setMaxHeight(maxHeight);
44+
}
45+
scrollContainer.add(description);
46+
return scrollContainer;
47+
},
48+
49+
/**
50+
* @param func {osparc.data.model.Function} Function Model
51+
*/
52+
createOwner: function(func) {
53+
const owner = new qx.ui.basic.Label();
54+
const canIWrite = func.getMyAccessRights()["write"];
55+
owner.setValue(canIWrite ? "My Function" : "Read Only");
56+
return owner;
57+
},
58+
59+
/**
60+
* @param func {osparc.data.model.Function} Function Model
61+
*/
62+
createCreationDate: function(func) {
63+
const creationDate = new qx.ui.basic.Label();
64+
func.bind("creationDate", creationDate, "value", {
65+
converter: date => osparc.utils.Utils.formatDateAndTime(date)
66+
});
67+
return creationDate;
68+
},
69+
70+
/**
71+
* @param func {osparc.data.model.Function} Function Model
72+
*/
73+
createLastChangeDate: function(func) {
74+
const lastChangeDate = new qx.ui.basic.Label();
75+
func.bind("lastChangeDate", lastChangeDate, "value", {
76+
converter: date => osparc.utils.Utils.formatDateAndTime(date)
77+
});
78+
return lastChangeDate;
79+
},
80+
81+
/**
82+
* @param func {osparc.data.model.Function} Function Model
83+
* @param maxWidth {Number} thumbnail's maxWidth
84+
* @param maxHeight {Number} thumbnail's maxHeight
85+
*/
86+
createThumbnail: function(func, maxWidth, maxHeight) {
87+
const thumbnail = osparc.info.Utils.createThumbnail(maxWidth, maxHeight);
88+
const noThumbnail = "osparc/no_photography_black_24dp.svg";
89+
func.bind("thumbnail", thumbnail, "source", {
90+
converter: thumb => thumb ? thumb : noThumbnail,
91+
onUpdate: (source, target) => {
92+
if (source.getThumbnail() === "") {
93+
target.getChildControl("image").set({
94+
minWidth: 120,
95+
minHeight: 139
96+
});
97+
}
98+
}
99+
});
100+
return thumbnail;
101+
},
102+
}
103+
});

services/static-webserver/client/source/class/osparc/store/Functions.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ qx.Class.define("osparc.store.Functions", {
9797
const functions = response["data"];
9898
functions.forEach(func => func["resourceType"] = "function");
9999
return response;
100-
})
101-
.catch(err => osparc.FlashMessenger.logError(err));
100+
});
102101
},
103102

104103
fetchFunction: function(functionId) {
@@ -111,8 +110,17 @@ qx.Class.define("osparc.store.Functions", {
111110
.then(func => {
112111
func["resourceType"] = "function";
113112
return func;
114-
})
115-
.catch(err => osparc.FlashMessenger.logError(err));
113+
});
114+
},
115+
116+
patchFunction: function(functionId, functionChanges) {
117+
const params = {
118+
url: {
119+
functionId
120+
},
121+
data: functionChanges
122+
};
123+
return osparc.data.Resources.fetch("functions", "patch", params);
116124
},
117125

118126
invalidateFunctions: function() {

0 commit comments

Comments
 (0)