Skip to content

Commit

Permalink
The latest version brings complete self-update mechanism, finally!
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaeverywhere committed Dec 13, 2015
1 parent 2c179e5 commit 96d6a09
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 36 deletions.
56 changes: 41 additions & 15 deletions export/template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Export generator="Cache" version="25">
<Class name="WebTerminal.Engine">
<Description>
Cache WEB Terminal vX.X.X/*build.replace:pkg.version*/
This class is the core of web terminal application.</Description>
Cache WEB Terminal version X.X.X/*build.replace:pkg.version*/ core.
This class is the server-side core of the terminal application.</Description>
<Super>%CSP.WebSocket,%Library.Routine</Super>
<TimeCreated>63891,56786.028532</TimeCreated>

Expand Down Expand Up @@ -835,9 +835,8 @@ This method transforms error </Description>
set httprequest = ##class(%Net.HttpRequest).%New()
set httprequest.Server = "intersystems-ru.github.io"
do ..SendData("34", ..#ConstClientOutputLocalized)
do ..SendData(" http://intersystems-ru.github.io/webterminal/files/WebTerminal-"
_ version _ ".xml ")
do httprequest.Get("/webterminal/files/WebTerminal-" _ version _ ".xml")
do ..SendData(" http://intersystems-ru.github.io/webterminal/files/" _ version _ ".xml ")
do httprequest.Get("/webterminal/files/" _ version _ ".xml")
if (httprequest.HttpResponse.StatusCode '= 200) {
do ..SendData($C(27)_"[31mFAIL" _ $C(27) _ "[0m (status code "
_ httprequest.HttpResponse.StatusCode _ ")" _ $C(13,10))
Expand All @@ -848,14 +847,32 @@ This method transforms error </Description>
do ..SendData($C(13,10))
do ..SendData("35", ..#ConstClientOutputLocalized)
do ..SendData($C(13,10))
set stload = $System.OBJ.LoadStream(httprequest.HttpResponse.Data,"",.error,.items)
if $$$ISERR(stload) { do ..SendData($System.Status.GetErrorText(stload)) quit $$$NOTOK }
set st2 = $System.OBJ.CompileList(.items)
if $$$ISERR(st2) { do ..SendData($System.Status.GetErrorText(st2)) quit $$$NOTOK }
if $$$ISERR(error) {
do ..SendData($C(27)_"[31mFAILED" _ $C(27) _ "[0m" _ $C(13,10))
do ..SendData("Moving back to terminal's home namespace " _ ..InitialZNamespace _ "...")
zn ..InitialZNamespace
do ..StartClearIO()
set stload = $System.OBJ.LoadStream(httprequest.HttpResponse.Data, "", .error, .items)
if $$$ISERR(stload) {
w $C(27)_"[31mFAILED" _ $C(27) _ "[0m " _ $System.Status.GetErrorText(stload)
quit $$$NOTOK
}
set logFileName = ##class(%File).SubDirectoryName(##class(%File).ManagerDirectory(),"CWTUpdateLog.txt")
open logFileName:("NRW"):5
set io = $IO
use logFileName
set st2 = $System.OBJ.CompileList(.items, "cuk /checkuptodate=none")
close logFileName
use io
if $$$ISERR(st2) { write $System.Status.GetErrorText(st2) quit $$$NOTOK }
do ..EndClearIO()
if ##class(%File).Exists(logFileName) {
set stream = ##class(%Stream.FileCharacter).%New()
set sc = stream.LinkToFile(logFileName)
while 'stream.AtEnd {
set line = stream.Read()
do ..SendData(line)
}
do ##class(%File).Delete(logFileName)
}
}
quit $$$OK
]]></Implementation>
Expand Down Expand Up @@ -1056,12 +1073,17 @@ Main method for every new client.</Description>
} elseif (action = ..#ConstServerActionCheckUpdate) {
do ..CheckUpdate()
if ('$$$ISOK(..CheckUpdate())) {
do ..SendData($NAMESPACE, ..#ConstClientPrompt)
}
} elseif (action = ..#ConstServerActionUpdate) {
do ..Update(data)
do ..SendData("39", ..#ConstClientOutputLocalized)
if $$$ISOK(..Update(data)) {
do ..SendData("39", ..#ConstClientOutputLocalized)
} else {
do ..SendData($NAMESPACE, ..#ConstClientPrompt)
}
} else { // something scary
Expand Down Expand Up @@ -1171,9 +1193,11 @@ This method is invoked when a class is compiled.</Description>
}
w !, "Mapping %WebTerminal package into all namespaces:"
set mapTo = $LISTBUILD("%All", "SAMPLES", "DOCBOOK")
set Properties("Database") = "CACHETEMP"
do ##Class(Config.Namespaces).Get("USER", .InstallNSProps)
set Properties("Database") = $get(InstallNSProps("Routines"))
set ptr = 0
while $LISTNEXT(mapTo, ptr, value) {
continue:(ns = value)
w " ", value
set status = ##Class(Config.MapPackages).Create(value, "WebTerminal", .Properties)
if ($$$ISERR(status)) {
Expand Down Expand Up @@ -1212,6 +1236,7 @@ This method is invoked when a class is 'uncompiled'.</Description>
set mapTo = $LISTBUILD("%All", "SAMPLES", "DOCBOOK")
set ptr = 0
while $LISTNEXT(mapTo, ptr, value) {
continue:(ns = value)
w " ", value
set status = ##Class(Config.MapPackages).Delete(value, "WebTerminal")
if ($$$ISERR(status)) {
Expand All @@ -1230,6 +1255,7 @@ This method is invoked when a class is 'uncompiled'.</Description>
<Class name="WebTerminal.Router">
<Description>
The REST interface: class that routes HTTP requests</Description>
<CompileAfter>StaticContent</CompileAfter>
<Super>%CSP.REST</Super>
<TimeCreated>63890,69646.001045</TimeCreated>

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"title": "Cache WEB Terminal",
"description": "Web-based terminal emulator for Caché administering.",
"author": "ZitRo",
"version": "3.1.1",
"releaseNumber": 13,
"version": "3.1.4",
"releaseNumber": 15,
"repository": {
"type": "git",
"url": "https://github.com/intersystems-ru/webterminal.git"
Expand Down
17 changes: 9 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Web-based terminal application for InterSystems Caché database. Access your dat
Visit [project page](http://intersystems-ru.github.io/webterminal) for more details.

### Installation
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.
Download the latest version from <a href="http://intersystems-ru.github.io/webterminal/#downloads">project page</a>
and import XML file into %SYS namespace. Later you can update application only by typing `/update` command.

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

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

```sh
git clone <this repository URL>
cd <cloned repository name>
npm install -g gulp
npm install
gulp
git clone <this repository URL> # clone this repository into new directory
cd <cloned repository name> # enter just created directory
npm install -g gulp # install the global module "gulp" to build the project
npm install # install all project's dependencies
gulp # build the project
```

Now, in `build` folder you will find `CacheWebTerminal-v*.xml` file ready to import. Every time you
Expand Down
12 changes: 6 additions & 6 deletions webSource/js/TerminalController.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,11 +533,10 @@ TerminalController.prototype.clientAction = {
PROMPT_UPDATE: function (data) {

var _this = this,
version,
releaseNumber = data.split("#");

version = releaseNumber[1];
releaseNumber = parseInt(releaseNumber[0]);
parts = data.split("#"),
version = parts[1],
releaseNumber = parseInt(parts[0]),
comment = parts[2] || "";

if (!version || !releaseNumber) {
console.error("Unable to parse version data: ", data);
Expand All @@ -547,8 +546,9 @@ TerminalController.prototype.clientAction = {
if (releaseNumber > this.TERMINAL.RELEASE_NUMBER) {
this.TERMINAL.output.print(this._lc.get(23) + "\r\n");
this.TERMINAL.input.prompt("", 1, function (string) {
if (string.toLowerCase() === "y") {
if (string === "" || string.toLowerCase() === "y") {
_this.TERMINAL.output.print(" " + _this._lc.get(24) + "\r\n");
if (comment) _this.TERMINAL.output.print("\r\n" + comment + "\r\n\r\n");
_this.server.send(_this.SERVER_ACTION.UPDATE + version);
} else {
_this.clientAction["PROMPT"].call(_this, _this.NAMESPACE);
Expand Down
8 changes: 3 additions & 5 deletions webSource/js/TerminalLocalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,10 @@ var TerminalLocalization = function (TERMINAL) {
ru: "Авторизация не удалась."
},
23: {
en: "A new version of Caché WEB Terminal available. Would you" +
"like to install it? (Make sure that user has write permission to CACHELIB " +
"database) (Y/N)",
en: "A new version of Caché WEB Terminal available. Would you " +
"like to install it? (Y/n)",
ru: "Новая версия Caché WEB Terminal доступна. Хотите ли вы " +
"установить её? (Убедитесь, что пользователь имеет права на запись в базу " +
"данных CACHELIB) (Y/N)"
"установить её? (Y/n)"
},
24: {
en: "Updating...",
Expand Down

0 comments on commit 96d6a09

Please sign in to comment.