@@ -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} ) ;
0 commit comments