IGNITE-5734 Web Console: Fixed bugs after ui-router upgrade.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ff7ba722 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ff7ba722 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ff7ba722 Branch: refs/heads/master Commit: ff7ba72251c18269a43a9dd0c57527124bbb307a Parents: 430bf06 Author: Andrey Novikov <anovi...@gridgain.com> Authored: Fri Jul 28 20:23:28 2017 +0700 Committer: Andrey Novikov <anovi...@gridgain.com> Committed: Fri Jul 28 20:23:28 2017 +0700 ---------------------------------------------------------------------- modules/web-console/backend/index.js | 6 +++ modules/web-console/frontend/app/app.js | 6 --- .../frontend/app/controllers/auth.controller.js | 9 ++-- .../app/modules/agent/AgentManager.service.js | 24 ++-------- .../app/modules/agent/AgentModal.service.js | 8 ++-- .../frontend/app/modules/demo/Demo.module.js | 22 +++++---- .../configuration/summary/summary.worker.js | 4 +- .../frontend/app/modules/states/errors.state.js | 2 +- .../app/modules/states/password.state.js | 2 + .../app/modules/states/profile.state.js | 2 +- .../frontend/app/modules/states/signin.state.js | 6 ++- .../app/modules/user/AclRoute.provider.js | 50 -------------------- .../frontend/app/modules/user/user.module.js | 35 +++++--------- .../web-console/frontend/views/signin.tpl.pug | 2 +- .../views/templates/agent-download.tpl.pug | 2 - 15 files changed, 55 insertions(+), 125 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/backend/index.js ---------------------------------------------------------------------- diff --git a/modules/web-console/backend/index.js b/modules/web-console/backend/index.js index 85e137c..18bb24d 100644 --- a/modules/web-console/backend/index.js +++ b/modules/web-console/backend/index.js @@ -88,6 +88,12 @@ const init = ([settings, apiSrv, agentsHnd, browsersHnd]) => { srv.on('error', _onError.bind(null, settings.server.port)); srv.on('listening', _onListening.bind(null, srv.address())); + process.on('unhandledRejection', (error) => { + // Will print "unhandledRejection err is not defined" + console.log('unhandledRejection', error); + }); + + apiSrv.attach(srv); agentsHnd.attach(srv, browsersHnd); http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/app.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/app.js b/modules/web-console/frontend/app/app.js index a322ff7..0925254 100644 --- a/modules/web-console/frontend/app/app.js +++ b/modules/web-console/frontend/app/app.js @@ -108,7 +108,6 @@ import id8 from './filters/id8.filter'; // Controllers import profile from 'Controllers/profile-controller'; -import auth from './controllers/auth.controller'; import resetPassword from './controllers/reset-password.controller'; // Components @@ -249,7 +248,6 @@ angular.module('ignite-console', [ .service('Clusters', Clusters) .service('Caches', Caches) // Controllers. -.controller(...auth) .controller(...resetPassword) .controller(...profile) // Filters. @@ -289,10 +287,6 @@ angular.module('ignite-console', [ $root.$on('user', () => agentMgr.connect()); }]) .run(['$transitions', ($transitions) => { - $transitions.onStart({ }, () => { - _.forEach(angular.element('.modal'), (m) => angular.element(m).scope().$hide()); - }); - $transitions.onSuccess({ }, (trans) => { try { const {name, params, unsaved} = trans.$to(); http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/controllers/auth.controller.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/controllers/auth.controller.js b/modules/web-console/frontend/app/controllers/auth.controller.js index 21ffeb8..caa74dc 100644 --- a/modules/web-console/frontend/app/controllers/auth.controller.js +++ b/modules/web-console/frontend/app/controllers/auth.controller.js @@ -16,10 +16,9 @@ */ // Sign in controller. -// TODO IGNITE-1936 Refactor this controller. -export default ['auth', [ - '$scope', 'IgniteFocus', 'IgniteCountries', 'Auth', - ($scope, Focus, Countries, Auth) => { +export default [ + '$scope', '$uiRouterGlobals', 'IgniteFocus', 'IgniteCountries', 'Auth', + ($scope, $uiRouterGlobals, Focus, Countries, Auth) => { $scope.auth = Auth.auth; $scope.forgotPassword = Auth.forgotPassword; $scope.action = 'signin'; @@ -27,4 +26,4 @@ export default ['auth', [ Focus.move('user_email'); } -]]; +]; http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/agent/AgentManager.service.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js index bdd1fda..6bc31a0 100644 --- a/modules/web-console/frontend/app/modules/agent/AgentManager.service.js +++ b/modules/web-console/frontend/app/modules/agent/AgentManager.service.js @@ -73,27 +73,13 @@ class ConnectionState { } export default class IgniteAgentManager { - static $inject = ['$rootScope', '$q', 'igniteSocketFactory', 'AgentModal', 'UserNotifications']; + static $inject = ['$rootScope', '$q', '$transitions', 'igniteSocketFactory', 'AgentModal', 'UserNotifications']; - constructor($root, $q, socketFactory, AgentModal, UserNotifications) { - this.$root = $root; - this.$q = $q; - this.socketFactory = socketFactory; - - /** - * @type {AgentModal} - */ - this.AgentModal = AgentModal; - - /** - * @type {UserNotifications} - */ - this.UserNotifications = UserNotifications; + constructor($root, $q, $transitions, socketFactory, AgentModal, UserNotifications) { + Object.assign(this, {$root, $q, $transitions, socketFactory, AgentModal, UserNotifications}); this.promises = new Set(); - $root.$on('$stateChangeSuccess', () => this.stopWatch()); - /** * Connection to backend. * @type {Socket} @@ -282,14 +268,14 @@ export default class IgniteAgentManager { } }); + self.$transitions.onExit({}, () => self.stopWatch()); + return self.awaitCluster(); } stopWatch() { this.modalSubscription && this.modalSubscription.unsubscribe(); - this.AgentModal.hide(); - this.promises.forEach((promise) => promise.reject('Agent watch stopped.')); } http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/agent/AgentModal.service.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/agent/AgentModal.service.js b/modules/web-console/frontend/app/modules/agent/AgentModal.service.js index 54f8e52..52abf6d 100644 --- a/modules/web-console/frontend/app/modules/agent/AgentModal.service.js +++ b/modules/web-console/frontend/app/modules/agent/AgentModal.service.js @@ -36,10 +36,6 @@ export default class AgentModal { controllerAs: 'ctrl' }); - self.modal.$scope.$on('modal.hide.before', () => { - Messages.hideAlert(); - }); - $root.$on('user', (event, user) => self.user = user); } @@ -51,8 +47,12 @@ export default class AgentModal { * Close dialog and go by specified link. */ back() { + this.Messages.hideAlert(); + this.hide(); + _.forEach(angular.element('.modal'), (m) => angular.element(m).scope().$hide()); + if (this.backState) this.$state.go(this.backState); } http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/demo/Demo.module.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/demo/Demo.module.js b/modules/web-console/frontend/app/modules/demo/Demo.module.js index 2445461..bf602f8 100644 --- a/modules/web-console/frontend/app/modules/demo/Demo.module.js +++ b/modules/web-console/frontend/app/modules/demo/Demo.module.js @@ -34,9 +34,8 @@ angular .state('demo.resume', { url: '/resume', permission: 'demo', - controller: ['$state', ($state) => { - $state.go('base.configuration.tabs.advanced.clusters'); - }], + redirectTo: 'base.configuration.tabs', + unsaved: true, tfMetaTags: { title: 'Demo resume' } @@ -44,15 +43,18 @@ angular .state('demo.reset', { url: '/reset', permission: 'demo', - controller: ['$state', '$http', 'IgniteMessages', ($state, $http, Messages) => { - $http.post('/api/v1/demo/reset') - .then(() => $state.go('base.configuration.tabs.advanced.clusters')) - .catch((res) => { - $state.go('base.configuration.tabs.advanced.clusters'); + redirectTo: (trans) => { + const $http = trans.injector().get('$http'); - Messages.showError(res); + return $http.post('/api/v1/demo/reset') + .then(() => 'base.configuration.tabs') + .catch((err) => { + trans.injector().get('IgniteMessages').showError(err); + + return 'base.configuration.tabs'; }); - }], + }, + unsaved: true, tfMetaTags: { title: 'Demo reset' } http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js b/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js index 91c2afa..11f19ee 100644 --- a/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js +++ b/modules/web-console/frontend/app/modules/states/configuration/summary/summary.worker.js @@ -69,8 +69,8 @@ onmessage = function(e) { zip.file('Dockerfile', data.docker); zip.file('.dockerignore', docker.ignoreFile()); - const cfg = generator.igniteConfiguration(cluster, targetVer.ignite, false); - const clientCfg = generator.igniteConfiguration(cluster, targetVer.ignite, true); + const cfg = generator.igniteConfiguration(cluster, targetVer, false); + const clientCfg = generator.igniteConfiguration(cluster, targetVer, true); const clientNearCaches = _.filter(cluster.caches, (cache) => cache.cacheMode === 'PARTITIONED' && _.get(cache, 'clientNearConfiguration.enabled')); http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/states/errors.state.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/states/errors.state.js b/modules/web-console/frontend/app/modules/states/errors.state.js index 3cc03be..fcc6a5b 100644 --- a/modules/web-console/frontend/app/modules/states/errors.state.js +++ b/modules/web-console/frontend/app/modules/states/errors.state.js @@ -23,7 +23,7 @@ angular .module('ignite-console.states.errors', [ 'ui.router' ]) - .config(['$stateProvider', 'AclRouteProvider', function($stateProvider) { + .config(['$stateProvider', function($stateProvider) { // set up the states $stateProvider .state('404', { http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/states/password.state.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/states/password.state.js b/modules/web-console/frontend/app/modules/states/password.state.js index 8e326bf..60d82b4 100644 --- a/modules/web-console/frontend/app/modules/states/password.state.js +++ b/modules/web-console/frontend/app/modules/states/password.state.js @@ -34,6 +34,7 @@ angular .state('password.reset', { url: '/reset?{token}', templateUrl, + unsaved: true, tfMetaTags: { title: 'Reset password' } @@ -41,6 +42,7 @@ angular .state('password.send', { url: '/send', templateUrl, + unsaved: true, tfMetaTags: { title: 'Password Send' } http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/states/profile.state.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/states/profile.state.js b/modules/web-console/frontend/app/modules/states/profile.state.js index 87d1d02..35e0ae6 100644 --- a/modules/web-console/frontend/app/modules/states/profile.state.js +++ b/modules/web-console/frontend/app/modules/states/profile.state.js @@ -23,7 +23,7 @@ angular .module('ignite-console.states.profile', [ 'ui.router' ]) -.config(['$stateProvider', 'AclRouteProvider', function($stateProvider) { +.config(['$stateProvider', function($stateProvider) { // set up the states $stateProvider.state('base.settings.profile', { url: '/profile', http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/states/signin.state.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/states/signin.state.js b/modules/web-console/frontend/app/modules/states/signin.state.js index f5a4964..8afcaa3 100644 --- a/modules/web-console/frontend/app/modules/states/signin.state.js +++ b/modules/web-console/frontend/app/modules/states/signin.state.js @@ -17,6 +17,7 @@ import angular from 'angular'; import templateUrl from 'views/signin.tpl.pug'; +import controller from 'app/controllers/auth.controller'; angular .module('ignite-console.states.login', [ @@ -44,6 +45,9 @@ angular } }) .catch(() => true); - } + }, + controller, + controllerAs: '$ctrl', + unsaved: true }); }]); http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/user/AclRoute.provider.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/user/AclRoute.provider.js b/modules/web-console/frontend/app/modules/user/AclRoute.provider.js deleted file mode 100644 index f5556ff..0000000 --- a/modules/web-console/frontend/app/modules/user/AclRoute.provider.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export default [() => { - class AclRoute { - static checkAccess(permissions, failState = '403') { - return ['$q', '$state', 'AclService', 'User', 'IgniteActivitiesData', function($q, $state, AclService, User, Activities) { - const action = ''; - - return User.read() - .catch(() => { - User.clean(); - - if ($state.current.name !== 'signin') - $state.go('signin'); - - return $q.reject('Failed to detect user'); - }) - .then(() => { - if (AclService.can(permissions)) - return Activities.post({ action }); - - $state.go(failState); - - return $q.reject('User are not authorized'); - }); - }]; - } - - static $get() { - return AclRoute; - } - } - - return AclRoute; -}]; http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/app/modules/user/user.module.js ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/app/modules/user/user.module.js b/modules/web-console/frontend/app/modules/user/user.module.js index 721d07f..cac8943 100644 --- a/modules/web-console/frontend/app/modules/user/user.module.js +++ b/modules/web-console/frontend/app/modules/user/user.module.js @@ -20,7 +20,6 @@ import aclData from './permissions'; import Auth from './Auth.service'; import User from './User.service'; -import AclRouteProvider from './AclRoute.provider'; angular.module('ignite-console.user', [ 'mm.acl', @@ -34,10 +33,10 @@ angular.module('ignite-console.user', [ if (response.status === 401) { $injector.get('User').clean(); - const $state = $injector.get('$state'); + const stateName = $injector.get('$uiRouterGlobals').current.name; - if ($state.current.name !== 'signin') - $state.go('signin'); + if (stateName !== 'signin') + $injector.get('$state').go('signin'); } return $q.reject(response); @@ -49,7 +48,6 @@ angular.module('ignite-console.user', [ }]) .service(...Auth) .service(...User) -.provider('AclRoute', AclRouteProvider) .run(['$rootScope', '$transitions', 'AclService', 'User', 'IgniteActivitiesData', ($root, $transitions, AclService, User, Activities) => { AclService.setAbilities(aclData); AclService.attachRole('guest'); @@ -71,31 +69,22 @@ angular.module('ignite-console.user', [ AclService.attachRole(role); }); - $transitions.onBefore({}, (t) => { - const $state = t.router.stateService; - const {name, permission} = t.to(); + $transitions.onEnter({}, (trans) => { + const $state = trans.router.stateService; + const {name, permission} = trans.to(); - return User.read() - .catch(() => { - User.clean(); - - if (name !== 'signin') - return $state.target('signin'); + if (_.isEmpty(permission)) + return; - return true; - }) + trans.injector().get('User').read() .then(() => { - if (_.isEmpty(permission)) - return true; - if (AclService.can(permission)) { - Activities.post({action: $state.href(name, t.params('to'))}); + Activities.post({action: $state.href(name, trans.params('to'))}); - return true; + return; } - return $state.target(t.to().failState || '403'); + return $state.target(trans.to().failState || '403'); }); - }); }]); http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/views/signin.tpl.pug ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/views/signin.tpl.pug b/modules/web-console/frontend/views/signin.tpl.pug index c7e2027..fcd19e5 100644 --- a/modules/web-console/frontend/views/signin.tpl.pug +++ b/modules/web-console/frontend/views/signin.tpl.pug @@ -22,7 +22,7 @@ web-console-header ignite-header-title .container.body-container - .main-content(ng-controller='auth') + .main-content .row.home .signin-greedy .col-xs-12.col-md-6 http://git-wip-us.apache.org/repos/asf/ignite/blob/ff7ba722/modules/web-console/frontend/views/templates/agent-download.tpl.pug ---------------------------------------------------------------------- diff --git a/modules/web-console/frontend/views/templates/agent-download.tpl.pug b/modules/web-console/frontend/views/templates/agent-download.tpl.pug index 7829581..fdb3a05 100644 --- a/modules/web-console/frontend/views/templates/agent-download.tpl.pug +++ b/modules/web-console/frontend/views/templates/agent-download.tpl.pug @@ -21,8 +21,6 @@ h4.modal-title i.fa.fa-download span Connection to Ignite Web Agent is not established - button.close(type='button' aria-label='Close' ng-click='$hide()') - svg(ignite-icon="cross") .modal-body.agent-download p Please download and run #[a(href='/api/v1/downloads/agent' target='_self') ignite-web-agent] to use this functionality: ul