@@ -26,42 +26,47 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
2626 Notification . notify ( title , options ) ;
2727 } ;
2828
29- $scope . loadData = function ( ) {
30- Application . query ( function ( applications ) {
31- function refresh ( app ) {
32- app . refreshing = true ;
33- app . info = { } ;
34-
35- //find application in known applications and copy state --> less flickering
36- for ( var j = 0 ; $scope . applications && j < $scope . applications . length ; j ++ ) {
37- if ( app . id === $scope . applications [ j ] . id ) {
38- app . infoShort = $scope . applications [ j ] . infoShort ;
39- app . infoDetails = $scope . applications [ j ] . infoDetails ;
40- app . version = $scope . applications [ j ] . version ;
41- //issue notifiaction on state change
42- if ( app . statusInfo . status !== $scope . applications [ j ] . statusInfo . status ) {
43- createNote ( app ) ;
44- }
45- break ;
46- }
29+ var refresh = function ( app ) {
30+ app . info = { } ;
31+ app . needRefresh = true ;
32+ //find application in known applications and copy state --> less flickering
33+ for ( var j = 0 ; $scope . applications && j < $scope . applications . length ; j ++ ) {
34+ if ( app . id === $scope . applications [ j ] . id ) {
35+ app . infoShort = $scope . applications [ j ] . infoShort ;
36+ app . infoDetails = $scope . applications [ j ] . infoDetails ;
37+ app . version = $scope . applications [ j ] . version ;
38+ app . capabilities = $scope . applications [ j ] . capabilities ;
39+ if ( app . statusInfo . status !== $scope . applications [ j ] . statusInfo . status ) {
40+ createNote ( app ) ; //issue notifiaction on state change
41+ } else {
42+ app . needRefresh = false ; //if state hasn't change don't fetch info
4743 }
48- app . getInfo ( ) . then ( function ( info ) {
49- app . version = info . version ;
50- app . infoDetails = null ;
51- app . infoShort = '' ;
52- delete info . version ;
53- var infoYml = $filter ( 'yaml' ) ( info ) ;
54- if ( infoYml !== '{}\n' ) {
55- app . infoShort = $filter ( 'limitLines' ) ( infoYml , 3 ) ;
56- if ( app . infoShort !== infoYml ) {
57- app . infoDetails = $filter ( 'limitLines' ) ( infoYml , 32000 , 3 ) ;
58- }
59- }
60- } ) . finally ( function ( ) {
61- app . refreshing = false ;
62- } ) ;
44+ break ;
6345 }
46+ }
47+ if ( app . needRefresh ) {
48+ app . refreshing = true ;
49+ app . getCapabilities ( ) ;
50+ app . getInfo ( ) . then ( function ( info ) {
51+ app . version = info . version ;
52+ app . infoDetails = null ;
53+ app . infoShort = '' ;
54+ delete info . version ;
55+ var infoYml = $filter ( 'yaml' ) ( info ) ;
56+ if ( infoYml !== '{}\n' ) {
57+ app . infoShort = $filter ( 'limitLines' ) ( infoYml , 3 ) ;
58+ if ( app . infoShort !== infoYml ) {
59+ app . infoDetails = $filter ( 'limitLines' ) ( infoYml , 32000 , 3 ) ;
60+ }
61+ }
62+ } ) . finally ( function ( ) {
63+ app . refreshing = false ;
64+ } ) ;
65+ }
66+ } ;
6467
68+ $scope . loadData = function ( ) {
69+ Application . query ( function ( applications ) {
6570 for ( var i = 0 ; i < applications . length ; i ++ ) {
6671 refresh ( applications [ i ] ) ;
6772 }
@@ -103,8 +108,10 @@ module.exports = function ($scope, $location, $interval, $state, $filter, Applic
103108 //initial load
104109 $scope . loadData ( ) ;
105110
106- // reload site every 30 seconds
107- $interval ( function ( ) {
111+ // reload site every 10 seconds
112+ var intervalPromise = $interval ( function ( ) {
108113 $scope . loadData ( ) ;
109114 } , 10000 ) ;
115+
116+ $scope . $on ( '$destroy' , function ( ) { $interval . cancel ( intervalPromise ) ; } ) ;
110117} ;
0 commit comments