Newer
Older
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { UntypedFormGroup, UntypedFormControl, Validators } from '@angular/forms';
import { DatasetGroup, Dataset } from 'src/app/metamodel/models';
selector: 'app-dataset-group-form',
templateUrl: 'dataset-group-form.component.html'
export class DatasetGroupFormComponent implements OnInit {
@Input() datasetGroup: DatasetGroup;
@Output() onSubmit: EventEmitter<DatasetGroup> = new EventEmitter();
public form = new UntypedFormGroup({
role: new UntypedFormControl('', [Validators.required])
if (this.datasetGroup) {
this.form.patchValue(this.datasetGroup);
this.groupDatasets = [...this.datasetGroup.datasets];
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
...this.form.value,
datasets: this.groupDatasets
});
} else {
this.onSubmit.emit({
...this.form.value,
datasets: this.groupDatasets
});
}
}
getAvailableDatasets(): Dataset[] {
return this.datasetList.filter(dataset => !this.groupDatasets.includes(dataset.name));
}
addDatasets(selectElement) {
let availableDatasetsSelected = [];
for (var i = 0; i < selectElement.options.length; i++) {
const optionElement = selectElement.options[i];
if (optionElement.selected == true) {
availableDatasetsSelected.push(optionElement.value);
}
}
this.groupDatasets.push(...availableDatasetsSelected);
this.form.markAsDirty();
}
removeDatasets(selectElement) {
let groupDatasetsSelected = [];
for (var i = 0; i < selectElement.options.length; i++) {
const optionElement = selectElement.options[i];
if (optionElement.selected == true) {
groupDatasetsSelected.push(optionElement.value);
}
}
this.groupDatasets = [...this.groupDatasets.filter(dataset => !groupDatasetsSelected.includes(dataset))]
this.form.markAsDirty();
}
}