Skip to content

Commit 9016667

Browse files
Navigation and linkage support
1 parent 58263ed commit 9016667

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cache-visual-editor",
33
"printableName": "Cache Visual Editor",
4-
"version": "0.4.1",
4+
"version": "0.4.2",
55
"description": "Visual class editor for InterSystems Caché",
66
"main": "index.js",
77
"keywords": [

source/cache/VisualEditor.REST.Editor.cls

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,27 @@ XData UrlMap
1515
/// { "TestPack.TestClass": { "properties": { "TestInt": { "Description": "Test desc!" } } } }
1616
ClassMethod Save() As %Status
1717
{
18+
1819
set ns = %request.Get("ns")
1920
if (##class(%SYS.Namespace).Exists(ns)) {
2021
znspace ns
2122
}
23+
2224
do %request.Content.%CopyToArray(.classes)
2325
set response = ##class(%ZEN.proxyObject).%New()
24-
set response.error = 0
26+
set response.error = ""
2527
set response.modified = 0
2628
set className = $order(classes(""))
2729
while (className '= "") {
30+
31+
set errorLog = ""
32+
2833
do classes(className).Properties.%CopyToArray(.properties)
2934
set propertyName = $order(properties(""))
3035
while (propertyName '= "") {
3136
set pDef = ##class(%Dictionary.PropertyDefinition).%OpenId(className_"||"_propertyName)
3237
if (pDef = "") {
33-
set response.error = response.error _ "Property " _ propertyName _ " not found in "
38+
set errorLog = errorLog _ "Property " _ propertyName _ " not found in "
3439
_ className _ $Char(10)
3540
set propertyName = $order(properties(propertyName))
3641
continue
@@ -39,7 +44,7 @@ ClassMethod Save() As %Status
3944
set pDef.Description = properties(propertyName).Description
4045
set error = $System.Status.GetErrorText(pDef.%Save())
4146
if (error '= "") {
42-
set response.error = response.error _ error _ $Char(10)
47+
set errorLog = errorLog _ error _ $Char(10)
4348
} else {
4449
set response.modified = response.modified + 1
4550
}
@@ -48,9 +53,24 @@ ClassMethod Save() As %Status
4853
}
4954

5055
set className = $order(classes(className))
56+
57+
if (errorLog '= "") {
58+
set response.error = response.error _ errorLog
59+
continue
60+
}
61+
62+
set st = $system.OBJ.Compile(className, , .errorLog)
63+
64+
if (errorLog '= "") {
65+
set response.error = response.error _ $CHAR(10) _ errorLog
66+
continue
67+
}
68+
5169
}
70+
5271
do response.%ToJSON(, "o")
5372
return $$$OK
73+
5474
}
5575

5676
/// This method is a handler that is executed before each request.

source/client/js/classEditor/index.js

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ let backButton = onInit(() => {
4040
for (let ns in data["namespaces"]) {
4141
let c = block("option", "", ns);
4242
c.setAttribute("value", ns);
43-
if (ns === data["namespace"]) c.setAttribute("selected", "true");
43+
if (ns === NAMESPACE) c.setAttribute("selected", "true");
4444
topNamespace.appendChild(c);
4545
}
4646
updateHeaderNamespaceWidth(NAMESPACE);
4747
topNamespace.addEventListener("change", (e) => {
48-
NAMESPACE = (e.target || e.srcElement).value;
48+
setNamespace((e.target || e.srcElement).value);
4949
updateHeaderNamespaceWidth(NAMESPACE);
5050
loadLevel("");
5151
});
@@ -60,6 +60,51 @@ let backButton = onInit(() => {
6060
});
6161
});
6262

63+
/**
64+
* Get the location hash parameter value.
65+
* @param {string} name - Parameter name.
66+
* @returns {string|undefined}
67+
*/
68+
export function getURLHashParameter (name) {
69+
let eName = encodeURIComponent(name),
70+
arr = location.hash.substr(1).split("&").filter(keyVal => keyVal.split("=")[0] === eName);
71+
if (!arr.length) return undefined;
72+
return decodeURIComponent(arr[0].split("=")[1] || "");
73+
}
74+
75+
/**
76+
* Set the location hash parameter value.
77+
* @param {string} name - Parameter name.
78+
* @param {string|undefined} [value] - If no value provided, then URL parameter will be removed.
79+
*/
80+
export function setURLHashParameter (name, value) {
81+
let eName = encodeURIComponent(name);
82+
if (getURLHashParameter(name) === undefined) {
83+
if (typeof value === "undefined") return;
84+
location.hash += `${ location.hash.length > 1 ? "&" : "" }${
85+
encodeURIComponent(name)
86+
}${ value ? `=${ encodeURIComponent(value) }` : `` }`;
87+
} else {
88+
location.hash = "#" + location.hash.substr(1).split("&").map((keyVal) => {
89+
let kv = keyVal.split("=");
90+
return (kv[0] === eName)
91+
? typeof value === "undefined"
92+
? ""
93+
: `${ kv[0] }=${ encodeURIComponent(value) }`
94+
: keyVal;
95+
}).filter(e => e !== "").join("&");
96+
}
97+
}
98+
99+
/**
100+
* This function sets the namespace. Note that namespace should be a valid namespace that exists.
101+
* @param {string} namespace
102+
*/
103+
export function setNamespace (namespace) {
104+
NAMESPACE = namespace;
105+
setURLHashParameter("namespace", NAMESPACE);
106+
}
107+
63108
/**
64109
* This function applies visual effects regarding to changes were made and
65110
* indicates that changes are needed to be saved.
@@ -118,6 +163,8 @@ export function loadLevel (level) {
118163
backButton.style.display = "none";
119164
setTitle(`${ PATH ? "." : "" }${ PATH }`);
120165

166+
setURLHashParameter("level", PATH || undefined);
167+
121168
getList(NAMESPACE, PATH, (data) => {
122169
grid.clear();
123170
if (PATH !== "")
@@ -131,7 +178,7 @@ export function loadLevel (level) {
131178
}
132179

133180
export function onInit (callback) {
134-
if (typeof callback !== "function") throw new Error(`onInit requires function`);
181+
if (typeof callback !== "function") throw new Error(`onInit requires a function`);
135182
if (INITIALIZED)
136183
callback();
137184
else
@@ -146,10 +193,10 @@ export function onInit (callback) {
146193
export function init (data) {
147194

148195
INITIALIZED = true;
149-
NAMESPACE = data["namespace"];
196+
setNamespace(getURLHashParameter("namespace") || data["namespace"]);
150197
initCallbacks.forEach(cb => cb(data));
151198
initCallbacks = [];
152199

153-
loadLevel(PATH);
200+
loadLevel(getURLHashParameter("level") || "");
154201

155202
}

source/client/js/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let BASE_URL = location.href.replace(/\/$/, ""); // = "http://[host]/VisualBuilder" (no slash)
1+
let BASE_URL = location.pathname.replace(/\/$/, ""); // = "http://[host]/VisualBuilder" (no slash)
22

33
/**
44
* @param {string} url

0 commit comments

Comments
 (0)