From be06a09c32cdb0d5953463f4f32b658c3537404f Mon Sep 17 00:00:00 2001 From: Nathan Python Date: Mon, 6 Oct 2025 14:43:39 +0200 Subject: [PATCH] feat: change any by other types Co-Authored-by: Nathan Python this.processDate(date)); + this.disabledDates = this.props.disabledDates.map((date: string | Date) =>this.processDate(date)); } if (this.props.minDate) { this.minDate = this.processDate(this.props.minDate); @@ -156,7 +156,7 @@ export class DatePickerComponent extends FieldType { + this.subscription.add(this.value.subscribe((value: string | Date) => { if (value) { const convertedDate = this.outputDate(value); if (convertedDate !== this.formControl.value) { diff --git a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox.ts b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox.ts index eb6057c3b..9abaeae74 100644 --- a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox.ts +++ b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-checkbox/multi-checkbox.ts @@ -24,6 +24,8 @@ import { CheckboxChangeEvent, CheckboxModule } from 'primeng/checkbox'; import { map, merge, Observable, Subscription, switchMap } from 'rxjs'; import { TranslateLabelService } from '../services/translate-label.service'; +/* eslint-disable @typescript-eslint/no-explicit-any */ + export interface IMultiCheckBoxProps extends FormlyFieldProps { labelStyleClass?: string; style: 'stacked' | 'inline'; diff --git a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-select/multi-select.ts b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-select/multi-select.ts index b3ca7db42..ba70c248a 100644 --- a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-select/multi-select.ts +++ b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/multi-select/multi-select.ts @@ -22,11 +22,13 @@ import { FormlyFieldSelectProps, FormlySelectModule } from '@ngx-formly/core/sel import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { MultiSelectModule as PrimeNgMultiSelectModule } from 'primeng/multiselect'; import { map, merge, Observable, Subscription, switchMap, tap } from 'rxjs'; -import { TranslateLabelService } from '../services/translate-label.service'; import { CONFIG } from '../../../../../utils/config'; +import { TranslateLabelService } from '../services/translate-label.service'; + +/* eslint-disable @typescript-eslint/no-explicit-any */ export interface IMultiSelectProps extends FormlyFieldProps, FormlyFieldSelectProps { - appendTo?: any; + appendTo?: string; class?: string; display: string; dropdownIcon?: string; diff --git a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/services/translate-label.service.ts b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/services/translate-label.service.ts index 971d68bfa..f21f44933 100644 --- a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/services/translate-label.service.ts +++ b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/services/translate-label.service.ts @@ -17,6 +17,8 @@ import { inject, Injectable } from "@angular/core"; import { TranslateService } from "@ngx-translate/core"; +/* eslint-disable @typescript-eslint/no-explicit-any */ + @Injectable({ providedIn: 'root' }) diff --git a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/tree-select/tree-select.ts b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/tree-select/tree-select.ts index 428983e1c..b1604e604 100644 --- a/projects/rero/ng-core/src/lib/record/editor/formly/primeng/tree-select/tree-select.ts +++ b/projects/rero/ng-core/src/lib/record/editor/formly/primeng/tree-select/tree-select.ts @@ -24,9 +24,10 @@ import { TreeNode } from 'primeng/api'; import { TreeNodeSelectEvent } from 'primeng/tree'; import { TreeSelectModule } from 'primeng/treeselect'; import { map, merge, Observable, Subscription, switchMap, tap } from 'rxjs'; -import { TranslateLabelService } from '../services/translate-label.service'; import { CONFIG } from '../../../../../utils/config'; +import { TranslateLabelService } from '../services/translate-label.service'; +/* eslint-disable @typescript-eslint/no-explicit-any */ // Doc https://primeng.org/treeselect export interface ITreeSelectProps extends FormlyFieldProps { @@ -103,7 +104,7 @@ export class TreeSelectComponent extends FieldType; diff --git a/projects/rero/ng-core/src/lib/record/editor/services/templates.service.spec.ts b/projects/rero/ng-core/src/lib/record/editor/services/templates.service.spec.ts index 5814e44d2..d60773309 100644 --- a/projects/rero/ng-core/src/lib/record/editor/services/templates.service.spec.ts +++ b/projects/rero/ng-core/src/lib/record/editor/services/templates.service.spec.ts @@ -17,10 +17,11 @@ import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; import { TestBed } from '@angular/core/testing'; import { TranslateModule } from '@ngx-translate/core'; -import { TemplatesService } from './templates.service'; import { of } from 'rxjs'; import { RecordService } from '../../record.service'; +import { TemplatesService } from './templates.service'; +/* eslint-disable @typescript-eslint/no-explicit-any */ describe('TemplatesService', () => { let service: TemplatesService; diff --git a/projects/rero/ng-core/src/lib/record/editor/type/array-type/array-type.component.ts b/projects/rero/ng-core/src/lib/record/editor/type/array-type/array-type.component.ts index 384ba0e18..25c923561 100644 --- a/projects/rero/ng-core/src/lib/record/editor/type/array-type/array-type.component.ts +++ b/projects/rero/ng-core/src/lib/record/editor/type/array-type/array-type.component.ts @@ -17,6 +17,7 @@ import { Component, OnInit } from '@angular/core'; import { FieldArrayType, FormlyFieldConfig } from '@ngx-formly/core'; +/* eslint-disable @typescript-eslint/no-explicit-any */ /** * Component for displaying array fields in editor. */ diff --git a/projects/rero/ng-core/src/lib/record/editor/type/textarea/textarea.component.ts b/projects/rero/ng-core/src/lib/record/editor/type/textarea/textarea.component.ts index 88c6789c3..051e19bd5 100644 --- a/projects/rero/ng-core/src/lib/record/editor/type/textarea/textarea.component.ts +++ b/projects/rero/ng-core/src/lib/record/editor/type/textarea/textarea.component.ts @@ -19,6 +19,7 @@ import { AbstractControl, ValidatorFn } from '@angular/forms'; import { FieldType, FormlyFieldConfig } from '@ngx-formly/core'; import { FormlyFieldProps } from '@ngx-formly/primeng/form-field'; +/* eslint-disable @typescript-eslint/no-explicit-any */ interface ExtraTextAreaProps extends FormlyFieldProps { displayChars: boolean; displayWords: boolean; diff --git a/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts b/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts index a650de51d..96d86eb83 100644 --- a/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts +++ b/projects/rero/ng-core/src/lib/record/editor/widgets/label/label.component.ts @@ -20,6 +20,8 @@ import { TranslateService } from '@ngx-translate/core'; import { MenuItem } from 'primeng/api'; import { merge, Subscription } from 'rxjs'; +/* eslint-disable @typescript-eslint/no-explicit-any */ + @Component({ selector: 'ng-core-label-editor', templateUrl: './label.component.html', diff --git a/projects/rero/ng-core/src/lib/record/record.service.spec.ts b/projects/rero/ng-core/src/lib/record/record.service.spec.ts index 65a6b9cb4..55e0aabb6 100644 --- a/projects/rero/ng-core/src/lib/record/record.service.spec.ts +++ b/projects/rero/ng-core/src/lib/record/record.service.spec.ts @@ -14,6 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; import { getTestBed, TestBed } from '@angular/core/testing'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; @@ -21,7 +22,8 @@ import { ApiService } from '../api/api.service'; import { Error } from '../error/error'; import { Record } from './record'; import { RecordService } from './record.service'; -import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; + +/* eslint-disable @typescript-eslint/no-explicit-any */ describe('RecordService', () => { const url = 'https://localhost:5000/api/documents'; @@ -65,13 +67,13 @@ describe('RecordService', () => { const expectedData: Record = { aggregations: {}, hits: { - total: 2 + total: { value: 2, relation: 'eq' } }, links: {} }; service.getRecords('documents', '', 1, 10, [{ key: 'author', values: ['John doe'] }]).subscribe((data: Record) => { - expect(service.totalHits(data.hits.total)).toBe(2); + expect(data.hits.total.value).toBe(2); }); const req = httpMock.expectOne(request => request.method === 'GET' && request.url === url + '/'); diff --git a/projects/rero/ng-core/src/lib/record/record.service.ts b/projects/rero/ng-core/src/lib/record/record.service.ts index 57dc43249..31c397e8e 100644 --- a/projects/rero/ng-core/src/lib/record/record.service.ts +++ b/projects/rero/ng-core/src/lib/record/record.service.ts @@ -18,10 +18,11 @@ import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular import { inject, Injectable } from '@angular/core'; import { FormlyFieldConfig } from '@ngx-formly/core'; import { TranslateService } from '@ngx-translate/core'; -import { Observable, Subject, of } from 'rxjs'; +import { Observable, of, Subject } from 'rxjs'; import { catchError, debounceTime, map, tap } from 'rxjs/operators'; import { ApiService } from '../api/api.service'; import { Error } from '../error/error'; +import { EsResult, InvenioRecord } from '../types'; import { resolveRefs } from './editor/utils'; import { Record } from './record'; import { RecordHandleErrorService } from './record.handle-error.service'; @@ -103,7 +104,7 @@ export class RecordService { headers: any = null, sort: string = null, facets: string[] = [] - ): Observable { + ): Observable { // Build query string let httpParams = new HttpParams().set('q', query); httpParams = httpParams.append('page', '' + page); @@ -168,10 +169,10 @@ export class RecordService { type: string, pid: string, resolve = 0, - headers: any = {} - ): Observable { + headers = {} + ): Observable { return this.http - .get( + .get( `${this.apiService.getEndpointByType( type, true @@ -254,7 +255,7 @@ export class RecordService { query += ` NOT pid:${excludePid}`; } return this.getRecords(recordType, query, 1, 1).pipe( - map((res: Record) => this.totalHits(res.hits.total)), + map((res: EsResult) => res.hits.total.value), map((total) => (total ? { alreadyTaken: value } : null)), debounceTime(1000) ); @@ -304,37 +305,12 @@ export class RecordService { query += ` NOT pid:${excludePid}`; } return this.getRecords(recordType, query, 1, 1).pipe( - map((res: Record) => this.totalHits(res.hits.total)), + map((res: EsResult) => res.hits.total.value), map((total) => (total ? { alreadyTaken: value } : null)), debounceTime(500) ); } - /** - * Transform a total value string or object representation - * (ES compatibility v6 and v7) - * @param total - string or object - * @param relation - boolean - * @return integer, text or null - */ - totalHits(total: any, relation = false): any { - switch (typeof total) { - case 'object': - if (relation) { - return `${this.translateService.instant( - total.relation - )} ${total.value.toString()}`; - } - return Number(total.value); - case 'number': - return total; - case 'string': - return Number(total); - default: - return null; - } - } - /** * Return the suggestions for query and field. * diff --git a/projects/rero/ng-core/src/lib/record/search/aggregation/buckets/buckets.component.ts b/projects/rero/ng-core/src/lib/record/search/aggregation/buckets/buckets.component.ts index 53964b032..9aee1c816 100644 --- a/projects/rero/ng-core/src/lib/record/search/aggregation/buckets/buckets.component.ts +++ b/projects/rero/ng-core/src/lib/record/search/aggregation/buckets/buckets.component.ts @@ -16,7 +16,8 @@ */ import { Component, OnChanges, OnDestroy, OnInit, SimpleChanges, inject, input } from '@angular/core'; import { Subscription } from 'rxjs'; -import { AggregationsFilter, RecordSearchService } from '../../record-search.service'; +import { AggregationsFilter } from '../../../../types'; +import { RecordSearchService } from '../../record-search.service'; @Component({ selector: 'ng-core-record-search-aggregation-buckets', diff --git a/projects/rero/ng-core/src/lib/record/search/record-search.component.spec.ts b/projects/rero/ng-core/src/lib/record/search/record-search.component.spec.ts index a91584443..575cca087 100644 --- a/projects/rero/ng-core/src/lib/record/search/record-search.component.spec.ts +++ b/projects/rero/ng-core/src/lib/record/search/record-search.component.spec.ts @@ -20,6 +20,8 @@ import { FormsModule } from '@angular/forms'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ActivatedRoute, convertToParamMap, Router } from '@angular/router'; import { TranslateFakeLoader, TranslateLoader, TranslateModule } from '@ngx-translate/core'; +import { ConfirmationService } from 'primeng/api'; +import { ButtonModule } from 'primeng/button'; import { Observable, of } from 'rxjs'; import { DialogComponent } from '../../dialog/dialog.component'; import { DefaultPipe } from '../../pipe/default.pipe'; @@ -34,8 +36,6 @@ import { RecordSearchAggregationComponent } from './aggregation/aggregation.comp import { RecordSearchComponent } from './record-search.component'; import { RecordSearchService } from './record-search.service'; import { RecordSearchResultComponent } from './result/record-search-result.component'; -import { ConfirmationService } from 'primeng/api'; -import { ButtonModule } from 'primeng/button'; const adminMode = (): Observable => { return of({ @@ -48,7 +48,7 @@ const adminMode = (): Observable => { describe('RecordSearchComponent', () => { let component: RecordSearchComponent; let fixture: ComponentFixture; - + const record = { created: '', id: '100', links: {}, metadata: {}, updated: '' }; const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'parseUrl']); routerSpy.parseUrl.and.returnValue({ root: { @@ -74,10 +74,10 @@ describe('RecordSearchComponent', () => { links: {} }; - const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecords', 'delete', 'totalHits']); + const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecords', 'delete']); recordServiceSpy.getRecords.and.returnValue(of(emptyRecords)); recordServiceSpy.delete.and.returnValue(of({})); - recordServiceSpy.totalHits.and.returnValue(10); + const recordUiServiceSpy = jasmine.createSpyObj('RecordUiService', [ 'getResourceConfig', @@ -244,13 +244,13 @@ describe('RecordSearchComponent', () => { component['currentType'] = 'documents'; component.detailUrl = '/custom/url/for/detail/:type/:pid'; - component.resolveDetailUrl$({ id: 100 }).subscribe((result: any) => { + component.resolveDetailUrl$(record).subscribe((result: any) => { expect(result.link).toBe('/custom/url/for/detail/documents/100'); }); component.detailUrl = null; - component.resolveDetailUrl$({ id: 100 }).subscribe((result: any) => { + component.resolveDetailUrl$(record).subscribe((result: any) => { expect(result.link).toBe('detail/100'); }); })); diff --git a/projects/rero/ng-core/src/lib/record/search/record-search.component.ts b/projects/rero/ng-core/src/lib/record/search/record-search.component.ts index e65b60d10..b3ef91eb9 100644 --- a/projects/rero/ng-core/src/lib/record/search/record-search.component.ts +++ b/projects/rero/ng-core/src/lib/record/search/record-search.component.ts @@ -39,13 +39,14 @@ import { BehaviorSubject, isObservable, Observable, of, Subscription } from 'rxj import { distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'; import { ApiService } from '../../api/api.service'; import { Error } from '../../error/error'; +import { AggregationsFilter, CanPermission, EsResult, ExportFormat, ExportFormatConfig, InvenioRecord, RecordPermissions, RecordsAggregation, Url } from '../../types'; import { ActionStatus } from '../action-status'; import { JSONSchema7 } from '../editor/utils'; import { Aggregation, Record, SearchField, SearchFilter, SearchFilterSection, SearchResult } from '../record'; import { RecordUiService } from '../record-ui.service'; import { RecordService } from '../record.service'; import { ChangeEvent } from './paginator/paginator.component'; -import { AggregationsFilter, RecordSearchService } from './record-search.service'; +import { RecordSearchService } from './record-search.service'; import { IChecked } from './search-filters/search-filters.component'; export interface SearchParams { @@ -107,16 +108,16 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { index?: string; component?: Component; total?: number; - canAdd?: any; - canUpdate?: any; - canDelete?: any; - canRead?: any; - permissions?: any; - aggregations?: any; - preFilters?: any; + canAdd?: CanPermission; + canUpdate?: CanPermission; + canDelete?: CanPermission; + canRead?: CanPermission; + permissions?: RecordPermissions; + aggregations?: (aggregations: object) => Observable; + preFilters?: object; defaultSearchInputFilters?: AggregationsFilter[]; - listHeaders?: any; - itemHeaders?: any; + listHeaders?: object; + itemHeaders?: object; aggregationsName?: any; aggregationsOrder?: string[]; aggregationsExpand?: string[] | (() => string[]); @@ -198,13 +199,13 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { } /** Request result record hits. */ - get records(): any[] { + get records(): InvenioRecord[] { return this.hits && this.hits.hits ? this.hits.hits : []; } /** Total records number corresponding to the request. */ get total(): number { - return this.hits && this.hits.total ? this.recordService.totalHits(this.hits.total) : 0; + return this.hits && this.hits.total.value; } /** Get the text for displaying results text. */ @@ -311,7 +312,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { */ ngOnInit() { this._subscriptions.add( - this.translateService.onLangChange.subscribe((lang: any) => { + this.translateService.onLangChange.subscribe(() => { this._loadSearchFields(); }) ); @@ -590,7 +591,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * Get Export formats for the current resource given by configuration. * @return Array of export format to generate an `export as` button or an empty array. */ - protected _exportFormats(): any[] { + protected _exportFormats(): ExportFormatConfig[] { if (!this.config || !this.config.exportFormats) { return []; } @@ -609,7 +610,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param format - export format object * @return formatted url for an export format. */ - getExportFormatUrl(format: any) { + getExportFormatUrl(format: Partial) { const queryParams = Object.keys(this.activatedRoute.snapshot.queryParams); // TODO: maybe we can use URLSerializer to build query string const baseUrl = format.endpoint ? format.endpoint : this.apiService.getEndpointByType(this._currentIndex()); @@ -649,7 +650,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param format - export format object * @return Boolean */ - canExport(format: any): boolean { + canExport(format: Partial): boolean { return Object.hasOwn(format, 'disableMaxRestResultsSize') && format.disableMaxRestResultsSize ? this.total > 0 : 0 < this.total && this.total < RecordService.MAX_REST_RESULTS_SIZE; @@ -688,7 +689,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param records - Result records * @return Observable containing aggregations corresponding to actual records. */ - aggregations$(aggregations: object): Observable { + aggregations$(aggregations: object): Observable { if (this.config.aggregations) { return this.config.aggregations(aggregations); } else { @@ -702,8 +703,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param record - Generate detail URL for this record. * @return Observable emitting detail URL object */ - resolveDetailUrl$(record: any): Observable { - const url = { link: `detail/${record.id}`, external: false }; + resolveDetailUrl$(record: InvenioRecord): Observable { + const url: Url = { link: `detail/${record.id}`, external: false }; if (this.detailUrl) { url.link = this.detailUrl.replace(':type', this._currentIndex()).replace(':pid', record.id); @@ -772,15 +773,15 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { if (event.expanded === false) { return; } - const aggregation = this.aggregations.find((item: any) => item.key === event.key); + const aggregation = this.aggregations.find((item: Aggregation) => item.key === event.key); // No aggregation found or buckets are already loaded. if (!aggregation || aggregation.loaded) { return; } // Get buckets for the aggregation - this._getRecords(1).subscribe((records: any) => { - this.aggregations$(records.aggregations).subscribe((aggregations: any) => { + this._getRecords(1).subscribe((records: EsResult) => { + this.aggregations$(records.aggregations).subscribe((aggregations: object) => { if (aggregations[event.key]) { this._mapAggregation(aggregation, aggregations[event.key]); } @@ -795,7 +796,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * Search for records. * @param size - number : force the number of records to return. If `null` the default component `size` attribute will be used. */ - protected _getRecords(size: number = null): Observable { + protected _getRecords(size: number = null): Observable { // Build query string const q = this._buildQueryString(); @@ -803,7 +804,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { // processed. if (this.config.allowEmptySearch === false && !q) { this.showEmptySearchMessage = true; - return of({ hits: { hits: [], total: 0 }, aggregations: {} }); + return of({ hits: { hits: [], total: { relation: 'eq', value: 0 } }, aggregations: {} }); } else { this.showEmptySearchMessage = false; } @@ -882,8 +883,8 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { // Update filters with default search filters only if the q parameter is empty if ((q === null || q.trim().length === 0) && this.config.defaultSearchInputFilters) { - this.config.defaultSearchInputFilters.forEach((filter: { key: string; values: any[] }) => { - this.recordSearchService.updateAggregationFilter(filter.key, filter.values); + this.config.defaultSearchInputFilters.forEach((filter: any) => { + this.recordSearchService.updateAggregationFilter(filter.key, filter.value); }); } } @@ -894,7 +895,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param defaultValue - Default value is returned if the parameter is not defined * @return A config value or the given default value instead */ - protected _getResourceConfig(paramName: string, defaultValue: any) { + protected _getResourceConfig(paramName: string, defaultValue: object) { return (paramName in this.config) ? this.config[paramName] : defaultValue; } @@ -1009,7 +1010,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { */ protected _flatSearchFilters(): SearchFilter[] { const flatFilters = []; - this.searchFilters.forEach((searchFilter: any) => { + this.searchFilters.forEach((searchFilter: SearchFilterSection) => { if (searchFilter.filters) { searchFilter.filters.forEach((filter: any) => flatFilters.push(filter)); } else { @@ -1025,7 +1026,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { * @param aggregation Aggregation object. * @param recordsAggregation Aggregation retrieved from record. */ - protected _mapAggregation(aggregation: Aggregation, recordsAggregation: any): void { + protected _mapAggregation(aggregation: Aggregation, recordsAggregation: RecordsAggregation): void { aggregation.doc_count = recordsAggregation.doc_count || null; aggregation.type = recordsAggregation.type || 'terms'; aggregation.config = recordsAggregation.config || null; @@ -1077,7 +1078,7 @@ export class RecordSearchComponent implements OnInit, OnChanges, OnDestroy { if ( agg.included === true || agg.expanded || - this.aggregationsFilters.some((filter: any) => filter.key === agg.key) + this.aggregationsFilters.some((filter: AggregationsFilter) => filter.key === agg.key) ) { facets.push(agg.key); } diff --git a/projects/rero/ng-core/src/lib/record/search/record-search.service.ts b/projects/rero/ng-core/src/lib/record/search/record-search.service.ts index 3ec77e5b9..58c1d2af3 100644 --- a/projects/rero/ng-core/src/lib/record/search/record-search.service.ts +++ b/projects/rero/ng-core/src/lib/record/search/record-search.service.ts @@ -17,14 +17,7 @@ import { Injectable } from '@angular/core'; import { cloneDeep } from 'lodash-es'; import { BehaviorSubject, Observable } from 'rxjs'; - -/** - * Interface representing aggregations filters - */ -export interface AggregationsFilter { - key: string; - values: any[]; -} +import { AggregationsFilter } from '../../types'; /** * Service for managing records search. diff --git a/projects/rero/ng-core/src/lib/types.ts b/projects/rero/ng-core/src/lib/types.ts new file mode 100644 index 000000000..94dc18280 --- /dev/null +++ b/projects/rero/ng-core/src/lib/types.ts @@ -0,0 +1,61 @@ +/* + * RERO angular core + * Copyright (C) 2025 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 { Observable } from "rxjs"; +import { ActionStatus } from "./record/action-status"; + +export interface InvenioRecord { created : string, id : string, links : object, metadata: object, updated : string } + +export interface EsResult { + aggregations : object, + hits : { + hits: InvenioRecord[], + total : { + relation : string, + value : number + } + } +} + +export interface ExportFormat { endpoint: string, disableMaxRestResultsSize: boolean, format: string } + +export interface ExportFormatConfig { label: string, url: string, disable : boolean, disabled_message: string } + +export interface Url { link: string, external: boolean } + +export interface AggregationsFilter { + key: string; + values: any[]; +} + +export interface RecordsAggregation { + doc_count: number, + type : string, + config: any, + name: string, + buckets: any[] +} + +export type CanPermission = (record : InvenioRecord) => Observable; + +export interface RecordPermissions { + canAdd?: CanPermission; + canUpdate?: CanPermission; + canDelete?: CanPermission; + canRead?: CanPermission; +} +