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 2eaeaa0 commit a286d30
Show file tree
Hide file tree
Showing 9 changed files with 168 additions and 125 deletions.
9 changes: 3 additions & 6 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,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,6 +156,7 @@ 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 { ItemInCollectionPipe } from './pipe/item-in-collection.pipe';

/** Init application factory */
export function appInitFactory(appInitService: AppInitService) {
Expand Down Expand Up @@ -233,7 +231,6 @@ export function appInitFactory(appInitService: AppInitService) {
CollectionBriefViewComponent,
CollectionDetailViewComponent,
CollectionItemsComponent,
HoldingItemInCollectionComponent,
DocumentRecordSearchComponent,
HoldingDetailComponent,
ContributionDetailViewComponent,
Expand Down Expand Up @@ -262,7 +259,8 @@ export function appInitFactory(appInitService: AppInitService) {
IdentifiedbyValueComponent,
DialogImportComponent,
SubjectProcessPipe,
NotificationTypePipe
NotificationTypePipe,
ItemInCollectionPipe
],
imports: [
AppRoutingModule,
Expand Down Expand Up @@ -395,7 +393,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>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1>{{ 'Barcode' | translate }} {{ record.metadata.barcode }}</h1>
</header>
<section class="mb-4">
<admin-record-masked *ngIf="record.metadata._masked" [record]="record" [withLabel]="true"></admin-record-masked>
<dl class="row">
<dl class="row mb-0">
<!-- INHERITED CALL NUMBER -->
<ng-container *ngIf="record | itemHoldingsCallNumber | async as callNumber">
<ng-container *ngIf="(callNumber | json) != ({ first: {}, second: {} } | json)">
Expand Down Expand Up @@ -78,6 +78,21 @@ <h1>{{ 'Barcode' | translate }} {{ record.metadata.barcode }}</h1>
<dd class="col-9">
<ng-container *ngIf="location">{{ location.metadata.name }}</ng-container>
</dd>
<!-- TEMPORARY LOCATION -->
<ng-container *ngIf="record.metadata.temporary_location">
<dt class="col-3 label-title" translate>Temporary location</dt>
<dd class="col-9">{{ record.metadata.temporary_location.pid | getRecord: 'locations' : 'field' : 'name' | async }}</dd>
</ng-container>
<!-- ITEM IN COLLECTION -->
<ng-container *ngIf="record.metadata.pid | itemInCollection | async as collections">
<dt class="col-3 label-title" translate>Exhibition/course</dt>
<dd class="col-9">
<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>
</dd>
</ng-container>
<!-- AVAILIBILITY -->
<dt class="col-3 label-title" translate>Availability</dt>
<dd class="col-9">
Expand Down Expand Up @@ -112,6 +127,7 @@ <h1>{{ 'Barcode' | translate }} {{ record.metadata.barcode }}</h1>
</dl>
</section>


<!-- ISSUE DATA -->
<section *ngIf="isIssue">
<header>
Expand Down
Loading

0 comments on commit a286d30

Please sign in to comment.