Skip to content

Commit

Permalink
items: add temporary location field
Browse files Browse the repository at this point in the history
* Displays the `temporary_location` field according to the
  exhibitions/courses and temporary location cascade on the document
  detailed view of the public interface.
* Displays the `temporary_location` field on the item detailed view of the
  professional interface.

* Closes rero/rero-ils#2038.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Jul 2, 2021
1 parent eddbb75 commit 28b0ac5
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 128 deletions.
15 changes: 6 additions & 9 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { MenuUserServicesComponent } from './menu/menu-user-services/menu-user-s
import { MenuUserComponent } from './menu/menu-user/menu-user.component';
import { MenuComponent } from './menu/menu.component';
import { LibrarySwitchService } from './menu/service/library-switch.service';
import { ItemInCollectionPipe } from './pipe/item-in-collection.pipe';
import { MarcPipe } from './pipe/marc.pipe';
import { NotesFormatPipe } from './pipe/notes-format.pipe';
import { SubjectProcessPipe } from './pipe/subject-process.pipe';
Expand All @@ -74,6 +75,9 @@ import { PatronTypesBriefViewComponent } from './record/brief-view/patron-types-
import { PatronsBriefViewComponent } from './record/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 { CirculationLogComponent } from './record/circulation-logs/circulation-log/circulation-log.component';
import { CirculationLogsDialogComponent } from './record/circulation-logs/circulation-logs-dialog/circulation-logs-dialog.component';
import { CirculationLogsComponent } from './record/circulation-logs/circulation-logs.component';
import { DocumentEditorComponent } from './record/custom-editor/document-editor/document-editor.component';
import { HoldingEditorComponent } from './record/custom-editor/holding-editor/holding-editor.component';
import { ExceptionDatesEditComponent } from './record/custom-editor/libraries/exception-dates-edit/exception-dates-edit.component';
Expand Down Expand Up @@ -110,9 +114,6 @@ import { HoldingSharedViewComponent } from './record/detail-view/document-detail
import {
DefaultHoldingItemComponent
} from './record/detail-view/document-detail-view/holding/default-holding-item/default-holding-item.component';
import {
HoldingItemInCollectionComponent
} from './record/detail-view/document-detail-view/holding/holding-item-in-collection/holding-item-in-collection.component';
import { HoldingItemNoteComponent } from './record/detail-view/document-detail-view/holding/holding-item-note/holding-item-note.component';
import { HoldingItemTemporaryItemTypeComponent } from './record/detail-view/document-detail-view/holding/holding-item-temporary-item-type/holding-item-temporary-item-type.component';
import { HoldingComponent } from './record/detail-view/document-detail-view/holding/holding.component';
Expand Down Expand Up @@ -159,9 +160,6 @@ import { TypeaheadFactoryService, typeaheadToken } from './service/typeahead-fac
import { UiRemoteTypeaheadService } from './service/ui-remote-typeahead.service';
import { CustomShortcutHelpComponent } from './widgets/custom-shortcut-help/custom-shortcut-help.component';
import { FrontpageComponent } from './widgets/frontpage/frontpage.component';
import { CirculationLogsComponent } from './record/circulation-logs/circulation-logs.component';
import { CirculationLogsDialogComponent } from './record/circulation-logs/circulation-logs-dialog/circulation-logs-dialog.component';
import { CirculationLogComponent } from './record/circulation-logs/circulation-log/circulation-log.component';

/** Init application factory */
export function appInitFactory(appInitService: AppInitService) {
Expand Down Expand Up @@ -236,7 +234,6 @@ export function appInitFactory(appInitService: AppInitService) {
CollectionBriefViewComponent,
CollectionDetailViewComponent,
CollectionItemsComponent,
HoldingItemInCollectionComponent,
DocumentRecordSearchComponent,
HoldingDetailComponent,
ContributionDetailViewComponent,
Expand Down Expand Up @@ -268,7 +265,8 @@ export function appInitFactory(appInitService: AppInitService) {
NotificationTypePipe,
CirculationLogsComponent,
CirculationLogsDialogComponent,
CirculationLogComponent
CirculationLogComponent,
ItemInCollectionPipe
],
imports: [
AppRoutingModule,
Expand Down Expand Up @@ -401,7 +399,6 @@ export function appInitFactory(appInitService: AppInitService) {
TemplateDetailViewComponent,
CollectionBriefViewComponent,
CollectionDetailViewComponent,
HoldingItemInCollectionComponent,
DocumentRecordSearchComponent,
CustomShortcutHelpComponent,
ContributionDetailViewComponent,
Expand Down
83 changes: 83 additions & 0 deletions projects/admin/src/app/pipe/item-in-collection.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* RERO ILS UI
* Copyright (C) 2021 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 { TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { RecordModule, RecordService } from '@rero/ng-core';
import { of } from 'rxjs';
import { ItemInCollectionPipe } from './item-in-collection.pipe';

describe('ItemInCollectionPipe', () => {
let pipe: ItemInCollectionPipe;

const emptyRecords = {
aggregations: {},
hits: {
total: {
relation: 'eq',
value: 0
},
hits: []
},
links: {}
};

const records = [{ pid: '1'}];

const withRecords = {
aggregations: {},
hits: {
total: {
relation: 'eq',
value: 1
},
hits: records
},
links: {}
};

const recordServiceSpy = jasmine.createSpyObj('RecordService', ['getRecords', 'totalHits']);

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

it('create an instance', () => {
expect(pipe).toBeTruthy();
});

it('should return a null value if no result', () => {
recordServiceSpy.getRecords.and.returnValue(of(emptyRecords));
recordServiceSpy.totalHits.and.returnValue(0);
pipe.transform('1').subscribe((result: any) => expect(result).toBeNull());
});

it('should return an array of results', () => {
recordServiceSpy.getRecords.and.returnValue(of(withRecords));
recordServiceSpy.totalHits.and.returnValue(1);
pipe.transform('1').subscribe((result: any) => expect(result).toEqual(records));
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2020 RERO
* Copyright (C) 2021 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
Expand All @@ -15,44 +15,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, Input, OnInit } from '@angular/core';
import { Pipe, PipeTransform } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { Record } from '@rero/ng-core/lib/record/record';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Component({
selector: 'admin-holding-item-in-collection',
templateUrl: './holding-item-in-collection.component.html'
@Pipe({
name: 'itemInCollection'
})
export class HoldingItemInCollectionComponent implements OnInit {

/** Item pid */
@Input() itemPid: string;
/** CSS Class for div element */
@Input() class: string;

/** Collections */
collections: [];
export class ItemInCollectionPipe implements PipeTransform {

/**
* Constructor
* @param _recordService - RecordService
*/
constructor(
private _recordService: RecordService
) { }

/** OnInit hook */
ngOnInit() {
this.isItemInCollection(this.itemPid);
}
constructor(private _recordService: RecordService) {}

/**
* Is this item in a collection
* @param itemPid - string, pid for item
* Get Exhibition/course for current item
* @param itemPid - Item pid
* @returns Observable
*/
private isItemInCollection(itemPid: string) {
this._recordService.getRecords(
transform(itemPid: string): Observable<[] | null> {
return this._recordService.getRecords(
'collections',
`items.pid:${itemPid} AND published:true`,
1,
Expand All @@ -64,9 +49,9 @@ export class HoldingItemInCollectionComponent implements OnInit {
).pipe(
map((result: any) => {
return (this._recordService.totalHits(result.hits.total) === 0)
? []
? null
: result.hits.hits;
})
).subscribe(collections => this.collections = collections);
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,24 @@
<div class="col-4 pl-5 font-weight-bold label-title" translate>Online access</div>
<div class="col-8"><a target="_blank" href="{{ item.metadata.url }}">{{ item.metadata.url }}</a></div>
</ng-container>
<!-- TEMPORARY LOCATION -->
<ng-container *ngIf="item.metadata.temporary_location">
<div class="col-4 pl-5 font-weight-bold label-title" translate>Temporary location</div>
<div class="col-8">{{ item.metadata.temporary_location.name }}</div>
</ng-container>
<!-- ITEM IN COLLECTION -->
<ng-container *ngIf="item.metadata.pid | itemInCollection | async as collections">
<div class="col-4 pl-5 font-weight-bold label-title" translate>Exhibition/course</div>
<div class="col-8">
<ng-container *ngFor="let collection of collections; let last=last">
<a [routerLink]="['/records', 'collections', 'detail', collection.metadata.pid]">{{ collection.metadata.title }}</a>
{{ last ? '' : '; ' }}
</ng-container>
</div>
</ng-container>
</div>
<admin-holding-item-note [note]="note" *ngFor="let note of item.metadata.notes"></admin-holding-item-note>
<admin-holding-item-temporary-item-type [record]="item"></admin-holding-item-temporary-item-type>
<admin-holding-item-in-collection [itemPid]="item.metadata.pid"></admin-holding-item-in-collection>
</div>
<!-- ACTIONS BUTTONS -->
<div class="col-2 text-right" name="buttons">
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,32 @@
</div>
<admin-holding-item-note [note]="note" *ngFor="let note of item.metadata.notes"></admin-holding-item-note>
<admin-holding-item-temporary-item-type [record]="item"></admin-holding-item-temporary-item-type>
<admin-holding-item-in-collection [itemPid]="item.metadata.pid"></admin-holding-item-in-collection>
<!-- TEMPORARY LOCATION -->
<ng-container *ngIf="item.metadata.temporary_location">
<div class="row">
<div class="col-4 pl-5">
<i class="fa fa-long-arrow-right pr-1"></i>
<span class="label-title" translate>Temporary location</span>
</div>
<div class="col-8">
{{ item.metadata.temporary_location.pid | getRecord: 'locations' : 'field': 'name' | async }}
</div>
</div>
</ng-container>
<!-- ITEM IN COLLECTION -->
<ng-container *ngIf="item.metadata.pid | itemInCollection | async as collections">
<div class="row">
<div class="col-4 pl-5">
<i class="fa fa-long-arrow-right pr-1"></i>
<span class="label-title" translate>Exhibition/course</span>
</div>
<div class="col-8">
<ng-container *ngFor="let collection of collections; let last=last">
<a [routerLink]="['/records', 'collections', 'detail', collection.metadata.pid]">
{{ collection.metadata.title }}
</a>{{ last ? '' : '; ' }}
</ng-container>
</div>
</div>
</ng-container>
</div>
Loading

0 comments on commit 28b0ac5

Please sign in to comment.