@spinnaker/core 0.22.2 → 0.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
 
3
3
  import { module } from 'angular';
4
4
  import _ from 'lodash';
5
+ import { $log } from 'ngimport';
5
6
 
6
7
  import { AccountService } from '../account/AccountService';
7
8
  import { AppListExtractor } from '../application/listExtractor/AppListExtractor';
@@ -27,104 +28,106 @@ module(CORE_WIDGETS_ACCOUNTREGIONCLUSTERSELECTOR_COMPONENT, []).directive('accou
27
28
  templateUrl: require('./accountRegionClusterSelector.component.html'),
28
29
  controllerAs: 'vm',
29
30
  controller: function controller() {
30
- this.clusterField = this.clusterField || 'cluster';
31
+ this.$onInit = () => {
32
+ this.clusterField = this.clusterField || 'cluster';
31
33
 
32
- const vm = this;
34
+ const vm = this;
33
35
 
34
- if (vm.showClusterSelect === undefined) {
35
- vm.showClusterSelect = true;
36
- }
37
-
38
- const showAllRegions = vm.showAllRegions || false;
39
-
40
- let isTextInputForClusterFiled;
41
-
42
- let regions;
43
-
44
- const setRegionList = () => {
45
- const accountFilter = (cluster) => (cluster ? cluster.account === vm.component.credentials : true);
46
- const regionList = AppListExtractor.getRegions([vm.application], accountFilter);
47
- vm.regions = showAllRegions ? regions : regionList.length ? regionList : regions;
48
- (vm.regions || []).sort();
49
- };
50
-
51
- const setClusterList = () => {
52
- const regionField = this.singleRegion ? vm.component.region : vm.component.regions;
53
- const clusterFilter = AppListExtractor.clusterFilterForCredentialsAndRegion(
54
- vm.component.credentials,
55
- regionField,
56
- );
57
- vm.clusterList = AppListExtractor.getClusters([vm.application], clusterFilter);
58
- };
59
-
60
- vm.regionChanged = () => {
61
- setClusterList();
62
- if (!isTextInputForClusterFiled && !_.includes(vm.clusterList, vm.component[this.clusterField])) {
63
- vm.component[this.clusterField] = undefined;
36
+ if (vm.showClusterSelect === undefined) {
37
+ vm.showClusterSelect = true;
64
38
  }
65
- };
66
39
 
67
- const setToggledState = () => {
68
- vm.regions = regions;
69
- isTextInputForClusterFiled = true;
70
- };
71
-
72
- const setUnToggledState = () => {
73
- vm.component[this.clusterField] = undefined;
74
- isTextInputForClusterFiled = false;
75
- setRegionList();
76
- };
77
-
78
- vm.clusterSelectInputToggled = (isToggled) => {
79
- isToggled ? setToggledState() : setUnToggledState();
80
- };
81
-
82
- vm.clusterChanged = (clusterName) => {
83
- const filterByCluster = AppListExtractor.monikerClusterNameFilter(clusterName);
84
- const clusterMoniker = _.first(_.uniq(AppListExtractor.getMonikers([vm.application], filterByCluster)));
85
- if (_.isNil(clusterMoniker)) {
86
- //remove the moniker from the stage if one doesn't exist.
87
- vm.component.moniker = undefined;
88
- } else {
89
- //clusters don't contain sequences, so null it out.
90
- clusterMoniker.sequence = null;
91
- vm.component.moniker = clusterMoniker;
92
- }
93
- };
94
-
95
- vm.accountUpdated = () => {
96
- vm.component[this.clusterField] = undefined;
97
- setRegionList();
98
- setClusterList();
99
- if (vm.onAccountUpdate) {
100
- vm.onAccountUpdate();
101
- }
102
- };
103
-
104
- const init = () => {
105
- AccountService.getUniqueAttributeForAllAccounts(vm.component.cloudProviderType, 'regions')
106
- .then((allRegions) => {
107
- regions = allRegions;
108
-
109
- // TODO(duftler): Remove this once we finish deprecating the old style regions/zones in clouddriver GCE credentials.
110
- const regionObjs = _.filter(regions, (region) => _.isObject(region));
111
- if (regionObjs.length) {
112
- const oldStyleRegions = _.chain(regionObjs)
113
- .map((regionObj) => _.keys(regionObj))
114
- .flatten()
115
- .value();
116
- regions = _.chain(regions).difference(regionObjs).union(oldStyleRegions).value();
117
- }
118
- return regions.sort();
119
- })
120
- .then((allRegions) => {
121
- setRegionList();
122
- setClusterList();
123
- vm.regions = _.includes(vm.clusterList, vm.component[this.clusterField]) ? vm.regions : allRegions;
124
- });
40
+ const showAllRegions = vm.showAllRegions || false;
41
+
42
+ let isTextInputForClusterFiled;
43
+
44
+ let regions;
45
+
46
+ const setRegionList = () => {
47
+ const accountFilter = (cluster) => (cluster ? cluster.account === vm.component.credentials : true);
48
+ const regionList = AppListExtractor.getRegions([vm.application], accountFilter);
49
+ vm.regions = showAllRegions ? regions : regionList.length ? regionList : regions;
50
+ (vm.regions || []).sort();
51
+ };
52
+
53
+ const setClusterList = () => {
54
+ const regionField = this.singleRegion ? vm.component.region : vm.component.regions;
55
+ const clusterFilter = AppListExtractor.clusterFilterForCredentialsAndRegion(
56
+ vm.component.credentials,
57
+ regionField,
58
+ );
59
+ vm.clusterList = AppListExtractor.getClusters([vm.application], clusterFilter);
60
+ };
61
+
62
+ vm.regionChanged = () => {
63
+ setClusterList();
64
+ if (!isTextInputForClusterFiled && !_.includes(vm.clusterList, vm.component[this.clusterField])) {
65
+ vm.component[this.clusterField] = undefined;
66
+ }
67
+ };
68
+
69
+ const setToggledState = () => {
70
+ vm.regions = regions;
71
+ isTextInputForClusterFiled = true;
72
+ };
73
+
74
+ const setUnToggledState = () => {
75
+ vm.component[this.clusterField] = undefined;
76
+ isTextInputForClusterFiled = false;
77
+ setRegionList();
78
+ };
79
+
80
+ vm.clusterSelectInputToggled = (isToggled) => {
81
+ isToggled ? setToggledState() : setUnToggledState();
82
+ };
83
+
84
+ vm.clusterChanged = (clusterName) => {
85
+ const filterByCluster = AppListExtractor.monikerClusterNameFilter(clusterName);
86
+ const clusterMoniker = _.first(_.uniq(AppListExtractor.getMonikers([vm.application], filterByCluster)));
87
+ if (_.isNil(clusterMoniker)) {
88
+ //remove the moniker from the stage if one doesn't exist.
89
+ vm.component.moniker = undefined;
90
+ } else {
91
+ //clusters don't contain sequences, so null it out.
92
+ clusterMoniker.sequence = null;
93
+ vm.component.moniker = clusterMoniker;
94
+ }
95
+ };
96
+
97
+ vm.accountUpdated = () => {
98
+ vm.component[this.clusterField] = undefined;
99
+ setRegionList();
100
+ setClusterList();
101
+ if (vm.onAccountUpdate) {
102
+ vm.onAccountUpdate();
103
+ }
104
+ };
105
+
106
+ const init = () => {
107
+ AccountService.getUniqueAttributeForAllAccounts(vm.component.cloudProviderType, 'regions')
108
+ .then((allRegions) => {
109
+ regions = allRegions;
110
+
111
+ // TODO(duftler): Remove this once we finish deprecating the old style regions/zones in clouddriver GCE credentials.
112
+ const regionObjs = _.filter(regions, (region) => _.isObject(region));
113
+ if (regionObjs.length) {
114
+ const oldStyleRegions = _.chain(regionObjs)
115
+ .map((regionObj) => _.keys(regionObj))
116
+ .flatten()
117
+ .value();
118
+ regions = _.chain(regions).difference(regionObjs).union(oldStyleRegions).value();
119
+ }
120
+ return regions.sort();
121
+ })
122
+ .then((allRegions) => {
123
+ setRegionList();
124
+ setClusterList();
125
+ vm.regions = _.includes(vm.clusterList, vm.component[this.clusterField]) ? vm.regions : allRegions;
126
+ });
127
+ };
128
+
129
+ init();
125
130
  };
126
-
127
- init();
128
131
  },
129
132
  };
130
133
  });