2019-10-15 16:25:43 +02:00
|
|
|
import { DOCUMENT } from '@angular/common';
|
2021-07-20 12:32:40 +02:00
|
|
|
import { Component, EventEmitter, Inject, OnInit, Output, Input, OnChanges, ViewChild } from '@angular/core';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2019-10-22 14:46:48 +02:00
|
|
|
import { interval, Subject, Subscription } from 'rxjs';
|
2021-04-08 17:29:08 +02:00
|
|
|
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators';
|
2020-09-16 17:19:29 +02:00
|
|
|
import { type } from 'os';
|
2020-09-24 19:28:03 +02:00
|
|
|
import { SimpleChanges } from '@angular/core';
|
2021-03-17 10:08:59 +01:00
|
|
|
import { ToCEntry, ToCEntryType } from '../dataset-description.component';
|
|
|
|
import { FormArray, FormGroup } from '@angular/forms';
|
|
|
|
import { VisibilityRulesService } from '../visibility-rules/visibility-rules.service';
|
|
|
|
import { Rule } from '@app/core/model/dataset-profile-definition/rule';
|
2021-07-20 12:32:40 +02:00
|
|
|
import { TableOfContentsInternal } from './table-of-contents-internal/table-of-contents-internal';
|
2019-10-15 16:25:43 +02:00
|
|
|
|
2020-11-06 11:42:31 +01:00
|
|
|
export interface Link {
|
2019-10-15 16:25:43 +02:00
|
|
|
/* id of the section*/
|
|
|
|
id: string;
|
|
|
|
/* header type h3/h4 */
|
|
|
|
type: string;
|
|
|
|
/* If the anchor is in view of the page */
|
|
|
|
active: boolean;
|
|
|
|
/* name of the anchor */
|
|
|
|
name: string;
|
|
|
|
/* top offset px of the anchor */
|
|
|
|
top: number;
|
|
|
|
page: number;
|
|
|
|
section: number;
|
2020-09-16 17:19:29 +02:00
|
|
|
show: boolean;
|
|
|
|
selected: boolean;
|
2019-10-15 16:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'table-of-contents',
|
|
|
|
styleUrls: ['./table-of-contents.scss'],
|
|
|
|
templateUrl: './table-of-contents.html'
|
|
|
|
})
|
2021-04-06 08:57:17 +02:00
|
|
|
export class TableOfContents extends BaseComponent implements OnInit, OnChanges {
|
2019-10-15 16:25:43 +02:00
|
|
|
|
2021-09-24 20:52:14 +02:00
|
|
|
@ViewChild('internalTable') internalTable: TableOfContentsInternal;
|
2021-07-20 12:32:40 +02:00
|
|
|
|
|
|
|
|
2020-11-06 11:42:31 +01:00
|
|
|
@Input() links: Link[];
|
2019-10-22 14:46:48 +02:00
|
|
|
container: string;
|
2020-10-07 12:14:19 +02:00
|
|
|
headerSelectors = '.toc-page-header, .toc-section-header, .toc-compositeField-header';
|
2019-10-15 16:25:43 +02:00
|
|
|
@Output() stepFound = new EventEmitter<LinkToScroll>();
|
2020-11-06 11:42:31 +01:00
|
|
|
@Output() currentLinks = new EventEmitter<Link[]>();
|
2019-10-22 14:46:48 +02:00
|
|
|
subscription: Subscription;
|
|
|
|
linksSubject: Subject<HTMLElement[]> = new Subject<HTMLElement[]>();
|
2019-10-15 16:25:43 +02:00
|
|
|
|
2020-09-16 17:19:29 +02:00
|
|
|
@Input() isActive: boolean;
|
2021-03-17 10:08:59 +01:00
|
|
|
|
|
|
|
tocentries: ToCEntry[] = null;
|
2021-03-17 16:49:42 +01:00
|
|
|
@Input() TOCENTRY_ID_PREFIX = '';
|
2021-03-17 10:08:59 +01:00
|
|
|
// visibilityRules:Rule[] = [];
|
|
|
|
@Input() visibilityRules:Rule[] = [];
|
2021-03-19 11:04:01 +01:00
|
|
|
@Input() showErrors: boolean = false;
|
2021-04-06 08:57:17 +02:00
|
|
|
@Input() selectedFieldsetId:string;
|
2021-03-17 10:08:59 +01:00
|
|
|
|
|
|
|
private _tocentrySelected:ToCEntry = null;
|
2021-04-08 17:29:08 +02:00
|
|
|
private _intersectionObserver: IntersectionObserver;
|
|
|
|
private _actOnObservation: boolean = true;
|
2021-04-12 18:08:09 +02:00
|
|
|
public hiddenEntries:string[] = [];
|
2021-03-17 10:08:59 +01:00
|
|
|
get tocentrySelected(){
|
|
|
|
return this.hasFocus?this._tocentrySelected: null;
|
|
|
|
}
|
|
|
|
set tocentrySelected(value){
|
|
|
|
this._tocentrySelected = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Input() formGroup: FormGroup;
|
|
|
|
@Input() hasFocus: boolean = false;
|
2021-04-13 10:19:09 +02:00
|
|
|
@Input() visibilityRulesService: VisibilityRulesService;
|
2020-09-16 17:19:29 +02:00
|
|
|
show: boolean = false;
|
|
|
|
|
2019-10-22 14:46:48 +02:00
|
|
|
constructor(
|
2021-03-17 10:08:59 +01:00
|
|
|
@Inject(DOCUMENT) private _document: Document,
|
2021-04-13 10:19:09 +02:00
|
|
|
// public visibilityRulesService: VisibilityRulesService
|
2021-03-17 10:08:59 +01:00
|
|
|
) {
|
2019-12-11 15:51:03 +01:00
|
|
|
super();
|
2019-10-15 16:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-10-22 14:46:48 +02:00
|
|
|
ngOnInit(): void {
|
2021-04-08 17:29:08 +02:00
|
|
|
|
2021-04-13 10:19:09 +02:00
|
|
|
// this.visibilityRulesService.visibilityChange
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .pipe(debounceTime(200))
|
|
|
|
// .subscribe(_=>{
|
|
|
|
// if(this.hasFocus){
|
|
|
|
// this._resetObserver();
|
|
|
|
// this.hiddenEntries = this._findHiddenEntries(this.tocentries);
|
|
|
|
// }
|
|
|
|
// })
|
2021-04-08 17:29:08 +02:00
|
|
|
|
2021-03-17 10:08:59 +01:00
|
|
|
if(this.formGroup){
|
|
|
|
this.tocentries = this.getTocEntries(this.formGroup.get('datasetProfileDefinition'));
|
|
|
|
const fg = this.formGroup.get('datasetProfileDefinition');
|
2021-04-13 10:19:09 +02:00
|
|
|
// this.visibilityRulesService.buildVisibilityRules(this.visibilityRules, fg);
|
|
|
|
if(this.visibilityRulesService){
|
|
|
|
this.hiddenEntries = this._findHiddenEntries(this.tocentries);
|
|
|
|
}
|
2021-04-12 18:08:09 +02:00
|
|
|
|
2021-03-17 10:08:59 +01:00
|
|
|
}else{
|
|
|
|
|
|
|
|
//emit value every 500ms
|
|
|
|
const source = interval(500);
|
|
|
|
this.subscription = source.subscribe(val => {
|
|
|
|
const headers = Array.from(this._document.querySelectorAll(this.headerSelectors)) as HTMLElement[];
|
|
|
|
this.linksSubject.next(headers);
|
|
|
|
});
|
2019-10-15 16:25:43 +02:00
|
|
|
|
2021-03-17 10:08:59 +01:00
|
|
|
if (!this.links || this.links.length === 0) {
|
|
|
|
this.linksSubject.asObservable()
|
|
|
|
.pipe(distinctUntilChanged((p: HTMLElement[], q: HTMLElement[]) => JSON.stringify(p) == JSON.stringify(q)))
|
|
|
|
.subscribe(headers => {
|
|
|
|
const links: Array<Link> = [];
|
|
|
|
|
|
|
|
if (headers.length) {
|
|
|
|
let page;
|
|
|
|
let section;
|
|
|
|
let show
|
|
|
|
for (const header of headers) {
|
|
|
|
let name;
|
|
|
|
let id;
|
|
|
|
if (header.classList.contains('toc-page-header')) { // deprecated after removing stepper
|
|
|
|
name = header.innerText.trim().replace(/^link/, '');
|
|
|
|
id = header.id;
|
|
|
|
page = header.id.split('_')[1];
|
|
|
|
section = undefined;
|
|
|
|
show = true;
|
|
|
|
} else if (header.classList.contains('toc-section-header')) {
|
|
|
|
name = header.childNodes[0].childNodes[0].childNodes[0].childNodes[0].childNodes[0].nodeValue.trim().replace(/^link/, '');
|
|
|
|
id = header.id;
|
|
|
|
page = header.id.split('.')[1];
|
|
|
|
section = header.id;
|
|
|
|
if (header.id.split('.')[4]) { show = false; }
|
|
|
|
else { show = true; }
|
|
|
|
} else if (header.classList.contains('toc-compositeField-header')) {
|
|
|
|
name = (header.childNodes[0]).nodeValue.trim().replace(/^link/, '');
|
|
|
|
id = header.id;
|
|
|
|
// id = header.parentElement.parentElement.parentElement.id;
|
|
|
|
show = false;
|
|
|
|
}
|
|
|
|
const { top } = header.getBoundingClientRect();
|
|
|
|
links.push({
|
|
|
|
name,
|
|
|
|
id,
|
|
|
|
type: header.tagName.toLowerCase(),
|
|
|
|
top: top,
|
|
|
|
active: false,
|
|
|
|
page: page,
|
|
|
|
section: section,
|
|
|
|
show: show,
|
|
|
|
selected: false
|
|
|
|
});
|
2020-11-06 11:42:31 +01:00
|
|
|
}
|
2019-10-22 14:46:48 +02:00
|
|
|
}
|
2021-03-17 10:08:59 +01:00
|
|
|
this.links = links;
|
|
|
|
// Initialize selected for button next on dataset wizard component editor
|
|
|
|
this.links.length > 0 ? this.links[0].selected = true : null;
|
|
|
|
})
|
|
|
|
}
|
2020-11-06 11:42:31 +01:00
|
|
|
}
|
|
|
|
|
2019-10-15 16:25:43 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 18:08:09 +02:00
|
|
|
private _findHiddenEntries(tocentries:ToCEntry[]):string[]{
|
|
|
|
if(!tocentries) return [];
|
|
|
|
|
|
|
|
const invisibleEntries:string[] = []
|
|
|
|
tocentries.forEach(entry=>{
|
|
|
|
if(entry.type === ToCEntryType.FieldSet){
|
|
|
|
const isVisible = this.visibilityRulesService.checkElementVisibility(entry.id);
|
|
|
|
if(!isVisible){
|
|
|
|
invisibleEntries.push(entry.id);
|
|
|
|
}else{
|
|
|
|
//check field inputs
|
|
|
|
const fields = entry.form.get('fields') as FormArray;
|
|
|
|
|
|
|
|
const oneFieldAtLeastIsVisible = fields.controls.some(field=> this.visibilityRulesService.checkElementVisibility(field.get('id').value));
|
|
|
|
if(!oneFieldAtLeastIsVisible){
|
|
|
|
invisibleEntries.push(entry.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
const hiddenEntries = this._findHiddenEntries(entry.subEntries);
|
|
|
|
|
|
|
|
if(entry.subEntries&& (entry.subEntries.every(e=> hiddenEntries.includes(e.id)))){
|
|
|
|
//all children all hidden then hide parent node;
|
|
|
|
invisibleEntries.push(entry.id);
|
|
|
|
}else{
|
|
|
|
invisibleEntries.push(...hiddenEntries);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return invisibleEntries;
|
|
|
|
}
|
|
|
|
|
2021-04-13 10:19:09 +02:00
|
|
|
private _visibilityRulesSubscription:Subscription;
|
2020-09-24 19:28:03 +02:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
2021-04-06 08:57:17 +02:00
|
|
|
|
|
|
|
if(this.selectedFieldsetId){
|
|
|
|
this.tocentrySelected = this._findTocEntryById(this.selectedFieldsetId,this.tocentries);
|
2021-04-08 17:29:08 +02:00
|
|
|
this._actOnObservation = false;
|
|
|
|
setTimeout(() => {
|
|
|
|
this._actOnObservation = true;
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(changes['hasFocus'] && changes.hasFocus.currentValue){
|
|
|
|
this._resetObserver();
|
|
|
|
|
2021-04-06 08:57:17 +02:00
|
|
|
}
|
|
|
|
|
2021-04-13 10:19:09 +02:00
|
|
|
if('visibilityRulesService'){
|
|
|
|
if(this._visibilityRulesSubscription){
|
|
|
|
this._visibilityRulesSubscription.unsubscribe();
|
|
|
|
this._visibilityRulesSubscription = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!this.visibilityRulesService) return;
|
|
|
|
|
|
|
|
this._visibilityRulesSubscription = this.visibilityRulesService.visibilityChange
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.pipe(debounceTime(200))
|
|
|
|
.subscribe(_=>{
|
|
|
|
if(this.hasFocus){
|
|
|
|
this._resetObserver();
|
|
|
|
this.hiddenEntries = this._findHiddenEntries(this.tocentries);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.hiddenEntries = this._findHiddenEntries(this.tocentries);
|
|
|
|
}
|
2020-11-06 11:42:31 +01:00
|
|
|
// if (!this.isActive && this.links && this.links.length > 0) {
|
|
|
|
// this.links.forEach(link => {
|
|
|
|
// link.selected = false;
|
|
|
|
// })
|
|
|
|
// this.links[0].selected = true;
|
|
|
|
// }
|
2020-09-24 19:28:03 +02:00
|
|
|
}
|
|
|
|
|
2021-04-08 17:29:08 +02:00
|
|
|
|
|
|
|
private _resetObserver(){
|
|
|
|
if(this._intersectionObserver){//clean up
|
|
|
|
this._intersectionObserver.disconnect();
|
|
|
|
this._intersectionObserver = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
root: null,
|
|
|
|
rootMargin: '-38% 0px -60% 0px',
|
|
|
|
threshold: 0
|
|
|
|
}
|
|
|
|
|
|
|
|
this._intersectionObserver = new IntersectionObserver((entries,observer)=>{
|
|
|
|
if(!this._actOnObservation){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entries.forEach(ie=>{
|
|
|
|
if(ie.isIntersecting){
|
|
|
|
try{
|
|
|
|
const target_id = ie.target.id.replace(this.TOCENTRY_ID_PREFIX,'');
|
|
|
|
if(this.visibilityRulesService.checkElementVisibility(target_id)){
|
|
|
|
this.tocentrySelected = this._findTocEntryById(target_id,this.tocentries);
|
|
|
|
}
|
|
|
|
}catch{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
const fieldsetsEtries = this._getAllFieldSets(this.tocentries);
|
|
|
|
|
|
|
|
fieldsetsEtries.forEach(e=>{
|
|
|
|
if(e.type === ToCEntryType.FieldSet){
|
|
|
|
try{
|
|
|
|
const targetElement = document.getElementById(this.TOCENTRY_ID_PREFIX+e.id);
|
|
|
|
this._intersectionObserver.observe(targetElement);
|
|
|
|
}catch{
|
|
|
|
console.log('element not found');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-15 16:25:43 +02:00
|
|
|
goToStep(link: Link) {
|
|
|
|
this.stepFound.emit({
|
|
|
|
page: link.page,
|
|
|
|
section: link.section
|
|
|
|
});
|
2020-11-06 11:42:31 +01:00
|
|
|
this.currentLinks.emit(this.links);
|
2019-10-15 16:25:43 +02:00
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
const target = document.getElementById(link.id);
|
|
|
|
target.scrollIntoView(true);
|
|
|
|
|
|
|
|
var scrolledY = window.scrollY;
|
|
|
|
if (scrolledY) {
|
|
|
|
window.scroll(0, scrolledY - 70);
|
|
|
|
}
|
2019-10-22 14:46:48 +02:00
|
|
|
}, 500);
|
2019-10-15 16:25:43 +02:00
|
|
|
}
|
|
|
|
|
2020-09-16 17:19:29 +02:00
|
|
|
toggle(headerLink: Link) {
|
2020-11-06 11:42:31 +01:00
|
|
|
const headerPage = +headerLink.name.split(" ", 1);
|
2020-09-16 17:19:29 +02:00
|
|
|
let innerPage;
|
|
|
|
for (const link of this.links) {
|
|
|
|
link.selected = false;
|
|
|
|
if (link.type === 'mat-expansion-panel') {
|
2020-11-06 11:42:31 +01:00
|
|
|
innerPage = +link.name.split(".", 1)[0];
|
|
|
|
if (isNaN(innerPage)) { innerPage = +link.name.split(" ", 1) }
|
2020-09-16 17:19:29 +02:00
|
|
|
} else if (link.type === 'h5') {
|
2020-11-06 11:42:31 +01:00
|
|
|
innerPage = +link.name.split(".", 1)[0];
|
2020-09-16 17:19:29 +02:00
|
|
|
}
|
2020-09-23 09:19:05 +02:00
|
|
|
if (headerPage === innerPage && (link.type !== 'mat-expansion-panel' || (link.type === 'mat-expansion-panel' && link.id.split(".")[4]))) {
|
2020-09-16 17:19:29 +02:00
|
|
|
link.show = !link.show;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
headerLink.selected = true;
|
|
|
|
}
|
|
|
|
|
2020-09-23 09:19:05 +02:00
|
|
|
// getIndex(link: Link): number {
|
|
|
|
// return +link.id.split("_", 2)[1];
|
|
|
|
// }
|
2020-09-16 17:19:29 +02:00
|
|
|
|
2021-03-17 10:08:59 +01:00
|
|
|
|
|
|
|
private _buildRecursively(form: FormGroup,whatAmI:ToCEntryType):ToCEntry{
|
|
|
|
if(!form) return null;
|
|
|
|
|
|
|
|
switch(whatAmI){
|
|
|
|
case ToCEntryType.Section:
|
|
|
|
const sections = form.get('sections') as FormArray;
|
|
|
|
const fieldsets = form.get('compositeFields') as FormArray;
|
|
|
|
|
|
|
|
|
|
|
|
const tempResult:ToCEntry[] = [];
|
|
|
|
|
|
|
|
if(sections &§ions.length){
|
|
|
|
sections.controls.forEach(section=>{
|
|
|
|
tempResult.push(this._buildRecursively(section as FormGroup, ToCEntryType.Section));
|
|
|
|
});
|
|
|
|
|
|
|
|
}else if(fieldsets && fieldsets.length){
|
|
|
|
fieldsets.controls.forEach(fieldset=>{
|
|
|
|
tempResult.push(this._buildRecursively(fieldset as FormGroup, ToCEntryType.FieldSet));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
form: form,
|
|
|
|
id: form.get('id').value,
|
|
|
|
label: form.get('title').value,
|
|
|
|
numbering: '',
|
|
|
|
subEntries:tempResult,
|
|
|
|
subEntriesType: sections &§ions.length? ToCEntryType.Section: ToCEntryType.FieldSet,
|
|
|
|
type: ToCEntryType.Section,
|
|
|
|
ordinal: form.get('ordinal').value
|
|
|
|
}
|
|
|
|
case ToCEntryType.FieldSet:
|
|
|
|
return {
|
|
|
|
form: form,
|
|
|
|
label:form.get('title').value,
|
|
|
|
id: form.get('id').value,
|
|
|
|
numbering:'s',
|
|
|
|
subEntries:[],
|
|
|
|
subEntriesType: ToCEntryType.Field,
|
|
|
|
type: ToCEntryType.FieldSet,
|
|
|
|
ordinal: form.get('ordinal').value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private _sortByOrdinal(tocentries: ToCEntry[]){
|
|
|
|
|
|
|
|
if(!tocentries || !tocentries.length) return;
|
|
|
|
|
|
|
|
tocentries.sort(this._customCompare);
|
|
|
|
tocentries.forEach(entry=>{
|
|
|
|
this._sortByOrdinal(entry.subEntries);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private _customCompare(a,b){
|
|
|
|
return a.ordinal - b.ordinal;
|
|
|
|
}
|
|
|
|
|
|
|
|
private _calculateNumbering(tocentries: ToCEntry[], depth:number[] = []){
|
|
|
|
if(!tocentries || !tocentries.length){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let prefixNumbering = depth.length? depth.join('.'): '';
|
|
|
|
|
|
|
|
if(depth.length) prefixNumbering = prefixNumbering+".";
|
|
|
|
tocentries.forEach((entry,i)=>{
|
|
|
|
entry.numbering = prefixNumbering + (i+1);
|
|
|
|
this._calculateNumbering(entry.subEntries, [...depth, i+1])
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getTocEntries(form): ToCEntry[] {
|
|
|
|
if (form == null) { return []; }
|
|
|
|
const result: ToCEntry[] = [];
|
|
|
|
|
|
|
|
//build parent pages
|
|
|
|
(form.get('pages') as FormArray).controls.forEach((pageElement, i) => {
|
|
|
|
result.push({
|
|
|
|
id: i+'id',
|
|
|
|
label: pageElement.get('title').value,
|
|
|
|
type: ToCEntryType.Page,
|
|
|
|
form: pageElement,
|
|
|
|
numbering: (i + 1).toString(),
|
|
|
|
subEntriesType: ToCEntryType.Section,
|
|
|
|
subEntries:[],
|
|
|
|
ordinal: pageElement.get('ordinal').value
|
|
|
|
} as ToCEntry)
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.forEach((entry,i)=>{
|
|
|
|
|
|
|
|
const sections = entry.form.get('sections') as FormArray;
|
|
|
|
|
|
|
|
sections.controls.forEach(section=>{
|
|
|
|
const tempResults = this._buildRecursively(section as FormGroup,ToCEntryType.Section);
|
|
|
|
entry.subEntries.push(tempResults);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this._sortByOrdinal(result);
|
|
|
|
//calculate numbering
|
|
|
|
this._calculateNumbering(result);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
onToCentrySelected(entry: ToCEntry){
|
|
|
|
this.tocentrySelected = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-19 13:32:17 +01:00
|
|
|
public seekToFirstElement(){//only on tocentry mode
|
|
|
|
if(this.tocentries && this.tocentries.length){
|
|
|
|
this.tocentrySelected = this.tocentries[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-06 08:57:17 +02:00
|
|
|
private _findTocEntryById(id: string, tocentries: ToCEntry[]): ToCEntry{
|
|
|
|
if(!tocentries || !tocentries.length){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tocEntryFound = tocentries.find(entry=>entry.id === id);
|
|
|
|
|
|
|
|
if(tocEntryFound){
|
|
|
|
return tocEntryFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(let entry of tocentries){
|
|
|
|
const result = this._findTocEntryById(id, entry.subEntries);
|
|
|
|
if(result){
|
|
|
|
tocEntryFound = result;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tocEntryFound? tocEntryFound: null;
|
|
|
|
}
|
2021-04-08 17:29:08 +02:00
|
|
|
/**
|
|
|
|
* Get all filedsets in a tocentry array;
|
|
|
|
* @param entries Tocentries to search in
|
|
|
|
* @returns The tocentries that are Fieldsets provided in the entries
|
|
|
|
*/
|
|
|
|
private _getAllFieldSets(entries: ToCEntry[]):ToCEntry[]{
|
|
|
|
|
|
|
|
const fieldsets:ToCEntry[] = [];
|
|
|
|
if(!entries || !entries.length) return fieldsets;
|
|
|
|
|
|
|
|
|
|
|
|
entries.forEach(e=>{
|
|
|
|
if(e.type === ToCEntryType.FieldSet){
|
|
|
|
fieldsets.push(e);
|
|
|
|
}else{
|
|
|
|
fieldsets.push(...this._getAllFieldSets(e.subEntries));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return fieldsets;
|
|
|
|
}
|
2021-04-06 08:57:17 +02:00
|
|
|
|
2021-07-20 12:32:40 +02:00
|
|
|
|
|
|
|
public hasVisibleInvalidFields():boolean {
|
|
|
|
if(!this.internalTable || !this.tocentries){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this.tocentries.some(e => this.internalTable.invalidChildsVisible(e));
|
|
|
|
}
|
|
|
|
|
2019-10-15 16:25:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface LinkToScroll {
|
|
|
|
page: number;
|
|
|
|
section: number;
|
|
|
|
}
|