Skip to content

Commit 22134e7

Browse files
Renaming terminal instances feature add
1 parent 0d82f63 commit 22134e7

File tree

7 files changed

+93
-17
lines changed

7 files changed

+93
-17
lines changed

export/WebTerminal/Common.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ How long to wait for authorization key when connection established</Description>
6161
<Default>U</Default>
6262
</Parameter>
6363

64+
<Parameter name="ServerActionRename">
65+
<Type>%Char</Type>
66+
<Default>RENAME</Default>
67+
</Parameter>
68+
6469
<Parameter name="ClientPrompt">
6570
<Type>%String</Type>
6671
<Default>PROMPT#</Default>

export/WebTerminal/Engine.xml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-12-21 13:52:46">
2+
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.3 (Build 215U)" ts="2015-12-27 13:48:44">
33
<Class name="WebTerminal.Engine">
44
<Description>
55
Cache WEB Terminal version X.X.X/*build.replace:pkg.version*/ core.
66
This class is the server-side core of the terminal application.</Description>
77
<Super>%CSP.WebSocket,Trace,Autocomplete</Super>
8-
<TimeChanged>63907,49887.419268</TimeChanged>
8+
<TimeChanged>63913,49707.26915</TimeChanged>
99
<TimeCreated>63891,56786.028532</TimeCreated>
1010
<DependsOn>Common</DependsOn>
1111

@@ -617,6 +617,12 @@ Main method for every new client.</Description>
617617
do ..SendData($NAMESPACE, ..#ClientPrompt)
618618
}
619619
620+
} elseif (action = ..#ServerActionRename) {
621+
622+
set ^WebTerminal("Name") = data
623+
do ..SendData("56", ..#ClientOutputLocalized)
624+
do ..SendData($NAMESPACE, ..#ClientPrompt)
625+
620626
} else { // something scary
621627
622628
do ..SendData("38", ..#ClientOutputLocalized)
@@ -629,19 +635,41 @@ Main method for every new client.</Description>
629635
]]></Implementation>
630636
</Method>
631637

638+
<Method name="SendLoginInfo">
639+
<Description>
640+
This method sends basic login info to the user. Use this method to set client variables
641+
during the WebTerminal initialization.</Description>
642+
<Implementation><![CDATA[
643+
set obj = ##class(%ZEN.proxyObject).%New()
644+
set obj.username = $USERNAME
645+
set obj.name = $get(^WebTerminal("Name"))
646+
647+
// "pretty" json formatter
648+
set data = "{""system"":""" _ $SYSTEM _ """"
649+
set key = $order(obj.%data(""))
650+
while (key '= "") {
651+
set data = data _ ","""_key_""":"""_obj.%data(key)_""""
652+
set key = $order(obj.%data(key))
653+
}
654+
set data = data _ "}"
655+
656+
do ..SendData(data, ..#ClientLoginInfo)
657+
]]></Implementation>
658+
</Method>
659+
632660
<Method name="Server">
633661
<Description>
634662
New connection established: require auth key, login and start client loop.</Description>
635663
<ReturnType>%Status</ReturnType>
636664
<Implementation><![CDATA[
637665
638-
/*UNCOMMENT ON RELEASE!*/
639666
if ($$$ISOK(..RequireAuthorization())) {
640667
641668
set ..CurrentNamespace = $Znspace
642669
643670
do ..SendData("1", ..#ClientAuthorizationStatus)
644671
do ..SendData(..CurrentNamespace, ..#ClientChangeNamespace)
672+
do ..SendLoginInfo()
645673
646674
use $io:(/NOXY:/BREAK):"^" _ ..InitialZName
647675
do ..ClientLoop()

package.json

Lines changed: 2 additions & 2 deletions
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.8",
7-
"releaseNumber": 18,
6+
"version": "3.2.0",
7+
"releaseNumber": 19,
88
"repository": {
99
"type": "git",
1010
"url": "https://github.com/intersystems-ru/webterminal.git"

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Type `/help` there to get more information.
5050
<td>Access to WebSocket is granted only if client will pass a session key given by csp page.</td>
5151
</tr>
5252
<tr>
53-
<td class="info">Self-update</td>
54-
<td>Terminal v3.1.4 can be automatically updated by `/update` command.</td>
53+
<td class="info">Self-updating</td>
54+
<td>Terminal version 3.1.4 and higher can be automatically updated by using `/update` command.</td>
5555
</tr>
5656
<tr>
5757
<td class="info">Explore!</td>

webSource/js/Terminal.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,27 @@ Terminal.prototype.initialize = function () {
170170

171171
};
172172

173+
/**
174+
* This function is executed when server instance ready and basic server info is sent to the client.
175+
*/
176+
Terminal.prototype.serverInit = function (data) {
177+
178+
if (typeof data.system === "string") {
179+
var nodeInfo = data.system.split(":"); // [PCName, Instance]
180+
data.node = nodeInfo[0];
181+
data.instance = nodeInfo[1];
182+
}
183+
184+
if (data.node && data.instance) {
185+
document.title = (data.name ? data.name + " " : "") + data.instance
186+
+ " (" + data.node + ")" + " - Caché WEB Terminal";
187+
this.output.print(this.localization.get(
188+
data.name ? 55 : 54, data.node, data.instance, data.name ? data.name : undefined
189+
) + "\r\n");
190+
}
191+
192+
};
193+
173194
/**
174195
* Function to register execution of other functions when terminal in ready state. (when all
175196
* modules loaded)

webSource/js/TerminalController.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ TerminalController.prototype.SERVER_ACTION = {
7777
RESET: "R#",
7878
ECHO: "E#",
7979
CHECK_UPDATE: "CU#",
80-
UPDATE: "U#"
80+
UPDATE: "U#",
81+
RENAME: "RENAME#"
8182
};
8283

8384
/**
@@ -121,14 +122,6 @@ TerminalController.prototype.internalCommands = {
121122
return;
122123
}
123124

124-
// if (args[0] === "gen") {
125-
// this.server.send(this.SERVER_ACTION.AUTOCOMPLETE);
126-
// } else {
127-
// this.mergeAutocompleteFile(this.NAMESPACE);
128-
// }
129-
//
130-
// return false;
131-
132125
this.server.send(this.SERVER_ACTION.AUTOCOMPLETE
133126
+ (!this.autocompleteController.SYSTEM_CLASSES_LOADED
134127
|| args[0] === "sys" ? "1" : "0"));
@@ -325,6 +318,13 @@ TerminalController.prototype.internalCommands = {
325318

326319
return false;
327320

321+
},
322+
323+
"rename": function (args) {
324+
325+
this.server.send(this.SERVER_ACTION.RENAME + (args[0] || ""));
326+
return false;
327+
328328
}
329329

330330
};
@@ -523,7 +523,11 @@ TerminalController.prototype.clientAction = {
523523
},
524524

525525
I: function (data) {
526-
this.TERMINAL.output.print(data + "\r\n");
526+
527+
var obj = {}; try { obj = JSON.parse(data) } catch (e) { }
528+
529+
this.TERMINAL.serverInit(obj);
530+
527531
},
528532

529533
CLRSCR: function () {

webSource/js/TerminalLocalization.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ var TerminalLocalization = function (TERMINAL) {
5252
"autocomplete again, use " +
5353
"\x1B[1msys\x1B[0m parameter.\r\n" +
5454
"\x1B[33m/echo\x1B[0m [param1] [param2] ...\x1B[32GEcho each argument of this command." +
55+
"\r\n\x1B[33m/rename\x1B[0m [name]\x1B[32GSpecify a name for the terminal instance. This name " +
56+
"will be shown after terminal startup and as a page title. Empty argument will remove specified name." +
5557
"\r\n\x1B[33m/trace\x1B[0m [global/filePath]\x1B[32GStart tracing global or file. To stop " +
5658
"tracing, enter command without arguments. To stop tracing particular file or " +
5759
"global, enter trace command again.\r\n" +
@@ -77,6 +79,8 @@ var TerminalLocalization = function (TERMINAL) {
7779
"в ваш код или хотите обновить автодополнение системных классов, воспользуйтесь параметром " +
7880
"\x1B[1msys\x1B[0m.\r\n" +
7981
"\x1B[33m/echo\x1B[0m [параметр1] [второй] ...\x1B[32GОтображает каждый аргумент команды." +
82+
"\r\n\x1B[33m/rename\x1B[0m [name]\x1B[32GУстановить имя для экземпляра терминала. Это имя " +
83+
"будет показано после загрузки терминала и как заголовок страницы. Пустой аргумент уберёт установленное имя." +
8084
"\r\n\x1B[33m/trace\x1B[0m [глобал/путь]\x1B[32GНаблюдать за изменениями в файле или глобале. Чтобы " +
8185
"перестать наблюдать за изменениями, введите команду ещё раз. Команда без аргументов" +
8286
" остановит наблюдение за всеми файлами и глобалами.\r\n" +
@@ -336,6 +340,20 @@ var TerminalLocalization = function (TERMINAL) {
336340
53: {
337341
en: "Loaded.",
338342
ru: "Загружено."
343+
},
344+
54: {
345+
en: "System %s, user %s.",
346+
ru: "Система %s, пользователь %s."
347+
},
348+
55: {
349+
en: "System %s, user %s, name: %s.",
350+
ru: "Система %s, пользователь %s, имя: %s."
351+
},
352+
56: {
353+
en: "Terminal instance name changed successfully. Please, reload the page to see" +
354+
" the changes.",
355+
ru: "Экземпляр терминала переименован успешно. Пожалуйста, обновите страницу чтобы" +
356+
" увидеть изменения."
339357
}
340358
};
341359

0 commit comments

Comments
 (0)