import { Component, Input, Output, EventEmitter } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { BaseComponent } from '@common/base/base.component'; import { GuidedTourService } from '@app/library/guided-tour/guided-tour.service'; import { GuidedTour, Orientation } from '@app/library/guided-tour/guided-tour.constants'; import { TranslateService } from '@ngx-translate/core'; import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile'; import { takeUntil } from 'rxjs/operators'; import { DmpProfileService } from '@app/core/services/dmp/dmp-profile.service'; import { DatasetWizardEditorModel } from '../dataset-wizard-editor.model'; import { MatDialog } from '@angular/material/dialog'; import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; @Component({ selector: 'app-dataset-editor-component', templateUrl: 'dataset-editor.component.html', styleUrls: ['./dataset-editor.component.scss'] }) export class DatasetEditorComponent extends BaseComponent { @Input() formGroup: FormGroup; // @Input() formGroup: FormGroup = null; @Input() availableProfiles: DatasetProfileModel[]; @Input() dmpId: string; showUri: boolean = false; dmpText: string = null; viewOnly = false; constructor( private router: Router, private dmpProfileService: DmpProfileService, private dialog: MatDialog, private guidedTourService: GuidedTourService, private language: TranslateService ) { super(); } public dashboardTourDmp: GuidedTour = { tourId: 'only-dmp-tour', useOrb: true, steps: [ { title: this.dmpText, content: 'Step 1', orientation: Orientation.Bottom, highlightPadding: 3, isStepUnique: true, customTopOffset: 8 } ] }; checkMinMax(event, profile: DatasetProfileModel) { const dmpSectionIndex = this.formGroup.get('dmpSectionIndex').value; const blueprintId = this.formGroup.get('dmp').value.profile.id; this.dmpProfileService.getSingleBlueprint(blueprintId) .pipe(takeUntil(this._destroyed)) .subscribe(result => { const section = result.definition.sections[dmpSectionIndex]; if(section.hasTemplates){ const foundTemplate = section.descriptionTemplates.find(template => template.descriptionTemplateId === profile.id); if (foundTemplate !== undefined) { let count = 0; if(this.formGroup.get('dmp').value.datasets != null){ for(let dataset of this.formGroup.get('dmp').value.datasets){ if(dataset.dmpSectionIndex === dmpSectionIndex && dataset.profile.id === foundTemplate.descriptionTemplateId){ count++; } } if(count === foundTemplate.maxMultiplicity){ event.stopPropagation(); this.dialog.open(ConfirmationDialogComponent, { data:{ message: 'MAX DATASETS USING TEMPLATE', confirmButton: 'RETURN', cancelButton: 'CANCEL' }, maxWidth:'30em' }) .afterClosed() .subscribe(confirm=>{}) } } } } }); } getDmpText(): string { return this.language.instant('DMP-LISTING.TEXT-INFO') + '\n\n' + this.language.instant('DMP-LISTING.TEXT-INFO-QUESTION') + ' ' + this.language.instant('DMP-LISTING.LINK-ZENODO') + ' ' + this.language.instant('DMP-LISTING.GET-IDEA'); } setDashboardTourDmp(label: string): void { this.dashboardTourDmp.steps[0].title = this.getDmpText(); this.dashboardTourDmp.steps[0].selector = '.dmp-tour-' + label; } public restartTour(label: string): void { this.setDashboardTourDmp(label); this.guidedTourService.startTour(this.dashboardTourDmp); } public cancel(): void { this.router.navigate(['/datasets']); } public compareWith(object1: any, object2: any) { return object1 && object2 && object1.id === object2.id; } }