-
Notifications
You must be signed in to change notification settings - Fork 902
/
serverGroup.component.ts
150 lines (126 loc) · 5.24 KB
/
serverGroup.component.ts
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import {has} from 'lodash';
import {IComponentController, IComponentOptions, IFilterService, ITimeoutService, IRootScopeService, IScope, module} from 'angular';
import {SERVER_GROUP_SEQUENCE_FILTER} from 'core/cluster/serverGroup.sequence.filter';
import {CLUSTER_FILTER_SERVICE} from 'core/cluster/filter/clusterFilter.service';
import {ENTITY_UI_TAGS_COMPONENT} from 'core/entityTag/entityUiTags.component';
import {Instance} from 'core/domain/instance';
import {ServerGroup} from 'core/domain/serverGroup';
interface JenkinsViewModel {
number: number;
href?: string;
}
interface ViewModel {
waypoint: string;
serverGroup: ServerGroup;
serverGroupSequence: string[];
jenkins: JenkinsViewModel;
hasBuildInfo: boolean;
instances: Instance[];
images?: string;
}
export class ServerGroupController implements IComponentController {
public cluster: string;
public serverGroup: ServerGroup;
public application: string;
public parentHeading: string;
public hasLoadBalancers: boolean;
public hasDiscovery: boolean;
public headerIsSticky: () => boolean;
public viewModel: ViewModel;
public sortFilter: any;
private lastStringVal: string = null;
static get $inject(): string[] { return ['$rootScope', '$scope', '$timeout', '$filter', 'clusterFilterService', 'MultiselectModel', 'ClusterFilterModel', 'serverGroupTransformer']; }
constructor(public $rootScope: IRootScopeService,
private $scope: IScope,
private $timeout: ITimeoutService,
private $filter: IFilterService,
private clusterFilterService: any,
private MultiselectModel: any,
private ClusterFilterModel: any, private serverGroupTransformer: any) {}
public $onInit(): void {
// TODO: Remove $scope. Keeping it here so we can use $watch for now.
// Eventually, there should be events fired when filters change.
this.sortFilter = this.ClusterFilterModel.sortFilter;
this.$scope.$watch(() => this.sortFilter, () => this.setViewModel(), true);
this.setViewModel();
this.headerIsSticky = function() {
if (!this.sortFilter.showAllInstances) {
return false;
}
if (this.sortFilter.listInstances) {
return this.viewModel.instances.length > 1;
}
return this.viewModel.instances.length > 20;
};
}
public loadDetails(event: JQueryEventObject): void {
this.$timeout(() => {
if (event.isDefaultPrevented() || (event.originalEvent && (event.originalEvent.defaultPrevented || (event.originalEvent.target as any).href))) {
return;
}
this.MultiselectModel.toggleServerGroup(this.serverGroup);
event.preventDefault();
});
};
private setViewModel(): void {
const filteredInstances = this.serverGroup.instances.filter(i => this.clusterFilterService.shouldShowInstance(i));
const serverGroup = this.serverGroup;
let viewModel: ViewModel = {
waypoint: [serverGroup.account, serverGroup.region, serverGroup.name].join(':'),
serverGroup: serverGroup,
serverGroupSequence: (<Function>this.$filter('serverGroupSequence'))(serverGroup.name),
jenkins: null,
hasBuildInfo: !!serverGroup.buildInfo,
instances: filteredInstances,
};
if (serverGroup.buildInfo && serverGroup.buildInfo.jenkins &&
(serverGroup.buildInfo.jenkins.host || serverGroup.buildInfo.jenkins.fullUrl || serverGroup.buildInfo.buildInfoUrl)) {
const jenkins = serverGroup.buildInfo.jenkins;
viewModel.jenkins = {
number: jenkins.number
};
if (serverGroup.buildInfo.jenkins.host) {
viewModel.jenkins.href = [jenkins.host + 'job', jenkins.name, jenkins.number, ''].join('/');
}
if (serverGroup.buildInfo.jenkins.fullUrl) {
viewModel.jenkins.href = serverGroup.buildInfo.jenkins.fullUrl;
}
if (serverGroup.buildInfo.buildInfoUrl) {
viewModel.jenkins.href = serverGroup.buildInfo.buildInfoUrl;
}
} else if (has(serverGroup, 'buildInfo.images')) {
viewModel.images = serverGroup.buildInfo.images.join(', ');
}
let modelStringVal = JSON.stringify(viewModel, this.serverGroupTransformer.jsonReplacer);
if (this.lastStringVal !== modelStringVal) {
this.viewModel = viewModel;
this.lastStringVal = modelStringVal;
}
viewModel.serverGroup.runningTasks = serverGroup.runningTasks;
viewModel.serverGroup.runningExecutions = serverGroup.runningExecutions;
}
}
class ServerGroupComponent implements IComponentOptions {
public bindings: any = {
cluster: '<',
serverGroup: '<',
application: '<',
parentHeading: '<',
hasLoadBalancers: '<',
hasDiscovery: '<',
};
public controller: any = ServerGroupController;
public templateUrl: string = require('./serverGroup.component.html');
}
export const SERVER_GROUP_COMPONENT = 'spinnaker.core.serverGroup.serverGroup.component';
module(SERVER_GROUP_COMPONENT, [
CLUSTER_FILTER_SERVICE,
SERVER_GROUP_SEQUENCE_FILTER,
require('../cluster/filter/clusterFilter.model'),
require('../cluster/filter/multiselect.model'),
require('../instance/instances.directive'),
require('../instance/instanceList.directive'),
require('./serverGroup.transformer'),
ENTITY_UI_TAGS_COMPONENT,
])
.component('serverGroup', new ServerGroupComponent());