/
allClusters.controller.js
133 lines (117 loc) · 4.58 KB
/
allClusters.controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use strict';
const angular = require('angular');
import { CLOUD_PROVIDER_REGISTRY } from 'core/cloudProvider/cloudProvider.registry';
import { SERVER_GROUP_COMMAND_BUILDER_SERVICE } from 'core/serverGroup/configure/common/serverGroupCommandBuilder.service';
import { INSIGHT_NGMODULE } from 'core/insight/insight.module';
import { ClusterState } from 'core/state';
import { PROVIDER_SELECTION_SERVICE } from 'core/cloudProvider/providerSelection/providerSelection.service';
import { SKIN_SELECTION_SERVICE } from 'core/cloudProvider/skinSelection/skinSelection.service';
import { CLUSTER_FILTER } from './filter/clusterFilter.component';
import { FILTER_TAGS_COMPONENT } from '../filterModel/filterTags.component';
import './rollups.less';
module.exports = angular
.module('spinnaker.core.cluster.allClusters.controller', [
CLUSTER_FILTER,
require('../account/account.module').name,
PROVIDER_SELECTION_SERVICE,
SKIN_SELECTION_SERVICE,
SERVER_GROUP_COMMAND_BUILDER_SERVICE,
FILTER_TAGS_COMPONENT,
require('../utils/waypoints/waypointContainer.directive').name,
INSIGHT_NGMODULE.name,
require('angular-ui-bootstrap'),
CLOUD_PROVIDER_REGISTRY,
])
.controller('AllClustersCtrl', function(
$scope,
app,
$uibModal,
$timeout,
providerSelectionService,
insightFilterStateModel,
serverGroupCommandBuilder,
cloudProviderRegistry,
skinSelectionService,
) {
this.$onInit = () => {
insightFilterStateModel.filtersHidden = true; // hidden to prevent filter flashing for on-demand apps
const groupsUpdatedSubscription = ClusterState.filterService.groupsUpdatedStream.subscribe(() =>
clusterGroupsUpdated(),
);
this.application = app;
ClusterState.filterModel.activate();
this.initialized = false;
this.dataSource = app.getDataSource('serverGroups');
this.application = app;
$scope.sortFilter = ClusterState.filterModel.sortFilter;
this.createLabel = 'Create Server Group';
app
.getDataSource('serverGroups')
.ready()
.then(
() => {
insightFilterStateModel.filtersHidden = false;
updateClusterGroups();
},
() => this.clustersLoadError(),
);
app.setActiveState(app.serverGroups);
app.serverGroups.onRefresh($scope, updateClusterGroups);
$scope.$on('$destroy', () => {
app.setActiveState();
ClusterState.multiselectModel.clearAll();
insightFilterStateModel.filtersHidden = false;
groupsUpdatedSubscription.unsubscribe();
});
};
let updateClusterGroups = () => {
if (app.getDataSource('serverGroups').fetchOnDemand) {
insightFilterStateModel.filtersHidden = true;
}
ClusterState.filterService.updateClusterGroups(app);
clusterGroupsUpdated();
// Timeout because the updateClusterGroups method is debounced by 25ms
$timeout(() => {
this.initialized = true;
}, 50);
};
let clusterGroupsUpdated = () => {
$scope.$applyAsync(() => {
$scope.groups = ClusterState.filterModel.groups;
$scope.tags = ClusterState.filterModel.tags;
});
};
this.toggleMultiselect = () => {
ClusterState.filterModel.sortFilter.multiselect = !ClusterState.filterModel.sortFilter.multiselect;
ClusterState.multiselectModel.syncNavigation();
updateClusterGroups();
};
this.clearFilters = function() {
ClusterState.filterService.clearFilters();
updateClusterGroups();
};
this.createServerGroup = function createServerGroup() {
providerSelectionService.selectProvider(app, 'serverGroup').then(function(selectedProvider) {
skinSelectionService.selectSkin(selectedProvider).then(function(selectedVersion) {
let provider = cloudProviderRegistry.getValue(selectedProvider, 'serverGroup', selectedVersion);
$uibModal.open({
templateUrl: provider.cloneServerGroupTemplateUrl,
controller: `${provider.cloneServerGroupController} as ctrl`,
size: 'lg',
resolve: {
title: () => 'Create New Server Group',
application: () => app,
serverGroup: () => null,
serverGroupCommand: () => serverGroupCommandBuilder.buildNewServerGroupCommand(app, selectedProvider),
provider: () => selectedProvider,
},
});
});
});
};
this.updateClusterGroups = _.debounce(updateClusterGroups, 200);
this.clustersLoadError = () => {
this.loadError = true;
this.initialized = true;
};
});