Skip to content

Commit a7f226b

Browse files
(fire) Embedded terminal support, select elements various fixes
1 parent 2399f09 commit a7f226b

File tree

12 files changed

+279
-65
lines changed

12 files changed

+279
-65
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ literally without touching any code.
55

66
### Preview
77

8+
![Screenshot 0](https://cloud.githubusercontent.com/assets/4989256/14316622/be325704-fc0c-11e5-93f0-a7cc0b9116f6.png)
9+
810
![Screenshot 1](https://cloud.githubusercontent.com/assets/4989256/14295116/efcc9774-fb7c-11e5-86bd-219864fe5634.png)
911

1012
![Screenshot 2](https://cloud.githubusercontent.com/assets/4989256/14295117/efcf2da4-fb7c-11e5-861f-e9f1231ec909.png)

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.6.2",
5+
"version": "0.7.0",
66
"description": "Visual class editor for InterSystems Caché",
77
"main": "index.js",
88
"keywords": [

source/client/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@
3333
</span>
3434
</div>
3535
</div>
36-
<div class="body" id="classBuilderBody">
36+
<div class="footer" id="footer">
37+
<div class="panel">
38+
<div class="controls inline float-right">
39+
<div class="interactive medium terminal icon" id="terminalButton"></div>
40+
</div>
41+
</div>
42+
</div>
43+
<div id="footer-terminal">
44+
45+
</div>
46+
<div class="body" id="classBuilderBody"> <!-- Keep bottom -->
3747

3848
</div>
3949
</div>

source/client/js/classEditor/class/MANIFEST.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
ClassType: {
1616
default: "",
1717
type: "select",
18-
values: [ "datatype", "index", "persistent", "serial", "stream", "view" ]
18+
options: [ "datatype", "index", "persistent", "serial", "stream", "view" ]
1919
},
2020
ClassVersion: {
2121
ignore: true,
@@ -25,7 +25,7 @@ export default {
2525
ClientDataType: {
2626
default: "VARCHAR",
2727
type: "select",
28-
values: [
28+
options: [
2929
"BIGINT", "BINARY", "BINARYSTREAM", "BOOLEAN", "CHARACTERSTREAM", "CURRENCY",
3030
"DATE", "DECIMAL", "DOUBLE", "FDATE", "FTIMESTAMP", "HANDLE", "INTEGER", "LIST",
3131
"LONGVARCHAR", "NUMERIC", "STATUS", "TIME", "TIMESTAMP", "VARCHAR"
@@ -62,12 +62,12 @@ export default {
6262
Inheritance: {
6363
default: "left",
6464
type: "select",
65-
values: [ "left", "right" ]
65+
options: [ "left", "right" ]
6666
},
6767
Language: {
6868
default: "cache",
6969
type: "select",
70-
values: [ "cache", "basic", "java", "javascript", "mvbasic", "tsql" ]
70+
options: [ "cache", "basic", "java", "javascript", "mvbasic", "tsql" ]
7171
},
7272
LegacyInstanceContext: {
7373
default: 0,
@@ -100,7 +100,7 @@ export default {
100100
OdbcType: {
101101
default: "VARCHAR",
102102
type: "select",
103-
values: [
103+
options: [
104104
"BIGINT", "BIT", "DATE", "DOUBLE", "INTEGER", "LONGVARBINARY", "LONGVARCHAR",
105105
"NUMERIC", "RESULTSET", "SMALLINT", "STRUCT", "TIME", "TIMESTAMP", "TINYINT",
106106
"VARBINARY", "VARCHAR"
@@ -113,17 +113,17 @@ export default {
113113
SoapBindingStyle : {
114114
default: "document",
115115
type: "select",
116-
values: [ "document", "rpc" ]
116+
options: [ "document", "rpc" ]
117117
},
118118
SoapBodyUse: {
119119
default: "literal",
120120
type: "select",
121-
values: [ "literal", "encoded" ]
121+
options: [ "literal", "encoded" ]
122122
},
123123
SqlCategory: {
124124
default: "STRING",
125125
type: "select",
126-
values: [
126+
options: [
127127
"DATE", "DOUBLE", "FMDATE", "FMTIMESTAMP", "INTEGER", "MVDATE", "NAME", "NUMERIC",
128128
"STRING", "TIME", "TIMESTAMP"
129129
],

source/client/js/classEditor/class/keyword.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,51 @@
1-
import { block } from "../../domUtils";
1+
import { block, toggle } from "../../domUtils";
22
import { addChange } from "../changes";
33

44
function getKeywordEditElement (propName, value, propManifest, savePath) {
55
let type = propManifest["type"] || "string",
66
input;
77
if (type === "boolean") {
8-
input = block(`input`, `toggle`);
9-
input.type = "checkbox";
10-
input.checked = !!value;
11-
input.addEventListener(`change`, () => addChange(
8+
input = toggle(!!value);
9+
input.checkbox.addEventListener(`change`, () => addChange(
1210
savePath.concat(propName),
13-
input.checked ? 1 : 0
11+
input.checkbox.checked ? 1 : 0
1412
));
15-
} else { // string type
13+
} else if (type === "string") { // string type
1614
input = block(`input`);
1715
input.type = "text";
1816
input.value = value;
1917
input.addEventListener(`input`, () => addChange(
2018
savePath.concat(propName),
2119
input.value
2220
));
21+
} else if (type === "select") selBlock: {
22+
23+
let options = propManifest["options"];
24+
25+
if (!(options instanceof Array)) {
26+
input = block(`div`, `errorMessage`, `No "options" specified for type "select".`);
27+
break selBlock;
28+
}
29+
30+
input = block(`select`);
31+
options.forEach(opt => {
32+
let el = block(`option`),
33+
cbValue = typeof opt === "object" && opt["value"] ? opt["value"] : opt;
34+
el.textContent = typeof opt === "object" && opt["label"] ? opt["label"] : opt;
35+
el.value = cbValue;
36+
input.appendChild(el);
37+
if (cbValue == value)
38+
input.value = cbValue;
39+
});
40+
41+
input.addEventListener(`change`, () => addChange(
42+
savePath.concat(propName),
43+
input.value
44+
));
45+
46+
} else {
47+
input = block(`div`, `errorMessage`);
48+
input.textContent = `Unknown type "${ type }"`;
2349
}
2450
return input;
2551
}

source/client/js/classEditor/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { block, awaitInlineInput, freeSelect } from "../domUtils";
55
import { saveChanges } from "./changes";
66
import { Toast } from "../toast";
77
import { addChange } from "./changes";
8+
import { init as initTerminal } from "./modules/terminal";
89

910
var PATH = "",
1011
INITIALIZED = false,
@@ -29,7 +30,10 @@ export function updateGrid () {
2930
* Behaviors for elements on page.
3031
* @type {HTMLElement}
3132
*/
32-
let backButton = onInit(() => {
33+
let footer = onInit(() => {
34+
footer = document.querySelector(`#footer`);
35+
}),
36+
backButton = onInit(() => {
3337
backButton = document.querySelector("#backButton");
3438
backButton.addEventListener("click", () => {
3539
if (PATH === "") return;
@@ -105,6 +109,22 @@ let backButton = onInit(() => {
105109

106110
});
107111
});
112+
}),
113+
terminalButton = onInit(() => {
114+
115+
let firstPress = true;
116+
117+
terminalButton = document.querySelector(`#terminalButton`);
118+
terminalButton.addEventListener(`click`, () => {
119+
if (firstPress) {
120+
firstPress = false;
121+
initTerminal(document.querySelector(`#footer-terminal`), NAMESPACE);
122+
}
123+
footer.classList.toggle("expanded");
124+
updateGrid();
125+
document.querySelector("#footer-terminal iframe").focus();
126+
});
127+
108128
});
109129

110130
/**
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { block } from "../../domUtils";
2+
3+
let INITIALIZED = false;
4+
5+
export function init (element, namespace) {
6+
7+
if (INITIALIZED) return;
8+
INITIALIZED = true;
9+
10+
let iFrame = block(`iframe`);
11+
iFrame.setAttribute(`src`, `/terminal/${ namespace ? "?NS=" + namespace : "" }`);
12+
iFrame.setAttribute(`frameborder`, "0");
13+
14+
element.appendChild(iFrame);
15+
16+
iFrame.addEventListener("load", () => {
17+
let title = document.querySelector("#footer-terminal iframe").contentDocument
18+
.querySelector("title").textContent.toLowerCase();
19+
if (title.indexOf(`not found`) !== -1 || title.indexOf(`404`) !== -1) {
20+
element.removeChild(iFrame);
21+
let b1 = block(`div`, `central`), b2 = block(`div`), b3 = block(`div`);
22+
b1.appendChild(b2);
23+
b2.appendChild(b3);
24+
b3.innerHTML = `To use the embedded terminal, you need <b>Cach&eacute; Web Terminal</b>
25+
to be installed in your system.<br/><br/>Please, visit
26+
<a href="http://intersystems-ru.github.io/webterminal/#downloads" target="_blank">
27+
WebTerminal homepage</a> to download and install it.`;
28+
element.appendChild(b1);
29+
}
30+
});
31+
32+
}

source/client/js/domUtils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ export function clearSelection () {
4040
document.selection.empty();
4141
}
4242

43+
/**
44+
* @param {boolean=false} [checked]
45+
* @returns {Element}
46+
*/
47+
export function toggle (checked = false) {
48+
let id = `checkbox-${ Math.random().toString().slice(2) }`,
49+
box = block(`span`, `toggle`),
50+
label = block(`label`),
51+
checkbox = block(`input`);
52+
checkbox.setAttribute(`type`, `checkbox`);
53+
checkbox.setAttribute(`id`, id);
54+
label.setAttribute(`for`, id);
55+
if (checked)
56+
checkbox.setAttribute(`checked`, "true");
57+
box.appendChild(checkbox);
58+
box.appendChild(label);
59+
box.checkbox = checkbox;
60+
return box;
61+
}
62+
4363
/**
4464
* This function removes child taking animation into account.
4565
* @param {HTMLElement} element

0 commit comments

Comments
 (0)