2018-11-27 18:33:17 +01:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2018-05-28 11:50:42 +02:00
|
|
|
import { FormGroup } from '@angular/forms';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BaseComponent } from '../../../../core/common/base/base.component';
|
|
|
|
import { DatasetProfileModel } from '../../../../core/model/dataset/dataset-profile';
|
|
|
|
import { DatasetService } from '../../../../core/services/dataset/dataset.service';
|
2018-05-28 11:50:42 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-available-profiles-component',
|
|
|
|
templateUrl: 'available-profiles.component.html',
|
2018-05-28 11:50:42 +02:00
|
|
|
})
|
2018-11-27 18:33:17 +01:00
|
|
|
export class AvailableProfilesComponent extends BaseComponent implements OnInit {
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public formGroup: FormGroup;
|
|
|
|
public profiles: DatasetProfileModel[] = [];
|
|
|
|
public selectedProfiles: DatasetProfileModel[] = [];
|
|
|
|
public selectedOptions: any;
|
|
|
|
constructor(
|
|
|
|
private datasetService: DatasetService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private dialogRef: MatDialogRef<AvailableProfilesComponent>,
|
2018-10-05 17:00:54 +02:00
|
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
2018-11-27 18:33:17 +01:00
|
|
|
) { super(); }
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.formGroup = this.data['profiles'];
|
2018-11-27 18:33:17 +01:00
|
|
|
this.datasetService.getDatasetProfiles()
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.profiles = data;
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
addProfiles(profiles) {
|
|
|
|
profiles.selectedOptions.selected.forEach(element => {
|
2019-01-18 18:03:45 +01:00
|
|
|
const selectedElement = {
|
|
|
|
id: element.value.id,
|
2019-07-31 09:24:54 +02:00
|
|
|
label: element.value.label,
|
|
|
|
description: element.value.description
|
2019-01-18 18:03:45 +01:00
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
this.selectedProfiles.push(selectedElement);
|
|
|
|
});
|
|
|
|
this.formGroup.setValue(this.selectedProfiles);
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2018-08-24 17:21:02 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
isOptionSelected(profile: any) {
|
|
|
|
return this.formGroup.value.map(x => x.id).indexOf(profile.id) !== -1;
|
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|