Skip to content

Commit c5f9e48

Browse files
authored
Wait for info on dependent pages (#283)
* Wait for info on dependent pages - add initialized variable - broadcast initialized event when info is read - if initialized, run mounting code immediately - otherwise, listen for "initialized" event once * Fix minification const -> var * use the same variable name
1 parent 330dbd0 commit c5f9e48

File tree

4 files changed

+124
-96
lines changed

4 files changed

+124
-96
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test_results
2020
### SublimeText ###
2121
# workspace files are user-specific
2222
*.sublime-workspace
23+
.vscode
2324

2425
# project files should be checked into the repository, unless a significant
2526
# proportion of contributors will probably not be using SublimeText

src/js/modules/projections/controllers/ProjectionsListCtrl.js

Lines changed: 80 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,99 @@ define(['./_module'], function (app) {
55
return app.controller('ProjectionsListCtrl', [
66
'$rootScope', '$scope', '$timeout', 'ProjectionsService', 'ProjectionsMapper', 'poller', 'MessageService', '$state',
77
function ($rootScope, $scope, $timeout, projectionsService, projectionsMapper, pollerProvider, msg, $state) {
8-
9-
if(!$rootScope.projectionsEnabled) {
10-
msg.failure('Projections are not enabled on the node');
11-
$state.go('dashboard.list');
12-
return;
13-
}
14-
15-
var all = pollerProvider.create({
16-
interval: 2000,
17-
action: projectionsService.all,
18-
params: [ false ]
19-
});
20-
21-
all.start();
22-
all.promise.then(null, null, function (data) {
23-
$scope.projections = projectionsMapper.map(data);
24-
});
25-
26-
all.promise.catch(function (error) {
27-
msg.failure('Failed to retrieve list of projections: ' + error.message);
28-
all.stop();
29-
});
30-
31-
$scope.disableAll = function ($event) {
32-
$event.preventDefault();
33-
$event.stopPropagation();
34-
35-
var confirmation = msg.confirm('Are you sure you want to disable & stop all projections?');
36-
37-
if(!confirmation) {
8+
function initialize() {
9+
if(!$rootScope.projectionsEnabled) {
10+
msg.failure('Projections are not enabled on the node');
11+
$state.go('dashboard.list');
3812
return;
3913
}
14+
15+
var all = pollerProvider.create({
16+
interval: 2000,
17+
action: projectionsService.all,
18+
params: [ false ]
19+
});
4020

41-
projectionsService.disableAll().then(function () {
42-
msg.success('All projections have been disabled');
43-
}, function (errorMessage) {
44-
msg.failure('Failed to disable all the projections: ' + errorMessage);
21+
all.start();
22+
all.promise.then(null, null, function (data) {
23+
$scope.projections = projectionsMapper.map(data);
4524
});
46-
};
4725

48-
$scope.enableAll = function ($event) {
49-
$event.preventDefault();
50-
$event.stopPropagation();
26+
all.promise.catch(function (error) {
27+
msg.failure('Failed to retrieve list of projections: ' + error.message);
28+
all.stop();
29+
});
5130

52-
var confirmation = msg.confirm('Are you sure you want to enable & start all projections?');
31+
$scope.disableAll = function ($event) {
32+
$event.preventDefault();
33+
$event.stopPropagation();
5334

54-
if(!confirmation) {
55-
return;
56-
}
35+
var confirmation = msg.confirm('Are you sure you want to disable & stop all projections?');
5736

58-
projectionsService.enableAll().then(function () {
59-
msg.success('All projections have been enabled');
60-
}, function (errorMessage) {
61-
msg.failure('Failed to enable all projections: ' + errorMessage);
62-
});
63-
};
37+
if(!confirmation) {
38+
return;
39+
}
6440

65-
$scope.includeQueries = false;
66-
$scope.toggleIncludeQueries = function(){
67-
$scope.includeQueries = !$scope.includeQueries;
68-
};
41+
projectionsService.disableAll().then(function () {
42+
msg.success('All projections have been disabled');
43+
}, function (errorMessage) {
44+
msg.failure('Failed to disable all the projections: ' + errorMessage);
45+
});
46+
};
6947

70-
$scope.showCopiedMessage = function (projection) {
71-
projection.copied = true;
48+
$scope.enableAll = function ($event) {
49+
$event.preventDefault();
50+
$event.stopPropagation();
7251

73-
msg.success('Copied "' + projection.name + '" to clipboard');
52+
var confirmation = msg.confirm('Are you sure you want to enable & start all projections?');
7453

75-
$timeout(function () {
76-
projection.copied = false;
77-
}, 4000);
78-
};
54+
if(!confirmation) {
55+
return;
56+
}
7957

80-
var unbindHandler = $scope.$watch('includeQueries', function (newVal, oldVal) {
81-
if(newVal !== oldVal) {
82-
all.update({params: [newVal]});
83-
}
84-
85-
});
86-
$scope.$on('$destroy', function () {
87-
unbindHandler();
88-
pollerProvider.clear();
89-
});
58+
projectionsService.enableAll().then(function () {
59+
msg.success('All projections have been enabled');
60+
}, function (errorMessage) {
61+
msg.failure('Failed to enable all projections: ' + errorMessage);
62+
});
63+
};
64+
65+
$scope.includeQueries = false;
66+
$scope.toggleIncludeQueries = function(){
67+
$scope.includeQueries = !$scope.includeQueries;
68+
};
69+
70+
$scope.showCopiedMessage = function (projection) {
71+
projection.copied = true;
72+
73+
msg.success('Copied "' + projection.name + '" to clipboard');
74+
75+
$timeout(function () {
76+
projection.copied = false;
77+
}, 4000);
78+
};
79+
80+
var unbindHandler = $scope.$watch('includeQueries', function (newVal, oldVal) {
81+
if(newVal !== oldVal) {
82+
all.update({params: [newVal]});
83+
}
84+
85+
});
86+
$scope.$on('$destroy', function () {
87+
unbindHandler();
88+
pollerProvider.clear();
89+
});
90+
}
91+
92+
93+
if ($rootScope.initialized) {
94+
initialize();
95+
} else {
96+
var unregister = $rootScope.$on("initialized", function() {
97+
initialize();
98+
unregister();
99+
});
100+
}
90101
}
91102
]);
92103
});

src/js/modules/users/controllers/UsersListCtrl.js

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,49 @@ define(['./_module'], function (app) {
22

33
'use strict';
44

5-
return app.controller('UsersListCtrl', [
6-
'$rootScope', '$scope', 'UserService', 'poller', 'MessageService',
7-
function ($rootScope, $scope, userService, poller, msg) {
8-
if(!$rootScope.userManagementEnabled) {
9-
msg.failure('User Management is not available');
10-
$state.go('dashboard.list');
11-
return;
12-
}
13-
14-
var all = poller.create({
15-
interval: 1000,
16-
action: userService.all,
17-
params: [
18-
]
19-
});
205

21-
all.start();
22-
all.promise.then(null, null, function (data) {
23-
$scope.users = data.data;
24-
});
25-
26-
all.promise.catch(function (error) {
27-
all.stop();
28-
msg.failure('Failed to retrieve list of users: ' + error.message);
29-
});
306

7+
return app.controller('UsersListCtrl', [
8+
'$rootScope', '$state', '$scope', 'UserService', 'poller', 'MessageService',
9+
function ($rootScope, $state, $scope, userService, poller, msg) {
10+
function initialize() {
11+
if(!$rootScope.userManagementEnabled) {
12+
msg.failure('User Management is not available');
13+
$state.go('dashboard.list');
14+
return;
15+
}
16+
17+
var all = poller.create({
18+
interval: 1000,
19+
action: userService.all,
20+
params: [
21+
]
22+
});
23+
24+
all.start();
25+
all.promise.then(null, null, function (data) {
26+
$scope.users = data.data;
27+
});
28+
29+
all.promise.catch(function (error) {
30+
all.stop();
31+
msg.failure('Failed to retrieve list of users: ' + error.message);
32+
});
33+
34+
35+
$scope.$on('$destroy', function () {
36+
poller.clear();
37+
});
38+
}
3139

32-
$scope.$on('$destroy', function () {
33-
poller.clear();
34-
});
40+
if ($rootScope.initialized) {
41+
initialize();
42+
} else {
43+
var unregister = $rootScope.$on("initialized", function() {
44+
initialize();
45+
unregister();
46+
});
47+
}
3548
}
3649
]);
3750
});

src/js/run.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define(['es-ui'], function (app) {
1515
$rootScope.projectionsEnabled = false;
1616
$rootScope.userManagementEnabled = false;
1717
$rootScope.streamsBrowserEnabled = false;
18+
$rootScope.initialized = false;
1819
$rootScope.logoutEnabled = true;
1920
$rootScope.logoutButtonText = 'Log Out';
2021
$rootScope.logoutText = 'You have been logged out.';
@@ -35,6 +36,8 @@ define(['es-ui'], function (app) {
3536
$rootScope.logoutButtonText = info.authentication.type === 'oauth' ? 'Disconnect' : $rootScope.logoutButtonText;
3637
$rootScope.logoutText = info.authentication.type === 'oauth' ? 'You have been disconnected.' : $rootScope.logoutText;
3738
$rootScope.previousUrl = $location.$$path;
39+
$rootScope.initialized = true;
40+
$rootScope.$broadcast('initialized');
3841

3942
authService.existsAndValid()
4043
.then(function () {

0 commit comments

Comments
 (0)