Skip to content

Commit

Permalink
fix: certain texts get unselected on keystroke
Browse files Browse the repository at this point in the history
* Closes rero/rero-ils#3276.

Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Aug 30, 2023
1 parent c00d1b4 commit e26a55a
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@ import { ResultItem } from '@rero/ng-core';
})
export class DocumentsBriefViewComponent implements ResultItem {

@Input()
record: any;
/** Set record */
@Input() set record(record) {
this._record = record;
this.processProvisionActivityPublications();
}

@Input()
type: string;
@Input() type: string;

@Input()
detailUrl: { link: string, external: boolean };
@Input() detailUrl: { link: string, external: boolean };

/** process provision activity publications */
get provisionActivityPublications() {
const provisionActivity = this.record.metadata.provisionActivity;
const publications = [];
if (undefined === provisionActivity) {
return publications;
}
provisionActivity.map((provision: any) => {
if (provision.type === 'bf:Publication' && '_text' in provision) {
provision._text.map((text: any) => publications.push(text));
}
});
return publications;
/** Provision activities */
provisionActivityPublications: any[] = [];

/** Record */
private _record: any;

/** Get current record */
get record(): any {
return this._record;
}

/**
Expand All @@ -71,4 +68,17 @@ export class DocumentsBriefViewComponent implements ResultItem {
return 'missing-contribution-type';
}
}

/** process provision activity publications */
private processProvisionActivityPublications() {
const { provisionActivity } = this.record.metadata;
if (undefined === provisionActivity) {
return;
}
provisionActivity.map((provision: any) => {
if (provision.type === 'bf:Publication' && '_text' in provision) {
provision._text.map((text: any) => this.provisionActivityPublications.push(text));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
<admin-description-zone>
<ng-container label>{{ 'General note' | translate }}</ng-container>
<ng-container content>
<ul class="list-unstyled mb-0">
<li *ngFor="let note of notesGeneral.general">{{ note }}</li>
</ul>
<ng-container *ngFor="let noteType of notesGeneral | keyvalue">
<ul class="list-unstyled mb-0">
<li *ngFor="let note of noteType.value">{{ note }}</li>
</ul>
</ng-container>
</ng-container>
</admin-description-zone>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* RERO ILS UI
* Copyright (C) 2021 RERO
* Copyright (C) 2019-2023 RERO
* Copyright (C) 2019-2023 UCLouvain
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
Expand All @@ -14,16 +15,33 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input } from '@angular/core';
import { Component, Input, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'admin-document-description',
templateUrl: './document-description.component.html'
})
export class DocumentDescriptionComponent {
export class DocumentDescriptionComponent implements OnInit {

/** Document record */
@Input() record: any;
/** Cartographic attributes */
cartographicAttributes: any[] = [];
/** Edition statement */
editionStatement: any[] = [];
/** Identified bye */
identifiedBy: any[] = [];
/** All notes without general */
notesExceptGeneral: any[] = [];
/** General notes only */
notesGeneral: any[] = [];
/** Provision activity original date */
provisionActivityOriginalDate: any[] = [];
/** Title variants */
titleVariants: any = {};
/** Work access point */
workAccessPoint: any[] = [];

/**
* Get Current language interface
Expand All @@ -33,47 +51,67 @@ export class DocumentDescriptionComponent {
return this.translateService.currentLang;
}

// ---- FIELDS
/**
* Constructor
* @param translateService - TranslateService
*/
constructor(public translateService: TranslateService) {}

/** Get cartographic attributes */
get cartographicAttributes(): any[] {
const cartographic = [];
/** On init hook */
ngOnInit(): void {
this.processCartographicAttributes();
this.processEditionStatement();
this.processIdentifiedBy();
this.processNotesExceptGeneral();
this.processNotesGeneral();
this.processProvisionActivityOriginalDate();
this.processTitleVariants();
this.processWorkAccessPoint();
}

/**
* Allow to filter provisionActivity keeping only activities that aren't 'Publication'
* @param element: the element to check
* @return True if element isn't a 'Publication', False otherwise
*/
filterNotPublicationProvisionActivity(element: any): boolean {
return ('key' in element && element.key !== 'bf:Publication');
}

/** Process cartographic attributes */
private processCartographicAttributes(): void {
if ('cartographicAttributes' in this.record.metadata) {
this.record.metadata.cartographicAttributes.forEach((attribute: any) => {
if ('projection' in attribute || ('coordinates' in attribute && 'label' in attribute.coordinates)) {
cartographic.push(attribute);
this.cartographicAttributes.push(attribute);
}
});
}
return cartographic;
}

/** Get list of document edition statement */
get editionStatement(): any[] {
const results = [];
/** Process edition statement */
private processEditionStatement(): void {
if ('seriesStatement' in this.record.metadata) {
this.record.metadata.seriesStatement.forEach((element: any) => {
if ('_text' in element) {
const elementText = element._text;
const keys = Object.keys(elementText);
const indexDefault = keys.indexOf('default');
if (indexDefault > -1) {
results.push(elementText.default);
this.editionStatement.push(elementText.default);
keys.splice(indexDefault, 1);
}

keys.forEach(key => {
results.push(elementText[key]);
this.editionStatement.push(elementText[key]);
});
}
});
}
return results;
}

/** Get list of document identifiers */
get identifiedBy(): any[] {
const identifiers = [];
/** Process identified by */
private processIdentifiedBy(): void {
if ('identifiedBy' in this.record.metadata) {
this.record.metadata.identifiedBy.forEach((id: any) => {
const details = [];
Expand All @@ -89,62 +127,49 @@ export class DocumentDescriptionComponent {
if (id.note) {
details.push(id.note);
}
identifiers.push({
this.identifiedBy.push({
type: idType,
value: id.value,
details: details.join(', ')
});
});
}
return identifiers;
}

/** Get notes except general type */
get notesExceptGeneral(): any {
/** Process General notes */
private processNotesGeneral(): void {
if ('note' in this.record.metadata) {
return this._sortedNotesByType(
this.record.metadata.note.filter((el: any) => el.noteType !== 'general')
this.notesGeneral = this._sortedNotesByType(
this.record.metadata.note.filter((el: any) => el.noteType === 'general')
);
}
return;
}

/** Get notes general only */
get notesGeneral(): any {
/** Process all without general */
private processNotesExceptGeneral(): void {
if ('note' in this.record.metadata) {
return this._sortedNotesByType(
this.record.metadata.note.filter((el: any) => el.noteType === 'general')
this.notesExceptGeneral = this._sortedNotesByType(
this.record.metadata.note.filter((el: any) => el.noteType !== 'general')
);
}
return;
}

/**
* Allow to filter provisionActivity keeping only activities that aren't 'Publication'
* @param element: the element to check
* @return True if element isn't a 'Publication', False otherwise
*/
filterNotPublicationProvisionActivity(element: any): boolean {
return ('key' in element && element.key !== 'bf:Publication');
}

/** Get provision activity with available original_date field */
get provisionActivityOriginalDate() {
return ('provisionActivity' in this.record.metadata)
? this.record.metadata.provisionActivity
/** Process provision activity original date */
private processProvisionActivityOriginalDate(): void {
if ('provisionActivity' in this.record.metadata) {
this.provisionActivityOriginalDate = this.record.metadata.provisionActivity
.filter((element: any) => element.key !== 'bf:Publication')
.filter((provision: any) => 'original_date' in provision)
: [];
}
}

/** Get title variants by type */
get titleVariants(): any {
const variants = {};
/** Process title variants */
private processTitleVariants(): void {
if ('title' in this.record.metadata) {
const titles = this.record.metadata.title.filter((title: any) => title.type !== 'bf:Title');
titles.forEach((title: any) => {
if (!(title.type in variants)) {
variants[title.type] = [];
if (!(title.type in this.titleVariants)) {
this.titleVariants[title.type] = [];
}
const result = [];
result.push(title.mainTitle[0].value);
Expand All @@ -168,15 +193,13 @@ export class DocumentDescriptionComponent {
if (variantData.length > 0) {
variantTitle += `. ${variantData.join('. ')}`;
}
variants[title.type].push(variantTitle);
this.titleVariants[title.type].push(variantTitle);
});
}
return variants;
}

/** Get work access point */
get workAccessPoint(): string[] {
const work = [];
/** Process work access point */
private processWorkAccessPoint(): void {
if ('work_access_point' in this.record.metadata) {
this.record.metadata.work_access_point.forEach((workAccess: any) => {
let agentFormatted = '';
Expand Down Expand Up @@ -264,18 +287,11 @@ export class DocumentDescriptionComponent {
if (workAccess.date_of_work) {
agentFormatted += workAccess.date_of_work + '. ';
}
work.push(agentFormatted.trim());
this.workAccessPoint.push(agentFormatted.trim());
});
}
return work;
}

/**
* Constructor
* @param translateService - TranslateService
*/
constructor(public translateService: TranslateService) {}

/**
* Sorted notes by type
* @param notes - Array of notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h3 id="{{ 'doc-altgr-title-' + i }}">{{ altgr_title }}</h3>
[header]="true"></admin-other-edition>

<!-- ELECTRONIC LOCATOR: RELATED RESOURCE -->
<div class="row" *ngIf="relatedResources">
<div class="row" *ngIf="relatedResources.length > 0">
<div class="col">
<ul class="list-unstyled mt-1 mb-0">
<li *ngFor="let eloc of relatedResources">
Expand Down
Loading

0 comments on commit e26a55a

Please sign in to comment.