refactor init sequence
This commit is contained in:
@@ -451,6 +451,70 @@ function translateFilterFactory($parse, $translate) {
|
||||
translateFilterFactory.displayName = 'translateFilterFactory';
|
||||
angular.module('Application').filter('tr', translateFilterFactory);
|
||||
|
||||
// checks provision status and redirects to correct view
|
||||
// {
|
||||
// setup: { active, message, errorMessage }
|
||||
// restore { active, message, errorMessage }
|
||||
// activated
|
||||
// adminFqn
|
||||
// }
|
||||
// returns true if redirected
|
||||
function redirectIfNeeded(status, currentView) {
|
||||
var search = decodeURIComponent(window.location.search).slice(1).split('&').map(function (item) { return item.split('='); }).reduce(function (o, k) { o[k[0]] = k[1]; return o; }, {});
|
||||
|
||||
if ('develop' in search || localStorage.getItem('develop')) {
|
||||
console.warn('Cloudron develop mode on. To disable run localStorage.removeItem(\'develop\')');
|
||||
localStorage.setItem('develop', true);
|
||||
return false;
|
||||
}
|
||||
|
||||
console.log(status, currentView);
|
||||
|
||||
if (status.activated) {
|
||||
console.log('Already activated');
|
||||
if (currentView === 'dashboard') {
|
||||
// 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;
|
||||
}
|
||||
window.location.href = '/';
|
||||
return true;
|
||||
}
|
||||
|
||||
if (status.setup.active) {
|
||||
console.log('Setup is active');
|
||||
if (currentView === 'setup') return false;
|
||||
window.location.href = '/setup.html' + window.location.search;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (status.restore.active) {
|
||||
console.log('Restore is active');
|
||||
if (currentView === 'restore') return;
|
||||
window.location.href = '/restore.html' + window.location.search;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (status.adminFqdn) {
|
||||
console.log('adminFqdn is set');
|
||||
// if we are here from https://ip/activation.html ,go to https://admin/activation.html
|
||||
if (status.adminFqdn !== window.location.hostname) {
|
||||
window.location.href = 'https://' + status.adminFqdn + '/activation.html' + (window.location.search);
|
||||
return true;
|
||||
}
|
||||
if (currentView === 'activation') return false;
|
||||
window.location.href = 'https://' + status.adminFqdn + '/activation.html' + (window.location.search);
|
||||
return true;
|
||||
}
|
||||
|
||||
// if we are here, proceed with current view
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------
|
||||
// Cloudron REST API wrapper
|
||||
|
||||
Reference in New Issue
Block a user