Skip to content

Commit ca5905c

Browse files
committed
Types
1 parent 3255d3f commit ca5905c

File tree

4 files changed

+45
-54
lines changed

4 files changed

+45
-54
lines changed

services/static-webserver/client/source/class/osparc/editor/AnnotationEditor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,20 @@ qx.Class.define("osparc.editor.AnnotationEditor", {
130130
}
131131

132132
const attrs = annotation.getAttributes();
133-
if (annotation.getType() === "text") {
133+
if (annotation.getType() === osparc.workbench.Annotation.TYPES.TEXT) {
134134
const textField = this.getChildControl("text-field").set({
135135
value: attrs.text
136136
});
137137
textField.addListener("changeValue", e => annotation.setText(e.getData()));
138-
} else if (annotation.getType() === "note") {
138+
} else if (annotation.getType() === osparc.workbench.Annotation.TYPES.NOTE) {
139139
const textArea = this.getChildControl("text-area").set({
140140
value: attrs.text
141141
});
142142
textArea.addListener("changeValue", e => annotation.setText(e.getData()));
143143
}
144144

145-
if (["text", "rect"].includes(annotation.getType())) {
145+
const annotationTypes = osparc.workbench.Annotation.TYPES;
146+
if ([annotationTypes.TEXT, annotationTypes.RECT].includes(annotation.getType())) {
146147
const colorPicker = this.getChildControl("color-picker");
147148
annotation.bind("color", colorPicker, "value");
148149
colorPicker.bind("value", annotation, "color");

services/static-webserver/client/source/class/osparc/file/FileDrop.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ qx.Class.define("osparc.file.FileDrop", {
256256
this._add(this.__dropMe);
257257
const svgLayer = this.__svgLayer;
258258
if (svgLayer.getReady()) {
259-
this.__dropMe.rect = svgLayer.drawDashedRect(boxWidth, boxHeight);
259+
this.__dropMe["rect"] = svgLayer.drawDashedRect(boxWidth, boxHeight);
260260
} else {
261-
svgLayer.addListenerOnce("SvgWidgetReady", () => this.__dropMe.rect = svgLayer.drawDashedRect(boxWidth, boxHeight), this);
261+
svgLayer.addListenerOnce("SvgWidgetReady", () => this.__dropMe["rect"] = svgLayer.drawDashedRect(boxWidth, boxHeight), this);
262262
}
263263
}
264264
const dropMe = this.__dropMe;
@@ -269,18 +269,18 @@ qx.Class.define("osparc.file.FileDrop", {
269269
top: posY - parseInt(dropMeBounds.height/2)- parseInt(boxHeight/2)
270270
});
271271
if ("rect" in dropMe) {
272-
dropMe.rect.stroke({
272+
dropMe["rect"].stroke({
273273
width: 1
274274
});
275-
osparc.wrapper.Svg.updateItemPos(dropMe.rect, posX - boxWidth, posY - boxHeight);
275+
osparc.wrapper.Svg.updateItemPos(dropMe["rect"], posX - boxWidth, posY - boxHeight);
276276
}
277277
},
278278

279279
__hideDropMe: function() {
280280
const dropMe = this.__dropMe;
281281
if (dropMe) {
282282
if ("rect" in dropMe) {
283-
dropMe.rect.stroke({
283+
dropMe["rect"].stroke({
284284
width: 0
285285
});
286286
}

services/static-webserver/client/source/class/osparc/workbench/Annotation.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ qx.Class.define("osparc.workbench.Annotation", {
4646
},
4747

4848
statics: {
49-
DEFAULT_COLOR: "#FFFF01"
49+
DEFAULT_COLOR: "#FFFF01",
50+
51+
TYPES: {
52+
NOTE: "note",
53+
RECT: "rect",
54+
TEXT: "text",
55+
},
5056
},
5157

5258
properties: {
@@ -56,6 +62,7 @@ qx.Class.define("osparc.workbench.Annotation", {
5662
},
5763

5864
type: {
65+
// check: [this.TYPES.NOTE, this.TYPES.RECT, , this.TYPES.TEXT],
5966
check: ["note", "rect", "text"],
6067
nullable: false
6168
},
@@ -95,15 +102,15 @@ qx.Class.define("osparc.workbench.Annotation", {
95102

96103
let representation = null;
97104
switch (this.getType()) {
98-
case "note": {
105+
case this.self().TYPES.NOTE: {
99106
const user = osparc.store.Groups.getInstance().getUserByGroupId(attrs.recipientGid);
100107
representation = this.__svgLayer.drawAnnotationNote(attrs.x, attrs.y, user ? user.getLabel() : "", attrs.text);
101108
break;
102109
}
103-
case "rect":
110+
case this.self().TYPES.RECT:
104111
representation = this.__svgLayer.drawAnnotationRect(attrs.width, attrs.height, attrs.x, attrs.y, this.getColor());
105112
break;
106-
case "text":
113+
case this.self().TYPES.TEXT:
107114
representation = this.__svgLayer.drawAnnotationText(attrs.x, attrs.y, attrs.text, this.getColor(), attrs.fontSize);
108115
break;
109116
}
@@ -124,10 +131,10 @@ qx.Class.define("osparc.workbench.Annotation", {
124131
const representation = this.getRepresentation();
125132
if (representation) {
126133
switch (this.getType()) {
127-
case "rect":
134+
case this.self().TYPES.RECT:
128135
osparc.wrapper.Svg.updateItemColor(representation, color);
129136
break;
130-
case "text":
137+
case this.self().TYPES.TEXT:
131138
osparc.wrapper.Svg.updateTextColor(representation, color);
132139
break;
133140
}
@@ -188,8 +195,8 @@ qx.Class.define("osparc.workbench.Annotation", {
188195
const representation = this.getRepresentation();
189196
if (representation) {
190197
switch (this.getType()) {
191-
case "rect":
192-
case "text": {
198+
case this.self().TYPES.RECT:
199+
case this.self().TYPES.TEXT: {
193200
if (selected) {
194201
if (!("bBox" in representation.node)) {
195202
const bBox = this.__svgLayer.drawBoundingBox(this);

services/static-webserver/client/source/class/osparc/workbench/WorkbenchUI.js

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
136136
__isDraggingFile: null,
137137
__isDraggingLink: null,
138138
__annotations: null,
139-
__annotatingNote: null,
140-
__annotatingRect: null,
141-
__annotatingText: null,
139+
__annotating: null,
142140
__annotationInitPos: null,
143141
__selectedAnnotations: null,
144142
__annotationEditor: null,
@@ -329,19 +327,19 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
329327
});
330328
temporaryNodeUI.getContentElement().addClass("rotate");
331329
this.__workbenchLayout.add(temporaryNodeUI);
332-
temporaryNodeUI.rect = this.__svgLayer.drawDashedRect(boxWidth, boxHeight);
330+
temporaryNodeUI["rect"] = this.__svgLayer.drawDashedRect(boxWidth, boxHeight);
333331
temporaryNodeUI.setLayoutProperties({
334332
left: pos.x + parseInt(boxWidth/2) - parseInt(circleSize/2),
335333
top: pos.y + parseInt(boxHeight/2) - parseInt(circleSize/2)
336334
});
337-
osparc.wrapper.Svg.updateItemPos(temporaryNodeUI.rect, pos.x, pos.y);
335+
osparc.wrapper.Svg.updateItemPos(temporaryNodeUI["rect"], pos.x, pos.y);
338336

339337
return temporaryNodeUI;
340338
},
341339

342340
__removeTemporaryNodeUI: function(temporaryNodeUI) {
343341
temporaryNodeUI.exclude();
344-
osparc.wrapper.Svg.removeItem(temporaryNodeUI.rect);
342+
osparc.wrapper.Svg.removeItem(temporaryNodeUI["rect"]);
345343
this.__workbenchLayout.add(temporaryNodeUI);
346344
temporaryNodeUI = null;
347345
},
@@ -1408,7 +1406,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
14081406

14091407
__mouseDownOnSVG: function(e) {
14101408
if (e.isLeftPressed()) {
1411-
if (this.__annotatingNote || this.__annotatingRect || this.__annotatingText) {
1409+
if (this.__annotating) {
14121410
this.__annotationInitPos = this.__pointerEventToWorkbenchPos(e);
14131411
} else {
14141412
this.__selectionRectInitPos = this.__pointerEventToWorkbenchPos(e);
@@ -1419,7 +1417,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
14191417
__mouseMove: function(e) {
14201418
if (this.__isDraggingLink) {
14211419
this.__draggingLink(e, true);
1422-
} else if (this.__tempEdgeRepr === null && (this.__annotatingNote || this.__annotatingRect || this.__annotatingText) && this.__annotationInitPos && e.isLeftPressed()) {
1420+
} else if (this.__tempEdgeRepr === null && this.__annotating && this.__annotationInitPos && e.isLeftPressed()) {
14231421
this.__drawingAnnotation(e);
14241422
} else if (this.__tempEdgeRepr === null && this.__selectionRectInitPos && e.isLeftPressed()) {
14251423
this.__drawingSelectionRect(e);
@@ -1449,23 +1447,13 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
14491447
if (this.__annotationInitPos) {
14501448
this.__annotationInitPos = null;
14511449
}
1452-
if (this.__annotatingNote || this.__annotatingRect || this.__annotatingText) {
1453-
let annotationType = null;
1454-
if (this.__annotatingNote) {
1455-
annotationType = "note";
1456-
} else if (this.__annotatingRect) {
1457-
annotationType = "rect";
1458-
} else if (this.__annotatingText) {
1459-
annotationType = "text";
1460-
}
1461-
if (this.__consolidateAnnotation(annotationType, annotationInitPos, this.__rectAnnotationRepr)) {
1450+
if (this.__annotating) {
1451+
if (this.__consolidateAnnotation(this.__annotating, annotationInitPos, this.__rectAnnotationRepr)) {
14621452
if (this.__rectAnnotationRepr) {
14631453
osparc.wrapper.Svg.removeItem(this.__rectAnnotationRepr);
14641454
this.__rectAnnotationRepr = null;
14651455
}
1466-
this.__annotatingNote = false;
1467-
this.__annotatingRect = false;
1468-
this.__annotatingText = false;
1456+
this.__annotating = null;
14691457
this.__toolHint.setValue(null);
14701458
}
14711459
}
@@ -1607,23 +1595,17 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
16071595
},
16081596

16091597
startAnnotationsNote: function() {
1610-
this.__annotatingNote = true;
1611-
this.__annotatingRect = false;
1612-
this.__annotatingText = false;
1598+
this.__annotating = osparc.workbench.Annotation.TYPES.NOTE;
16131599
this.__toolHint.setValue(this.tr("Pick the position"));
16141600
},
16151601

16161602
startAnnotationsRect: function() {
1617-
this.__annotatingNote = false;
1618-
this.__annotatingRect = true;
1619-
this.__annotatingText = false;
1603+
this.__annotating = osparc.workbench.Annotation.TYPES.RECT;
16201604
this.__toolHint.setValue(this.tr("Draw a rectangle"));
16211605
},
16221606

16231607
startAnnotationsText: function(workbenchPos) {
1624-
this.__annotatingNote = false;
1625-
this.__annotatingText = true;
1626-
this.__annotatingRect = false;
1608+
this.__annotating = osparc.workbench.Annotation.TYPES.TEXT;
16271609
if (workbenchPos) {
16281610
this.__annotationInitPos = workbenchPos;
16291611
this.__mouseUp();
@@ -1825,7 +1807,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
18251807
});
18261808
dropHereNodeUI.exclude();
18271809
this.__workbenchLayout.add(dropHereNodeUI);
1828-
dropHereNodeUI.rect = this.__svgLayer.drawDashedRect(boxWidth, boxHeight);
1810+
dropHereNodeUI["rect"] = this.__svgLayer.drawDashedRect(boxWidth, boxHeight);
18291811
}
18301812
let dropHere = this.__dropHereUI;
18311813
if (show) {
@@ -1836,11 +1818,11 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
18361818
top: posY - parseInt(dropMeBounds.height/2)- parseInt(boxHeight/2)
18371819
});
18381820
if ("rect" in dropHere) {
1839-
osparc.wrapper.Svg.updateItemPos(dropHere.rect, posX - boxWidth, posY - boxHeight);
1821+
osparc.wrapper.Svg.updateItemPos(dropHere["rect"], posX - boxWidth, posY - boxHeight);
18401822
}
18411823
} else {
18421824
dropHere.exclude();
1843-
osparc.wrapper.Svg.removeItem(dropHere.rect);
1825+
osparc.wrapper.Svg.removeItem(dropHere["rect"]);
18441826
dropHere = null;
18451827
}
18461828
},
@@ -1915,13 +1897,14 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
19151897
},
19161898

19171899
__consolidateAnnotation: function(type, initPos, annotation) {
1900+
const annotationTypes = osparc.workbench.Annotation.TYPES;
19181901
const color = this.__annotationLastColor ? this.__annotationLastColor : osparc.workbench.Annotation.DEFAULT_COLOR;
19191902
const serializeData = {
19201903
type,
19211904
color,
19221905
attributes: {}
19231906
};
1924-
if (type === "rect") {
1907+
if (type === annotationTypes.RECT) {
19251908
if ([null, undefined].includes(annotation)) {
19261909
osparc.FlashMessenger.logAs(this.tr("Draw a rectangle first"), "WARNING");
19271910
return false;
@@ -1930,7 +1913,7 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
19301913
} else {
19311914
serializeData.attributes = initPos;
19321915
}
1933-
if (type === "note") {
1916+
if (type === annotationTypes.NOTE) {
19341917
const noteEditor = new osparc.editor.AnnotationNoteCreator(this.getStudy());
19351918
const win = osparc.editor.AnnotationNoteCreator.popUpInWindow(noteEditor);
19361919
noteEditor.addListener("addNote", () => {
@@ -1945,11 +1928,11 @@ qx.Class.define("osparc.workbench.WorkbenchUI", {
19451928
win.close();
19461929
}, this);
19471930
noteEditor.addListener("cancel", () => win.close());
1948-
} else if (type === "rect") {
1931+
} else if (type === annotationTypes.RECT) {
19491932
this.__addAnnotation(serializeData);
1950-
} else if (type === "text") {
1933+
} else if (type === annotationTypes.TEXT) {
19511934
const tempAnnotation = new osparc.workbench.Annotation(null, {
1952-
type: "text",
1935+
type: annotationTypes.TEXT,
19531936
color,
19541937
attributes: {
19551938
text: "",

0 commit comments

Comments
 (0)