/
fastPropertyPods.component.ts
69 lines (52 loc) · 1.81 KB
/
fastPropertyPods.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
import { IComponentController, IComponentOptions, isArray, module } from 'angular';
import { StateParams, StateService } from 'angular-ui-router';
import { Property } from '../domain/property.domain';
import { flatten, values } from 'lodash';
export class FastPropertyPodsController implements IComponentController {
public properties: any[];
public $onInit() {
this.resetPropertyDetails();
}
constructor(private $state: StateService,
public $stateParams: StateParams) {
'ngInject';
}
public isPropertyListArray(): boolean {
return isArray(this.properties);
}
public isGrouped(): boolean {
return !this.isPropertyListArray();
}
private isDetailInPropInList(): boolean {
let included = false;
if (this.isPropertyListArray()) {
included = this.properties.some(this.hasPropId.bind(this));
} else {
included = flatten(values(this.properties)).some(this.hasPropId.bind(this));
}
return included;
}
private hasPropId(prop: Property): boolean {
return prop.propertyId === this.$stateParams['propertyId'];
}
private resetPropertyDetails(): void {
if (this.$stateParams['propertyId'] && !this.isDetailInPropInList()) {
delete this.$stateParams['propertyId'];
this.$state.go('home.data.properties', this.$stateParams);
}
}
}
class FastPropertyPods implements IComponentOptions {
public templateUrl: string = require('./fastPropertyPods.html');
public controller: any = FastPropertyPodsController;
public controllerAs = 'fpPod';
public bindings: any = {
properties: '<',
groupedBy: '=?'
};
}
export const FAST_PROPERTY_PODS = 'spinnaker.netflix.globalFastProperty.pods.component';
module(FAST_PROPERTY_PODS, [
require('angular-ui-router').default,
])
.component('fastPropertyPods', new FastPropertyPods());