@@ -3215,10 +3215,11 @@ angular.module('patternfly.filters').component('pfFilterFields', {
32153215 addFilterFn : '<'
32163216 } ,
32173217 templateUrl : 'filters/filter-fields.html' ,
3218- controller : [ "$scope" , function ( $scope ) {
3218+ controller : function ( ) {
32193219 'use strict' ;
32203220
32213221 var ctrl = this ;
3222+ var prevConfig ;
32223223
32233224 ctrl . $onInit = function ( ) {
32243225 angular . extend ( ctrl , {
@@ -3228,45 +3229,61 @@ angular.module('patternfly.filters').component('pfFilterFields', {
32283229 } ) ;
32293230 } ;
32303231
3231- ctrl . $postLink = function ( ) {
3232- $scope . $watch ( 'config' , function ( ) {
3232+ ctrl . $onChanges = function ( ) {
3233+ setupConfig ( ) ;
3234+ } ;
3235+
3236+ ctrl . $doCheck = function ( ) {
3237+ // do a deep compare on config
3238+ if ( ! angular . equals ( ctrl . config , prevConfig ) ) {
32333239 setupConfig ( ) ;
3234- } , true ) ;
3240+ }
32353241 } ;
32363242
32373243 function selectField ( item ) {
32383244 ctrl . currentField = item ;
3239- ctrl . config . currentValue = null ;
3245+ ctrl . currentValue = null ;
32403246 }
32413247
32423248 function selectValue ( filterValue ) {
32433249 if ( angular . isDefined ( filterValue ) ) {
3244- ctrl . addFilterFn ( scope . currentField , filterValue ) ;
3245- ctrl . config . currentValue = null ;
3250+ ctrl . addFilterFn ( ctrl . currentField , filterValue ) ;
3251+ ctrl . currentValue = null ;
32463252 }
32473253 }
32483254
32493255 function onValueKeyPress ( keyEvent ) {
32503256 if ( keyEvent . which === 13 ) {
3251- ctrl . addFilterFn ( ctrl . currentField , ctrl . config . currentValue ) ;
3252- ctrl . config . currentValue = undefined ;
3257+ ctrl . addFilterFn ( ctrl . currentField , ctrl . currentValue ) ;
3258+ ctrl . currentValue = undefined ;
32533259 }
32543260 }
32553261
32563262 function setupConfig ( ) {
3257- if ( ctrl . fields === undefined ) {
3258- ctrl . fields = [ ] ;
3263+ var fieldFound = false ;
3264+
3265+ prevConfig = angular . copy ( ctrl . config ) ;
3266+
3267+ if ( ctrl . config . fields === undefined ) {
3268+ ctrl . config . fields = [ ] ;
3269+ }
3270+
3271+ if ( ctrl . currentField ) {
3272+ fieldFound = _ . find ( ctrl . config . fields , function ( nextField ) {
3273+ return nextField . id === ctrl . currentField . id ;
3274+ } ) ;
32593275 }
3260- if ( ! ctrl . currentField ) {
3276+
3277+ if ( ! fieldFound ) {
32613278 ctrl . currentField = ctrl . config . fields [ 0 ] ;
3262- ctrl . config . currentValue = null ;
3279+ ctrl . currentValue = null ;
32633280 }
32643281
3265- if ( ctrl . config . currentValue === undefined ) {
3266- ctrl . config . currentValue = null ;
3282+ if ( ctrl . currentValue === undefined ) {
3283+ ctrl . currentValue = null ;
32673284 }
32683285 }
3269- } ]
3286+ }
32703287} ) ;
32713288; /**
32723289 * @ngdoc directive
@@ -3298,10 +3315,11 @@ angular.module('patternfly.filters').component('pfFilterResults', {
32983315 config : '='
32993316 } ,
33003317 templateUrl : 'filters/filter-results.html' ,
3301- controller : [ "$scope" , function ( $scope ) {
3318+ controller : function ( ) {
33023319 'use strict' ;
33033320
33043321 var ctrl = this ;
3322+ var prevConfig ;
33053323
33063324 ctrl . $onInit = function ( ) {
33073325 angular . extend ( ctrl , {
@@ -3310,13 +3328,20 @@ angular.module('patternfly.filters').component('pfFilterResults', {
33103328 } ) ;
33113329 } ;
33123330
3313- ctrl . $postLink = function ( ) {
3314- $scope . $watch ( 'config' , function ( ) {
3315- setupConfig ( ) ;
3316- } , true ) ;
3331+ ctrl . $onChanges = function ( ) {
3332+ setupConfig ( ) ;
3333+ } ;
3334+
3335+ ctrl . $doCheck = function ( ) {
3336+ // do a deep compare on config
3337+ if ( ! angular . equals ( ctrl . config , prevConfig ) ) {
3338+ // setupConfig();
3339+ }
33173340 } ;
33183341
33193342 function setupConfig ( ) {
3343+ prevConfig = angular . copy ( ctrl . config ) ;
3344+
33203345 if ( ! ctrl . config . appliedFilters ) {
33213346 ctrl . config . appliedFilters = [ ] ;
33223347 }
@@ -3346,7 +3371,7 @@ angular.module('patternfly.filters').component('pfFilterResults', {
33463371 ctrl . config . onFilterChange ( ctrl . config . appliedFilters ) ;
33473372 }
33483373 }
3349- } ]
3374+ }
33503375} ) ;
33513376; /**
33523377 * @ngdoc directive
@@ -6913,31 +6938,36 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
69136938 config : '='
69146939 } ,
69156940 templateUrl : 'sort/sort.html' ,
6916- controller : [ "$scope" , function ( $scope ) {
6941+ controller : function ( ) {
69176942 'use strict' ;
69186943
69196944 var ctrl = this ;
6945+ var prevConfig ;
69206946
69216947 ctrl . $onInit = function ( ) {
69226948 angular . extend ( ctrl , {
69236949 selectField : selectField ,
69246950 changeDirection : changeDirection ,
69256951 getSortIconClass : getSortIconClass
69266952 } ) ;
6953+ } ;
69276954
6955+ ctrl . $onChanges = function ( ) {
69286956 setupConfig ( ) ;
6929-
69306957 } ;
69316958
6932- ctrl . $postLink = function ( ) {
6933- $scope . $watch ( 'config' , function ( ) {
6959+ ctrl . $doCheck = function ( ) {
6960+ // do a deep compare on config
6961+ if ( ! angular . equals ( ctrl . config , prevConfig ) ) {
69346962 setupConfig ( ) ;
6935- } , true ) ;
6963+ }
69366964 } ;
69376965
69386966 function setupConfig ( ) {
69396967 var updated = false ;
69406968
6969+ prevConfig = angular . copy ( ctrl . config ) ;
6970+
69416971 if ( ctrl . config . fields === undefined ) {
69426972 ctrl . config . fields = [ ] ;
69436973 }
@@ -6993,7 +7023,7 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
69937023
69947024 return iconClass ;
69957025 }
6996- } ]
7026+ }
69977027} ) ;
69987028; /**
69997029 * @ngdoc directive
@@ -7411,10 +7441,11 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
74117441 'actions' : '?'
74127442 } ,
74137443 templateUrl : 'toolbars/toolbar.html' ,
7414- controller : [ "$scope" , function ( $scope ) {
7444+ controller : function ( ) {
74157445 'use strict' ;
74167446
74177447 var ctrl = this ;
7448+ var prevConfig ;
74187449
74197450 ctrl . $onInit = function ( ) {
74207451 angular . extend ( ctrl , {
@@ -7426,18 +7457,29 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
74267457 } ) ;
74277458 } ;
74287459
7429- ctrl . $postLink = function ( ) {
7430- $scope . $watch ( 'config' , function ( ) {
7431- if ( ctrl . config && ctrl . config . viewsConfig && ctrl . config . viewsConfig . views ) {
7432- ctrl . config . viewsConfig . viewsList = angular . copy ( ctrl . config . viewsConfig . views ) ;
7460+ ctrl . $onChanges = function ( ) {
7461+ setupConfig ( ) ;
7462+ } ;
74337463
7434- if ( ! ctrl . config . viewsConfig . currentView ) {
7435- ctrl . config . viewsConfig . currentView = ctrl . config . viewsConfig . viewsList [ 0 ] ;
7436- }
7437- }
7438- } , true ) ;
7464+ ctrl . $doCheck = function ( ) {
7465+ // do a deep compare on config
7466+ if ( ! angular . equals ( ctrl . config , prevConfig ) ) {
7467+ setupConfig ( ) ;
7468+ }
74397469 } ;
74407470
7471+ function setupConfig ( ) {
7472+ prevConfig = angular . copy ( ctrl . config ) ;
7473+
7474+ if ( ctrl . config && ctrl . config . viewsConfig && ctrl . config . viewsConfig . views ) {
7475+ ctrl . config . viewsConfig . viewsList = angular . copy ( ctrl . config . viewsConfig . views ) ;
7476+
7477+ if ( ! ctrl . config . viewsConfig . currentView ) {
7478+ ctrl . config . viewsConfig . currentView = ctrl . config . viewsConfig . viewsList [ 0 ] ;
7479+ }
7480+ }
7481+ }
7482+
74417483 function viewSelected ( viewId ) {
74427484 ctrl . config . viewsConfig . currentView = viewId ;
74437485 if ( ctrl . config . viewsConfig . onViewSelect && ! ctrl . checkViewDisabled ( viewId ) ) {
@@ -7485,7 +7527,7 @@ angular.module( 'patternfly.notification' ).component('pfToastNotification', {
74857527 action . actionFn ( action ) ;
74867528 }
74877529 }
7488- } ]
7530+ }
74897531} ) ;
74907532; /**
74917533 * @ngdoc directive
@@ -10189,7 +10231,7 @@ angular.module('patternfly.wizard').component('pfWizard', {
1018910231 'use strict' ;
1019010232
1019110233 $templateCache . put ( 'filters/filter-fields.html' ,
10192- "<div class=\"filter-pf filter-fields\"><div class=\"input-group form-group\"><div uib-dropdown class=input-group-btn><button uib-dropdown-toggle type=button class=\"btn btn-default filter-fields\" uib-tooltip=\"Filter by\" tooltip-placement=top>{{$ctrl.currentField.title}} <span class=caret></span></button><ul uib-dropdown-menu><li ng-repeat=\"item in $ctrl.config.fields\"><a class=filter-field role=menuitem tabindex=-1 ng-click=$ctrl.selectField(item)>{{item.title}}</a></li></ul></div><div ng-if=\"$ctrl.currentField.filterType !== 'select'\"><input class=form-control type={{$ctrl.currentField.filterType}} ng-model=$ctrl.config.currentValue placeholder={{$ctrl.currentField.placeholder}} ng-keypress=\"$ctrl.onValueKeyPress($event)\"></div><div ng-if=\"$ctrl.currentField.filterType === 'select'\"><div class=\"btn-group bootstrap-select form-control filter-select\" uib-dropdown><button type=button uib-dropdown-toggle class=\"btn btn-default dropdown-toggle\"><span class=\"filter-option pull-left\">{{$ctrl.config.currentValue || $ctrl.currentField.placeholder}}</span> <span class=caret></span></button><ul uib-dropdown-menu class=dropdown-menu-right role=menu><li ng-if=$ctrl.currentField.placeholder><a role=menuitem tabindex=-1 ng-click=$ctrl.selectValue()>{{$ctrl.currentField.placeholder}}</a></li><li ng-repeat=\"filterValue in $ctrl.currentField.filterValues\" ng-class=\"{'selected': filterValue === $ctrl.config.currentValue}\"><a role=menuitem tabindex=-1 ng-click=$ctrl.selectValue(filterValue)>{{filterValue}}</a></li></ul></div></div></div></div>"
10234+ "<div class=\"filter-pf filter-fields\"><div class=\"input-group form-group\"><div uib-dropdown class=input-group-btn><button uib-dropdown-toggle type=button class=\"btn btn-default filter-fields\" uib-tooltip=\"Filter by\" tooltip-placement=top>{{$ctrl.currentField.title}} <span class=caret></span></button><ul uib-dropdown-menu><li ng-repeat=\"item in $ctrl.config.fields\"><a class=filter-field role=menuitem tabindex=-1 ng-click=$ctrl.selectField(item)>{{item.title}}</a></li></ul></div><div ng-if=\"$ctrl.currentField.filterType !== 'select'\"><input class=form-control type={{$ctrl.currentField.filterType}} ng-model=$ctrl.currentValue placeholder={{$ctrl.currentField.placeholder}} ng-keypress=\"$ctrl.onValueKeyPress($event)\"></div><div ng-if=\"$ctrl.currentField.filterType === 'select'\"><div class=\"btn-group bootstrap-select form-control filter-select\" uib-dropdown><button type=button uib-dropdown-toggle class=\"btn btn-default dropdown-toggle\"><span class=\"filter-option pull-left\">{{$ctrl.currentValue || $ctrl.currentField.placeholder}}</span> <span class=caret></span></button><ul uib-dropdown-menu class=dropdown-menu-right role=menu><li ng-if=$ctrl.currentField.placeholder><a role=menuitem tabindex=-1 ng-click=$ctrl.selectValue()>{{$ctrl.currentField.placeholder}}</a></li><li ng-repeat=\"filterValue in $ctrl.currentField.filterValues\" ng-class=\"{'selected': filterValue === $ctrl.currentValue}\"><a role=menuitem tabindex=-1 ng-click=$ctrl.selectValue(filterValue)>{{filterValue}}</a></li></ul></div></div></div></div>"
1019310235 ) ;
1019410236
1019510237
0 commit comments