Skip to content

Commit

Permalink
GG-18998 Remove instances of $rootScope use (#155)
Browse files Browse the repository at this point in the history
Remove user object from $rootScope.
Remove some unused files.
Remove unused some $rootScope injects.
Remove IgniteDemo from $rootScope.
Covnert AdminData service to TS.
Remove revertIdentity function from $rootScope.
Remove getting started from $rootScope.
Remove $state from $rootScope.
Remove lodash from $rootScope.
  • Loading branch information
Klaster1 committed Jun 21, 2019
1 parent 6771897 commit 1ebc665
Show file tree
Hide file tree
Showing 42 changed files with 256 additions and 445 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import negate from 'lodash/negate';
import isNil from 'lodash/isNil';
import isEmpty from 'lodash/isEmpty';
import mixin from 'lodash/mixin';
import {UserService} from './modules/user/User.service';

import {user as userAction, register as registerStore} from './store';
import {user as userAction, register as registerStore, AppStore} from './store';
const nonNil = negate(isNil);
const nonEmpty = negate(isEmpty);

Expand Down Expand Up @@ -136,6 +137,6 @@ igniteConsoleCfg.directive('uiGridSelection', function() {
};
});

igniteConsoleCfg.run(['$rootScope', 'Store', ($root, store) => {
$root.$on('user', (event, user) => store.dispatch(userAction({...user})));
igniteConsoleCfg.run(['User', 'Store', (User: UserService, store: AppStore) => {
User.current$.subscribe((user) => store.dispatch(userAction({...user})));
}]);
41 changes: 4 additions & 37 deletions modules/web-console/frontend/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import './modules/user/user.module';
import './modules/branding/branding.module';
import './modules/navbar/navbar.module';
import './modules/getting-started/GettingStarted.provider';
import './modules/dialog/dialog.module';
import './modules/ace.module';
import './modules/loading/loading.module';
import servicesModule from './services';
Expand Down Expand Up @@ -83,6 +82,7 @@ import {CSV} from './services/CSV';
import {$exceptionHandler} from './services/exceptionHandler';

import {Store} from './services/store';
import {UserService} from './modules/user/User.service';

import AngularStrapTooltip from './services/AngularStrapTooltip.decorator';
import AngularStrapSelect from './services/AngularStrapSelect.decorator';
Expand Down Expand Up @@ -194,7 +194,6 @@ export default angular
'ignite-console.states.errors',
'ignite-console.states.settings',
// Common modules.
'ignite-console.dialog',
'ignite-console.navbar',
'ignite-console.getting-started',
'ignite-console.loading',
Expand Down Expand Up @@ -320,27 +319,14 @@ export default angular
$urlRouterProvider.otherwise('/404');
$locationProvider.html5Mode(true);
}])
.run(['$rootScope', '$state', 'gettingStarted',
.run(['User', 'AgentManager',
/**
* @param {ng.IRootScopeService} $root
* @param {import('@uirouter/angularjs').StateService} $state
* @param {ReturnType<typeof import('./modules/getting-started/GettingStarted.provider').service>} gettingStarted
*/
($root, $state, gettingStarted) => {
$root._ = _;
$root.$state = $state;
$root.gettingStarted = gettingStarted;
}
])
.run(['$rootScope', 'AgentManager',
/**
* @param {ng.IRootScopeService} $root
* @param {import('./modules/agent/AgentManager.service').default} agentMgr
*/
($root, agentMgr) => {
(User: UserService, agentMgr) => {
let lastUser;

$root.$on('user', (e, user) => {
User.current$.subscribe((user) => {
if (lastUser)
return;

Expand Down Expand Up @@ -371,25 +357,6 @@ export default angular
});
}
])
.run(['$rootScope', '$http', '$state', 'IgniteMessages', 'User', 'IgniteNotebookData',
/**
* @param {ng.IRootScopeService} $root
* @param {ng.IHttpService} $http
* @param $state
* @param {ReturnType<typeof import('./services/Messages.service').default>} Messages
* @param User
* @param Notebook
*/
($root, $http, $state, Messages, User, Notebook) => { // eslint-disable-line no-shadow
$root.revertIdentity = () => {
$http.get('/api/v1/admin/revert/identity')
.then(() => User.load())
.then(() => $state.go('base.settings.admin'))
.then(() => Notebook.load())
.catch(Messages.showError);
};
}
])
.run(['IgniteIcon',
/**
* @param {import('./components/ignite-icon/service').default} IgniteIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import MessagesFactory from '../../services/Messages.service';
import FormUtilsFactoryFactory from '../../services/FormUtils.service';
import LoadingServiceFactory from '../../modules/loading/loading.service';
import {ISignupData} from '../form-signup';
import {UserService} from 'app/modules/user/User.service';

export class DialogAdminCreateUser {
close: ng.ICompiledExpression;
Expand All @@ -36,10 +37,10 @@ export class DialogAdminCreateUser {

serverError: string | null = null;

static $inject = ['$rootScope', 'IgniteAdminData', 'IgniteMessages', 'IgniteFormUtils', 'IgniteLoading'];
static $inject = ['User', 'IgniteAdminData', 'IgniteMessages', 'IgniteFormUtils', 'IgniteLoading'];

constructor(
private $root: ng.IRootScopeService,
private User: UserService,
private AdminData: IgniteAdminData,
private IgniteMessages: ReturnType<typeof MessagesFactory>,
private IgniteFormUtils: ReturnType<typeof FormUtilsFactoryFactory>,
Expand All @@ -66,7 +67,7 @@ export class DialogAdminCreateUser {

this.AdminData.registerUser(this.data)
.then(() => {
this.$root.$broadcast('userCreated');
this.User.created$.next(this.data);
this.IgniteMessages.showInfo(`User ${this.data.email} created`);
this.close({});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import _ from 'lodash';

import columnDefs from './column-defs';
import categories from './categories';
import {UserService} from 'app/modules/user/User.service';
import {Subscription} from 'rxjs';
import {tap} from 'rxjs/operators';

import headerTemplate from 'app/primitives/ui-grid-header/index.tpl.pug';

Expand All @@ -36,12 +39,11 @@ const treeAggregationFinalizerFn = function(agg) {
export default class IgniteListOfRegisteredUsersCtrl {
static $inject = ['$scope', '$state', '$filter', 'User', 'uiGridGroupingConstants', 'uiGridPinningConstants', 'IgniteAdminData', 'IgniteNotebookData', 'IgniteConfirm', 'IgniteActivitiesUserDialog'];

constructor($scope, $state, $filter, User, uiGridGroupingConstants, uiGridPinningConstants, AdminData, NotebookData, Confirm, ActivitiesUserDialog) {
constructor($scope, $state, $filter, private User: UserService, uiGridGroupingConstants, uiGridPinningConstants, AdminData, NotebookData, Confirm, ActivitiesUserDialog) {
this.$state = $state;
this.AdminData = AdminData;
this.ActivitiesDialogFactory = ActivitiesUserDialog;
this.Confirm = Confirm;
this.User = User;
this.NotebookData = NotebookData;

const dtFilter = $filter('date');
Expand Down Expand Up @@ -178,11 +180,17 @@ export default class IgniteListOfRegisteredUsersCtrl {
reloadUsers({ startDate, endDate });
}, 250);

$scope.$on('userCreated', filterDates);
this.subscriber = this.User.created$.pipe(tap(() => filterDates())).subscribe();
$scope.$watch(() => this.params.startDate, filterDates);
$scope.$watch(() => this.params.endDate, filterDates);
}

subscriber: Subscription

$onDestroy() {
if (this.subscriber) this.subscriber.unsubscribe();
}

adjustHeight(rows) {
// Add header height.
const height = Math.min(rows, 11) * 48 + 78;
Expand Down Expand Up @@ -233,7 +241,7 @@ export default class IgniteListOfRegisteredUsersCtrl {
becomeUser() {
const user = this.gridApi.selection.legacyGetSelectedRows()[0];

this.AdminData.becomeUser(user)
this.AdminData.becomeUser(user.id)
.then(() => this.User.load())
.then(() => this.$state.go('default-state'))
.then(() => this.NotebookData.load());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ export default {
queriesTitle: '?queriesTitle'
},
controller: class Ctrl {
static $inject = ['$element', '$rootScope', '$state', 'IgniteNotebook'];
static $inject = ['$element', '$state', 'IgniteNotebook'];

/**
* @param {JQLite} $element
* @param {ng.IRootScopeService} $rootScope
* @param {import('@uirouter/angularjs').StateService} $state
* @param {import('./notebook.service').default} IgniteNotebook
*/
constructor($element, $rootScope, $state, IgniteNotebook) {
constructor($element, $state, IgniteNotebook) {
this.$element = $element;
this.$rootScope = $rootScope;
this.$state = $state;
this.IgniteNotebook = IgniteNotebook;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {default as LegacyConfirmServiceFactory} from 'app/services/Confirm.servi
import {default as InputDialog} from 'app/components/input-dialog/input-dialog.service';
import {QueryActions} from './components/query-actions-button/controller';
import {CancellationError} from 'app/errors/CancellationError';
import {DemoService} from 'app/modules/demo/Demo.module';

// Time line X axis descriptor.
const TIME_LINE = {value: -1, type: 'java.sql.Date', label: 'TIME_LINE'};
Expand Down Expand Up @@ -285,24 +286,24 @@ class Paragraph {

// Controller for SQL notebook screen.
export class NotebookCtrl {
static $inject = ['IgniteInput', '$rootScope', '$scope', '$http', '$q', '$timeout', '$transitions', '$interval', '$animate', '$location', '$anchorScroll', '$state', '$filter', '$modal', '$popover', '$window', 'IgniteLoading', 'IgniteLegacyUtils', 'IgniteMessages', 'IgniteConfirm', 'AgentManager', 'IgniteChartColors', 'IgniteNotebook', 'IgniteNodes', 'uiGridExporterConstants', 'IgniteVersion', 'IgniteActivitiesData', 'JavaTypes', 'IgniteCopyToClipboard', 'CSV', 'IgniteErrorParser', 'DemoInfo'];
static $inject = ['Demo', 'IgniteInput', '$scope', '$http', '$q', '$timeout', '$transitions', '$interval', '$animate', '$location', '$anchorScroll', '$state', '$filter', '$modal', '$popover', '$window', 'IgniteLoading', 'IgniteLegacyUtils', 'IgniteMessages', 'IgniteConfirm', 'AgentManager', 'IgniteChartColors', 'IgniteNotebook', 'IgniteNodes', 'uiGridExporterConstants', 'IgniteVersion', 'IgniteActivitiesData', 'JavaTypes', 'IgniteCopyToClipboard', 'CSV', 'IgniteErrorParser', 'DemoInfo'];

/**
* @param {CSV} CSV
*/
constructor(private IgniteInput: InputDialog, $root, private $scope, $http, $q, $timeout, $transitions, $interval, $animate, $location, $anchorScroll, $state, $filter, $modal, $popover, $window, Loading, LegacyUtils, private Messages: ReturnType<typeof MessagesServiceFactory>, private Confirm: ReturnType<typeof LegacyConfirmServiceFactory>, agentMgr, IgniteChartColors, private Notebook: Notebook, Nodes, uiGridExporterConstants, Version, ActivitiesData, JavaTypes, IgniteCopyToClipboard, CSV, errorParser, DemoInfo) {
constructor(private Demo: DemoService, private IgniteInput: InputDialog, private $scope, $http, $q, $timeout, $transitions, $interval, $animate, $location, $anchorScroll, $state, $filter, $modal, $popover, $window, Loading, LegacyUtils, private Messages: ReturnType<typeof MessagesServiceFactory>, private Confirm: ReturnType<typeof LegacyConfirmServiceFactory>, agentMgr, IgniteChartColors, private Notebook: Notebook, Nodes, uiGridExporterConstants, Version, ActivitiesData, JavaTypes, IgniteCopyToClipboard, CSV, errorParser, DemoInfo) {
const $ctrl = this;

this.CSV = CSV;
Object.assign(this, { $root, $scope, $http, $q, $timeout, $transitions, $interval, $animate, $location, $anchorScroll, $state, $filter, $modal, $popover, $window, Loading, LegacyUtils, Messages, Confirm, agentMgr, IgniteChartColors, Notebook, Nodes, uiGridExporterConstants, Version, ActivitiesData, JavaTypes, errorParser, DemoInfo });
Object.assign(this, { $scope, $http, $q, $timeout, $transitions, $interval, $animate, $location, $anchorScroll, $state, $filter, $modal, $popover, $window, Loading, LegacyUtils, Messages, Confirm, agentMgr, IgniteChartColors, Notebook, Nodes, uiGridExporterConstants, Version, ActivitiesData, JavaTypes, errorParser, DemoInfo });

// Define template urls.
$ctrl.paragraphRateTemplateUrl = paragraphRateTemplateUrl;
$ctrl.cacheMetadataTemplateUrl = cacheMetadataTemplateUrl;
$ctrl.chartSettingsTemplateUrl = chartSettingsTemplateUrl;
$ctrl.demoStarted = false;

this.isDemo = $root.demoMode;
this.isDemo = this.Demo.enabled;

const _tryStopRefresh = function(paragraph) {
paragraph.cancelRefresh($interval);
Expand Down Expand Up @@ -340,7 +341,7 @@ export class NotebookCtrl {

$scope.modes = LegacyUtils.mkOptions(['PARTITIONED', 'REPLICATED', 'LOCAL']);

$scope.loadingText = $root.demoMode ? 'Demo grid is starting. Please wait...' : 'Loading query notebook screen...';
$scope.loadingText = this.Demo.enabled ? 'Demo grid is starting. Please wait...' : 'Loading query notebook screen...';

$scope.timeUnit = [
{value: 1000, label: 'seconds', short: 's'},
Expand Down Expand Up @@ -933,7 +934,7 @@ export class NotebookCtrl {
});

// Await for demo caches.
if (!$ctrl.demoStarted && $root.demoMode && nonEmpty(cacheNames)) {
if (!$ctrl.demoStarted && this.Demo.enabled && nonEmpty(cacheNames)) {
$ctrl.demoStarted = true;

Loading.finish('sqlLoading');
Expand All @@ -948,7 +949,7 @@ export class NotebookCtrl {

const _startWatch = () => {
const finishLoading$ = defer(() => {
if (!$root.demoMode)
if (!this.Demo.enabled)
Loading.finish('sqlLoading');
}).pipe(take(1));

Expand Down Expand Up @@ -1014,7 +1015,7 @@ export class NotebookCtrl {
$scope.rebuildScrollParagraphs();
})
.then(() => {
if ($root.demoMode && sessionStorage.showDemoInfo !== 'true') {
if (this.Demo.enabled && sessionStorage.showDemoInfo !== 'true') {
sessionStorage.showDemoInfo = 'true';

this.DemoInfo.show().then(_startWatch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

import {DemoService} from 'app/modules/demo/Demo.module';
import _ from 'lodash';

export class NotebooksListCtrl {
static $inject = ['IgniteNotebook', 'IgniteMessages', 'IgniteLoading', 'IgniteInput', '$scope', '$modal'];
static $inject = ['IgniteNotebook', 'IgniteMessages', 'IgniteLoading', 'IgniteInput', '$scope', '$modal', 'Demo'];

constructor(IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal) {
constructor(IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal, private Demo: DemoService) {
Object.assign(this, { IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal });

this.notebooks = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ page-queries-slot(slot-name="'queriesTitle'")
h1 Queries

page-queries-slot(slot-name="'queriesButtons'")
button#createNotebookBtn.btn-ignite.btn-ignite--primary(ng-click='$ctrl.createNotebook()' ng-if='!$root.demoMode')
button#createNotebookBtn.btn-ignite.btn-ignite--primary(ng-click='$ctrl.createNotebook()' ng-if='!$ctrl.Demo.enabled')
svg.icon-left(ignite-icon='plus')
| Create Notebook

Expand All @@ -30,7 +30,7 @@ page-queries-slot(slot-name="'queriesButtons'")
div
span Notebooks

div(ng-if="!$root.demoMode")
div(ng-if="!$ctrl.Demo.enabled")
+ignite-form-field-bsdropdown({
label: 'Actions',
model: '$ctrl.action',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import {DemoService} from 'app/modules/demo/Demo.module';
import _ from 'lodash';

const DEMO_NOTEBOOK = {
Expand Down Expand Up @@ -73,23 +74,15 @@ const DEMO_NOTEBOOK = {
};

export default class NotebookData {
static $inject = ['$rootScope', '$http', '$q'];

/**
* @param {ng.IRootScopeService} $root
* @param {ng.IHttpService} $http
* @param {ng.IQService} $q
*/
constructor($root, $http, $q) {
this.demo = $root.demoMode;
static $inject = ['Demo', '$http', '$q'];

constructor(private Demo: DemoService, private $http: ng.IHttpService, private $q: ng.IQService) {
this.initLatch = null;
this.notebooks = null;

this.$http = $http;
this.$q = $q;
}

demo = this.Demo.enabled;

load() {
if (this.demo) {
if (this.initLatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,29 @@
* limitations under the License.
*/

import {UserService} from '../../modules/user/User.service';
import {DemoService} from 'app/modules/demo/Demo.module';
import {pluck} from 'rxjs/operators';
import {default as AdminData} from 'app/core/admin/Admin.data';

export default class PermanentNotifications {
static $inject = ['UserNotifications', '$rootScope', '$window'];
static $inject = ['Demo', 'UserNotifications', 'User', '$window', 'IgniteAdminData'];

constructor(
private Demo: DemoService,
private UserNotifications: unknown,
private $rootScope: ng.IRootScopeService,
private $window: ng.IWindowService
private User: UserService,
private $window: ng.IWindowService,
private AdminData: AdminData
) {}

user$ = this.User.current$

closeDemo() {
this.$window.close();
}

revertIdentity() {
this.AdminData.revertIdentity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
.wch-notification(ng-show='$ctrl.UserNotifications.visible && $ctrl.UserNotifications.message' ng-bind-html='$ctrl.UserNotifications.message')

.wch-notification(ng-show='$ctrl.$rootScope.user.becomeUsed')
| You are currently viewing user #[strong {{$ctrl.$rootScope.user.firstName}} {{$ctrl.$rootScope.user.lastName}}] as administrator. #[a(ng-click='$ctrl.$rootScope.revertIdentity()') Revert to your identity?]
.wch-notification(ng-show='($ctrl.user$|async:this).becomeUsed')
| You are currently viewing user #[strong {{($ctrl.user$|async:this).firstName}} {{($ctrl.user$|async:this).lastName}}] as administrator. #[a(ng-click='$ctrl.revertIdentity()') Revert to your identity?]

.wch-notification.wch-notification--demo(ng-if='$ctrl.$rootScope.demoMode')
.wch-notification.wch-notification--demo(ng-if='$ctrl.Demo.enabled')
| You are now in Demo Mode. #[a(ng-click='$ctrl.closeDemo()') Close Demo?]
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {

/**
* @param {import('app/services/Version.service').default} Version
* @param {ng.IRootScopeService} $scope
* @param {ng.IScope} $scope
*/
constructor(Version, $scope) {
this.currentSbj = Version.currentSbj;
Expand Down

0 comments on commit 1ebc665

Please sign in to comment.