Skip to content

Commit 7a95033

Browse files
Class update after save experimental function
1 parent 727b9f3 commit 7a95033

File tree

8 files changed

+51
-16
lines changed

8 files changed

+51
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cache-visual-editor",
33
"printableName": "Cache Visual Editor",
44
"packageName": "VisualEditor",
5-
"version": "0.9.3",
5+
"version": "0.9.4",
66
"description": "Visual class editor for InterSystems Caché",
77
"main": "index.js",
88
"keywords": [

source/cache/REST/Editor.cls

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ClassMethod Save() As %Status
9191
set classes = %request.Content
9292
set response = {}
9393
set response.error = ""
94-
set response.modified = 0
94+
set response.modified = {}
9595

9696
#define logError(%e) if (%e '= "") { set response.error = response.error _ %e _ $Char(10) }
9797

@@ -132,7 +132,10 @@ ClassMethod Save() As %Status
132132
continue
133133
}
134134

135-
set response.modified = response.modified + 1
135+
do response.modified.$set(className, {
136+
"success": 1,
137+
"class": ##class(VisualEditor.REST.Informer).GetClassData(className)
138+
})
136139

137140
}
138141

source/cache/REST/Informer.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ ClassMethod GetClassData(className As %String) As %Object
7171
set oClass = {}
7272
if (class = "") { return oClass }
7373

74+
do oClass.$set("_type", "class")
75+
do oClass.$set("_fullName", className)
76+
do oClass.$set("_name", $PIECE(className, ".", *))
7477
do oClass.$set("_isDataType", class.ClientDataTypeIsDefined())
7578
do oClass.$set("_isOdbcType", class.OdbcTypeIsDefined())
7679
do oClass.$set("_isSoapBindingStyle", class.SoapBindingStyleIsDefined())
@@ -133,9 +136,6 @@ ClassMethod List() As %Status
133136
} elseif ($LENGTH(clsName, ".") = $LENGTH(baseLevel, ".")) {
134137
set className = $PIECE(clsName, ".", $LENGTH(baseLevel, "."))
135138
set oClass = ..GetClassData(clsName)
136-
do oClass.$set("_type", "class")
137-
do oClass.$set("_fullName", clsName)
138-
do oClass.$set("_name", className)
139139
do data.$set(className, oClass)
140140
} else {
141141
continue

source/client/js/AutoGrid

source/client/js/classEditor/class/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function getClassElement (data, serviceData = {}) {
2020
}`),
2121
header = block(`div`, `header`);
2222

23-
serviceData[`visualClassElement`] = card;
23+
serviceData[`cardElement`] = card;
2424
serviceData[`cardWidth`] = 1;
2525

2626
if (type === "class") // float priority

source/client/js/classEditor/class/member.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ function enableMember ({
194194

195195
if (classBlockName === "Methods" || classBlockName === "XDatas") {
196196
serviceData[`visualCodeBlocksOpened`] += opened ? 1 : -1;
197-
updateGridElement(serviceData[`visualClassElement`], {
197+
updateGridElement(serviceData[`cardElement`], {
198198
width: serviceData[`cardWidth`] = serviceData[`visualCodeBlocksOpened`] > 0 ? 2 : 1
199199
});
200200
}

source/client/js/classEditor/class/memberSection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const MEMBER_SECTIONS = [
1212
"XDatas"
1313
];
1414

15-
function getMemberControls (body, classData, classBlockName) {
15+
function getMemberControls (body, classData, classBlockName, serviceData) {
1616

1717
let controls = block(`div`, `controls`),
1818
add = block(`div`, `interactive normal icon add`);
@@ -34,7 +34,7 @@ function getMemberControls (body, classData, classBlockName) {
3434

3535
classData[classBlockName][propName] = { Name: propName };
3636
body.appendChild(getMemberBlock({
37-
classData, classBlockName, classBlockPropName: propName
37+
classData, classBlockName, classBlockPropName: propName, serviceData
3838
}));
3939

4040
updateGrid();
@@ -62,7 +62,7 @@ export function getMemberSection (classBlockName, classData, serviceData) {
6262
let header = block(`div`, `header`),
6363
span = block(`span`, `title`);
6464
body = block(`div`, `body`);
65-
header.appendChild(getMemberControls(body, classData, classBlockName));
65+
header.appendChild(getMemberControls(body, classData, classBlockName, serviceData));
6666
header.appendChild(span);
6767
span.textContent = classBlockName;
6868
section.appendChild(header);

source/client/js/classEditor/index.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { init as initTerminal } from "./modules/terminal";
99

1010
var PATH = "",
1111
INITIALIZED = false,
12-
NAMESPACE = "";
12+
NAMESPACE = "",
13+
CLASSES_RENDERED = {}; // { className: serviceData }
1314

1415
let initCallbacks = [];
1516

@@ -65,12 +66,32 @@ let footer = onInit(() => {
6566
saveButton = document.querySelector("#saveIndicator");
6667
saveButton.addEventListener("click", () => {
6768
saveChanges(NAMESPACE, (res) => {
69+
6870
if (!res["error"]) {
6971
changeIsMade(false);
7072
new Toast(Toast.TYPE_DONE, `Saved!`);
7173
} else {
7274
new Toast(Toast.TYPE_ERROR, res["error"], Toast.TIME_LONG);
7375
}
76+
77+
// // REPLACES CLASS ON SAVE (temporary commented as side effects appear)
78+
// for (let className in res[`modified`] || {}) { // update modified classes
79+
// let renderedServiceData = CLASSES_RENDERED[className];
80+
// // [`cardElement`] is assigned during new class spawn.
81+
// if (
82+
// !(renderedServiceData || {})[`cardElement`]
83+
// || !res[`modified`][className][`success`]
84+
// || !res[`modified`][className][`class`]
85+
// )
86+
// continue;
87+
// let b, a;
88+
// grid.replaceChild(
89+
// b = renderedServiceData[`cardElement`],
90+
// a = applyClass(res[`modified`][className][`class`], renderedServiceData)
91+
// );
92+
// console.log("replacing", b, a);
93+
// }
94+
7495
});
7596
});
7697
}),
@@ -124,8 +145,8 @@ let footer = onInit(() => {
124145
} else {
125146
setup["_fullName"] = fullName;
126147
}
127-
128-
grid.applyChild(getClassElement(setup));
148+
149+
grid.applyChild(applyClass(setup));
129150

130151
if (type !== "package")
131152
addChange([fullName, "$add"], true);
@@ -256,6 +277,16 @@ function setTitle (text) {
256277
document.querySelector("#topTitle").textContent = text;
257278
}
258279

280+
/**
281+
* Attaches new class to the body and returns it's element.
282+
* @param classMetadata
283+
* @param serviceData
284+
*/
285+
function applyClass (classMetadata, serviceData = {}) {
286+
CLASSES_RENDERED[classMetadata[`_fullName`] || classMetadata[`Name`]] = serviceData;
287+
return getClassElement(classMetadata, serviceData);
288+
}
289+
259290
/**
260291
* Displays the classes and packages located on the current level.
261292
* @param {string} level - Class part.
@@ -273,11 +304,12 @@ export function loadLevel (level) {
273304

274305
getList(NAMESPACE, PATH, (data) => {
275306
grid.clear();
307+
CLASSES_RENDERED = {};
276308
if (PATH !== "")
277309
backButton.style.display = "";
278310
data = orderData(data);
279311
for (let obj in data) {
280-
grid.applyChild(getClassElement(data[obj]));
312+
grid.applyChild(applyClass(data[obj]));
281313
}
282314
});
283315

0 commit comments

Comments
 (0)