Skip to content

Commit 5adff4f

Browse files
committed
GG-20245 Backport to 8.8-master of GG-18998 Remove instances of $rootScope use (#155)
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.
1 parent 980c9c0 commit 5adff4f

File tree

42 files changed

+256
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+256
-445
lines changed

modules/web-console/frontend/app/app.config.js renamed to modules/web-console/frontend/app/app.config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import negate from 'lodash/negate';
2020
import isNil from 'lodash/isNil';
2121
import isEmpty from 'lodash/isEmpty';
2222
import mixin from 'lodash/mixin';
23+
import {UserService} from './modules/user/User.service';
2324

24-
import {user as userAction, register as registerStore} from './store';
25+
import {user as userAction, register as registerStore, AppStore} from './store';
2526
const nonNil = negate(isNil);
2627
const nonEmpty = negate(isEmpty);
2728

@@ -136,6 +137,6 @@ igniteConsoleCfg.directive('uiGridSelection', function() {
136137
};
137138
});
138139

139-
igniteConsoleCfg.run(['$rootScope', 'Store', ($root, store) => {
140-
$root.$on('user', (event, user) => store.dispatch(userAction({...user})));
140+
igniteConsoleCfg.run(['User', 'Store', (User: UserService, store: AppStore) => {
141+
User.current$.subscribe((user) => store.dispatch(userAction({...user})));
141142
}]);

modules/web-console/frontend/app/app.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import './modules/user/user.module';
4040
import './modules/branding/branding.module';
4141
import './modules/navbar/navbar.module';
4242
import './modules/getting-started/GettingStarted.provider';
43-
import './modules/dialog/dialog.module';
4443
import './modules/ace.module';
4544
import './modules/loading/loading.module';
4645
import servicesModule from './services';
@@ -83,6 +82,7 @@ import {CSV} from './services/CSV';
8382
import {$exceptionHandler} from './services/exceptionHandler';
8483

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

8787
import AngularStrapTooltip from './services/AngularStrapTooltip.decorator';
8888
import AngularStrapSelect from './services/AngularStrapSelect.decorator';
@@ -194,7 +194,6 @@ export default angular
194194
'ignite-console.states.errors',
195195
'ignite-console.states.settings',
196196
// Common modules.
197-
'ignite-console.dialog',
198197
'ignite-console.navbar',
199198
'ignite-console.getting-started',
200199
'ignite-console.loading',
@@ -320,27 +319,14 @@ export default angular
320319
$urlRouterProvider.otherwise('/404');
321320
$locationProvider.html5Mode(true);
322321
}])
323-
.run(['$rootScope', '$state', 'gettingStarted',
322+
.run(['User', 'AgentManager',
324323
/**
325-
* @param {ng.IRootScopeService} $root
326-
* @param {import('@uirouter/angularjs').StateService} $state
327-
* @param {ReturnType<typeof import('./modules/getting-started/GettingStarted.provider').service>} gettingStarted
328-
*/
329-
($root, $state, gettingStarted) => {
330-
$root._ = _;
331-
$root.$state = $state;
332-
$root.gettingStarted = gettingStarted;
333-
}
334-
])
335-
.run(['$rootScope', 'AgentManager',
336-
/**
337-
* @param {ng.IRootScopeService} $root
338324
* @param {import('./modules/agent/AgentManager.service').default} agentMgr
339325
*/
340-
($root, agentMgr) => {
326+
(User: UserService, agentMgr) => {
341327
let lastUser;
342328

343-
$root.$on('user', (e, user) => {
329+
User.current$.subscribe((user) => {
344330
if (lastUser)
345331
return;
346332

@@ -371,25 +357,6 @@ export default angular
371357
});
372358
}
373359
])
374-
.run(['$rootScope', '$http', '$state', 'IgniteMessages', 'User', 'IgniteNotebookData',
375-
/**
376-
* @param {ng.IRootScopeService} $root
377-
* @param {ng.IHttpService} $http
378-
* @param $state
379-
* @param {ReturnType<typeof import('./services/Messages.service').default>} Messages
380-
* @param User
381-
* @param Notebook
382-
*/
383-
($root, $http, $state, Messages, User, Notebook) => { // eslint-disable-line no-shadow
384-
$root.revertIdentity = () => {
385-
$http.get('/api/v1/admin/revert/identity')
386-
.then(() => User.load())
387-
.then(() => $state.go('base.settings.admin'))
388-
.then(() => Notebook.load())
389-
.catch(Messages.showError);
390-
};
391-
}
392-
])
393360
.run(['IgniteIcon',
394361
/**
395362
* @param {import('./components/ignite-icon/service').default} IgniteIcon

modules/web-console/frontend/app/components/dialog-admin-create-user/controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import MessagesFactory from '../../services/Messages.service';
1919
import FormUtilsFactoryFactory from '../../services/FormUtils.service';
2020
import LoadingServiceFactory from '../../modules/loading/loading.service';
2121
import {ISignupData} from '../form-signup';
22+
import {UserService} from 'app/modules/user/User.service';
2223

2324
export class DialogAdminCreateUser {
2425
close: ng.ICompiledExpression;
@@ -36,10 +37,10 @@ export class DialogAdminCreateUser {
3637

3738
serverError: string | null = null;
3839

39-
static $inject = ['$rootScope', 'IgniteAdminData', 'IgniteMessages', 'IgniteFormUtils', 'IgniteLoading'];
40+
static $inject = ['User', 'IgniteAdminData', 'IgniteMessages', 'IgniteFormUtils', 'IgniteLoading'];
4041

4142
constructor(
42-
private $root: ng.IRootScopeService,
43+
private User: UserService,
4344
private AdminData: IgniteAdminData,
4445
private IgniteMessages: ReturnType<typeof MessagesFactory>,
4546
private IgniteFormUtils: ReturnType<typeof FormUtilsFactoryFactory>,
@@ -66,7 +67,7 @@ export class DialogAdminCreateUser {
6667

6768
this.AdminData.registerUser(this.data)
6869
.then(() => {
69-
this.$root.$broadcast('userCreated');
70+
this.User.created$.next(this.data);
7071
this.IgniteMessages.showInfo(`User ${this.data.email} created`);
7172
this.close({});
7273
})

modules/web-console/frontend/app/components/list-of-registered-users/controller.js renamed to modules/web-console/frontend/app/components/list-of-registered-users/controller.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import _ from 'lodash';
1818

1919
import columnDefs from './column-defs';
2020
import categories from './categories';
21+
import {UserService} from 'app/modules/user/User.service';
22+
import {Subscription} from 'rxjs';
23+
import {tap} from 'rxjs/operators';
2124

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

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

39-
constructor($scope, $state, $filter, User, uiGridGroupingConstants, uiGridPinningConstants, AdminData, NotebookData, Confirm, ActivitiesUserDialog) {
42+
constructor($scope, $state, $filter, private User: UserService, uiGridGroupingConstants, uiGridPinningConstants, AdminData, NotebookData, Confirm, ActivitiesUserDialog) {
4043
this.$state = $state;
4144
this.AdminData = AdminData;
4245
this.ActivitiesDialogFactory = ActivitiesUserDialog;
4346
this.Confirm = Confirm;
44-
this.User = User;
4547
this.NotebookData = NotebookData;
4648

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

181-
$scope.$on('userCreated', filterDates);
183+
this.subscriber = this.User.created$.pipe(tap(() => filterDates())).subscribe();
182184
$scope.$watch(() => this.params.startDate, filterDates);
183185
$scope.$watch(() => this.params.endDate, filterDates);
184186
}
185187

188+
subscriber: Subscription
189+
190+
$onDestroy() {
191+
if (this.subscriber) this.subscriber.unsubscribe();
192+
}
193+
186194
adjustHeight(rows) {
187195
// Add header height.
188196
const height = Math.min(rows, 11) * 48 + 78;
@@ -233,7 +241,7 @@ export default class IgniteListOfRegisteredUsersCtrl {
233241
becomeUser() {
234242
const user = this.gridApi.selection.legacyGetSelectedRows()[0];
235243

236-
this.AdminData.becomeUser(user)
244+
this.AdminData.becomeUser(user.id)
237245
.then(() => this.User.load())
238246
.then(() => this.$state.go('default-state'))
239247
.then(() => this.NotebookData.load());

modules/web-console/frontend/app/components/page-queries/component.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ export default {
2424
queriesTitle: '?queriesTitle'
2525
},
2626
controller: class Ctrl {
27-
static $inject = ['$element', '$rootScope', '$state', 'IgniteNotebook'];
27+
static $inject = ['$element', '$state', 'IgniteNotebook'];
2828

2929
/**
3030
* @param {JQLite} $element
31-
* @param {ng.IRootScopeService} $rootScope
3231
* @param {import('@uirouter/angularjs').StateService} $state
3332
* @param {import('./notebook.service').default} IgniteNotebook
3433
*/
35-
constructor($element, $rootScope, $state, IgniteNotebook) {
34+
constructor($element, $state, IgniteNotebook) {
3635
this.$element = $element;
37-
this.$rootScope = $rootScope;
3836
this.$state = $state;
3937
this.IgniteNotebook = IgniteNotebook;
4038
}

modules/web-console/frontend/app/components/page-queries/components/queries-notebook/controller.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {default as LegacyConfirmServiceFactory} from 'app/services/Confirm.servi
3333
import {default as InputDialog} from 'app/components/input-dialog/input-dialog.service';
3434
import {QueryActions} from './components/query-actions-button/controller';
3535
import {CancellationError} from 'app/errors/CancellationError';
36+
import {DemoService} from 'app/modules/demo/Demo.module';
3637

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

286287
// Controller for SQL notebook screen.
287288
export class NotebookCtrl {
288-
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'];
289+
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'];
289290

290291
/**
291292
* @param {CSV} CSV
292293
*/
293-
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) {
294+
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) {
294295
const $ctrl = this;
295296

296297
this.CSV = CSV;
297-
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 });
298+
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 });
298299

299300
// Define template urls.
300301
$ctrl.paragraphRateTemplateUrl = paragraphRateTemplateUrl;
301302
$ctrl.cacheMetadataTemplateUrl = cacheMetadataTemplateUrl;
302303
$ctrl.chartSettingsTemplateUrl = chartSettingsTemplateUrl;
303304
$ctrl.demoStarted = false;
304305

305-
this.isDemo = $root.demoMode;
306+
this.isDemo = this.Demo.enabled;
306307

307308
const _tryStopRefresh = function(paragraph) {
308309
paragraph.cancelRefresh($interval);
@@ -340,7 +341,7 @@ export class NotebookCtrl {
340341

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

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

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

935936
// Await for demo caches.
936-
if (!$ctrl.demoStarted && $root.demoMode && nonEmpty(cacheNames)) {
937+
if (!$ctrl.demoStarted && this.Demo.enabled && nonEmpty(cacheNames)) {
937938
$ctrl.demoStarted = true;
938939

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

949950
const _startWatch = () => {
950951
const finishLoading$ = defer(() => {
951-
if (!$root.demoMode)
952+
if (!this.Demo.enabled)
952953
Loading.finish('sqlLoading');
953954
}).pipe(take(1));
954955

@@ -1014,7 +1015,7 @@ export class NotebookCtrl {
10141015
$scope.rebuildScrollParagraphs();
10151016
})
10161017
.then(() => {
1017-
if ($root.demoMode && sessionStorage.showDemoInfo !== 'true') {
1018+
if (this.Demo.enabled && sessionStorage.showDemoInfo !== 'true') {
10181019
sessionStorage.showDemoInfo = 'true';
10191020

10201021
this.DemoInfo.show().then(_startWatch);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

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

1920
export class NotebooksListCtrl {
20-
static $inject = ['IgniteNotebook', 'IgniteMessages', 'IgniteLoading', 'IgniteInput', '$scope', '$modal'];
21+
static $inject = ['IgniteNotebook', 'IgniteMessages', 'IgniteLoading', 'IgniteInput', '$scope', '$modal', 'Demo'];
2122

22-
constructor(IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal) {
23+
constructor(IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal, private Demo: DemoService) {
2324
Object.assign(this, { IgniteNotebook, IgniteMessages, IgniteLoading, IgniteInput, $scope, $modal });
2425

2526
this.notebooks = [];

modules/web-console/frontend/app/components/page-queries/components/queries-notebooks-list/template.tpl.pug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ page-queries-slot(slot-name="'queriesTitle'")
1919
h1 Queries
2020

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

@@ -30,7 +30,7 @@ page-queries-slot(slot-name="'queriesButtons'")
3030
div
3131
span Notebooks
3232

33-
div(ng-if="!$root.demoMode")
33+
div(ng-if="!$ctrl.Demo.enabled")
3434
+ignite-form-field-bsdropdown({
3535
label: 'Actions',
3636
model: '$ctrl.action',

modules/web-console/frontend/app/components/page-queries/notebook.data.js renamed to modules/web-console/frontend/app/components/page-queries/notebook.data.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

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

1920
const DEMO_NOTEBOOK = {
@@ -73,23 +74,15 @@ const DEMO_NOTEBOOK = {
7374
};
7475

7576
export default class NotebookData {
76-
static $inject = ['$rootScope', '$http', '$q'];
77-
78-
/**
79-
* @param {ng.IRootScopeService} $root
80-
* @param {ng.IHttpService} $http
81-
* @param {ng.IQService} $q
82-
*/
83-
constructor($root, $http, $q) {
84-
this.demo = $root.demoMode;
77+
static $inject = ['Demo', '$http', '$q'];
8578

79+
constructor(private Demo: DemoService, private $http: ng.IHttpService, private $q: ng.IQService) {
8680
this.initLatch = null;
8781
this.notebooks = null;
88-
89-
this.$http = $http;
90-
this.$q = $q;
9182
}
9283

84+
demo = this.Demo.enabled;
85+
9386
load() {
9487
if (this.demo) {
9588
if (this.initLatch)

modules/web-console/frontend/app/components/permanent-notifications/controller.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,29 @@
1414
* limitations under the License.
1515
*/
1616

17+
import {UserService} from '../../modules/user/User.service';
18+
import {DemoService} from 'app/modules/demo/Demo.module';
19+
import {pluck} from 'rxjs/operators';
20+
import {default as AdminData} from 'app/core/admin/Admin.data';
21+
1722
export default class PermanentNotifications {
18-
static $inject = ['UserNotifications', '$rootScope', '$window'];
23+
static $inject = ['Demo', 'UserNotifications', 'User', '$window', 'IgniteAdminData'];
1924

2025
constructor(
26+
private Demo: DemoService,
2127
private UserNotifications: unknown,
22-
private $rootScope: ng.IRootScopeService,
23-
private $window: ng.IWindowService
28+
private User: UserService,
29+
private $window: ng.IWindowService,
30+
private AdminData: AdminData
2431
) {}
2532

33+
user$ = this.User.current$
34+
2635
closeDemo() {
2736
this.$window.close();
2837
}
38+
39+
revertIdentity() {
40+
this.AdminData.revertIdentity();
41+
}
2942
}

0 commit comments

Comments
 (0)