mirror of https://github.com/rancher/ui.git
refactor sever-url set into its own route and always check on load
This commit is contained in:
parent
ccb3923993
commit
6d9cc84a33
|
|
@ -23,7 +23,8 @@ const App = Application.extend({
|
|||
externalRoutes: {
|
||||
index: 'index',
|
||||
authenticated: 'authenticated',
|
||||
'update-password': 'update-password'
|
||||
'update-password': 'update-password',
|
||||
'update-critical-settings': 'update-critical-settings'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -64,7 +65,7 @@ const App = Application.extend({
|
|||
}
|
||||
}
|
||||
},
|
||||
logging: {
|
||||
logging: {
|
||||
dependencies: {
|
||||
services: [
|
||||
'app',
|
||||
|
|
|
|||
|
|
@ -34,9 +34,17 @@ export default Route.extend(Preload, {
|
|||
}, CHECK_AUTH_TIMER));
|
||||
|
||||
return this.testAuthToken().then(() => {
|
||||
|
||||
if (get(this, 'access.mustChangePassword')) {
|
||||
this.transitionTo('update-password');
|
||||
}
|
||||
|
||||
return this.loadPublicSettings().then(() => {
|
||||
if (get(this, 'settings.serverUrlIsEmpty')) {
|
||||
get(this, 'router').transitionTo('update-critical-settings');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -58,7 +66,7 @@ export default Route.extend(Preload, {
|
|||
this.loadClusters(),
|
||||
this.loadProjects(),
|
||||
this.loadPreferences(),
|
||||
this.loadPublicSettings(),
|
||||
// this.loadPublicSettings(),
|
||||
];
|
||||
|
||||
const globalStore = get(this, 'globalStore');
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ Router.map(function() {
|
|||
|
||||
this.route('verify-auth');
|
||||
this.route('update-password', {path: '/update-password'});
|
||||
this.route('update-critical-settings', {path: '/update-setting'});
|
||||
|
||||
this.route('authenticated', {path: '/'}, function() {
|
||||
// Global
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { get } from '@ember/object';
|
||||
import C from 'ui/utils/constants';
|
||||
|
||||
export default Controller.extend({
|
||||
});
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { get } from '@ember/object';
|
||||
import C from 'ui/utils/constants';
|
||||
|
||||
export default Route.extend({
|
||||
access: service(),
|
||||
settings: service(),
|
||||
globalStore: service(),
|
||||
|
||||
activate() {
|
||||
$('BODY').addClass('container-farm');
|
||||
},
|
||||
|
||||
deactivate() {
|
||||
$('BODY').removeClass('container-farm');
|
||||
},
|
||||
|
||||
model: function() {
|
||||
let globalStore = get(this, 'globalStore');
|
||||
|
||||
return globalStore.find('setting', C.SETTING.SERVER_URL).then((serverUrl) => {
|
||||
return {
|
||||
serverUrl: get(serverUrl, 'value') || window.location.host,
|
||||
serverUrlSetting: serverUrl,
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<div class="login">
|
||||
{{settings/server-url
|
||||
serverUrlSetting=model.serverUrlSetting
|
||||
serverUrl=model.serverUrl
|
||||
}}
|
||||
</div>
|
||||
|
|
@ -23,7 +23,8 @@ const Eng = Engine.extend({
|
|||
externalRoutes: [
|
||||
'index',
|
||||
'authenticated',
|
||||
'update-password'
|
||||
'update-password',
|
||||
'update-critical-settings',
|
||||
]
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { inject as service } from '@ember/service';
|
|||
import Controller from '@ember/controller';
|
||||
import { on } from '@ember/object/evented';
|
||||
import C from 'ui/utils/constants';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
|
||||
const USER_PASS_PROVIDERS = ['local','activedirectory'];
|
||||
|
||||
|
|
@ -60,28 +61,17 @@ export default Controller.extend({
|
|||
isCaas: computed('app.mode', function() {
|
||||
return get(this, 'app.mode') === 'caas' ? true : false;
|
||||
}),
|
||||
setServerUrl: false,
|
||||
serverUrlSetting: null,
|
||||
shouldSetServerUrl() {
|
||||
// setting isn't loaded yet
|
||||
let globalStore = get(this, 'globalStore');
|
||||
|
||||
return globalStore.find('setting', C.SETTING.SERVER_URL).then((serverUrl) => {
|
||||
|
||||
if (serverUrl && get(serverUrl, 'value') === "" && get(serverUrl, 'links.update')) {
|
||||
setProperties(this, {
|
||||
user: null,
|
||||
code: null,
|
||||
serverUrl: window.location.host,
|
||||
setServerUrl: true,
|
||||
serverUrlSetting: serverUrl,
|
||||
});
|
||||
if (serverUrl && isEmpty(get(serverUrl, 'value')) && get(serverUrl, 'links.update')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}).catch((err)=> {
|
||||
|
||||
return err;
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -99,8 +89,10 @@ export default Controller.extend({
|
|||
this.shouldSetServerUrl().then((proceed) => {
|
||||
if (proceed) {
|
||||
this.send('finishComplete');
|
||||
} else {
|
||||
get(this, 'router').transitionTo('update-critical-settings');
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -114,7 +106,7 @@ export default Controller.extend({
|
|||
|
||||
later(() => {
|
||||
get(this, 'access').login(provider, code).then((user) => {
|
||||
if ( user.mustChangePassword && provider === 'local' ) {
|
||||
if ( get(user, 'mustChangePassword') && provider === 'local' ) {
|
||||
get(this,'session').set(C.SESSION.BACK_TO, window.location.origin);
|
||||
get(this, 'router').transitionTo('update-password');
|
||||
} else {
|
||||
|
|
@ -123,7 +115,6 @@ export default Controller.extend({
|
|||
code: null,
|
||||
});
|
||||
this.send('complete', true);
|
||||
// this.send('finishLogin');
|
||||
}
|
||||
}).catch((err) => {
|
||||
set(this, 'waiting', false);
|
||||
|
|
|
|||
|
|
@ -1,68 +1,61 @@
|
|||
<div class="login">
|
||||
{{#if setServerUrl}}
|
||||
{{settings/server-url
|
||||
serverUrlSetting=serverUrlSetting
|
||||
serverUrl=serverUrl
|
||||
}}
|
||||
{{else}}
|
||||
<h1>
|
||||
{{t 'loginPage.greeting' appName=settings.appName htmlSafe=true}}
|
||||
<div class="logo"></div>
|
||||
</h1>
|
||||
<section class="pb-0">
|
||||
{{language-dropdown login=true class='mb-10'}}
|
||||
<br/>
|
||||
{{#unless promptPasswordReset}}
|
||||
{{#if isGithub}}
|
||||
{{login-github action="started"}}
|
||||
{{/if}}
|
||||
<h1>
|
||||
{{t 'loginPage.greeting' appName=settings.appName htmlSafe=true}}
|
||||
<div class="logo"></div>
|
||||
</h1>
|
||||
<section class="pb-0">
|
||||
{{language-dropdown login=true class='mb-10'}}
|
||||
<br/>
|
||||
{{#unless promptPasswordReset}}
|
||||
{{#if isGithub}}
|
||||
{{login-github action="started"}}
|
||||
{{/if}}
|
||||
|
||||
{{#if isShibboleth}}
|
||||
<p>{{t 'loginPage.shibbolethMessage' appName=settings.appName}}</p>
|
||||
<br/>
|
||||
{{login-shibboleth
|
||||
{{#if isShibboleth}}
|
||||
<p>{{t 'loginPage.shibbolethMessage' appName=settings.appName}}</p>
|
||||
<br/>
|
||||
{{login-shibboleth
|
||||
action="started"
|
||||
waiting=waiting
|
||||
}}
|
||||
{{/if}}
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{#if isCaas}}
|
||||
{{caas-login promptReset=(mut promptPasswordReset)}}
|
||||
{{/if}}
|
||||
{{#if isCaas}}
|
||||
{{caas-login promptReset=(mut promptPasswordReset)}}
|
||||
{{/if}}
|
||||
|
||||
{{#if isActiveDirectory}}
|
||||
{{login-user-pass
|
||||
{{#if isActiveDirectory}}
|
||||
{{login-user-pass
|
||||
classNames="row"
|
||||
action="authenticate"
|
||||
waiting=waiting
|
||||
provider="activedirectory"
|
||||
}}
|
||||
{{/if}}
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{#if isLocal}}
|
||||
{{login-user-pass
|
||||
{{#if isLocal}}
|
||||
{{login-user-pass
|
||||
classNames="row"
|
||||
action="authenticate"
|
||||
waiting=waiting
|
||||
shown=onlyLocal
|
||||
provider="local"
|
||||
}}
|
||||
{{/if}}
|
||||
|
||||
{{#if infoMsg}}
|
||||
<div class="banner p-10 {{if errorMsg 'bg-error' 'bg-warning'}}" role="alert">
|
||||
{{infoMsg}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
|
||||
{{#if app.initError}}
|
||||
{{banner-message color='bg-error' icon='icon-alert' message=app.initError.message}}
|
||||
|
||||
<button class="btn bg-primary" {{action "reload"}}>
|
||||
<i class="icon icon-refresh text-small"/> Reload
|
||||
</button>
|
||||
}}
|
||||
{{/if}}
|
||||
</section>
|
||||
{{/if}}
|
||||
|
||||
{{#if infoMsg}}
|
||||
<div class="banner p-10 {{if errorMsg 'bg-error' 'bg-warning'}}" role="alert">
|
||||
{{infoMsg}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/unless}}
|
||||
|
||||
{{#if app.initError}}
|
||||
{{banner-message color='bg-error' icon='icon-alert' message=app.initError.message}}
|
||||
|
||||
<button class="btn bg-primary" {{action "reload"}}>
|
||||
<i class="icon icon-refresh text-small"/> Reload
|
||||
</button>
|
||||
{{/if}}
|
||||
</section>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import Evented from '@ember/object/evented';
|
|||
import Service, { inject as service } from '@ember/service';
|
||||
import C from 'shared/utils/constants';
|
||||
import { minorVersion } from 'shared/utils/parse-version';
|
||||
import { get, set, computed } from '@ember/object';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
|
||||
export function normalizeName(str) {
|
||||
return str; //.replace(/\./g, C.SETTING.DOT_CHAR).toLowerCase();
|
||||
|
|
@ -27,7 +29,7 @@ export default Service.extend(Evented, {
|
|||
|
||||
init() {
|
||||
this._super();
|
||||
this.set('all', this.get('globalStore').all('setting'));
|
||||
set(this, 'all', get(this, 'globalStore').all('setting'));
|
||||
},
|
||||
|
||||
unknownProperty(key) {
|
||||
|
|
@ -64,7 +66,7 @@ export default Service.extend(Evented, {
|
|||
|
||||
if ( !obj )
|
||||
{
|
||||
obj = this.get('globalStore').createRecord({
|
||||
obj = get(this, 'globalStore').createRecord({
|
||||
type: 'setting',
|
||||
name: denormalizeName(key),
|
||||
});
|
||||
|
|
@ -87,17 +89,17 @@ export default Service.extend(Evented, {
|
|||
|
||||
promiseCountObserver: function() {
|
||||
|
||||
if (this.get('promiseCount') <= 0) {
|
||||
if (get(this, 'promiseCount') <= 0) {
|
||||
this.trigger('settingsPromisesResolved');
|
||||
}
|
||||
}.observes('promiseCount'),
|
||||
|
||||
findByName(name) {
|
||||
return this.get('asMap')[normalizeName(name)];
|
||||
return get(this, 'asMap')[normalizeName(name)];
|
||||
},
|
||||
|
||||
loadAll() {
|
||||
return this.get('globalStore').find('setting');
|
||||
return get(this, 'globalStore').find('setting');
|
||||
},
|
||||
|
||||
load(names) {
|
||||
|
|
@ -110,7 +112,7 @@ export default Service.extend(Evented, {
|
|||
names = [names];
|
||||
}
|
||||
|
||||
var globalStore = this.get('globalStore');
|
||||
var globalStore = get(this, 'globalStore');
|
||||
|
||||
var promise = new EmberPromise((resolve, reject) => {
|
||||
async.eachLimit(names, 3, function(name, cb) {
|
||||
|
|
@ -132,7 +134,7 @@ export default Service.extend(Evented, {
|
|||
|
||||
asMap: function() {
|
||||
var out = {};
|
||||
(this.get('all')||[]).forEach((setting) => {
|
||||
(get(this, 'all')||[]).forEach((setting) => {
|
||||
var name = normalizeName(setting.get('name'));
|
||||
out[name] = setting;
|
||||
});
|
||||
|
|
@ -141,25 +143,25 @@ export default Service.extend(Evented, {
|
|||
}.property('all.@each.{name,value}'),
|
||||
|
||||
uiVersion: function() {
|
||||
return 'v' + this.get('app.version');
|
||||
return 'v' + get(this, 'app.version');
|
||||
}.property('app.version'),
|
||||
|
||||
issueUrl: function() {
|
||||
var str = '*Describe your issue here*\n\n\n---\n| Useful | Info |\n| :-- | :-- |\n' +
|
||||
`|Versions|Rancher \`${this.get('rancherVersion')||'-'}\` ` +
|
||||
`UI: \`${this.get('uiVersion')||'--'}\` |\n`;
|
||||
`|Versions|Rancher \`${get(this, 'rancherVersion')||'-'}\` ` +
|
||||
`UI: \`${get(this, 'uiVersion')||'--'}\` |\n`;
|
||||
|
||||
if ( this.get('access.enabled') )
|
||||
if ( get(this, 'access.enabled') )
|
||||
{
|
||||
let provider = (this.get('access.provider')||'').replace(/config/,'');
|
||||
str += `|Access|\`${provider}\` ${this.get('access.admin') ? '\`admin\`' : ''}|\n`;
|
||||
let provider = (get(this, 'access.provider')||'').replace(/config/,'');
|
||||
str += `|Access|\`${provider}\` ${get(this, 'access.admin') ? '\`admin\`' : ''}|\n`;
|
||||
}
|
||||
else
|
||||
{
|
||||
str += '|Access|`Disabled`|\n';
|
||||
}
|
||||
|
||||
str += `|Route|\`${this.get('app.currentRouteName')}\`|\n`;
|
||||
str += `|Route|\`${get(this, 'app.currentRouteName')}\`|\n`;
|
||||
|
||||
var url = C.EXT_REFERENCES.GITHUB + '/issues/new?body=' + encodeURIComponent(str);
|
||||
return url;
|
||||
|
|
@ -170,36 +172,40 @@ export default Service.extend(Evented, {
|
|||
cliVersion: alias(`asMap.${C.SETTING.VERSION_CLI}.value`),
|
||||
dockerMachineVersion: alias(`asMap.${C.SETTING.VERSION_MACHINE}.value`),
|
||||
helmVersion: alias(`asMap.${C.SETTING.VERSION_HELM}.value`),
|
||||
serverUrl: alias(`asMap.${C.SETTING.SERVER_URL}.value`),
|
||||
serverUrlIsEmpty: computed('serverUrl', function() {
|
||||
return isEmpty(get(this, 'serverUrl'));
|
||||
}),
|
||||
|
||||
_plValue: function() {
|
||||
let TRUE=true; // @TODO-2.0
|
||||
if ( TRUE ) {
|
||||
return 'rancher';
|
||||
}
|
||||
return this.get(`cookies.${C.COOKIE.PL}`) || '';
|
||||
return get(this, `cookies.${C.COOKIE.PL}`) || '';
|
||||
}.property(`cookies.${C.COOKIE.PL}`),
|
||||
|
||||
isRancher: function() {
|
||||
return this.get('_plValue').toUpperCase() === C.COOKIE.PL_RANCHER_VALUE.toUpperCase();
|
||||
return get(this, '_plValue').toUpperCase() === C.COOKIE.PL_RANCHER_VALUE.toUpperCase();
|
||||
}.property('_plValue'),
|
||||
|
||||
isEnterprise: function() {
|
||||
return this.get('rancherImage') === 'rancher/enterprise';
|
||||
return get(this, 'rancherImage') === 'rancher/enterprise';
|
||||
}.property('rancherImage'),
|
||||
|
||||
appName: function() {
|
||||
var isCaas = this.get('app.mode') === 'caas' ? true : false;
|
||||
var isCaas = get(this, 'app.mode') === 'caas' ? true : false;
|
||||
|
||||
if (isCaas) {
|
||||
return 'Rancher Container Cloud';
|
||||
} else {
|
||||
if ( this.get('isRancher') )
|
||||
if ( get(this, 'isRancher') )
|
||||
{
|
||||
return this.get('app.appName') || "Rancher"; // Rancher
|
||||
return get(this, 'app.appName') || "Rancher"; // Rancher
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.get('_plValue');
|
||||
return get(this, '_plValue');
|
||||
}
|
||||
}
|
||||
}.property('isRancher','_plValue'),
|
||||
|
|
@ -207,7 +213,7 @@ export default Service.extend(Evented, {
|
|||
minDockerVersion: alias(`asMap.${C.SETTING.MIN_DOCKER}.value`),
|
||||
|
||||
minorVersion: function() {
|
||||
let version = this.get('rancherVersion');
|
||||
let version = get(this, 'rancherVersion');
|
||||
if ( !version )
|
||||
{
|
||||
return null;
|
||||
|
|
@ -217,15 +223,15 @@ export default Service.extend(Evented, {
|
|||
}.property('rancherVersion'),
|
||||
|
||||
docsBase: function() {
|
||||
let full = this.get('rancherVersion');
|
||||
let full = get(this, 'rancherVersion');
|
||||
let version;
|
||||
if ( full ) {
|
||||
version = minorVersion(full);
|
||||
} else {
|
||||
version = minorVersion(this.get('uiVersion'));
|
||||
version = minorVersion(get(this, 'uiVersion'));
|
||||
}
|
||||
|
||||
let lang = ((this.get('intl.locale')||[])[0]||'').replace(/-.*$/,'');
|
||||
let lang = ((get(this, 'intl.locale')||[])[0]||'').replace(/-.*$/,'');
|
||||
if ( !lang || lang === 'none' || C.LANGUAGE.DOCS.indexOf(lang) === -1 ) {
|
||||
lang = 'en';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue