allow save pre-config list of server
This commit is contained in:
parent
211152a70d
commit
8efd97ba75
@ -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
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@ $(document).ready(function() {
|
||||
$("#serverContainer").hide();
|
||||
persistenceManager.initializeSettings();
|
||||
setLanguage(persistenceManager.getLanguage());
|
||||
readServerList();
|
||||
updateServerList();
|
||||
|
||||
//Check SSL host
|
||||
@ -223,4 +224,4 @@ $("#showDateSettingsSwitch").click(function() {
|
||||
$("#readLogFileSwitch").click(function() {
|
||||
//Update modal switches and boxes with saved settings
|
||||
persistenceManager.setSetting("retrieveLogFile", $("#readLogFileSwitch").is(":checked"));
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user