From a6ae21a95b259df66f594d1edb4bc1734b88e40f Mon Sep 17 00:00:00 2001 From: Bertrand Zuchuat Date: Mon, 20 Feb 2023 14:19:47 +0100 Subject: [PATCH] entity: use entity instead of contribution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Renames contribution to entity. * Uses authorized_access_point. Co-Authored-by: Johnny Mariéthoz Co-Authored-by: Bertrand Zuchuat --- projects/admin/src/app/app.module.ts | 40 ++-- .../app/circulation/item/item.component.html | 19 +- .../requested-item.component.html | 19 +- .../history-log/history-log.component.html | 25 +-- .../history-log/history-log.component.ts | 10 +- .../pending-item/pending-item.component.html | 19 +- .../pickup-item/pickup-item.component.html | 19 +- .../classes/typeahead/ITypeahead-interface.ts | 4 +- .../classes/typeahead/documents-typeahead.ts | 8 +- .../app/classes/typeahead/items-typeahead.ts | 4 +- .../typeahead/mef-organisation-typeahead.ts | 41 ---- .../classes/typeahead/mef-person-typeahead.ts | 41 ---- .../app/classes/typeahead/mef-typeahead.ts | 29 ++- .../classes/typeahead/patrons-typeahead.ts | 10 +- .../src/app/pipe/subject-process.pipe.spec.ts | 6 +- .../src/app/pipe/subject-process.pipe.ts | 2 +- .../documents-brief-view.component.html | 21 +-- .../collection-items.component.html | 22 +-- .../contribution-detail-view.component.ts | 2 +- .../document-description.component.ts | 4 +- .../document-detail-view.component.html | 30 +-- .../src/app/routes/corporate-bodies-route.ts | 2 +- .../src/app/routes/import-documents-route.ts | 1 - .../admin/src/app/routes/persons-route.ts | 2 +- .../ui-remote-typeahead.service.spec.ts | 8 +- .../document-brief.component.html | 23 +-- .../patron-profile-document.component.html | 19 +- .../patron-profile-document.component.ts | 19 +- .../patron-profile-history.component.html | 18 +- .../patron-profile-history.component.spec.ts | 3 +- .../patron-profile-history.component.ts | 10 +- .../src/app/routes/documents-route.service.ts | 4 +- .../lib/pipe/contribution-entity.pipe.spec.ts | 155 +++++++++++++++ .../src/lib/pipe/contribution-entity.pipe.ts | 92 +++++++++ .../lib/pipe/contribution-filter.pipe.spec.ts | 90 --------- .../src/lib/pipe/contribution-filter.pipe.ts | 69 ------- .../lib/pipe/contribution-format.pipe.spec.ts | 178 ------------------ .../src/lib/pipe/contribution-format.pipe.ts | 87 --------- .../src/lib/pipe/contribution-type.pipe.ts | 2 +- .../src/lib/pipe/extract-source-field.pipe.ts | 6 +- .../shared/src/lib/pipe/url-active.pipe.ts | 4 +- .../lib/service/app-settings.service.spec.ts | 6 +- .../src/lib/service/app-settings.service.ts | 18 +- .../lib/service/search-bar-config.service.ts | 14 +- projects/shared/src/lib/shared.module.ts | 27 +-- .../organisation-brief.component.ts | 2 +- .../person-brief/person-brief.component.ts | 2 +- .../contribution/contribution.component.html | 42 +++++ .../contribution/contribution.component.ts | 34 ++++ projects/shared/src/public-api.ts | 10 +- projects/shared/src/tests/user.ts | 18 +- 51 files changed, 501 insertions(+), 839 deletions(-) delete mode 100644 projects/admin/src/app/classes/typeahead/mef-organisation-typeahead.ts delete mode 100644 projects/admin/src/app/classes/typeahead/mef-person-typeahead.ts create mode 100644 projects/shared/src/lib/pipe/contribution-entity.pipe.spec.ts create mode 100644 projects/shared/src/lib/pipe/contribution-entity.pipe.ts delete mode 100644 projects/shared/src/lib/pipe/contribution-filter.pipe.spec.ts delete mode 100644 projects/shared/src/lib/pipe/contribution-filter.pipe.ts delete mode 100644 projects/shared/src/lib/pipe/contribution-format.pipe.spec.ts delete mode 100644 projects/shared/src/lib/pipe/contribution-format.pipe.ts create mode 100644 projects/shared/src/lib/view/contribution/contribution.component.html create mode 100644 projects/shared/src/lib/view/contribution/contribution.component.ts diff --git a/projects/admin/src/app/app.module.ts b/projects/admin/src/app/app.module.ts index f27367881..b138abc78 100644 --- a/projects/admin/src/app/app.module.ts +++ b/projects/admin/src/app/app.module.ts @@ -1,7 +1,7 @@ /* * RERO ILS UI - * Copyright (C) 2019-2022 RERO - * Copyright (C) 2019-2022 UCLouvain + * 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 @@ -17,7 +17,7 @@ */ import { APP_BASE_HREF, PlatformLocation } from '@angular/common'; -import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http'; import { APP_INITIALIZER, CUSTOM_ELEMENTS_SCHEMA, LOCALE_ID, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; @@ -44,13 +44,10 @@ import { SelectAccountEditorWidgetComponent } from './acquisition/components/editor/widget/select-account-editor-widget/select-account-editor-widget.component'; import { ReceivedOrderPermissionValidator } from './acquisition/utils/permissions'; -import { PaymentsDataComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/payments-data.component'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { DocumentsTypeahead } from './classes/typeahead/documents-typeahead'; import { ItemsTypeahead } from './classes/typeahead/items-typeahead'; -import { MefOrganisationTypeahead } from './classes/typeahead/mef-organisation-typeahead'; -import { MefPersonTypeahead } from './classes/typeahead/mef-person-typeahead'; import { MefTypeahead } from './classes/typeahead/mef-typeahead'; import { PatronsTypeahead } from './classes/typeahead/patrons-typeahead'; import { TabOrderDirective } from './directives/tab-order.directive'; @@ -72,6 +69,7 @@ import { ItemInCollectionPipe } from './pipe/item-in-collection.pipe'; import { MainTitleRelationPipe } from './pipe/main-title-relation.pipe'; import { MarcPipe } from './pipe/marc.pipe'; import { NotesFormatPipe } from './pipe/notes-format.pipe'; +import { PatronNamePipe } from './pipe/patron-name.pipe'; import { SubjectProcessPipe } from './pipe/subject-process.pipe'; import { CircPoliciesBriefViewComponent } from './record/brief-view/circ-policies-brief-view.component'; import { CollectionBriefViewComponent } from './record/brief-view/collection-brief-view.component'; @@ -82,10 +80,15 @@ import { ItemTypesBriefViewComponent } from './record/brief-view/item-types-brie import { ItemsBriefViewComponent } from './record/brief-view/items-brief-view/items-brief-view.component'; import { LibrariesBriefViewComponent } from './record/brief-view/libraries-brief-view.component'; import { LoansBriefViewComponent } from './record/brief-view/loans-brief-view/loans-brief-view.component'; +import { PatronTransactionEventDefaultComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-event-default.component'; +import { PatronTransactionEventOverdueComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-event-overdue.component'; +import { PatronTransactionEventsBriefViewComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-events-brief-view.component'; import { PatronTypesBriefViewComponent } from './record/brief-view/patron-types-brief-view.component'; import { PatronsBriefViewComponent } from './record/brief-view/patrons-brief-view/patrons-brief-view.component'; import { TemplatesBriefViewComponent } from './record/brief-view/templates-brief-view.component'; import { VendorBriefViewComponent } from './record/brief-view/vendor-brief-view.component'; +import { CirculationLogLoanComponent } from './record/circulation-logs/circulation-log/circulation-log-loan/circulation-log-loan.component'; +import { CirculationLogNotificationComponent } from './record/circulation-logs/circulation-log/circulation-log-notification/circulation-log-notification.component'; import { CirculationLogComponent } from './record/circulation-logs/circulation-log/circulation-log.component'; import { CirculationLogsDialogComponent } from './record/circulation-logs/circulation-logs-dialog.component'; import { CirculationLogsComponent } from './record/circulation-logs/circulation-logs.component'; @@ -150,18 +153,24 @@ import { LocalFieldComponent } from './record/detail-view/local-field/local-fiel import { LocationDetailViewComponent } from './record/detail-view/location-detail-view/location-detail-view.component'; import { OrganisationDetailViewComponent } from './record/detail-view/organisation-detail-view/organisation-detail-view.component'; import { PatronDetailViewComponent } from './record/detail-view/patron-detail-view/patron-detail-view.component'; +import { PatronPermissionComponent } from './record/detail-view/patron-detail-view/patron-permissions/patron-permission/patron-permission.component'; +import { PatronPermissionsComponent } from './record/detail-view/patron-detail-view/patron-permissions/patron-permissions.component'; import { PatronTypesDetailViewComponent } from './record/detail-view/patron-types-detail-view/patron-types-detail-view.component'; import { PermissionDetailViewComponent } from './record/detail-view/permission-detail-view/permission-detail-view.component'; import { RecordMaskedComponent } from './record/detail-view/record-masked/record-masked.component'; import { TemplateDetailViewComponent } from './record/detail-view/template-detail-view/template-detail-view.component'; import { VendorDetailViewComponent } from './record/detail-view/vendor-detail-view/vendor-detail-view.component'; -import { DocumentRecordSearchComponent } from './record/search-view/document-record-search/document-record-search.component'; import { IdentifiedbyValueComponent } from './record/editor/wrappers/identifiedby-value.component'; import { UserIdComponent } from './record/editor/wrappers/user-id/user-id.component'; import { CipoPatronTypeItemTypeComponent } from './record/formly/type/cipo-patron-type-item-type/cipo-patron-type-item-type.component'; import { ItemAvailabilityComponent } from './record/item-availability/item-availability.component'; import { OperationLogsDialogComponent } from './record/operation-logs/operation-logs-dialog/operation-logs-dialog.component'; import { OperationLogsComponent } from './record/operation-logs/operation-logs.component'; +import { DocumentRecordSearchComponent } from './record/search-view/document-record-search/document-record-search.component'; +import { PatronTransactionEventSearchViewComponent } from './record/search-view/patron-transaction-event-search-view/patron-transaction-event-search-view.component'; +import { PaymentsDataComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/payments-data.component'; +import { PaymentDataPieComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/pie/payment-data-pie.component'; +import { PaymentsDataTableComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/table/payments-data-table.component'; import { AppConfigService } from './service/app-config.service'; import { AppInitializerService } from './service/app-initializer.service'; import { OrganisationService } from './service/organisation.service'; @@ -170,17 +179,6 @@ import { UiRemoteTypeaheadService } from './service/ui-remote-typeahead.service' import { CurrentLibraryPermissionValidator } from './utils/permissions'; import { CustomShortcutHelpComponent } from './widgets/custom-shortcut-help/custom-shortcut-help.component'; import { FrontpageComponent } from './widgets/frontpage/frontpage.component'; -import { PatronTransactionEventsBriefViewComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-events-brief-view.component'; -import { PatronNamePipe } from './pipe/patron-name.pipe'; -import { PatronTransactionEventOverdueComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-event-overdue.component'; -import { PatronTransactionEventDefaultComponent } from './record/brief-view/patron-transaction-events-brief-view/patron-transaction-event-default.component'; -import { PatronTransactionEventSearchViewComponent } from './record/search-view/patron-transaction-event-search-view/patron-transaction-event-search-view.component'; -import { PaymentsDataTableComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/table/payments-data-table.component'; -import { PaymentDataPieComponent } from './record/search-view/patron-transaction-event-search-view/payments-data/pie/payment-data-pie.component'; -import { PatronPermissionsComponent } from './record/detail-view/patron-detail-view/patron-permissions/patron-permissions.component'; -import { PatronPermissionComponent } from './record/detail-view/patron-detail-view/patron-permissions/patron-permission/patron-permission.component'; -import { CirculationLogLoanComponent } from './record/circulation-logs/circulation-log/circulation-log-loan/circulation-log-loan.component'; -import { CirculationLogNotificationComponent } from './record/circulation-logs/circulation-log/circulation-log-notification/circulation-log-notification.component'; /** Init application factory */ export function appInitFactory(appInitializerService: AppInitializerService): () => Promise { @@ -370,8 +368,7 @@ export function appInitFactory(appInitializerService: AppInitializerService): () // Use the "multi" parameter to allow the recovery of several services in the injector. { provide: typeaheadToken, useExisting: DocumentsTypeahead, multi: true }, { provide: typeaheadToken, useExisting: ItemsTypeahead, multi: true }, - { provide: typeaheadToken, useExisting: MefOrganisationTypeahead, multi: true }, - { provide: typeaheadToken, useExisting: MefPersonTypeahead, multi: true }, + { provide: typeaheadToken, useExisting: MefTypeahead, multi: true }, { provide: typeaheadToken, useExisting: PatronsTypeahead, multi: true }, { provide: CoreConfigService, @@ -388,8 +385,7 @@ export function appInitFactory(appInitializerService: AppInitializerService): () ItemsTypeahead, PatronsTypeahead, MainTitlePipe, - MefPersonTypeahead, - MefOrganisationTypeahead, + MefTypeahead, TruncateTextPipe, CurrentLibraryPermissionValidator, ReceivedOrderPermissionValidator, diff --git a/projects/admin/src/app/circulation/item/item.component.html b/projects/admin/src/app/circulation/item/item.component.html index cde35c228..73eb44e1c 100644 --- a/projects/admin/src/app/circulation/item/item.component.html +++ b/projects/admin/src/app/circulation/item/item.component.html @@ -1,6 +1,6 @@
diff --git a/projects/admin/src/app/circulation/main-request/requested-item/requested-item.component.html b/projects/admin/src/app/circulation/main-request/requested-item/requested-item.component.html index 434172f2c..546421144 100644 --- a/projects/admin/src/app/circulation/main-request/requested-item/requested-item.component.html +++ b/projects/admin/src/app/circulation/main-request/requested-item/requested-item.component.html @@ -1,6 +1,6 @@
diff --git a/projects/admin/src/app/circulation/patron/pickup/pickup-item/pickup-item.component.html b/projects/admin/src/app/circulation/patron/pickup/pickup-item/pickup-item.component.html index f52e33da4..1ecbccd03 100644 --- a/projects/admin/src/app/circulation/patron/pickup/pickup-item/pickup-item.component.html +++ b/projects/admin/src/app/circulation/patron/pickup/pickup-item/pickup-item.component.html @@ -1,6 +1,6 @@ - +
  • {{ publication.value }}
  • diff --git a/projects/admin/src/app/record/detail-view/collection-detail-view/collection-items/collection-items.component.html b/projects/admin/src/app/record/detail-view/collection-detail-view/collection-items/collection-items.component.html index a33968def..b5cbd747f 100644 --- a/projects/admin/src/app/record/detail-view/collection-detail-view/collection-items/collection-items.component.html +++ b/projects/admin/src/app/record/detail-view/collection-detail-view/collection-items/collection-items.component.html @@ -1,6 +1,6 @@ - + {{ genre.entity.authorized_access_point }}
@@ -75,22 +72,11 @@

{{ altgr_title }}

- -
    -
  • - - - ; -
  • -
-
+ @@ -200,8 +186,8 @@

{{ altgr_title }}

- {{ subject._text }} + title="{{ subject.entity.type | translate }}"> + {{ subject.entity.authorized_access_point }}
diff --git a/projects/admin/src/app/routes/corporate-bodies-route.ts b/projects/admin/src/app/routes/corporate-bodies-route.ts index 5791e4e1b..eb3484a25 100644 --- a/projects/admin/src/app/routes/corporate-bodies-route.ts +++ b/projects/admin/src/app/routes/corporate-bodies-route.ts @@ -59,7 +59,7 @@ export class CorporateBodiesRoute extends BaseRoute implements RouteInterface { types: [ { key: 'corporate-bodies', - index: 'contributions', + index: 'entities', label: _('Organisation'), component: ContributionBriefComponent, detailComponent: ContributionDetailViewComponent, diff --git a/projects/admin/src/app/routes/import-documents-route.ts b/projects/admin/src/app/routes/import-documents-route.ts index 164faecb0..0eeac30c0 100644 --- a/projects/admin/src/app/routes/import-documents-route.ts +++ b/projects/admin/src/app/routes/import-documents-route.ts @@ -21,7 +21,6 @@ import { PERMISSIONS, PERMISSION_OPERATOR } from '@rero/shared'; import { Observable, of } from 'rxjs'; import { ImportSourceApiService } from '../api/import-source-api.service'; import { ExternalSourceSetting } from '../classes/external-source'; -import { CanAccessGuard, CAN_ACCESS_ACTIONS } from '../guard/can-access.guard'; import { PermissionGuard } from '../guard/permission.guard'; import { DocumentsBriefViewComponent } from '../record/brief-view/documents-brief-view/documents-brief-view.component'; import { DocumentDetailViewComponent } from '../record/detail-view/document-detail-view/document-detail-view.component'; diff --git a/projects/admin/src/app/routes/persons-route.ts b/projects/admin/src/app/routes/persons-route.ts index 5566005b2..1941f8bc9 100644 --- a/projects/admin/src/app/routes/persons-route.ts +++ b/projects/admin/src/app/routes/persons-route.ts @@ -59,7 +59,7 @@ export class PersonsRoute extends BaseRoute implements RouteInterface { types: [ { key: 'persons', - index: 'contributions', + index: 'entities', label: _('Persons'), component: ContributionBriefComponent, detailComponent: ContributionDetailViewComponent, diff --git a/projects/admin/src/app/service/ui-remote-typeahead.service.spec.ts b/projects/admin/src/app/service/ui-remote-typeahead.service.spec.ts index f37e82521..bf4c825cc 100644 --- a/projects/admin/src/app/service/ui-remote-typeahead.service.spec.ts +++ b/projects/admin/src/app/service/ui-remote-typeahead.service.spec.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2020 RERO + * Copyright (C) 2020-2023 RERO * * 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 @@ -22,8 +22,7 @@ import { RecordModule, TruncateTextPipe } from '@rero/ng-core'; import { MainTitlePipe, SharedModule } from '@rero/shared'; import { DocumentsTypeahead } from '../classes/typeahead/documents-typeahead'; import { ItemsTypeahead } from '../classes/typeahead/items-typeahead'; -import { MefOrganisationTypeahead } from '../classes/typeahead/mef-organisation-typeahead'; -import { MefPersonTypeahead } from '../classes/typeahead/mef-person-typeahead'; +import { MefTypeahead } from '../classes/typeahead/mef-typeahead'; import { PatronsTypeahead } from '../classes/typeahead/patrons-typeahead'; import { UiRemoteTypeaheadService } from './ui-remote-typeahead.service'; @@ -40,8 +39,7 @@ describe('UiRemoteTypeaheadService', () => { providers: [ DocumentsTypeahead, ItemsTypeahead, - MefPersonTypeahead, - MefOrganisationTypeahead, + MefTypeahead, PatronsTypeahead, TruncateTextPipe, MainTitlePipe diff --git a/projects/public-search/src/app/document-brief/document-brief.component.html b/projects/public-search/src/app/document-brief/document-brief.component.html index ca0412589..85dfec45f 100644 --- a/projects/public-search/src/app/document-brief/document-brief.component.html +++ b/projects/public-search/src/app/document-brief/document-brief.component.html @@ -1,6 +1,6 @@ - +
  • {{ publication.value }}
  • diff --git a/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.html b/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.html index 70faf0bb1..cab767924 100644 --- a/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.html +++ b/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.html @@ -1,6 +1,6 @@ diff --git a/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.ts b/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.ts index 50801c4be..66221fb77 100644 --- a/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.ts +++ b/projects/public-search/src/app/patron-profile/patron-profile-document/patron-profile-document.component.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2021 RERO + * Copyright (C) 2021-2023 RERO * * 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 @@ -40,10 +40,6 @@ export class PatronProfileDocumentComponent implements OnInit { get viewcode(): string { return this._patronProfileMenuService.currentPatron.organisation.code; } - /** Get current language */ - get language(): string { - return this._translateService.currentLang; - } /** Get the formatted call numbers for the related item */ get callNumbers(): string { @@ -53,19 +49,6 @@ export class PatronProfileDocumentComponent implements OnInit { ).filter(Boolean).join(' | '); } - /** - * Translate contribution type to parameter - * @param type - contribution type - * @returns string, contribution parameter - */ - getContributorLinkType(type: string): string { - switch (type) { - case 'bf:Person': return 'persons'; - case 'bf:Organisation': return 'corporate-bodies'; - default: return type; - } - } - // CONSTRUCTOR & HOOKS ====================================================== /** * Constructor diff --git a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.html b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.html index 3ecc6fd59..b2553a39f 100644 --- a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.html +++ b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.html @@ -24,19 +24,11 @@ {{ record.metadata.loan.item.document.title }} {{ record.metadata.loan.item.document.title }} - +
    diff --git a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.spec.ts b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.spec.ts index c7b513486..20770e732 100644 --- a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.spec.ts +++ b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.spec.ts @@ -19,7 +19,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { CoreModule, RecordModule } from '@rero/ng-core'; -import { ContributionFilterPipe, SharedModule, testUserPatronWithSettings, UserApiService, UserService } from '@rero/shared'; +import { SharedModule, testUserPatronWithSettings, UserApiService, UserService } from '@rero/shared'; import { cloneDeep } from 'lodash-es'; import { of } from 'rxjs'; import { PatronProfileMenuService } from '../../patron-profile-menu.service'; @@ -53,7 +53,6 @@ describe('PatronProfileHistoryComponent', () => { TestBed.configureTestingModule({ declarations: [ PatronProfileHistoryComponent, - ContributionFilterPipe ], imports: [ HttpClientTestingModule, diff --git a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.ts b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.ts index 1ed013e1b..588fa976b 100644 --- a/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.ts +++ b/projects/public-search/src/app/patron-profile/patron-profile-histories/patron-profile-history/patron-profile-history.component.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2021 RERO + * Copyright (C) 2021-2023 RERO * * 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 @@ -15,7 +15,6 @@ * along with this program. If not, see . */ import { Component, Input } from '@angular/core'; -import { TranslateService } from '@ngx-translate/core'; import { PatronProfileMenuService } from '../../patron-profile-menu.service'; @Component({ @@ -36,18 +35,11 @@ export class PatronProfileHistoryComponent { return this._patronProfileMenuService.currentPatron.organisation.code; } - /** Get current language */ - get language(): string { - return this._translateService.currentLang; - } - /** * Constructor - * @param _translateService - TranslateService * @param _patronProfileMenuService - PatronProfileMenuService */ constructor( - private _translateService: TranslateService, private _patronProfileMenuService: PatronProfileMenuService ) {} } diff --git a/projects/public-search/src/app/routes/documents-route.service.ts b/projects/public-search/src/app/routes/documents-route.service.ts index c8dacaadd..2b088aedc 100644 --- a/projects/public-search/src/app/routes/documents-route.service.ts +++ b/projects/public-search/src/app/routes/documents-route.service.ts @@ -176,7 +176,7 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt }, { key: 'persons', - index: 'contributions', + index: 'entities', component: ContributionBriefComponent, label: _('Persons'), aggregationsOrder: ['sources'], @@ -193,7 +193,7 @@ export class DocumentsRouteService extends BaseRoute implements ResourceRouteInt }, { key: 'corporate-bodies', - index: 'contributions', + index: 'entities', component: ContributionBriefComponent, label: _('Corporate bodies'), aggregationsOrder: ['sources'], diff --git a/projects/shared/src/lib/pipe/contribution-entity.pipe.spec.ts b/projects/shared/src/lib/pipe/contribution-entity.pipe.spec.ts new file mode 100644 index 000000000..e4cae0a77 --- /dev/null +++ b/projects/shared/src/lib/pipe/contribution-entity.pipe.spec.ts @@ -0,0 +1,155 @@ +/* + * RERO ILS UI + * Copyright (C) 2023 RERO + * + * 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 + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { TestBed } from '@angular/core/testing'; +import { TranslateModule, TranslateService } from '@ngx-translate/core'; +import { AppSettingsService } from '../service/app-settings.service'; +import { ContributionEntityPipe, EntityInterface } from './contribution-entity.pipe'; +import { cloneDeep } from 'lodash-es'; + +describe('ContributionEntityPipe', () => { + + let contributionEntityPipe: ContributionEntityPipe; + let translateService: TranslateService; + + const appSettingsServiceSpy = jasmine.createSpyObj('AppSettingsService', ['']); + appSettingsServiceSpy.settings = { + 'agentAgentTypes': { + 'bf:Person': 'persons', + 'bf:Organisation': 'corporate-bodies' + } + }; + + const contributions = [ + { + entity: { + authorized_access_point_de: 'Schweizerischer Fischereiverein', + authorized_access_point_en: 'Swiss Fishing Federation', + authorized_access_point_fr: 'Fédération suisse de pêche', + authorized_access_point_it: 'Federazione svizzera della pesca', + id_gnd: '1086038177', + id_idref: '184282624', + id_rero: 'A000153245', + pid: '4360604', + primary_source: 'idref', + type: 'bf:Organisation' + }, + role: ['ctb'] + }, + { + entity: { + authorized_access_point: 'Casas Ros, Antoni, 1972-', + authorized_access_point_de: 'Casas Ros, Antoni, 1972-', + authorized_access_point_en: 'Casas Ros, Antoni, 1972-', + authorized_access_point_fr: 'Casas Ros, Antoni, 1972-', + authorized_access_point_it: 'Casas Ros, Antoni, 1972-', + type: 'bf:Person' + }, + role: ['cre'] + } + ]; + + const contributions_result_en: EntityInterface = { + count: 2, + entries: [ + { + authorizedAccessPoint: 'Swiss Fishing Federation', + pid: '4360604', + type: 'bf:Organisation', + roles: ['contributor'], + target: 'corporate-bodies' + }, + { + authorizedAccessPoint: 'Casas Ros, Antoni, 1972-', + pid: undefined, + type: 'bf:Person', + roles: ['creator'], + target: 'persons' + } + ] + }; + + const contributions_result_fr: EntityInterface = { + count: 2, + entries: [ + { + authorizedAccessPoint: 'Fédération suisse de pêche', + pid: '4360604', + type: 'bf:Organisation', + roles: ['contributeur'], + target: 'corporate-bodies' + }, + { + authorizedAccessPoint: 'Casas Ros, Antoni, 1972-', + pid: undefined, + type: 'bf:Person', + roles: ['créateur'], + target: 'persons' + } + ] + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot() + ], + providers: [ + ContributionEntityPipe, + TranslateService, + { provide: AppSettingsService, useValue: appSettingsServiceSpy } + ] + }); + contributionEntityPipe = TestBed.inject(ContributionEntityPipe); + translateService = TestBed.inject(TranslateService); + translateService.setTranslation('fr', { + 'cre': 'créateur', + 'ctb': 'contributeur' + }); + translateService.setTranslation('en', { + 'cre': 'creator', + 'ctb': 'contributor' + }); + }); + + it('create an instance', () => { + expect(contributionEntityPipe).toBeTruthy(); + }); + + it('Should return 2 converted records (french)', () => { + translateService.use('fr'); + expect(contributionEntityPipe.transform(contributions)).toEqual(contributions_result_fr); + }); + + it('Should return 2 converted records (english)', () => { + translateService.use('en'); + expect(contributionEntityPipe.transform(contributions)).toEqual(contributions_result_en); + }); + + it('Should return 1 record converted with the Person filter (english)', () => { + translateService.use('en'); + const result = cloneDeep(contributions_result_en); + result.entries.splice(0, 1); + expect(contributionEntityPipe.transform(contributions, ['bf:Person'])).toEqual(result); + }); + + it('Should return 1 record converted with the limit parameter (english)', () => { + translateService.use('en'); + const result = cloneDeep(contributions_result_en); + result.entries.splice(1, 1); + expect(contributionEntityPipe.transform(contributions, ['bf:Person', 'bf:Organisation'], 1)).toEqual(result); + }); +}); diff --git a/projects/shared/src/lib/pipe/contribution-entity.pipe.ts b/projects/shared/src/lib/pipe/contribution-entity.pipe.ts new file mode 100644 index 000000000..24d889c87 --- /dev/null +++ b/projects/shared/src/lib/pipe/contribution-entity.pipe.ts @@ -0,0 +1,92 @@ +/* + * RERO ILS UI + * Copyright (C) 2023 RERO + * + * 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 + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { Pipe, PipeTransform } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; +import { AppSettingsService } from '../service/app-settings.service'; + +@Pipe({ + name: 'contributionEntity' +}) +export class ContributionEntityPipe implements PipeTransform { + + private _authorizedKey = 'authorized_access_point'; + /** + * Constructor + * @param _appSettingsService - AppSettingsService + * @param _translateService - TranslateService + */ + constructor( + private _appSettingsService: AppSettingsService, + private _translateService: TranslateService + ) {} + + transform( + contributions: any[], + filters: string[] = ['bf:Person', 'bf:Organisation'], + limit?: number + ): EntityInterface { + const result = { count: contributions.length, entries: []}; + contributions.filter(c => filters.includes(c.entity.type)).map(contrib => { + const newContrib = { + authorizedAccessPoint: this._authorizedAccessPoint(contrib.entity), + pid: contrib.entity?.pid, + type: contrib.entity.type, + roles: [], + target: this._target(contrib.entity.type), + }; + if (contrib.role != null) { + newContrib.roles = contrib.role.map( + (r: string) => this._translateService.instant(r)); + } + result.entries.push(newContrib); + }); + if (limit) { + result.entries = result.entries.slice(0, limit); + } + + return result; + } + + private _authorizedAccessPoint(entity: any): string { + if (entity.pid) { + // Mef + const key = `${this._authorizedKey}_${this._translateService.currentLang}`; + const fallbackKey = `${this._authorizedKey}_en`; + return (key in entity) ? entity[key] : entity[fallbackKey]; + } else { + // Local + return entity[this._authorizedKey] + } + } + + private _target(type: string): string | undefined { + const entityTypes = this._appSettingsService.settings.agentAgentTypes || {}; + + return (type in entityTypes) ? entityTypes[type] : undefined; + } +} + +export interface EntityInterface { + count: number, + entries: { + authorizedAccessPoint: string; + pid: string | undefined; + type: string; + roles: string[]; + target: string | undefined; + }[] +} diff --git a/projects/shared/src/lib/pipe/contribution-filter.pipe.spec.ts b/projects/shared/src/lib/pipe/contribution-filter.pipe.spec.ts deleted file mode 100644 index 04b29dfa6..000000000 --- a/projects/shared/src/lib/pipe/contribution-filter.pipe.spec.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2021-2023 RERO - * - * 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 - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { ContributionFilterPipe } from './contribution-filter.pipe'; - -describe('ContributionFilterPipe', () => { - const pipe = new ContributionFilterPipe(); - - const contributions = [ - { - agent: { - pid: 1, - type: 'bf:Person', - authorized_access_point_en: 'contribution EN', - authorized_access_point_fr: 'contribution FR' - }, - role: 'author' - }, - { - agent: { - preferred_name: 'Müller, Hans', - type: 'bf:Person' - }, - role: 'author' - } - ]; - - const contributionsResultsEn = [ - { - authorizedAccessPoint: 'contribution EN', - pid: 1, - type: 'bf:Person', - role: 'author', - target: 'persons' - }, - { - authorizedAccessPoint: 'Müller, Hans', - pid: undefined, - type: 'bf:Person', - role: 'author', - target: 'persons' - } - ]; - - const contributionsResultsFr = [ - { - authorizedAccessPoint: 'contribution FR', - pid: 1, - type: 'bf:Person', - role: 'author', - target: 'persons' - }, - { - authorizedAccessPoint: 'Müller, Hans', - pid: undefined, - type: 'bf:Person', - role: 'author', - target: 'persons' - } - ]; - - it('create an instance', () => { - expect(pipe).toBeTruthy(); - }); - - it('should extract the right contributor (default language)', () => { - expect(pipe.transform(contributions)).toEqual(contributionsResultsEn); - }); - - it('should extract the right contributor (language: french)', () => { - expect(pipe.transform(contributions, 'fr')).toEqual(contributionsResultsFr); - }); - - it('should extract the right contributor in english if language does not exists', () => { - expect(pipe.transform(contributions, 'de')).toEqual(contributionsResultsEn); - }); -}); diff --git a/projects/shared/src/lib/pipe/contribution-filter.pipe.ts b/projects/shared/src/lib/pipe/contribution-filter.pipe.ts deleted file mode 100644 index 782370a72..000000000 --- a/projects/shared/src/lib/pipe/contribution-filter.pipe.ts +++ /dev/null @@ -1,69 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2021-2023 RERO - * - * 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 - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { Pipe, PipeTransform } from '@angular/core'; - -@Pipe({ - name: 'contributionFilter' -}) -export class ContributionFilterPipe implements PipeTransform { - - /** - * Transform agent to extract access point for current language - * @param contributions - array of contributions (agent) - * @param language - current language interface - * @return array of contributions - */ - transform(contributions: any[], language: string = 'en'): any[] { - const output = []; - const key = `authorized_access_point_${language}`; - if (contributions) { - contributions.forEach(contribution => { - const agent = contribution.agent; - const accessPoint = !('pid' in agent) - ? agent.preferred_name - : (key in agent) - ? agent[key] - : agent.authorized_access_point_en; - output.push({ - authorizedAccessPoint: accessPoint, - pid: ('pid' in agent) ? agent.pid : undefined, - type: agent.type, - role: contribution.role, - target: this._linkTarget(agent.type) - }); - }); - } - return output; - } - - /** - * Link Target - * @param type - type of agent - * @return target name - */ - private _linkTarget(type: string): string { - switch (type) { - case 'bf:Person': - return 'persons'; - case 'bf:Organisation': - return 'corporate-bodies'; - default: - return undefined; - } - } - -} diff --git a/projects/shared/src/lib/pipe/contribution-format.pipe.spec.ts b/projects/shared/src/lib/pipe/contribution-format.pipe.spec.ts deleted file mode 100644 index 88637de19..000000000 --- a/projects/shared/src/lib/pipe/contribution-format.pipe.spec.ts +++ /dev/null @@ -1,178 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2020 RERO - * - * 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 - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -import { ContributionFormatPipe } from './contribution-format.pipe'; -import { TranslateModule, TranslateService } from '@ngx-translate/core'; -import { TestBed } from '@angular/core/testing'; - -const contributionPerson = { - agent: { - authorized_access_point_en: 'Köhler, Peter Thomas (en)', - authorized_access_point_fr: 'Köhler, Peter T (fr)', - pid: '12809924', - type: 'bf:Person' - }, - role: [ - 'cre' - ] -}; - -const contributionMultipleRolesPerson = { - agent: { - authorized_access_point_en: 'Köhler, Peter Thomas (en)', - authorized_access_point_fr: 'Köhler, Peter T (fr)', - pid: '12809924', - type: 'bf:Person' - }, - role: [ - 'cre', - 'con' - ] -}; - -const contributionPreferredPerson = { - agent: { - authorized_access_point_en: 'Köhler, Peter Thomas (en)', - authorized_access_point_fr: 'Köhler, Peter T (fr)', - preferred_name: 'Köhler, Peter T', - type: 'bf:Person' - }, - role: [ - 'cre' - ] -}; - -const contributionOrganisation = { - agent: { - authorized_access_point_en: 'Vita et Pax Foundation (en)', - authorized_access_point_fr: 'Vita et Pax Foundation (fr)', - type: 'bf:Organisation' - }, - role: [ - 'ctb' - ] -}; - -const contributionPreferredOrganisation = { - agent: { - preferred_name: 'Vita et Pax Foundation', - type: 'bf:Organisation' - }, - role: [ - 'ctb' - ] -}; - -describe('Pipe: ContributionFormate', () => { - - let contributionFormatPipe: ContributionFormatPipe; - - let translateService: TranslateService; - - beforeEach(() => { - TestBed.configureTestingModule({ - imports: [ - TranslateModule.forRoot() - ], - providers: [ - ContributionFormatPipe, - TranslateService - ] - }); - contributionFormatPipe = TestBed.inject(ContributionFormatPipe); - translateService = TestBed.inject(TranslateService); - }); - - it('create an instance', () => { - expect(contributionFormatPipe).toBeTruthy(); - }); - - /* ----- Person ----- */ - it('Pipe return the default value EN for person agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionPerson)) - .toBe('Köhler, Peter Thomas (en)'); - }); - - it('Pipe return the default value FR for person agent', () => { - translateService.currentLang = 'fr'; - expect(contributionFormatPipe.transform(contributionPerson)) - .toBe('Köhler, Peter T (fr)'); - }); - - it('Pipe return the fallback value FR for person agent', () => { - translateService.currentLang = 'de'; - expect(contributionFormatPipe.transform(contributionPerson)) - .toBe('Köhler, Peter T (fr)'); - }); - - it('Pipe return the value EN with role for person agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionPerson, true)) - .toBe('Köhler, Peter Thomas (en) (cre)'); - }); - - it('Pipe return the value EN with roles for person agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionMultipleRolesPerson, true)) - .toBe('Köhler, Peter Thomas (en) (cre, con)'); - }); - - it('Pipe return the value EN with fallback EN for person agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionPerson, false, 'en')) - .toBe('Köhler, Peter Thomas (en)'); - }); - - it('Pipe return the preferred value for person agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionPreferredPerson)) - .toBe('Köhler, Peter Thomas (en)'); - }); - - - /* ----- Organisation ----- */ - it('Pipe return the default value EN for organisation agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionOrganisation)) - .toBe('Vita et Pax Foundation (en)'); - }); - - it('Pipe return the default value FR for organisation agent', () => { - translateService.currentLang = 'fr'; - expect(contributionFormatPipe.transform(contributionOrganisation)) - .toBe('Vita et Pax Foundation (fr)'); - }); - - it('Pipe return the default value FR for organisation agent', () => { - translateService.currentLang = 'de'; - expect(contributionFormatPipe.transform(contributionOrganisation)) - .toBe('Vita et Pax Foundation (fr)'); - }); - - it('Pipe return the fallback value EN for organisation agent', () => { - translateService.currentLang = 'de'; - expect(contributionFormatPipe.transform(contributionOrganisation, false, 'en')) - .toBe('Vita et Pax Foundation (en)'); - }); - - it('Pipe return the preferred value for organisation agent', () => { - translateService.currentLang = 'en'; - expect(contributionFormatPipe.transform(contributionPreferredOrganisation)) - .toBe('Vita et Pax Foundation'); - }); -}); diff --git a/projects/shared/src/lib/pipe/contribution-format.pipe.ts b/projects/shared/src/lib/pipe/contribution-format.pipe.ts deleted file mode 100644 index 3ad2fb1f3..000000000 --- a/projects/shared/src/lib/pipe/contribution-format.pipe.ts +++ /dev/null @@ -1,87 +0,0 @@ -/* - * RERO ILS UI - * Copyright (C) 2020 RERO - * - * 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 - * the Free Software Foundation, version 3 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -import { Pipe, PipeTransform } from '@angular/core'; -import { TranslateService } from '@ngx-translate/core'; - -@Pipe({ - name: 'contributionFormat', - pure: false -}) -export class ContributionFormatPipe implements PipeTransform { - - /** field name prefix for access point */ - private accessPoint = 'authorized_access_point'; - - /** - * Constructor - * @param translate - TranslateService - */ - constructor(private _translate: TranslateService) {} - - /** - * @param contribution - Object - * @param withRole - Flag to add role(s) after agent - * @param fallbackLanguage - default language if the value isn't found - * @return string - */ - transform(contribution: any, withRole = false, fallbackLanguage = 'fr'): any { - let agent = null; - if (contribution.agent) { - agent = this._transformAgent(contribution.agent, fallbackLanguage); - if ('role' in contribution && withRole) { - agent += ' ' + this._transformRole(contribution.role); - } - } - return agent; - } - - /** - * Transform Person - * @param agent - Agent - * @param fallbackLanguage - Default language - * @return string - */ - private _transformAgent(agent: any, fallbackLanguage = null) { - let result = null; - const agentIndexName = `${this.accessPoint}_${this._translate.currentLang}`; - const agentfallback = `${this.accessPoint}_${fallbackLanguage}`; - if (agentIndexName in agent) { - result = agent[agentIndexName]; - } else if (agentfallback in agent) { - result = agent[agentfallback]; - } else if ('preferred_name' in agent) { - result = agent.preferred_name; - } - return result; - } - - /** - * Transform Role - * @param agentRole - Agent role(s) - * @return string - */ - private _transformRole(agentRole: any) { - const roles = []; - agentRole.map((role: string) => { - roles.push(this._translate.instant(role)); - }); - if (roles.length > 0) { - return `(${roles.join(', ')})`; - } - return null; - } -} diff --git a/projects/shared/src/lib/pipe/contribution-type.pipe.ts b/projects/shared/src/lib/pipe/contribution-type.pipe.ts index e8f88f8d3..f94386544 100644 --- a/projects/shared/src/lib/pipe/contribution-type.pipe.ts +++ b/projects/shared/src/lib/pipe/contribution-type.pipe.ts @@ -36,7 +36,7 @@ export class ContributionTypePipe implements PipeTransform { * @throws Error on missing type */ transform(type: string): any { - const configType = this._appSettingsService.contributionAgentTypes[type]; + const configType = this._appSettingsService.agentAgentTypes[type]; if (configType) { return configType; } diff --git a/projects/shared/src/lib/pipe/extract-source-field.pipe.ts b/projects/shared/src/lib/pipe/extract-source-field.pipe.ts index 34521fcd4..a42eed2d9 100644 --- a/projects/shared/src/lib/pipe/extract-source-field.pipe.ts +++ b/projects/shared/src/lib/pipe/extract-source-field.pipe.ts @@ -42,12 +42,12 @@ export class ExtractSourceFieldPipe implements PipeTransform { * @return string or null */ transform(metadata: any, field: string): string | null { - const contributionsLabel: any = this._appSettingsService.contributionsLabelOrder; + const contributionsLabel: any = this._appSettingsService.agentLabelOrder; const language = this._translateService.currentLang; - const contributionsLabelOrder = (language in contributionsLabel) + const agentLabelOrder = (language in contributionsLabel) ? contributionsLabel[language] : contributionsLabel[contributionsLabel.fallback]; - for (const source of contributionsLabelOrder) { + for (const source of agentLabelOrder) { if ( metadata.hasOwnProperty(source) && metadata[source].hasOwnProperty(field) diff --git a/projects/shared/src/lib/pipe/url-active.pipe.ts b/projects/shared/src/lib/pipe/url-active.pipe.ts index af95237ce..2c6b6834f 100644 --- a/projects/shared/src/lib/pipe/url-active.pipe.ts +++ b/projects/shared/src/lib/pipe/url-active.pipe.ts @@ -23,13 +23,13 @@ import { Pipe, PipeTransform } from '@angular/core'; export class UrlActivePipe implements PipeTransform { transform(text: string, target: string = '_self'): any { - let output = ''; + let output = text; const re = new RegExp(/(https?:\/\/[\w|.|\-|\/]+)/, 'gm'); let match: RegExpExecArray; // tslint:disable-next-line: no-conditional-assignment while ((match = re.exec(text)) !== null) { const url = match[0]; - output += text.replace(url, `${url}`); + output = output.replace(url, `${url}`); } return output; } diff --git a/projects/shared/src/lib/service/app-settings.service.spec.ts b/projects/shared/src/lib/service/app-settings.service.spec.ts index a89e68646..7e23db040 100644 --- a/projects/shared/src/lib/service/app-settings.service.spec.ts +++ b/projects/shared/src/lib/service/app-settings.service.spec.ts @@ -50,17 +50,17 @@ describe('ApplicationSettingsService', () => { it('should return the parameter contribution sources', () => { service.settings = settings; - expect(service.contributionSources).toEqual(settings.contributionSources); + expect(service.agentSources).toEqual(settings.agentSources); }); it('should return the parameter contributions agent types', () => { service.settings = settings; - expect(service.contributionAgentTypes).toEqual(settings.contributionAgentTypes); + expect(service.agentAgentTypes).toEqual(settings.agentAgentTypes); }); it('should return the parameter contributions label order', () => { service.settings = settings; - expect(service.contributionsLabelOrder).toEqual(settings.contributionsLabelOrder); + expect(service.agentLabelOrder).toEqual(settings.agentLabelOrder); }); it('should return the parameter global view', () => { diff --git a/projects/shared/src/lib/service/app-settings.service.ts b/projects/shared/src/lib/service/app-settings.service.ts index 803f2faa7..6633124d4 100644 --- a/projects/shared/src/lib/service/app-settings.service.ts +++ b/projects/shared/src/lib/service/app-settings.service.ts @@ -71,27 +71,27 @@ export class AppSettingsService { * Get contribution sources * @return array of string */ - get contributionSources(): string[] { + get agentSources(): string[] { this._checkSettings(); - return this._settings.contributionSources; + return this._settings.agentSources; } /** * Get contribution agent types * @return any */ - get contributionAgentTypes(): any { + get agentAgentTypes(): any { this._checkSettings(); - return this._settings.contributionAgentTypes; + return this._settings.agentAgentTypes; } /** * Get contribution order * @return array of order with fallback */ - get contributionsLabelOrder(): any { + get agentLabelOrder(): any { this._checkSettings(); - return this._settings.contributionsLabelOrder; + return this._settings.agentLabelOrder; } /** @@ -135,9 +135,9 @@ export class AppSettingsService { /** Interface for settings */ export interface ISettings { baseUrl: string; - contributionSources: string[]; - contributionAgentTypes: any; - contributionsLabelOrder: any; + agentSources: string[]; + agentAgentTypes: any; + agentLabelOrder: any; globalView: string; language: string; operationLogs: any; diff --git a/projects/shared/src/lib/service/search-bar-config.service.ts b/projects/shared/src/lib/service/search-bar-config.service.ts index aa70f69b5..371b7df27 100644 --- a/projects/shared/src/lib/service/search-bar-config.service.ts +++ b/projects/shared/src/lib/service/search-bar-config.service.ts @@ -76,7 +76,7 @@ export class SearchBarConfigService { this._maxLengthSuggestion = maxLengthSuggestion; // If you add a new type, please specify it in the "shared-config.service.ts" - // file on contributionAgentTypes attribute + // file on agentAgentTypes attribute return [ { type: 'documents', @@ -87,7 +87,7 @@ export class SearchBarConfigService { }, { type: 'persons', - index: 'contributions', + index: 'entities', field: 'autocomplete_name', maxNumberOfSuggestions: 5, getSuggestions: (query: any, persons: any) => this._getPersonsSuggestions(query, persons), @@ -96,7 +96,7 @@ export class SearchBarConfigService { }, { type: 'organisations', - index: 'contributions', + index: 'entities', field: 'autocomplete_name', maxNumberOfSuggestions: 5, getSuggestions: (query: any, organisations: any) => this._getOrganisationsSuggestions(query, organisations), @@ -187,7 +187,7 @@ export class SearchBarConfigService { values.push({ text: this._highlightSearch(text, query), query: '', - index: 'contributions', + index: 'entities', category, href: this._generateContributionLink(urlIndex, hit.metadata.pid), iconCssClass: `fa fa-${icon}` @@ -239,13 +239,13 @@ export class SearchBarConfigService { */ private _getContributionName(metadata: any): string { const language = this._translateService.currentLang; - const order: any = this._appSettingsService.contributionsLabelOrder; + const order: any = this._appSettingsService.agentLabelOrder; const key = (language in order) ? language : 'fallback'; - const contributionSources = (key === 'fallback') + const agentSources = (key === 'fallback') ? order[order[key]] : order[key]; - for (const source of contributionSources) { + for (const source of agentSources) { if (metadata[source] && metadata[source].authorized_access_point) { return metadata[source].authorized_access_point; } diff --git a/projects/shared/src/lib/shared.module.ts b/projects/shared/src/lib/shared.module.ts index 4ea4455ac..790b7cb94 100644 --- a/projects/shared/src/lib/shared.module.ts +++ b/projects/shared/src/lib/shared.module.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2020 RERO + * Copyright (C) 2020-2023 RERO * * 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 @@ -22,11 +22,14 @@ import { CoreModule, NgVarDirective, Nl2brPipe, RecordModule, TruncateTextPipe } import { PopoverModule } from 'ngx-bootstrap/popover'; import { TooltipModule } from 'ngx-bootstrap/tooltip'; import { ActionButtonComponent } from './component/action-button/action-button.component'; +import { LinkPermissionsDirective } from './directive/link-permissions.directive'; +import { PermissionsDirective } from './directive/permissions.directive'; import { PrimeNgImportModule } from './modules/prime-ng-import/prime-ng-import.module'; import { ShowMorePagerComponent } from './paginator/show-more-pager/show-more-pager.component'; -import { ContributionFormatPipe } from './pipe/contribution-format.pipe'; +import { ContributionEntityPipe } from './pipe/contribution-entity.pipe'; import { ContributionTypePipe } from './pipe/contribution-type.pipe'; import { ExtractSourceFieldPipe } from './pipe/extract-source-field.pipe'; +import { GetTranslatedLabelPipe } from './pipe/get-translated-label.pipe'; import { IdAttributePipe } from './pipe/id-attribute.pipe'; import { ItemHoldingsCallNumberPipe } from './pipe/item-holdings-call-number.pipe'; import { JoinPipe } from './pipe/join.pipe'; @@ -43,12 +46,9 @@ import { ContributionSourcesComponent } from './view/brief/contribution-sources/ import { OrganisationBriefComponent } from './view/brief/organisation-brief/organisation-brief.component'; import { PartOfComponent } from './view/brief/part-of/part-of.component'; import { PersonBriefComponent } from './view/brief/person-brief/person-brief.component'; +import { ContributionComponent } from './view/contribution/contribution.component'; import { InheritedCallNumberComponent } from './view/inherited-call-number/inherited-call-number.component'; import { ThumbnailComponent } from './view/thumbnail/thumbnail.component'; -import { GetTranslatedLabelPipe } from './pipe/get-translated-label.pipe'; -import { ContributionFilterPipe } from './pipe/contribution-filter.pipe'; -import { PermissionsDirective } from './directive/permissions.directive'; -import { LinkPermissionsDirective } from './directive/link-permissions.directive'; @NgModule({ declarations: [ @@ -56,7 +56,6 @@ import { LinkPermissionsDirective } from './directive/link-permissions.directive ContributionSourcesComponent, OrganisationBriefComponent, PersonBriefComponent, - ContributionFormatPipe, ExtractSourceFieldPipe, IdAttributePipe, JoinPipe, @@ -72,12 +71,13 @@ import { LinkPermissionsDirective } from './directive/link-permissions.directive ShowMorePagerComponent, KeyExistsPipe, GetTranslatedLabelPipe, - ContributionFilterPipe, ActionButtonComponent, NotesFilterPipe, SafeUrlPipe, PermissionsDirective, - LinkPermissionsDirective + LinkPermissionsDirective, + ContributionEntityPipe, + ContributionComponent, ], exports: [ CommonModule, @@ -86,7 +86,6 @@ import { LinkPermissionsDirective } from './directive/link-permissions.directive ContributionSourcesComponent, OrganisationBriefComponent, PersonBriefComponent, - ContributionFormatPipe, ExtractSourceFieldPipe, IdAttributePipe, JoinPipe, @@ -103,12 +102,13 @@ import { LinkPermissionsDirective } from './directive/link-permissions.directive ShowMorePagerComponent, KeyExistsPipe, GetTranslatedLabelPipe, - ContributionFilterPipe, ActionButtonComponent, NotesFilterPipe, SafeUrlPipe, PermissionsDirective, - LinkPermissionsDirective + LinkPermissionsDirective, + ContributionEntityPipe, + ContributionComponent ], imports: [ CommonModule, @@ -129,7 +129,8 @@ import { LinkPermissionsDirective } from './directive/link-permissions.directive Nl2brPipe, NgVarDirective, KeyExistsPipe, - NotesFilterPipe + NotesFilterPipe, + ContributionEntityPipe ], schemas: [ NO_ERRORS_SCHEMA diff --git a/projects/shared/src/lib/view/brief/organisation-brief/organisation-brief.component.ts b/projects/shared/src/lib/view/brief/organisation-brief/organisation-brief.component.ts index 70e09852a..fe3305e5c 100644 --- a/projects/shared/src/lib/view/brief/organisation-brief/organisation-brief.component.ts +++ b/projects/shared/src/lib/view/brief/organisation-brief/organisation-brief.component.ts @@ -44,7 +44,7 @@ export class OrganisationBriefComponent implements ResultItem { */ contributionType(detailUrlLink: string) { return detailUrlLink.replace( - 'contributions', + 'entities', this._contributionTypePipe.transform(this.record.metadata.type) ); } diff --git a/projects/shared/src/lib/view/brief/person-brief/person-brief.component.ts b/projects/shared/src/lib/view/brief/person-brief/person-brief.component.ts index 64589761e..017bef2ad 100644 --- a/projects/shared/src/lib/view/brief/person-brief/person-brief.component.ts +++ b/projects/shared/src/lib/view/brief/person-brief/person-brief.component.ts @@ -47,7 +47,7 @@ export class PersonBriefComponent implements ResultItem { */ contributionType(detailUrlLink: string) { return detailUrlLink.replace( - 'contributions', + 'entities', this._contributionTypePipe.transform(this.record.metadata.type) ); } diff --git a/projects/shared/src/lib/view/contribution/contribution.component.html b/projects/shared/src/lib/view/contribution/contribution.component.html new file mode 100644 index 000000000..5525ea882 --- /dev/null +++ b/projects/shared/src/lib/view/contribution/contribution.component.html @@ -0,0 +1,42 @@ + + diff --git a/projects/shared/src/lib/view/contribution/contribution.component.ts b/projects/shared/src/lib/view/contribution/contribution.component.ts new file mode 100644 index 000000000..3160ed362 --- /dev/null +++ b/projects/shared/src/lib/view/contribution/contribution.component.ts @@ -0,0 +1,34 @@ +/* + * RERO ILS UI + * Copyright (C) 2023 RERO + * + * 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 + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'shared-contribution', + templateUrl: './contribution.component.html' +}) +export class ContributionComponent { + + @Input() contributions: any[]; + + @Input() filters: string[] = ['bf:Person', 'bf:Organisation'] + + @Input() limitRecord: number | undefined; + + @Input() withRoles: boolean = false; + + @Input() view: string | undefined; +} diff --git a/projects/shared/src/public-api.ts b/projects/shared/src/public-api.ts index 166a6eb5d..8371ab669 100644 --- a/projects/shared/src/public-api.ts +++ b/projects/shared/src/public-api.ts @@ -1,6 +1,6 @@ /* * RERO ILS UI - * Copyright (C) 2020-2022 RERO + * Copyright (C) 2020-2023 RERO * * 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 @@ -21,19 +21,17 @@ export * from './lib/api/base-api'; export * from './lib/api/user-api.service'; -export * from './lib/modules/prime-ng-import/prime-ng-import.module'; export * from './lib/class/core'; export * from './lib/class/holdings'; export * from './lib/class/item-status'; export * from './lib/class/user'; export * from './lib/component/action-button/action-button.component'; -export * from './lib/modules/prime-ng-import/prime-ng-import.module'; export * from './lib/directive/link-permissions.directive'; export * from './lib/directive/permissions.directive'; +export * from './lib/modules/prime-ng-import/prime-ng-import.module'; export * from './lib/paginator/paginator'; export * from './lib/paginator/show-more-pager/show-more-pager.component'; -export * from './lib/pipe/contribution-filter.pipe'; -export * from './lib/pipe/contribution-format.pipe'; +export * from './lib/pipe/contribution-entity.pipe'; export * from './lib/pipe/contribution-type.pipe'; export * from './lib/pipe/extract-source-field.pipe'; export * from './lib/pipe/get-translated-label.pipe'; @@ -58,7 +56,7 @@ export * from './lib/view/brief/contribution-sources/contribution-sources.compon export * from './lib/view/brief/organisation-brief/organisation-brief.component'; export * from './lib/view/brief/part-of/part-of.component'; export * from './lib/view/brief/person-brief/person-brief.component'; +export * from './lib/view/contribution/contribution.component'; export * from './lib/view/inherited-call-number/inherited-call-number.component'; export * from './lib/view/thumbnail/thumbnail.component'; export * from './tests/user'; - diff --git a/projects/shared/src/tests/user.ts b/projects/shared/src/tests/user.ts index 08c97adec..e7b0c4ac7 100644 --- a/projects/shared/src/tests/user.ts +++ b/projects/shared/src/tests/user.ts @@ -152,16 +152,16 @@ export const testUserPatronWithSettings = { ], settings: { baseUrl: 'https://bib.rero.ch', - contributionSources: [ + agentSources: [ 'idref', 'gnd', 'rero' ], - contributionAgentTypes: { + agentAgentTypes: { 'bf:Person': 'persons', 'bf:Organisation': 'corporate-bodies' }, - contributionsLabelOrder: { + agentLabelOrder: { de: [ 'gnd', 'idref', @@ -365,16 +365,16 @@ export const testUserPatronMultipleOrganisationsWithSettings = { ], settings: { baseUrl: 'https://bib.rero.ch', - contributionSources: [ + agentSources: [ 'idref', 'gnd', 'rero' ], - contributionAgentTypes: { + agentAgentTypes: { 'bf:Person': 'persons', 'bf:Organisation': 'corporate-bodies' }, - contributionsLabelOrder: { + agentLabelOrder: { de: [ 'gnd', 'idref', @@ -457,16 +457,16 @@ export const testUserLibrarianWithSettings = { ], settings: { baseUrl: 'https://bib.rero.ch', - contributionSources: [ + agentSources: [ 'idref', 'gnd', 'rero' ], - contributionAgentTypes: { + agentAgentTypes: { 'bf:Person': 'persons', 'bf:Organisation': 'corporate-bodies' }, - contributionsLabelOrder: { + agentLabelOrder: { de: [ 'gnd', 'idref',