Skip to content

Commit

Permalink
document: implement advanced search
Browse files Browse the repository at this point in the history
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Oct 31, 2023
1 parent b4f8eeb commit ff37c62
Show file tree
Hide file tree
Showing 19 changed files with 1,042 additions and 147 deletions.
6 changes: 6 additions & 0 deletions projects/admin/src/app/api/document-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IAvailability, IAvailabilityService } from '@rero/shared';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AppConfigService } from '../service/app-config.service';
import { IAdvancedSearchConfig } from '../record/search-view/document-advanced-search-form/i-advanced-search-config-interface';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -63,4 +64,9 @@ export class DocumentApiService implements IAvailabilityService {
const url = `${this._appConfigService.apiEndpointPrefix}/document/${pid}/availability`;
return this._httpClient.get<IAvailability>(url);
}

getAdvancedSearchConfig(): Observable<IAdvancedSearchConfig> {
const url = `${this._appConfigService.apiEndpointPrefix}/document/advanced-search-config`;
return this._httpClient.get<IAdvancedSearchConfig>(url);
}
}
59 changes: 59 additions & 0 deletions projects/admin/src/app/api/organisation-api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* RERO ILS UI
* Copyright (C) 2021-2023 RERO
* Copyright (C) 2021-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
* 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 <http://www.gnu.org/licenses/>.
*/
import { TestBed } from '@angular/core/testing';
import { RecordService } from '@rero/ng-core';
import { of } from 'rxjs';
import { OrganisationApiService } from './organisation-api.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TranslateModule } from '@ngx-translate/core';

describe('OrganisationApiService', () => {
let service: OrganisationApiService;

const response = {
metadata: {
name: 'Organisation name'
}
}
const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecord']);
recordServiceSpy.getRecord.and.returnValue(of(response));

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
TranslateModule.forRoot()
],
providers: [
{ provide: RecordService, useValue: recordServiceSpy }
]
});
service = TestBed.inject(OrganisationApiService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should return the organization\'s data', () => {
service.getByPid('1').subscribe((data: any) => {
expect(data.name).toEqual(response.metadata.name);
});

});
});
34 changes: 34 additions & 0 deletions projects/admin/src/app/api/organisation-api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* RERO ILS UI
* Copyright (C) 2021-2023 RERO
* Copyright (C) 2021-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
* 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 <http://www.gnu.org/licenses/>.
*/
import { Injectable } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
providedIn: 'root'
})
export class OrganisationApiService {

constructor(private recordService: RecordService) { }

getByPid(pid: string): Observable<any> {
return this.recordService.getRecord('organisations', pid)
.pipe(map(record => record.metadata));
}
}
21 changes: 18 additions & 3 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { PrimengImportModule } from '@app/admin/shared/primeng-import/primeng-import.module';
import { HotkeysModule, HotkeysService } from '@ngneat/hotkeys';
import { FormlyFieldSelect } from '@ngx-formly/bootstrap';
import { FormlyModule } from '@ngx-formly/core';
import { LoadingBarHttpClientModule } from '@ngx-loading-bar/http-client';
import { TranslateLoader as BaseTranslateLoader, TranslateModule } from '@ngx-translate/core';
import {
BucketNameService as CoreBucketNameService,
CoreConfigService, LocalStorageService, RecordModule, RemoteTypeaheadService,
TranslateLoader, TranslateService, TruncateTextPipe
} from '@rero/ng-core';
Expand Down Expand Up @@ -169,6 +171,8 @@ import { PermissionDetailViewComponent } from './record/detail-view/permission-d
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 { FieldCustomInputTypeComponent } from './record/editor/type/field-custom.type';
import { RepeatTypeComponent } from './record/editor/type/repeat-section.type';
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';
Expand All @@ -177,13 +181,16 @@ import { AddEntityLocalComponent } from './record/formly/type/entity-typeahead/a
import { EntityTypeaheadComponent } from './record/formly/type/entity-typeahead/entity-typeahead.component';
import { OperationLogsDialogComponent } from './record/operation-logs/operation-logs-dialog/operation-logs-dialog.component';
import { OperationLogsComponent } from './record/operation-logs/operation-logs.component';
import { DocumentAdvancedSearchFormComponent } from './record/search-view/document-advanced-search-form/document-advanced-search-form.component';
import { DocumentAdvancedSearchComponent } from './record/search-view/document-advanced-search.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 { BucketNameService } from './service/bucket-name.service';
import { OrganisationService } from './service/organisation.service';
import { TypeaheadFactoryService, typeaheadToken } from './service/typeahead-factory.service';
import { UiRemoteTypeaheadService } from './service/ui-remote-typeahead.service';
Expand Down Expand Up @@ -322,7 +329,11 @@ export function appInitFactory(appInitializerService: AppInitializerService): ()
LocalWorkDetailViewComponent,
RemoteTopicDetailViewComponent,
AddEntityLocalComponent,
AddEntityLocalFormComponent
AddEntityLocalFormComponent,
DocumentAdvancedSearchFormComponent,
RepeatTypeComponent,
FieldCustomInputTypeComponent,
DocumentAdvancedSearchComponent,
],
imports: [
AppRoutingModule,
Expand All @@ -343,7 +354,10 @@ export function appInitFactory(appInitializerService: AppInitializerService): ()
types: [
{name: 'cipo-pt-it', component: CipoPatronTypeItemTypeComponent},
{name: 'account-select', component: SelectAccountEditorWidgetComponent},
{name: 'entityTypeahead', component: EntityTypeaheadComponent}
{name: 'entityTypeahead', component: EntityTypeaheadComponent},
{name: 'repeat', component: RepeatTypeComponent},
{name: 'select-formly', component: FormlyFieldSelect },
{name: 'custom', component: FieldCustomInputTypeComponent }
],
wrappers: [
{name: 'user-id', component: UserIdComponent},
Expand Down Expand Up @@ -428,7 +442,8 @@ export function appInitFactory(appInitializerService: AppInitializerService): ()
},
MainTitlePipe,
ItemHoldingsCallNumberPipe,
CountryCodeTranslatePipe
CountryCodeTranslatePipe,
{ provide: CoreBucketNameService, useClass: BucketNameService }
],
bootstrap: [AppComponent],
schemas: [
Expand Down
47 changes: 47 additions & 0 deletions projects/admin/src/app/record/editor/type/field-custom.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* RERO ILS UI
* Copyright (C) 2019-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 <http://www.gnu.org/licenses/>.
*/
import { Component, OnInit } from '@angular/core';
import { FieldType } from '@ngx-formly/core';

@Component({
selector: 'admin-field-custom-input',
template: `
<div class="form-group m-0 d-flex align-items-start">
<!-- label -->
<label [attr.for]="id" class="mr-2 col-form-label" *ngIf="to.label && to.hideLabel !== true" [tooltip]="to.description">
{{ to.label }}<ng-container *ngIf="to.required && to.hideRequiredMarker !== true">&nbsp;*</ng-container>
</label>
<!-- field -->
<div class="flex-grow-1">
<ng-container [ngSwitch]="field.type">
<formly-field *ngSwitchCase="'input'" [field]="field"></formly-field>
<formly-field *ngSwitchCase="'select'" [field]="field"></formly-field>
</ng-container>
</div>
</div>
`,
})
export class FieldCustomInputTypeComponent extends FieldType implements OnInit {

/** OnInit hook */
ngOnInit(): void {
// We delete the class, as it is already set to the top level by the config.
if (Object.keys(this.field).includes('className')) {
delete this.field.className;
}
}
}
44 changes: 44 additions & 0 deletions projects/admin/src/app/record/editor/type/repeat-section.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* RERO ILS UI
* Copyright (C) 2019-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 <http://www.gnu.org/licenses/>.
*/
import { Component } from '@angular/core';
import { FieldArrayType } from '@ngx-formly/core';

@Component({
selector: 'admin-repeat-section',
template: `
<div *ngFor="let field of field.fieldGroup; let i = index;" class="row">
<div class="col-11">
<formly-field [field]="field"></formly-field>
</div>
<div class="col-1 my-0 d-flex align-items-center">
<button
*ngIf="field.parent.fieldGroup.length > to.minItems"
class="btn"
type="button"
(click)="remove(i)"
><i class="fa fa-trash text-danger" aria-hidden="true"></i></button>
<button
*ngIf="field.parent.templateOptions.maxItems > field.parent.fieldGroup.length && field.parent.fieldGroup.length -1 === i"
class="btn"
type="button"
(click)="add()"
><i class="fa fa-plus-circle text-primary" aria-hidden="true"></i></button>
</div>
</div>
`,
})
export class RepeatTypeComponent extends FieldArrayType { }
Loading

0 comments on commit ff37c62

Please sign in to comment.