/
comparison.component.ts
60 lines (47 loc) · 1.65 KB
/
comparison.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
import { Component, Input, OnChanges } from '@angular/core';
import { ShortResInfo } from '../results/list-view/list-view.component';
import { SplitSize } from '../results/results.component';
@Component({
selector: 'app-comparison',
templateUrl: './comparison.component.html',
styleUrls: ['./comparison.component.scss']
})
export class ComparisonComponent implements OnChanges {
/**
* number of resources
*/
@Input() noOfResources?: number;
/**
* resource ids
*/
@Input() resourceIds?: string[];
/**
* list of resources with id and label
*/
@Input() resources?: ShortResInfo[];
// parent (or own) split size changed
@Input() splitSizeChanged: SplitSize;
// if number of selected resources > 3, divide them into 2 rows
topRow: string[] = [];
bottomRow: string[] = [];
constructor() { }
ngOnChanges(): void {
if (this.resources && this.resources.length) {
this.resourceIds = [];
this.resources.forEach(res => {
this.resourceIds.push(res.id);
});
}
if (!this.noOfResources) {
this.noOfResources = ((this.resourceIds && this.resourceIds.length) ? this.resourceIds.length : this.resources.length);
}
// if number of resources are more than 3, divide it into 2 rows
// otherwise display then in 1 row only
if (this.noOfResources < 4) {
this.topRow = this.resourceIds;
} else {
this.topRow = this.resourceIds.slice(0, this.noOfResources / 2);
this.bottomRow = this.resourceIds.slice(this.noOfResources / 2);
}
}
}