Skip to content

Commit

Permalink
allow save pre-config list of server
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzvn committed Sep 25, 2021
1 parent 211152a commit 8efd97b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions client/scripts/WebConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ var autoPasswordCompleted = false; //When true, saved password was used. If a 40
var statusCommandsInterval = -1;
var commandHistoryIndex = -1; //Saves current command history index. -1 when not browsing history.

/**
* Load list of servers in file servers.json
* and auto update in next request when file is changed
*/
function readServerList() {
let hash = persistenceManager.getSetting('server:hash')

/**
* Hash code function used for compare version of file servers.json
* https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
*/
const hashCode = s => s.split('').reduce((a,b)=>{a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);

fetch('servers.json')
.then(res => res.text())
.then(json => {
if (hash !== hashCode(json)) {
persistenceManager.setSetting('server:hash', hashCode(json))
JSON.parse(json).forEach(server => persistenceManager.saveServer(server))
}
})
.then(updateServerList)
.catch(() => console.info('Ignore load new list in file servers.json.'));
}

/**
* Prepare and show server to user
*/
Expand Down
3 changes: 2 additions & 1 deletion client/scripts/WebConsoleJqueryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $(document).ready(function() {
$("#serverContainer").hide();
persistenceManager.initializeSettings();
setLanguage(persistenceManager.getLanguage());
readServerList();
updateServerList();

//Check SSL host
Expand Down Expand Up @@ -223,4 +224,4 @@ $("#showDateSettingsSwitch").click(function() {
$("#readLogFileSwitch").click(function() {
//Update modal switches and boxes with saved settings
persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked"));
});
});

0 comments on commit 8efd97b

Please sign in to comment.