2018-11-27 18:33:17 +01:00
|
|
|
import { Component, Inject, OnInit } from '@angular/core';
|
2023-10-05 15:39:17 +02:00
|
|
|
import { UntypedFormGroup } from '@angular/forms';
|
2023-10-06 10:10:53 +02:00
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2018-05-28 11:50:42 +02:00
|
|
|
|
|
|
|
@Component({
|
2021-10-12 17:14:22 +02:00
|
|
|
styleUrls: ['available-profiles.component.scss'],
|
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
|
|
|
|
2023-10-05 15:39:17 +02:00
|
|
|
public formGroup: UntypedFormGroup;
|
2018-10-05 17:00:54 +02:00
|
|
|
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'];
|
2019-09-24 10:25:16 +02:00
|
|
|
const fields: Array<string> = new Array<string>();
|
|
|
|
fields.push('asc');
|
|
|
|
const profileRequestItem: DataTableRequest<DatasetProfileCriteria> = new DataTableRequest(0, null, { fields: fields });
|
|
|
|
profileRequestItem.criteria = new DatasetProfileCriteria();
|
|
|
|
profileRequestItem.criteria.like = '';
|
|
|
|
|
|
|
|
this.datasetService.getDatasetProfiles(profileRequestItem)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
2021-04-07 18:19:22 +02:00
|
|
|
|
|
|
|
const dataArray = data;
|
|
|
|
dataArray.sort((a,b)=> (a.label as string).localeCompare(b.label));
|
|
|
|
this.profiles = dataArray;
|
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) {
|
2020-09-14 13:30:12 +02:00
|
|
|
return this.formGroup.value ? this.formGroup.value.map(x => x.id).indexOf(profile.id) !== -1 : null;
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|