Skip to content

Commit f07f19f

Browse files
Namespace switch
1 parent 0071f30 commit f07f19f

File tree

9 files changed

+133
-40
lines changed

9 files changed

+133
-40
lines changed

package.json

Lines changed: 4 additions & 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.2.5",
4+
"version": "0.3.0",
55
"description": "Visual class editor for InterSystems Caché",
66
"main": "index.js",
77
"keywords": [
@@ -27,5 +27,8 @@
2727
"rimraf": "^2.5.2",
2828
"vinyl-buffer": "^1.0.0",
2929
"vinyl-source-stream": "^1.1.0"
30+
},
31+
"scripts": {
32+
"gulp": "gulp"
3033
}
3134
}

source/cache/VisualEditor.REST.Informer.cls

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,27 @@ XData UrlMap
1010
</Routes>
1111
}
1212

13+
/// Returns all available namespaces for the current instance.
14+
ClassMethod getAllNamespacesList() As %ZEN.proxyObject
15+
{
16+
set namespaces = ##class(%ZEN.proxyObject).%New()
17+
set result = ##class(%ResultSet).%New("%SYS.Namespace:List")
18+
do result.Execute()
19+
while (result.Next()) {
20+
set ns = ##class(%ZEN.proxyObject).%New()
21+
set ns.remote = result.Get("Remote")
22+
set ns.status = result.Get("Status")
23+
do namespaces.%DispatchSetProperty(result.Get("Nsp"), ns)
24+
}
25+
return namespaces
26+
}
27+
28+
///
1329
ClassMethod Init() As %Status
1430
{
1531
set data = ##class(%ZEN.proxyObject).%New()
1632
set data.namespace = $Namespace
33+
set data.namespaces = ..getAllNamespacesList()
1734
do data.%ToJSON(, "o")
1835
quit $$$OK
1936
}
@@ -132,6 +149,10 @@ ClassMethod GetClassData(className As %String) As %ZEN.proxyObject
132149
/// This method lists all the classes on the current level.
133150
ClassMethod List() As %Status
134151
{
152+
set ns = %request.Get("ns")
153+
if (##class(%SYS.Namespace).Exists(ns)) {
154+
znspace ns
155+
}
135156
set baseLevel = $case(%request.Get("level"), "":"", :%request.Get("level") _ ".")
136157
set classes = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:ClassIndex")
137158
do classes.Execute()

source/client/index.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
<div class="header">
1919
<div class="medium menu icon"></div>
2020
<div class="medium back icon" id="backButton"></div>
21-
<span class="title" id="topTitle">Class Editor</span>
21+
<span class="title">
22+
<select id="topNamespace">
23+
<option>Loading...</option>
24+
</select><span id="topTitle"></span>
25+
</span>
2226
</div>
2327
<div class="body" id="classBuilderBody">
2428

source/client/js/classEditor/card.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import { loadLevel } from "./index";
2-
3-
function block (className, element = "div") {
4-
let el = document.createElement(element);
5-
el.className = className;
6-
return el;
7-
}
2+
import { block } from "../utils";
83

94
function getPropertyBlock (prop) {
10-
let item = block(`item`),
11-
icon = block(`icon ${ prop["Private"] ? "private" : "public" }`),
12-
text = block(`label`, `span`),
13-
pName = block(`name`, `span`),
5+
let item = block(`div`, `item`),
6+
icon = block(`div`, `icon ${ prop["Private"] ? "private" : "public" }`),
7+
text = block(`span`, `label`),
8+
pName = block(`span`, `name`),
149
type = prop["Type"] || prop["ReturnType"] || prop["MimeType"] || "",
15-
pTypeText = type ? block("", "span") : null,
16-
pType = type ? block(`type`, `span`) : null;
10+
pTypeText = type ? block(`span`) : null,
11+
pType = type ? block(`span`, `type`) : null;
1712
item.appendChild(icon);
1813
pName.textContent = prop["Name"];
1914
text.appendChild(pName);
@@ -29,11 +24,11 @@ function getPropertyBlock (prop) {
2924

3025
function getBlock (key, data) {
3126

32-
let section = block(`section`), body, header;
27+
let section = block(`div`, `section`), body, header;
3328
for (let prop in data[key]) {
34-
header = block(`header`);
29+
header = block(`div`, `header`);
3530
header.textContent = key;
36-
body = block(`body`);
31+
body = block(`div`, `body`);
3732
section.appendChild(header);
3833
section.appendChild(body);
3934
break;
@@ -51,10 +46,10 @@ function getBlock (key, data) {
5146
* @returns {HTMLElement}
5247
*/
5348
export function getCardElement (data) {
54-
let card = block(`card ${ data["_type"] }`),
55-
head = block(`head`),
56-
headIcon = block(`cardIcon ${ data["ClassType"] || "" }`),
57-
header = block(`header`);
49+
let card = block(`div`, `card ${ data["_type"] }`),
50+
head = block(`div`, `head`),
51+
headIcon = block(`div`, `cardIcon ${ data["ClassType"] || "" }`),
52+
header = block(`div`, `header`);
5853

5954
header.textContent = data["name"];
6055
head.appendChild(headIcon);

source/client/js/classEditor/index.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getList } from "../server";
22
import { AutoGrid } from "../autoGrid";
33
import { getCardElement } from "./card";
4+
import { block } from "../utils";
45

56
var PATH = "",
67
INITIALIZED = false,
@@ -12,19 +13,33 @@ let initCallbacks = [];
1213
* @type {AutoGrid}
1314
*/
1415
let grid = onInit(() => grid = new AutoGrid(document.querySelector("#classBuilderBody")));
16+
1517
/**
1618
* @type {HTMLElement}
1719
*/
1820
let backButton = onInit(() => {
19-
20-
backButton = document.querySelector("#backButton");
21-
backButton.addEventListener("click", () => {
22-
if (PATH === "") return;
23-
loadLevel(PATH.replace(/\.?[^\.]+$/, ""));
21+
backButton = document.querySelector("#backButton");
22+
backButton.addEventListener("click", () => {
23+
if (PATH === "") return;
24+
loadLevel(PATH.replace(/\.?[^\.]+$/, ""));
25+
});
26+
}),
27+
topNamespace = onInit((data) => {
28+
topNamespace = document.querySelector("#topNamespace");
29+
while (topNamespace.firstChild)
30+
topNamespace.removeChild(topNamespace.firstChild);
31+
for (let ns in data["namespaces"]) {
32+
let c = block("option", "", ns);
33+
c.setAttribute("value", ns);
34+
if (ns === data["namespace"]) c.setAttribute("selected", "true");
35+
topNamespace.appendChild(c);
36+
}
37+
topNamespace.addEventListener("change", (e) => {
38+
NAMESPACE = (e.target || e.srcElement).value;
39+
loadLevel("");
40+
});
2441
});
2542

26-
});
27-
2843
function orderData (data) {
2944
var sortable = [],
3045
sorted = {};
@@ -47,16 +62,23 @@ function setTitle (text) {
4762
document.querySelector("#topTitle").textContent = text;
4863
}
4964

65+
/**
66+
* This namespace should be trusted - setting wrong namespace will result as "no data".
67+
*/
68+
function setNamespace (namespace) {
69+
topNamespace.textContent = namespace;
70+
}
71+
5072
export function loadLevel (level) {
5173

5274
PATH = level;
5375
grid.clear();
5476

5577
if (PATH === "")
5678
backButton.style.display = "none";
57-
setTitle(`${ NAMESPACE }${ PATH ? "." : "" }${ PATH }`);
79+
setTitle(`${ PATH ? "." : "" }${ PATH }`);
5880

59-
getList("SAMPLES", PATH, (data) => {
81+
getList(NAMESPACE, PATH, (data) => {
6082
grid.clear();
6183
if (PATH !== "")
6284
backButton.style.display = "";
@@ -79,9 +101,9 @@ export function onInit (callback) {
79101

80102
export function init (data) {
81103

82-
NAMESPACE = data["namespace"] || "";
83104
INITIALIZED = true;
84-
initCallbacks.forEach(cb => cb());
105+
NAMESPACE = data["namespace"];
106+
initCallbacks.forEach(cb => cb(data));
85107
initCallbacks = [];
86108

87109
loadLevel(PATH);

source/client/js/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Creates an element.
3+
* @param {string} element - Tag Name
4+
* @param {string} [className] - CSS class name
5+
* @param {string} [textContent] - Optional content
6+
* @returns {Element}
7+
*/
8+
export function block (element = "div", className, textContent) {
9+
let el = document.createElement(element || "div");
10+
if (className) el.className = className;
11+
if (textContent) el.textContent = textContent;
12+
return el;
13+
}

source/client/scss/basic.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import "const";
2+
@import "mixins";
23

34
html, body {
45
margin: 0;
@@ -39,9 +40,35 @@ html, body {
3940
}
4041

4142
> .title {
43+
4244
font-size: 24px;
4345
font-weight: bold;
4446
vertical-align: middle;
47+
48+
#topNamespace {
49+
50+
background: none;
51+
border: none;
52+
font: inherit;
53+
outline: none;
54+
-webkit-appearance: none;
55+
-moz-appearance: none;
56+
appearance: none;
57+
text-indent: 1px;
58+
text-overflow: '';
59+
cursor: pointer;
60+
@include transition($defaultTransition);
61+
62+
&::-ms-expand {
63+
display: none;
64+
}
65+
66+
&:hover {
67+
color: $colorP2;
68+
}
69+
70+
}
71+
4572
}
4673

4774
}

source/client/scss/classBuilder/card.scss

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,25 @@ $headerIconWidth: 32px;
1313
background: #fff;
1414
cursor: pointer;
1515

16-
&:hover {
17-
background: $colorP1;
18-
left: -2px;
19-
top: -2px;
20-
padding: $defaultPadding + 2px;
21-
}
22-
2316
> .head {
2417
> .cardIcon {
2518
border: 1px solid black;
2619
background: $colorP1;
20+
@include transition($defaultTransition);
21+
}
22+
}
23+
24+
&:hover {
25+
26+
background: $colorP1;
27+
padding-left: $defaultPadding + $defaultTransitionPadding;
28+
29+
> .head {
30+
> .cardIcon {
31+
background: white;
32+
}
2733
}
34+
2835
}
2936

3037
}
@@ -141,7 +148,7 @@ $headerIconWidth: 32px;
141148

142149
&:hover {
143150

144-
padding-left: 4px;
151+
padding-left: $defaultTransitionPadding;
145152
background: $colorP1;
146153
border-radius: 3px;
147154

source/client/scss/const.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ $huge: 64px;
55

66
$defaultMargin: 5px;
77
$defaultPadding: 6px;
8+
$defaultTransitionPadding: 4px;
89
$defaultShadow: 0 1px 3px rgba(0, 0, 0, .4);
910
$defaultTransition: all .3s ease;
1011

0 commit comments

Comments
 (0)