refactor init sequence

This commit is contained in:
Girish Ramakrishnan
2024-07-15 17:30:50 +02:00
parent 5b567ac941
commit 11dce549bd
6 changed files with 89 additions and 76 deletions
+2 -25
View File
@@ -1,6 +1,6 @@
'use strict';
/* global angular:false */
/* global angular:false, window, document, localStorage, redirectIfNeeded */
/* global $:false */
/* global async */
/* global ERROR,ISTATES,HSTATES,RSTATES,APP_TYPES,NOTIFICATION_TYPES */
@@ -778,35 +778,12 @@ app.controller('MainController', ['$scope', '$route', '$timeout', '$location', '
});
}
function redirectIfNeeded(status) {
if (!status.activated) {
console.log('Not activated yet, redirecting', status);
if (status.restore.active || status.restore.errorMessage) { // show the error message in restore page
window.location.href = '/restore.html' + window.location.search;
} else if (status.adminFqdn) {
window.location.href = 'https://' + status.adminFqdn + '/activation.html' + (window.location.search);
} else {
window.location.href = '/setup.html' + window.location.search;
}
return true;
}
// support local development with localhost check
if (window.location.hostname !== status.adminFqdn && window.location.hostname !== 'localhost' && !window.location.hostname.startsWith('192.')) {
// user is accessing by IP or by the old admin location (pre-migration)
window.location.href = '/setup.html' + window.location.search;
return true;
}
return false;
}
// this loads the very first thing when accessing via IP or domain
function init() {
Client.getProvisionStatus(function (error, status) {
if (error) return Client.initError(error, init);
if (redirectIfNeeded(status)) return;
if (redirectIfNeeded(status, 'dashboard')) return; // we got redirected...
// check version and force reload if needed
if (!localStorage.version) {