Compare commits

..

2 Commits

2 changed files with 99 additions and 11 deletions

View File

@ -17,5 +17,5 @@ export interface ToCEntry {
isLastEntry?: boolean;
isFirstEntry?: boolean;
previousEntry?: ToCEntry;
NextEntry?: ToCEntry;
nextEntry?: ToCEntry;
}

View File

@ -116,23 +116,56 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
});
}
private _buildRecursivelySection(item: DescriptionTemplateSection): ToCEntry {
private _buildRecursivelySection(item: DescriptionTemplateSection, previousTocentry?: ToCEntry): ToCEntry {
if (!item) return null;
const sections = item.sections;
const fieldsets = item.fieldSets;
const tempResult: ToCEntry[] = [];
if (sections && sections.length) {
sections.forEach(section => {
tempResult.push(this._buildRecursivelySection(section));
if (previousTocentry == null) {
let tocentry = this._buildRecursivelySection(section);
if (tocentry != null) {
tempResult.push(tocentry);
previousTocentry = tocentry;
}
} else {
let tocentry = this._buildRecursivelySection(section, previousTocentry); // the nested fieldsets inherit the previousTocEntry
if (tocentry) {
tempResult.push(tocentry);
previousTocentry = tocentry;
}
}
});
} else if (fieldsets && fieldsets.length) {
fieldsets.forEach(fieldset => {
tempResult.push(this._buildRecursivelyFieldSet(fieldset));
if (previousTocentry == null) {
let tocentry = this._buildRecursivelyFieldSet(fieldset);
if (tocentry != null) {
tempResult.push(tocentry);
previousTocentry = tocentry;
}
} else {
let tocentry = this._buildRecursivelyFieldSet(fieldset, previousTocentry, null);
if (tocentry) {
if (tempResult.length > 0) {
tempResult[tempResult.length-1].nextEntry = tocentry;
tempResult[tempResult.length-1].isLastEntry = tocentry == null;
}
tempResult.push(tocentry);
previousTocentry = tocentry;
}
}
});
}
return {
@ -145,11 +178,11 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
type: ToCEntryType.Section,
ordinal: item.ordinal,
visibilityRuleKey: item.id,
validityAbstractControl: this.formGroup.get('fieldSets').get(item.id)
validityAbstractControl: this.formGroup.get('fieldSets').get(item.id),
}
}
private _buildRecursivelyFieldSet(item: DescriptionTemplateFieldSet): ToCEntry {
private _buildRecursivelyFieldSet(item: DescriptionTemplateFieldSet, previousEntry?: ToCEntry, nextEntry?: ToCEntry): ToCEntry {
if (!item) return null;
return {
@ -162,7 +195,11 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
type: ToCEntryType.FieldSet,
ordinal: item.ordinal,
visibilityRuleKey: item.id,
validityAbstractControl: this.formGroup.get('fieldSets').get(item.id)
validityAbstractControl: this.formGroup.get('fieldSets').get(item.id),
isLastEntry: nextEntry == null,
isFirstEntry: previousEntry == null ,
previousEntry: previousEntry,
nextEntry: nextEntry
};
}
@ -199,6 +236,8 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
if (descriptionTemplate == null) { return []; }
const result: ToCEntry[] = [];
let previousTocentry: ToCEntry = null;
//build parent pages
descriptionTemplate.definition.pages.forEach((pageElement, i) => {
const tocEntry: ToCEntry = {
@ -213,13 +252,29 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
validityAbstractControl: null
};
const sections = descriptionTemplate.definition.pages.find(x => x.id == pageElement.id)?.sections;
const sections = pageElement.sections;
sections.forEach(section => {
const tempResults = this._buildRecursivelySection(section);
const tempResults = this._buildRecursivelySection(section, previousTocentry);
// explanation: previous-section[last-field].next = current-section[first-field]
let firstTocentryOfCurrentSection = this._getHeadField(tempResults);
if (tocEntry.subEntries.length > 0) {
tocEntry.subEntries[tocEntry.subEntries.length - 1] = this._setTocentryNext(tocEntry.subEntries[tocEntry.subEntries.length - 1], firstTocentryOfCurrentSection);
}
tocEntry.subEntries.push(tempResults);
previousTocentry = this._getTailField(tempResults);
});
result.push(tocEntry)
// explanation: previous-page[last-section][last-field].next = current-page[first-section][first-field]
let firstTocentryOfCurrentPage = this._getHeadField(tocEntry);
if (result.length > 0) {
result[result.length - 1] = this._setTocentryNext(result[result.length - 1], firstTocentryOfCurrentPage);
}
result.push(tocEntry);
});
this._sortByOrdinal(result);
@ -276,6 +331,39 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
return tocEntryFound ? tocEntryFound : null;
}
private _getHeadField(item: ToCEntry): ToCEntry {
if (!item) return null;
const subEntries = item.subEntries;
if (subEntries && subEntries.length) return this._getHeadField(subEntries[0]);
else return item;
}
private _getTailField(item: ToCEntry): ToCEntry {
if (!item) return null;
const subEntries = item.subEntries;
if (subEntries && subEntries.length) return this._getTailField(subEntries[subEntries.length-1]);
else return item;
}
private _setTocentryNext(previous: ToCEntry, next: ToCEntry): ToCEntry {
if (!previous) return null;
if (previous.subEntries && previous.subEntries.length) {
let last: number = previous.subEntries.length-1;
previous.subEntries[last] = this._setTocentryNext(previous.subEntries[last], next);
return previous;
}
else {
previous.nextEntry = next;
previous.isLastEntry = next == null
return previous;
}
}
}
export interface LinkToScroll {