2018-05-28 11:50:42 +02:00
|
|
|
import { JsonSerializer } from '../../../utilities/JsonSerializer';
|
|
|
|
import { RequestItem } from '../../../models/criteria/RequestItem';
|
2018-10-05 17:00:54 +02:00
|
|
|
import { Component, OnInit, Inject } from '@angular/core';
|
2018-05-28 11:50:42 +02:00
|
|
|
import { FormGroup } from '@angular/forms';
|
|
|
|
import { Params, ActivatedRoute, Router } from '@angular/router';
|
|
|
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
|
|
|
import { DatasetService } from '../../../services/dataset/dataset.service';
|
|
|
|
import { DatasetProfileModel } from '../../../models/datasetprofile/DatasetProfileModel';
|
|
|
|
import { DatasetProfileModule } from '../../../dataset-profile-form/dataset-profile.module';
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
})
|
|
|
|
export class AvailableProfilesComponent implements OnInit {
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public formGroup: FormGroup;
|
|
|
|
public profiles: DatasetProfileModel[] = [];
|
|
|
|
public selectedProfiles: DatasetProfileModel[] = [];
|
|
|
|
public selectedOptions: any;
|
|
|
|
constructor(
|
|
|
|
private datasetService: DatasetService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
public router: Router,
|
|
|
|
public dialogRef: MatDialogRef<AvailableProfilesComponent>,
|
|
|
|
@Inject(MAT_DIALOG_DATA) public data: any
|
|
|
|
) { }
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.formGroup = this.data['profiles'];
|
|
|
|
this.datasetService.getDatasetProfiles().subscribe(data => {
|
|
|
|
this.profiles = JsonSerializer.fromJSONArray(data, DatasetProfileModel);
|
|
|
|
});
|
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
addProfiles(profiles) {
|
|
|
|
profiles.selectedOptions.selected.forEach(element => {
|
|
|
|
const selectedElement = new DatasetProfileModel();
|
|
|
|
selectedElement.id = element.value.id;
|
|
|
|
selectedElement.label = element.value.label;
|
|
|
|
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
|
|
|
}
|