Compare commits

..

No commits in common. "996f0de0549c02b644883d9da199acefc2db8c0b" and "b1497c108e74402c8a4c9be772799fa9b2df1407" have entirely different histories.

2 changed files with 11 additions and 99 deletions

View File

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

View File

@ -116,56 +116,23 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
});
}
private _buildRecursivelySection(item: DescriptionTemplateSection, previousTocentry?: ToCEntry): ToCEntry {
private _buildRecursivelySection(item: DescriptionTemplateSection): ToCEntry {
if (!item) return null;
const sections = item.sections;
const fieldsets = item.fieldSets;
const tempResult: ToCEntry[] = [];
if (sections && sections.length) {
sections.forEach(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;
}
}
tempResult.push(this._buildRecursivelySection(section));
});
} else if (fieldsets && fieldsets.length) {
fieldsets.forEach(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;
}
}
tempResult.push(this._buildRecursivelyFieldSet(fieldset));
});
}
return {
@ -178,11 +145,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, previousEntry?: ToCEntry, nextEntry?: ToCEntry): ToCEntry {
private _buildRecursivelyFieldSet(item: DescriptionTemplateFieldSet): ToCEntry {
if (!item) return null;
return {
@ -195,11 +162,7 @@ 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),
isLastEntry: nextEntry == null,
isFirstEntry: previousEntry == null ,
previousEntry: previousEntry,
nextEntry: nextEntry
validityAbstractControl: this.formGroup.get('fieldSets').get(item.id)
};
}
@ -236,8 +199,6 @@ 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 = {
@ -252,29 +213,13 @@ export class TableOfContentsComponent extends BaseComponent implements OnInit, O
validityAbstractControl: null
};
const sections = pageElement.sections;
const sections = descriptionTemplate.definition.pages.find(x => x.id == pageElement.id)?.sections;
sections.forEach(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);
}
const tempResults = this._buildRecursivelySection(section);
tocEntry.subEntries.push(tempResults);
previousTocentry = this._getTailField(tempResults);
});
// 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);
result.push(tocEntry)
});
this._sortByOrdinal(result);
@ -331,39 +276,6 @@ 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 {