Skip to content

Commit 333a8f9

Browse files
autocomplete restored
1 parent d054dd7 commit 333a8f9

File tree

6 files changed

+57
-91
lines changed

6 files changed

+57
-91
lines changed

DEVELOPMENT.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Contributing
1010
* <code>npm install</code> (to install all required dependencies).
1111
1. To test your changes in sources without exporting:
1212
1. Comment/replace <code>$$$ISOK(..RequireAuthorization())</code> in %WebTerminal.Engine studio class;
13-
2. Run <code>index.html</code> file from any local server. You may also need to change the debug port 57772 in TerminalController.js.
13+
2. Open <code>index.html</code> file from local server (execute `node localServer/run.js`). You may also need to change the debug port 57772 in TerminalController.js.
1414
2. After changes tested, export the project to studio:
15-
1. Run <code>grunt</code> command to build the project;
16-
2. If there is no errors, then run <code>grunt export</code> task;
17-
3. Find build/CWTWebSource.xml file and import it to the studio.
18-
3. By making changes in studio files (*.cls, *.mac) just copy source code into appropriate files in repository.
19-
4. If you commented line as the first step says, DO NOT FORGET to uncomment it.
15+
1. Run <code>gulp</code> command to build the project;
16+
3. Find build/CacheWebTerminal-v*.xml file and import it to the studio.
17+
3. By making changes in studio files (*.cls, *.mac) just export the code into appropriate files in repository. (insert changes by copying them into `export/template.xml` file)
18+
4. If you commented line as the first step says, fo not forget to uncomment it.
2019

2120
## Applications Integration
2221
If you want to integrate WebTerminal with your application, follow the next tips & tricks:
23-
* An <code>NS</code> parameter of GET request can set default namespace. For example, URL <code>../WebTerminal/index.csp?NS=USER</code> will open terminal in USER namespace.
22+
* An <code>NS</code> parameter of GET request can set default namespace. For example, URL `../terminal/?NS=USER` will open terminal in USER namespace.
2423
* In order to use IFrame to insert terminal on page, you may need to add <code>sandbox="allow-same-origin allow-scripts"</code> attribute to IFrame tag to enable storage and scripts which are required.
25-
* To get latest version of terminal, you can parse [latestVersion](http://intersystems-ru.github.io/webterminal/latestVersion) file which is always available on WEB and then request XML to import from <code>http://intersystems-ru.github.io/webterminal/files/WebTerminal-<b>{FILE PART}</b>.xml</code>.
24+
* To get latest version of terminal, you can parse [latestVersion](http://intersystems-ru.github.io/webterminal/latestVersion) file which is always available on WEB and then request XML to import from `http://intersystems-ru.github.io/webterminal/files/WebTerminal-<b>{FILE PART}</b>.xml`.
25+
* Web Terminal is able to auto-update itself, just execute `/update` command in the terminal.

export/template.xml

Lines changed: 37 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -582,33 +582,6 @@ This method watches only for tail of global and detects if global still alive</D
582582
]]></Implementation>
583583
</Method>
584584

585-
<Method name="GetJSAutocompleteFilePath">
586-
<ClassMethod>1</ClassMethod>
587-
<FormalSpec>namespace:%String</FormalSpec>
588-
<ReturnType>%String</ReturnType>
589-
<Implementation><![CDATA[
590-
set data = ##class(%Library.File).ManagerDirectory()
591-
set data = ##class(%Library.File).ParentDirectoryName(data)
592-
593-
set dataTest = ##class(%Library.File).SubDirectoryName(data, "CSP")
594-
if (##class(%Library.File).DirectoryExists(dataTest)) {
595-
set data = ##class(%Library.File).SubDirectoryName(data, "CSP")
596-
} else {
597-
set data = ##class(%Library.File).SubDirectoryName(data, "csp")
598-
}
599-
600-
set data = ##class(%Library.File).SubDirectoryName(data,
601-
$ZCONVERT($REPLACE("%SYS", "%", ""), "l")
602-
)
603-
set data = ##class(%Library.File).SubDirectoryName(data, "webterminal")
604-
set data = ##class(%Library.File).SubDirectoryName(data, "js")
605-
set data = ##class(%Library.File).SubDirectoryName(data, "autocomplete")
606-
set data = ##class(%Library.File).SubDirectoryName(data, namespace _ ".js")
607-
608-
quit data
609-
]]></Implementation>
610-
</Method>
611-
612585
<Method name="WriteToFile">
613586
<ClassMethod>1</ClassMethod>
614587
<FormalSpec>filename:%String,data:%String</FormalSpec>
@@ -643,45 +616,34 @@ This method watches only for tail of global and detects if global still alive</D
643616
]]></Implementation>
644617
</Method>
645618

646-
<Method name="GenerateAutocompleteFile">
619+
<Method name="AutocompleteExists">
620+
<FormalSpec>namespace:%String</FormalSpec>
621+
<ReturnType>%Boolean</ReturnType>
622+
<Implementation><![CDATA[ quit $get(^%WebTerminal.Autocomplete(namespace)) '= ""
623+
]]></Implementation>
624+
</Method>
625+
626+
<Method name="GenerateAutocomplete">
647627
<Description>
648-
Generates autocomplete file for namespace. Second parameter decides if
628+
Generates autocomplete for namespace. Second parameter decides if
649629
it will be regenerated again. But if namespace equals to "%" - generates
650-
autocomplete file for system classes. Make sure that autocomplete for
630+
autocomplete for system classes. Make sure that autocomplete for
651631
system classes generates one time and forever.
652632
@param genSystem - Shows if system classes need to be generated. </Description>
653633
<FormalSpec>namespace:%String,genSystem:%Boolean</FormalSpec>
654634
<ReturnType>%String</ReturnType>
655635
<Implementation><![CDATA[
656-
657-
if (genSystem) {
658-
set filename = ..GetJSAutocompleteFilePath("%")
659-
} else {
660-
set filename = ..GetJSAutocompleteFilePath(namespace)
661-
}
636+
set trueNs = $case(genSystem, 1:"%", :namespace)
662637
663638
do ..SendData("29", ..ConstClientOutputLocalized)
664-
do ..SendData(" " _ filename _ $C(13, 10))
639+
do ..SendData(" " _ trueNs _ $C(13, 10))
665640
666641
if ('##class(%SYS.Namespace).Exists(namespace)) {
667642
do ..SendData("30", ..ConstClientOutputLocalized)
668643
do ..SendData(" " _ namespace _ $C(13, 10))
669644
quit $$$NOTOK
670645
}
671646
672-
if ('##class(%File).DirectoryExists(##class(%File).GetDirectory(filename))) {
673-
674-
// try to create missed directory
675-
set result = ##class(%File).CreateDirectoryChain(##class(%File).GetDirectory(filename))
676-
677-
if (result '= 1) {
678-
do ..SendData("31", ..ConstClientOutputLocalized)
679-
do ..SendData($C(13, 10))
680-
quit $$$OK
681-
}
682-
683-
}
684-
685647
// get all classes names
686648
set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary")
687649
do result.Execute()
@@ -711,11 +673,7 @@ system classes generates one time and forever.
711673
do ..SendData($C(13, 10))
712674
do ..SendData("32", ..ConstClientOutputLocalized)
713675
714-
set file=##class(%File).%New(filename)
715-
do file.Open("WSN")
716-
717-
// final data generation
718-
do file.Write("{""class"":{")
676+
set ac = "{""class"":{" // string with autocomplete
719677
set first = ""
720678
set u = 1
721679
@@ -730,7 +688,7 @@ system classes generates one time and forever.
730688
do ..SendData($C(27) _ "[30G" _ u)
731689
s u = u + 1
732690
733-
do file.Write(first _ """" _ className _ """:{")
691+
set ac = ac _ first _ """" _ className _ """:{"
734692
if (first = "") set first = ","
735693
736694
set cdefs = ##class(%Dictionary.ClassDefinition).%OpenId(className)
@@ -743,30 +701,31 @@ system classes generates one time and forever.
743701
744702
for i=1:1:countMethods {
745703
set current = current + 1
746-
do file.Write("""" _ cdefs.Methods.GetAt(i).Name _ """:0")
747-
if (current'=total) do file.Write(",")
704+
set ac = ac _ """" _ cdefs.Methods.GetAt(i).Name _ """:0"
705+
if (current'=total) set ac = ac _ ","
748706
}
749707
750708
for i=1:1:countProperties {
751709
set current = current + 1
752-
do file.Write("""" _ cdefs.Properties.GetAt(i).Name _ """:0")
753-
if (current'=total) do file.Write(",")
710+
set ac = ac _ """" _ cdefs.Properties.GetAt(i).Name _ """:0"
711+
if (current'=total) set ac = ac _ ","
754712
}
755713
756714
for i=1:1:countParameters {
757715
set current = current + 1
758-
do file.Write("""" _ cdefs.Parameters.GetAt(i).Name _ """:0")
759-
if (current'=total) do file.Write(",")
716+
set ac = ac _ """" _ cdefs.Parameters.GetAt(i).Name _ """:0"
717+
if (current'=total) set ac = ac _ ","
760718
}
761719
762-
do file.Write("}")
720+
set ac = ac _ "}"
763721
764722
}
765723
766-
do file.Write("}")
767-
if ('genSystem) do file.Write(",""global"":" _ ..getGlobalsJSON())
768-
do file.Write("}")
769-
do file.Close()
724+
set ac = ac _ "}"
725+
if ('genSystem) set ac = ac _ ",""global"":" _ ..getGlobalsJSON()
726+
set ac = ac _ "}"
727+
728+
set ^%WebTerminal.Autocomplete(trueNs) = ac
770729
771730
do ..SendData($C(13, 10))
772731
do ..SendData("33", ..ConstClientOutputLocalized)
@@ -784,10 +743,7 @@ Returns terminal to default state</Description>
784743
<ReturnType>%Status</ReturnType>
785744
<Implementation><![CDATA[
786745
// delete autocompletion files
787-
set dir = ##class(%File).GetDirectory(..GetJSAutocompleteFilePath("TEST"))
788-
if (##class(%File).DirectoryExists(dir)) {
789-
do ##class(%File).RemoveDirectoryTree(dir)
790-
}
746+
kill ^%WebTerminal.Autocomplete
791747
quit $$$OK
792748
]]></Implementation>
793749
</Method>
@@ -1059,7 +1015,7 @@ Main method for every new client.</Description>
10591015
10601016
} elseif (action = ..ConstServerActionStopTraceAll) { // add/remove
10611017
1062-
FOR i=1:1:$LISTLENGTH(..Watches) {
1018+
for i=1:1:$LISTLENGTH(..Watches) {
10631019
d ..StopTracing($LIST(..Watches, i))
10641020
}
10651021
do ..SendData($NAMESPACE, ..ConstClientPrompt)
@@ -1073,12 +1029,11 @@ Main method for every new client.</Description>
10731029
10741030
// data shows if system classes required
10751031
1076-
if ('##class("%Library.File").Exists(..GetJSAutocompleteFilePath("%")))
1077-
|| (data = "1") {
1078-
do ..GenerateAutocompleteFile("%SYS", 1)
1032+
if ('..AutocompleteExists("%")) || (data = "1") {
1033+
do ..GenerateAutocomplete("%SYS", 1)
10791034
do ..SendData("%", ..ConstClientLoadAutocomplete)
10801035
}
1081-
do ..GenerateAutocompleteFile(..CurrentNamespace, 0)
1036+
do ..GenerateAutocomplete(..CurrentNamespace, 0)
10821037
do ..SendData(..CurrentNamespace, ..ConstClientLoadAutocomplete)
10831038
10841039
} elseif (action = ..ConstServerActionReset) {
@@ -1215,6 +1170,7 @@ This method is invoked when a class is 'uncompiled'.</Description>
12151170
w !, "WEB application ""/terminal"" was successfully removed."
12161171
}
12171172
}
1173+
kill ^%WebTerminal.Autocomplete
12181174
zn:ns'="%SYS" ns
12191175
QUIT $$$OK
12201176
]]></Implementation>
@@ -1236,7 +1192,7 @@ The REST interface: class that routes HTTP requests</Description>
12361192
<Route Url="/css/terminal.css" Method="GET" Call="GetCss"/>
12371193
<Route Url="/css/terminal-theme/:theme" Method="GET" Call="GetTheme"/>
12381194
<Route Url="/js/terminal.js" Method="GET" Call="GetJs"/>
1239-
<Route Url="/Autocomplete" Method="GET" Call="WriteAutocomplete"/>
1195+
<Route Url="/autocomplete" Method="GET" Call="WriteAutocomplete"/>
12401196
</Routes>
12411197
]]></Data>
12421198
</XData>
@@ -1247,7 +1203,10 @@ Method returns autocomplete data in JSON format</Description>
12471203
<ClassMethod>1</ClassMethod>
12481204
<ReturnType>%Status</ReturnType>
12491205
<Implementation><![CDATA[
1250-
write "{""test"":1}"
1206+
set namespace = %request.Get("NS", $znspace)
1207+
set %response.CharSet = "utf-8"
1208+
set %response.ContentType = "application/json"
1209+
write $get(^%WebTerminal.Autocomplete(namespace), "{}")
12511210
return $$$OK
12521211
]]></Implementation>
12531212
</Method>

localServer/run.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var express = require("express"),
2+
app = express();
3+
4+
app.use(express.static(__dirname + "/../webSource"));
5+
6+
app.listen(80);
7+
console.log("Server listens on port 80.");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Cache WEB Terminal",
44
"description": "Web-based terminal emulator for Caché administering.",
55
"author": "ZitRo",
6-
"version": "3.0.0-alpha.2",
6+
"version": "3.0.0-alpha.3",
77
"releaseNumber": 11,
88
"repository": {
99
"type": "git",

webSource/js/CacheWebTerminalServer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ CacheWebTerminalServer.prototype.initialize = function () {
9898
*/
9999
CacheWebTerminalServer.prototype.getAutocompleteFile = function (namespace, callback) {
100100

101-
AJAX.get("js/autocomplete/" + encodeURIComponent(namespace) + ".js", function (data) {
101+
AJAX.get("autocomplete?NS=" + encodeURIComponent(namespace), function (data) {
102102

103103
try {
104104
data = JSON.parse(data);
105105
} catch (e) {
106106
data = null;
107-
console.warn("No autocomplete data for " + namespace);
107+
console.warn("Unable to parse autocomplete data for " + namespace);
108108
}
109109

110110
callback(data, namespace);

webSource/js/TerminalLocalization.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ var TerminalLocalization = function (TERMINAL) {
234234
ru: "Невозможно изменить язык на %s."
235235
},
236236
29: {
237-
en: "Start generating file",
238-
ru: "Начинается генерация файла"
237+
en: "Start generating autocomplete",
238+
ru: "Начинается генерация автодополнения"
239239
},
240240
30: {
241241
en: "Wrong namespace:",

0 commit comments

Comments
 (0)