Fix: on save of datset, table of contents remains open

This commit is contained in:
apapachristou 2020-11-06 12:42:31 +02:00
parent 2313cd1ca5
commit 0bd5afffe1
5 changed files with 74 additions and 66 deletions

View File

@ -48,13 +48,13 @@
<div class="col-auto dmp-label ml-3">{{'DATASET-LISTING.TOOLTIP.DMP' | translate}}</div>
</div>
<div class="stepper-title">{{'DMP-EDITOR.STEPPER.USER-GUIDE' | translate}}</div>
<div class="stepper-options">
<div class="stepper-options" id="stepper-options">
<div class="col stepper-list">
<div (click)="changeStep(0)" *ngIf="!datasetInfoValid()" class="main-info" [ngClass]="{'active': this.step === 0}">0. {{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (2)</div>
<div (click)="changeStep(0)" *ngIf="datasetInfoValid()" class="main-info" [ngClass]="{'active': this.step === 0}">0. {{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (<mat-icon class="done-icon">done</mat-icon>)</div>
<div class="row toc-pane-container" #boundary (click)="changeStep(1)">
<div #spacer></div>
<table-of-contents class="toc-pane-container" [boundary]="boundary" [spacer]="spacer" [isActive]="step !== 0" stickyThing (stepFound)="onStepFound($event)" (linksInit)="onLinksInit($event)"></table-of-contents>
<table-of-contents class="toc-pane-container" [links]="links" [boundary]="boundary" [spacer]="spacer" [isActive]="step !== 0" stickyThing (stepFound)="onStepFound($event)" (currentLinks)="getLinks($event)"></table-of-contents>
</div>
</div>
</div>

View File

@ -23,7 +23,7 @@ import { DatasetWizardEditorModel } from '@app/ui/dataset/dataset-wizard/dataset
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
import { IBreadCrumbComponent } from '@app/ui/misc/breadcrumb/definition/IBreadCrumbComponent';
import { DatasetDescriptionFormEditorModel } from '@app/ui/misc/dataset-description-form/dataset-description-form.model';
import { LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
import { Link, LinkToScroll } from '@app/ui/misc/dataset-description-form/tableOfContentsMaterial/table-of-contents';
import { BaseComponent } from '@common/base/base.component';
import { FormService } from '@common/forms/form-service';
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
@ -85,6 +85,8 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
datasetSavedLinks: any = null;
scrollTop: number;
tocScrollTop: number;
links: Link[] = [];
constructor(
private datasetWizardService: DatasetWizardService,
@ -548,6 +550,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
submit(saveType?: SaveType) {
this.scrollTop = document.getElementById('dataset-editor-form').scrollTop;
this.tocScrollTop = document.getElementById('stepper-options').scrollTop;
this.datasetWizardService.createDataset(this.formGroup.getRawValue())
.pipe(takeUntil(this._destroyed))
.subscribe(
@ -657,6 +660,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
setTimeout(() => {
document.getElementById('dataset-editor-form').scrollTop = this.scrollTop;
document.getElementById('stepper-options').scrollTop = this.tocScrollTop;
}, 500);
// this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', data.id]); });
@ -916,7 +920,7 @@ export class DatasetWizardComponent extends BaseComponent implements OnInit, IBr
return this.formGroup.get('label') && this.formGroup.get('label').valid && this.formGroup.get('profile') && this.formGroup.get('profile').valid;
}
onLinksInit(event) {
this.datasetSavedLinks = event;
getLinks(currentLinks: Link[]) {
this.links = currentLinks;
}
}

View File

@ -60,7 +60,7 @@
<div class="row editor-content">
<div class="col-auto" [ngClass]="{'dmp-stepper': this.step < stepsBeforeDatasets, 'dataset-stepper': this.step >= stepsBeforeDatasets}">
<div class="stepper-title">{{'DMP-EDITOR.STEPPER.USER-GUIDE' | translate}}</div>
<div class="stepper-options">
<div class="stepper-options" id="stepper-options">
<ol class="stepper-list">
<li (click)="changeStep(0)" [ngClass]="{'active': this.step === 0}">{{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (4)</li>
<li (click)="changeStep(1)" [ngClass]="{'active': this.step === 1}">{{'DMP-EDITOR.STEPPER.FUNDING-INFO' | translate}} (3)</li>

View File

@ -31,7 +31,7 @@
<div class="row editor-content">
<div class="col-auto" [ngClass]="{'dmp-stepper': this.step < stepsBeforeDatasets, 'dataset-stepper': this.step >= stepsBeforeDatasets}">
<div class="stepper-title">{{'DMP-EDITOR.STEPPER.USER-GUIDE' | translate}}</div>
<div class="stepper-options">
<div class="stepper-options" id="stepper-options">
<ol class="stepper-list">
<li (click)="changeStep(0)" *ngIf="!formGroup.get('extraProperties').get('visible').value && !mainInfoValid()" [ngClass]="{'active': this.step === 0}">{{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (1)</li>
<li (click)="changeStep(0)" *ngIf="!formGroup.get('extraProperties').get('visible').value && mainInfoValid()" [ngClass]="{'active': this.step === 0}">{{'DMP-EDITOR.STEPPER.MAIN-INFO' | translate}} (<mat-icon class="done-icon">done</mat-icon>)</li>

View File

@ -6,7 +6,7 @@ import { distinctUntilChanged } from 'rxjs/operators';
import { type } from 'os';
import { SimpleChanges } from '@angular/core';
interface Link {
export interface Link {
/* id of the section*/
id: string;
/* header type h3/h4 */
@ -30,10 +30,11 @@ interface Link {
})
export class TableOfContents extends BaseComponent implements OnInit {
links: Link[] = [];
@Input() links: Link[];
container: string;
headerSelectors = '.toc-page-header, .toc-section-header, .toc-compositeField-header';
@Output() stepFound = new EventEmitter<LinkToScroll>();
@Output() currentLinks = new EventEmitter<Link[]>();
subscription: Subscription;
linksSubject: Subject<HTMLElement[]> = new Subject<HTMLElement[]>();
@ -54,6 +55,7 @@ export class TableOfContents extends BaseComponent implements OnInit {
this.linksSubject.next(headers);
});
if (!this.links || this.links.length === 0) {
this.linksSubject.asObservable()
.pipe(distinctUntilChanged((p: HTMLElement[], q: HTMLElement[]) => JSON.stringify(p) == JSON.stringify(q)))
.subscribe(headers => {
@ -105,21 +107,23 @@ export class TableOfContents extends BaseComponent implements OnInit {
})
}
ngOnChanges(changes: SimpleChanges) {
if (!this.isActive && this.links && this.links.length > 0) {
this.links.forEach(link => {
link.selected = false;
})
this.links[0].selected = true;
}
ngOnChanges(changes: SimpleChanges) {
// if (!this.isActive && this.links && this.links.length > 0) {
// this.links.forEach(link => {
// link.selected = false;
// })
// this.links[0].selected = true;
// }
}
goToStep(link: Link) {
// this.selectedLinkId = link.id;
this.stepFound.emit({
page: link.page,
section: link.section
});
this.currentLinks.emit(this.links);
setTimeout(() => {
const target = document.getElementById(link.id);