2019-03-05 11:20:10 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2019-03-14 19:00:02 +01:00
|
|
|
import { FormBuilder, FormGroup, FormArray } from '@angular/forms';
|
2019-03-05 11:20:10 +01:00
|
|
|
import { MatStepper } from '@angular/material';
|
2019-03-06 15:41:24 +01:00
|
|
|
import { Router } from '@angular/router';
|
2019-03-05 12:21:04 +01:00
|
|
|
import { BaseComponent } from '../../core/common/base/base.component';
|
2019-03-05 11:20:10 +01:00
|
|
|
import { QuickWizardService } from '../../core/services/quick-wizard/quick-wizard.service';
|
2019-03-05 12:21:04 +01:00
|
|
|
import { DatasetCreateWizardModel } from './dataset-create-wizard.model';
|
2019-03-06 15:41:24 +01:00
|
|
|
import { IBreadCrumbComponent } from '../misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { Observable } from 'rxjs';
|
2019-03-14 17:04:20 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-03-06 15:41:24 +01:00
|
|
|
import { BreadcrumbItem } from '../misc/breadcrumb/definition/breadcrumb-item';
|
2019-03-14 17:04:20 +01:00
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../core/services/notification/ui-notification-service';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-03-05 11:20:10 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'dataset-create-wizard.component',
|
|
|
|
templateUrl: 'dataset-create-wizard.component.html',
|
|
|
|
styleUrls: ['./dataset-create-wizard.component.scss'],
|
|
|
|
})
|
2019-03-06 15:41:24 +01:00
|
|
|
export class DatasetCreateWizard extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2019-03-05 11:20:10 +01:00
|
|
|
isLinear = false;
|
2019-03-14 17:04:20 +01:00
|
|
|
isNew = true;
|
2019-03-05 11:20:10 +01:00
|
|
|
formGroup: FormGroup;
|
|
|
|
|
|
|
|
datasetCreateWizardModel: DatasetCreateWizardModel;
|
|
|
|
@ViewChild('stepper') stepper: MatStepper;
|
|
|
|
|
|
|
|
constructor(
|
2019-03-06 15:41:24 +01:00
|
|
|
private router: Router,
|
2019-03-05 11:20:10 +01:00
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
public quickWizardService: QuickWizardService,
|
2019-03-14 17:04:20 +01:00
|
|
|
public language: TranslateService,
|
|
|
|
private uiNotificationService: UiNotificationService
|
2019-03-05 11:20:10 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.datasetCreateWizardModel = new DatasetCreateWizardModel();
|
|
|
|
this.formGroup = this.datasetCreateWizardModel.buildForm();
|
2019-03-06 15:41:24 +01:00
|
|
|
this.breadCrumbs = Observable.of([
|
2019-03-14 17:04:20 +01:00
|
|
|
{
|
|
|
|
parentComponentName: 'Dashboard',
|
|
|
|
label: 'Dataset description wizard',
|
|
|
|
url: '/datasetcreatewizard'
|
|
|
|
}]
|
|
|
|
);
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
save() {
|
2019-03-14 19:00:02 +01:00
|
|
|
for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
|
|
|
|
control.get('status').setValue('0');
|
|
|
|
}
|
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
saveFinalize() {
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
for(let control of (this.formGroup.get('datasets').get('datasetsList') as FormArray).controls){
|
|
|
|
control.get('status').setValue('1');
|
|
|
|
}
|
2019-03-05 11:20:10 +01:00
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
this.quickWizardService.createQuickDatasetWizard(this.formGroup.value)
|
2019-03-14 17:04:20 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => this.onCallbackSuccess()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:00:02 +01:00
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
2019-03-14 17:04:20 +01:00
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/home']);
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|
2019-03-06 10:43:48 +01:00
|
|
|
isActive(step: string): boolean {
|
2019-03-14 17:04:20 +01:00
|
|
|
switch (step) {
|
|
|
|
case 'step1':
|
|
|
|
return this.stepper.selectedIndex == 0;
|
|
|
|
case 'step2':
|
|
|
|
return this.stepper.selectedIndex == 1;
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 11:20:10 +01:00
|
|
|
}
|