Skip to content

Commit

Permalink
Add usage of OriginalEncodingNodeType in originalEncoding property of…
Browse files Browse the repository at this point in the history
… the new elements
  • Loading branch information
davivcu committed Oct 24, 2023
1 parent d59561c commit b52ca01
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ <h3 class="sources-cat">{{'analogueIn' | translate}}</h3>
<li ngbNavItem="xml" *ngIf="analogue.originalEncoding">
<a class="source-detail-btn" ngbNavLink>{{'xml' | translate}}</a>
<ng-template ngbNavContent>
<pre>{{ analogue.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="analogue.originalEncoding">
</evt-original-encoding-viewer>
<!-- children bibl element -->
<ng-container *ngIf="analogue.sources">
<ng-container *ngFor="let sourceXML of analogue.sources">
<ng-container *ngIf="sourceXML.type.name === 'BibliographicList'">
<ng-container *ngFor="let intBib of sourceXML.sources">
<pre>{{ intBib.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="intBib.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
<ng-container *ngIf="sourceXML.type.name !== 'BibliographicList'">
<pre>{{ sourceXML.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="sourceXML.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
</ng-container>
Expand All @@ -69,12 +72,14 @@ <h3 class="sources-cat">{{'analogueIn' | translate}}</h3>
<ng-container *ngFor="let extBiblXML of analogue.extSources">
<ng-container *ngIf="extBiblXML.type.name === 'BibliographicList'">
<ng-container *ngFor="let bibl of extBiblXML.sources">
<pre>{{ bibl.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="bibl.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
<ng-container *ngIf="extBiblXML.type.name !== 'BibliographicList'">
<ng-container *ngIf="extBiblXML.originalEncoding">
<pre>{{ extBiblXML.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="extBiblXML.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ <h3 class="sources-cat">{{'references' | translate}}</h3>
<li ngbNavItem="xml" *ngIf="source.originalEncoding">
<a class="source-detail-btn" ngbNavLink>{{'xml' | translate}}</a>
<ng-template ngbNavContent>
<pre>{{ source.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="source.originalEncoding">
</evt-original-encoding-viewer>
<!-- children bibl element -->
<ng-container *ngIf="source.sources && source.insideCit">
<ng-container *ngFor="let sourceXML of source.sources">
<ng-container *ngIf="sourceXML.type.name === 'BibliographicList'">
<ng-container *ngFor="let intBib of sourceXML.sources">
<pre>{{ intBib.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="intBib.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
<ng-container *ngIf="sourceXML.type.name !== 'BibliographicList'">
<pre>{{ sourceXML.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="sourceXML.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
</ng-container>
Expand All @@ -86,12 +89,14 @@ <h3 class="sources-cat">{{'references' | translate}}</h3>
<ng-container *ngFor="let extBiblXML of source.extSources">
<ng-container *ngIf="extBiblXML.type?.name === 'BibliographicList'">
<ng-container *ngFor="let bibl of extBiblXML.sources">
<pre>{{ bibl.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="bibl.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
<ng-container *ngIf="extBiblXML.type?.name !== 'BibliographicList'">
<ng-container *ngIf="extBiblXML.originalEncoding">
<pre>{{ extBiblXML.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="extBiblXML.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
</ng-container>
Expand All @@ -100,7 +105,8 @@ <h3 class="sources-cat">{{'references' | translate}}</h3>
<ng-container *ngIf="source.extElements">
<ng-container *ngFor="let extEl of source.extElements">
<ng-container *ngIf="extEl.originalEncoding">
<pre>{{ extEl.originalEncoding | xmlBeautify }}</pre>
<evt-original-encoding-viewer [originalEncoding]="extEl.originalEncoding">
</evt-original-encoding-viewer>
</ng-container>
</ng-container>
</ng-container>
Expand Down
8 changes: 4 additions & 4 deletions src/app/models/evt-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export class QuoteEntry extends GenericElement {
extElements: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
analogues: any;
originalEncoding: string;
originalEncoding: OriginalEncodingNodeType;
insideCit: boolean;
quotedText: string[];
noteView: boolean;
Expand All @@ -211,15 +211,15 @@ export class BibliographicEntry extends GenericElement {
text: string;
quotedText: string;
insideCit: boolean;
originalEncoding: string;
originalEncoding: OriginalEncodingNodeType;
}

export class BibliographicStructEntry extends GenericElement {
id: string;
analytic: BibliographicEntry[];
monogrs: BibliographicEntry[];
series: BibliographicEntry[];
originalEncoding: string;
originalEncoding: OriginalEncodingNodeType;
}

export class Analogue extends GenericElement {
Expand All @@ -231,7 +231,7 @@ export class Analogue extends GenericElement {
extLinkedElements: any;
quotedElements: [{ id: string, quote: string }];
contentToShow: Array<ParseResult<GenericElement>>
originalEncoding: string;
originalEncoding: OriginalEncodingNodeType;
}

export class Reading extends GenericElement {
Expand Down
5 changes: 4 additions & 1 deletion src/app/services/evt-status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,12 @@ export class EVTStatusService {
}

getPageElementsByClassList(classList) {
const notInterestingProps = ['originalEncoding','type'];
const maxEffort = 4000;

return this.currentStatus$.pipe(
map(({ page }) => page.parsedContent),
map((pageSubElements) => deepSearch(pageSubElements, 'class', classList)),
map((pageSubElements) => deepSearch(pageSubElements, 'class', classList, maxEffort, notInterestingProps)),
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/app/services/xml-parsers/analogue-parser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AppConfig } from 'src/app/app.config';
import { parse, ParserRegister, xmlParser } from '.';
import { Analogue, AnalogueClass, BibliographicEntry, BibliographicList, GenericElement, Milestone, XMLElement } from '../../models/evt-models';
import { getOuterHTML } from '../../utils/dom-utils';
import { AnchorParser, AttributeParser, GenericElemParser, MilestoneParser } from './basic-parsers';
import { createParser, getID, parseChildren, Parser } from './parser-models';
import { chainFirstChildTexts, getExternalElements, normalizeSpaces } from '../../utils/xml-utils';
Expand Down Expand Up @@ -48,7 +47,7 @@ export class AnalogueParser extends BasicParser implements Parser<XMLElement> {
extSources: sources.extSources,
extLinkedElements: sources.extLinkedElements,
quotedElements: this.getQuotedTextFromElements(sources.sources.concat(sources.extSources), sources.extLinkedElements),
originalEncoding: getOuterHTML(analogue),
originalEncoding: analogue,
};
}

Expand Down
5 changes: 2 additions & 3 deletions src/app/services/xml-parsers/bilbliography-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { normalizeSpaces } from 'src/app/utils/xml-utils';
import { parse, xmlParser } from '.';
import { BibliographicEntry, BibliographicList, BibliographicStructEntry, BibliographyClass, XMLElement } from '../../models/evt-models';
import { getOuterHTML } from '../../utils/dom-utils';
import { AttributeParser, GenericElemParser } from './basic-parsers';
import { createParser, getID, parseChildren, Parser } from './parser-models';
import { BasicParser } from './quotes-parser';
Expand Down Expand Up @@ -66,7 +65,7 @@ export class BibliographyParser extends BasicParser implements Parser<XMLElement
text: xml.textContent,
quotedText: this.getQuoteElementText(xml),
insideCit: (xml.parentNode['tagName'] === 'cit' || xml.parentNode['tagName'] === 'note'),
originalEncoding: getOuterHTML(xml),
originalEncoding: xml,
};
case 'cit':
case 'listBibl':
Expand All @@ -88,7 +87,7 @@ export class BibliographyParser extends BasicParser implements Parser<XMLElement
monogrs: Array.from(xml.querySelectorAll<XMLElement>('monogr')).map((x) => this.parse(x)),
series: Array.from(xml.querySelectorAll<XMLElement>('series')).map((x) => this.parse(x)),
content: parseChildren(xml, this.genericParse),
originalEncoding: getOuterHTML(xml),
originalEncoding: xml,
};
default:
return this.elementParser.parse(xml)
Expand Down
13 changes: 6 additions & 7 deletions src/app/services/xml-parsers/quotes-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Analogue, BibliographicEntry, BibliographicList, BibliographicStructEnt
XMLElement } from '../../models/evt-models';
import { AnalogueParser } from './analogue-parser';
import { createParser, getID, parseChildren, ParseFn, Parser } from './parser-models';
import { getOuterHTML } from 'src/app/utils/dom-utils';
import { isAnalogue, isSource, normalizeSpaces } from 'src/app/utils/xml-utils';
import { BibliographyParser } from './bilbliography-parsers';
import { chainFirstChildTexts } from '../../utils/xml-utils';
Expand Down Expand Up @@ -137,7 +136,7 @@ export class QuoteParser extends BasicParser implements Parser<XMLElement> {
noteView: ((quote.tagName === 'note') || (quote.tagName === 'ptr')) ? true : false,
content: content,
contentToShow: content.filter((el) => !(this.notNiceInTextFlow.includes(el['type'].name))),
originalEncoding: this.cleanXMLString(quote, isInCit),
originalEncoding: this.getXML(quote, isInCit),
};
}

Expand All @@ -157,14 +156,14 @@ export class QuoteParser extends BasicParser implements Parser<XMLElement> {
}

/**
* Remove unwanted output from XML string
* Choose proper XML node
*/
private cleanXMLString(quote: XMLElement, inCitElem: boolean): string {
private getXML(quote: XMLElement, inCitElem: boolean): XMLElement {
if (inCitElem) {
return getOuterHTML(quote.parentElement).replace(this.xpathRegex,'');
return quote.parentElement;
}

return getOuterHTML(quote).replace(this.xpathRegex,'');
return quote;
}


Expand Down Expand Up @@ -317,7 +316,7 @@ export class QuoteParser extends BasicParser implements Parser<XMLElement> {
noteView: true,
content: content,
contentToShow: content.filter((el) => !(this.notNiceInTextFlow.includes(el['type'].name))),
originalEncoding: this.cleanXMLString(quote, false),
originalEncoding: this.getXML(quote, false),
};
}

Expand Down
26 changes: 14 additions & 12 deletions src/app/utils/dom-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,23 @@ export function updateCSS(rules: Array<[string, string]>) {
/**
* This function searches inside every property of an object for the provided attribute it
* it has one of the provided list of values. It falls back after a customizable number of iterations.
* The limit counter could be inserted in a config
* The limit counter could be inserted in a config, same as the ignoredProperties
*/
export function deepSearch(obj, attrToMatch: string, valuesToMatch, counter: number = 4000) {
export function deepSearch(obj, attrToMatch: string, valuesToMatch, counter: number = 4000, ignoredProperties = []) {
let results = [];
for (const key in obj) {
const value = obj[key];
if ((key === attrToMatch) && (valuesToMatch.includes(obj[attrToMatch]))) {
results.push(obj);
}
if (typeof value === 'object' && value !== null) {
if (counter > 0) {
results = results.concat(deepSearch(value, attrToMatch, valuesToMatch, counter));
counter = counter - 1;
} else {
console.log('EVT WARN: element is too deep, not searching further in', obj);
if (!ignoredProperties.includes(key)) {
const value = obj[key];
if ((key === attrToMatch) && (valuesToMatch.includes(obj[attrToMatch]))) {
results.push(obj);
}
if (typeof value === 'object' && value !== null) {
if (counter > 0) {
results = results.concat(deepSearch(value, attrToMatch, valuesToMatch, counter, ignoredProperties));
counter = counter - 1;
} else {
console.log('EVT WARN: element is too deep, not searching further in', obj);
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,21 @@ evt-analogue-entry evt-paragraph p,
evt-quote-entry evt-paragraph p {
margin-bottom: 0;
}

evt-source-detail evt-original-encoding-viewer pre,
evt-analogue-detail evt-original-encoding-viewer pre {
margin-top:-2% !important;
padding:0 !important;
background-color:transparent !important;
}

evt-source-detail evt-original-encoding-viewer code,
evt-analogue-detail evt-original-encoding-viewer code {
color: initial;
font-size:85%;
}

evt-source-detail evt-original-encoding-viewer code .token,
evt-analogue-detail evt-original-encoding-viewer code .token {
color: #212529 !important;
}

0 comments on commit b52ca01

Please sign in to comment.