/
resource-list.component.ts
65 lines (52 loc) · 2.08 KB
/
resource-list.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
import { Component, EventEmitter, Input, OnInit, Output, ViewChildren } from '@angular/core';
import { MatCheckbox } from '@angular/material/checkbox';
import { ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { CheckboxUpdate, FilteredResources } from '../list-view.component';
import { ListViewService } from '../list-view.service';
@Component({
selector: 'app-resource-list',
templateUrl: './resource-list.component.html',
styleUrls: ['./resource-list.component.scss']
})
export class ResourceListComponent implements OnInit {
/**
* list of all resource checkboxes. This list is used to
* unselect all checkboxes when single selection to view
* resource is used
*/
@ViewChildren('ckbox') resChecks: MatCheckbox[];
/**
* list of resources of type ReadResourceSequence
*
* @param {ReadResourceSequence} resources
*/
@Input() resources: ReadResourceSequence;
/**
* list of all selected resources indices
*/
@Input() selectedResourceIdx: number[];
/**
* set to true if multiple resources can be selected for comparison
*/
@Input() withMultipleSelection?: boolean = false;
/**
* click on checkbox will emit the resource info
*
* @param {EventEmitter<FilteredResources>} resourcesSelected
*/
@Output() resourcesSelected?: EventEmitter<FilteredResources> = new EventEmitter<FilteredResources>();
constructor(
private _listView: ListViewService
) { }
ngOnInit() {
// select the first item in the list
if (this.resources.resources.length) {
this.selectResource({ checked: true, resIndex: 0, resId: this.resources.resources[0].id, resLabel: this.resources.resources[0].label, isCheckbox: false });
}
}
selectResource(status: CheckboxUpdate) {
const selection: FilteredResources = this._listView.viewResource(status, this.withMultipleSelection, this.selectedResourceIdx, this.resChecks);
this.selectedResourceIdx = selection.resListIndex;
this.resourcesSelected.emit(selection);
}
}