Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,10 @@ export class ApparatusEntryDetailComponent implements OnInit, OnDestroy {
return result;
});

this.showLemma = !!this.data.lemma;
if (this.witnessPanelService) {
const isWitnessExcluded = this.data.isWitnessExcluded(this.witnessPanelService.witnessId);
this.showLemma = !!this.data.lemma && !isWitnessExcluded;
}
else{
this.showLemma = false;
this.showLemma = !isWitnessExcluded;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EVTStatusService } from '../../services/evt-status.service';
import { combineLatest, map, Observable, tap } from 'rxjs';
import { ApparatusEntry } from 'src/app/models/evt-models';
import { HoverService } from 'src/app/services/hover.service';
import { distinctBy } from 'src/app/utils/js-utils';

@Component({
selector: 'evt-critical-apparatus',
Expand All @@ -12,20 +13,24 @@ import { HoverService } from 'src/app/services/hover.service';
})
export class CriticalApparatusComponent {
@Input() pageID: string;
@ViewChildren('appDetails', { read: ElementRef}) appDetails!: QueryList<ElementRef>;
@ViewChildren('appDetails', { read: ElementRef }) appDetails!: QueryList<ElementRef>;

private appClasses = ['app'];
private apparatusInCurrentPage = this.evtStatusService.getPageElementsByClassList(this.appClasses)
entries$: Observable<{ entry: ApparatusEntry, isSelected: boolean }[]> = combineLatest([
this.apparatusInCurrentPage.pipe(map(data => data.flat())),
this.apparatusInCurrentPage.pipe(
map(data => data.flat()),
map(data => distinctBy(data, item => item.id))
),
this.hoverService.selectedApparatusEntries$
]).pipe(
map(([appEntries, selectedAppEntries]) => {
const apparatusEntries = appEntries as ApparatusEntry[];
const apps = apparatusEntries.map(entry => {
const selectedApp = selectedAppEntries.find(app => app.additionalAttributes.exponentId === entry.additionalAttributes.exponentId);
return { entry, isSelected: !!selectedApp };
});
const apps = apparatusEntries
.map(entry => {
const selectedApp = selectedAppEntries.find(app => app.additionalAttributes.exponentId === entry.additionalAttributes.exponentId);
return { entry, isSelected: !!selectedApp };
});
const orderedApps = apps.sort((a, b) => {
const lengthComparison = a.entry.exponent.length - b.entry.exponent.length;
if (lengthComparison !== 0) {
Expand Down
32 changes: 32 additions & 0 deletions src/app/services/xml-parsers/structure-xml-parser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ export class StructureXmlParserService {
const app = item as ApparatusEntry;
if (!app) throw new Error("Invalid type " + app);

const callback = (content: any[]) => this.addApparatusExponents(
content,
onApparatusEntryReplaced,
getExponentLabel,
onShouldResetCounter);
this.addNestedApparatusExponents(app, callback);

const id = this.getExponentId();
const to = id; // the exponent itself as the To element
let exponent: ApparatusEntryExponent = null;
Expand Down Expand Up @@ -423,6 +430,27 @@ export class StructureXmlParserService {
}
}

private addNestedApparatusExponents(app: ApparatusEntry, callback: (content: any[]) => void) {
const contentValues: ContentValue[] = [];
this.populateValuesWithContent(app, contentValues);
for (const value of contentValues) {
callback(value.content);
}
}

private populateValuesWithContent(obj: any, accumulator: ContentValue[]) {
const values = Object.values(obj)
.flatMap(x => x as any)
.filter(x => typeof (x) === 'object');
for (let index = 0; index < values.length; index++) {
const value = values[index];
if (value.content) {
accumulator.push(value);
this.populateValuesWithContent({ content: value.content }, accumulator);
}
}
}

private getExponentId(): string {
const uuid = uuidv4();
return 'app-exponent-' + uuid;
Expand Down Expand Up @@ -603,4 +631,8 @@ function getEditionOrigNode(el: XMLElement, doc: Document) {
}

return el;
}

interface ContentValue {
content: any[]
}
10 changes: 10 additions & 0 deletions src/app/utils/js-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ export function interleave<T>(items: T[], separator: T): T[] {
}
return result;
}

export function distinctBy<T, K>(array: T[], keySelector: (item: T) => K): T[] {
const seen = new Set<K>();
return array.filter(item => {
const key = keySelector(item);
if (seen.has(key)) return false;
seen.add(key);
return true;
})
}