Skip to content

Commit 96d6a09

Browse files
The latest version brings complete self-update mechanism, finally!
1 parent 2c179e5 commit 96d6a09

File tree

5 files changed

+61
-36
lines changed

5 files changed

+61
-36
lines changed

export/template.xml

+41-15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<Export generator="Cache" version="25">
33
<Class name="WebTerminal.Engine">
44
<Description>
5-
Cache WEB Terminal vX.X.X/*build.replace:pkg.version*/
6-
This class is the core of web terminal application.</Description>
5+
Cache WEB Terminal version X.X.X/*build.replace:pkg.version*/ core.
6+
This class is the server-side core of the terminal application.</Description>
77
<Super>%CSP.WebSocket,%Library.Routine</Super>
88
<TimeCreated>63891,56786.028532</TimeCreated>
99

@@ -835,9 +835,8 @@ This method transforms error </Description>
835835
set httprequest = ##class(%Net.HttpRequest).%New()
836836
set httprequest.Server = "intersystems-ru.github.io"
837837
do ..SendData("34", ..#ConstClientOutputLocalized)
838-
do ..SendData(" http://intersystems-ru.github.io/webterminal/files/WebTerminal-"
839-
_ version _ ".xml ")
840-
do httprequest.Get("/webterminal/files/WebTerminal-" _ version _ ".xml")
838+
do ..SendData(" http://intersystems-ru.github.io/webterminal/files/" _ version _ ".xml ")
839+
do httprequest.Get("/webterminal/files/" _ version _ ".xml")
841840
if (httprequest.HttpResponse.StatusCode '= 200) {
842841
do ..SendData($C(27)_"[31mFAIL" _ $C(27) _ "[0m (status code "
843842
_ httprequest.HttpResponse.StatusCode _ ")" _ $C(13,10))
@@ -848,14 +847,32 @@ This method transforms error </Description>
848847
do ..SendData($C(13,10))
849848
do ..SendData("35", ..#ConstClientOutputLocalized)
850849
do ..SendData($C(13,10))
851-
set stload = $System.OBJ.LoadStream(httprequest.HttpResponse.Data,"",.error,.items)
852-
if $$$ISERR(stload) { do ..SendData($System.Status.GetErrorText(stload)) quit $$$NOTOK }
853-
set st2 = $System.OBJ.CompileList(.items)
854-
if $$$ISERR(st2) { do ..SendData($System.Status.GetErrorText(st2)) quit $$$NOTOK }
855-
if $$$ISERR(error) {
856-
do ..SendData($C(27)_"[31mFAILED" _ $C(27) _ "[0m" _ $C(13,10))
850+
do ..SendData("Moving back to terminal's home namespace " _ ..InitialZNamespace _ "...")
851+
zn ..InitialZNamespace
852+
do ..StartClearIO()
853+
set stload = $System.OBJ.LoadStream(httprequest.HttpResponse.Data, "", .error, .items)
854+
if $$$ISERR(stload) {
855+
w $C(27)_"[31mFAILED" _ $C(27) _ "[0m " _ $System.Status.GetErrorText(stload)
857856
quit $$$NOTOK
858857
}
858+
set logFileName = ##class(%File).SubDirectoryName(##class(%File).ManagerDirectory(),"CWTUpdateLog.txt")
859+
open logFileName:("NRW"):5
860+
set io = $IO
861+
use logFileName
862+
set st2 = $System.OBJ.CompileList(.items, "cuk /checkuptodate=none")
863+
close logFileName
864+
use io
865+
if $$$ISERR(st2) { write $System.Status.GetErrorText(st2) quit $$$NOTOK }
866+
do ..EndClearIO()
867+
if ##class(%File).Exists(logFileName) {
868+
set stream = ##class(%Stream.FileCharacter).%New()
869+
set sc = stream.LinkToFile(logFileName)
870+
while 'stream.AtEnd {
871+
set line = stream.Read()
872+
do ..SendData(line)
873+
}
874+
do ##class(%File).Delete(logFileName)
875+
}
859876
}
860877
quit $$$OK
861878
]]></Implementation>
@@ -1056,12 +1073,17 @@ Main method for every new client.</Description>
10561073
10571074
} elseif (action = ..#ConstServerActionCheckUpdate) {
10581075
1059-
do ..CheckUpdate()
1076+
if ('$$$ISOK(..CheckUpdate())) {
1077+
do ..SendData($NAMESPACE, ..#ConstClientPrompt)
1078+
}
10601079
10611080
} elseif (action = ..#ConstServerActionUpdate) {
10621081
1063-
do ..Update(data)
1064-
do ..SendData("39", ..#ConstClientOutputLocalized)
1082+
if $$$ISOK(..Update(data)) {
1083+
do ..SendData("39", ..#ConstClientOutputLocalized)
1084+
} else {
1085+
do ..SendData($NAMESPACE, ..#ConstClientPrompt)
1086+
}
10651087
10661088
} else { // something scary
10671089
@@ -1171,9 +1193,11 @@ This method is invoked when a class is compiled.</Description>
11711193
}
11721194
w !, "Mapping %WebTerminal package into all namespaces:"
11731195
set mapTo = $LISTBUILD("%All", "SAMPLES", "DOCBOOK")
1174-
set Properties("Database") = "CACHETEMP"
1196+
do ##Class(Config.Namespaces).Get("USER", .InstallNSProps)
1197+
set Properties("Database") = $get(InstallNSProps("Routines"))
11751198
set ptr = 0
11761199
while $LISTNEXT(mapTo, ptr, value) {
1200+
continue:(ns = value)
11771201
w " ", value
11781202
set status = ##Class(Config.MapPackages).Create(value, "WebTerminal", .Properties)
11791203
if ($$$ISERR(status)) {
@@ -1212,6 +1236,7 @@ This method is invoked when a class is 'uncompiled'.</Description>
12121236
set mapTo = $LISTBUILD("%All", "SAMPLES", "DOCBOOK")
12131237
set ptr = 0
12141238
while $LISTNEXT(mapTo, ptr, value) {
1239+
continue:(ns = value)
12151240
w " ", value
12161241
set status = ##Class(Config.MapPackages).Delete(value, "WebTerminal")
12171242
if ($$$ISERR(status)) {
@@ -1230,6 +1255,7 @@ This method is invoked when a class is 'uncompiled'.</Description>
12301255
<Class name="WebTerminal.Router">
12311256
<Description>
12321257
The REST interface: class that routes HTTP requests</Description>
1258+
<CompileAfter>StaticContent</CompileAfter>
12331259
<Super>%CSP.REST</Super>
12341260
<TimeCreated>63890,69646.001045</TimeCreated>
12351261

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"title": "Cache WEB Terminal",
44
"description": "Web-based terminal emulator for Caché administering.",
55
"author": "ZitRo",
6-
"version": "3.1.1",
7-
"releaseNumber": 13,
6+
"version": "3.1.4",
7+
"releaseNumber": 15,
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/intersystems-ru/webterminal.git"

readme.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Web-based terminal application for InterSystems Caché database. Access your dat
44
Visit [project page](http://intersystems-ru.github.io/webterminal) for more details.
55

66
### Installation
7-
Download latest version from <a href="http://intersystems-ru.github.io/webterminal/#downloads">project page</a> and import XML file into %SYS namespace. Make sure that you have enabled write access to CACHELIB database during installation process. Later you can update application by typing "/update" command.
7+
Download the latest version from <a href="http://intersystems-ru.github.io/webterminal/#downloads">project page</a>
8+
and import XML file into %SYS namespace. Later you can update application only by typing `/update` command.
89

910
### Usage
1011
After installation, you will be able to access application at `http://[host]:[port]/terminal/` (slash at the end is required).
@@ -50,7 +51,7 @@ Type "/help" there to get more information.
5051
</tr>
5152
<tr>
5253
<td class="info">Self-update</td>
53-
<td>Second version of terminal can be automatically updated by one command.</td>
54+
<td>Terminal v3.1.4 can be automatically updated by `/update` command.</td>
5455
</tr>
5556
<tr>
5657
<td class="info">Explore!</td>
@@ -62,15 +63,15 @@ Type "/help" there to get more information.
6263
We are glad to see anyone who want to contribute to Caché WEB Terminal development! Check the
6364
[developer's](https://github.com/intersystems-ru/webterminal/blob/master/DEVELOPMENT.md) guide.
6465

65-
In short, the "hot start" is extremely easy. Having latest [NodeJS](https://nodejs.org/en/) installed,
66+
In short, the "hot start" is extremely easy. Having latest [Git](https://git-scm.com/) and [NodeJS](https://nodejs.org/en/) installed,
6667
execute the following:
6768

6869
```sh
69-
git clone <this repository URL>
70-
cd <cloned repository name>
71-
npm install -g gulp
72-
npm install
73-
gulp
70+
git clone <this repository URL> # clone this repository into new directory
71+
cd <cloned repository name> # enter just created directory
72+
npm install -g gulp # install the global module "gulp" to build the project
73+
npm install # install all project's dependencies
74+
gulp # build the project
7475
```
7576

7677
Now, in `build` folder you will find `CacheWebTerminal-v*.xml` file ready to import. Every time you

webSource/js/TerminalController.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,10 @@ TerminalController.prototype.clientAction = {
533533
PROMPT_UPDATE: function (data) {
534534

535535
var _this = this,
536-
version,
537-
releaseNumber = data.split("#");
538-
539-
version = releaseNumber[1];
540-
releaseNumber = parseInt(releaseNumber[0]);
536+
parts = data.split("#"),
537+
version = parts[1],
538+
releaseNumber = parseInt(parts[0]),
539+
comment = parts[2] || "";
541540

542541
if (!version || !releaseNumber) {
543542
console.error("Unable to parse version data: ", data);
@@ -547,8 +546,9 @@ TerminalController.prototype.clientAction = {
547546
if (releaseNumber > this.TERMINAL.RELEASE_NUMBER) {
548547
this.TERMINAL.output.print(this._lc.get(23) + "\r\n");
549548
this.TERMINAL.input.prompt("", 1, function (string) {
550-
if (string.toLowerCase() === "y") {
549+
if (string === "" || string.toLowerCase() === "y") {
551550
_this.TERMINAL.output.print(" " + _this._lc.get(24) + "\r\n");
551+
if (comment) _this.TERMINAL.output.print("\r\n" + comment + "\r\n\r\n");
552552
_this.server.send(_this.SERVER_ACTION.UPDATE + version);
553553
} else {
554554
_this.clientAction["PROMPT"].call(_this, _this.NAMESPACE);

webSource/js/TerminalLocalization.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ var TerminalLocalization = function (TERMINAL) {
202202
ru: "Авторизация не удалась."
203203
},
204204
23: {
205-
en: "A new version of Caché WEB Terminal available. Would you" +
206-
"like to install it? (Make sure that user has write permission to CACHELIB " +
207-
"database) (Y/N)",
205+
en: "A new version of Caché WEB Terminal available. Would you " +
206+
"like to install it? (Y/n)",
208207
ru: "Новая версия Caché WEB Terminal доступна. Хотите ли вы " +
209-
"установить её? (Убедитесь, что пользователь имеет права на запись в базу " +
210-
"данных CACHELIB) (Y/N)"
208+
"установить её? (Y/n)"
211209
},
212210
24: {
213211
en: "Updating...",

0 commit comments

Comments
 (0)