Skip to content

Commit

Permalink
public-search: hide not received issues for public
Browse files Browse the repository at this point in the history
Closes rero/rero-ils#1661

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Feb 18, 2021
1 parent 97a5b95 commit 8d43a87
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 30 deletions.
8 changes: 7 additions & 1 deletion projects/public-search/src/app/api/item-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ describe('ItemService', () => {
});

it('should return a set of Items by holdings pid', () => {
service.getItemsByHoldingsPidAndViewcode('1', 'global', 1).subscribe((result: QueryResponse) => {
const holdings = {
metadata: {
pid: '1',
holdings_type: 'regular'
}
};
service.getItemsByHoldingsAndViewcode(holdings, 'global', 1).subscribe((result: QueryResponse) => {
expect(result.hits[0]).toEqual(record);
});
});
Expand Down
26 changes: 14 additions & 12 deletions projects/public-search/src/app/api/item-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Injectable } from '@angular/core';
import { Record, RecordService } from '@rero/ng-core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { IssueItemStatus } from '../../../../admin/src/app/class/items';
import { QueryResponse } from '../record';
import { HoldingsApiService } from './holdings-api.service';

Expand All @@ -36,7 +37,7 @@ export class ItemApiService {
* Constructor
* @param _recordService - RecordService
* @param _httpClient - HttpClient
* @param _holdingsService - HoldingsService
* @param _holdingsApiService - HoldingsService
*/
constructor(
private _recordService: RecordService,
Expand All @@ -46,19 +47,20 @@ export class ItemApiService {

/**
* Get items by holdings pid and viewcode
* @param holdingsPid - string
* @param viewcode - string
* @param page - number
* @param itemsPerPage - number
* @return Observable
* @param holdings - any: the holding to search
* @param viewcode - string: the view to filter
* @param page - number: page number
* @param itemsPerPage - number: number of item to return
* @return Observable<QueryResponse>
*/
getItemsByHoldingsPidAndViewcode(
holdingsPid: string, viewcode: string, page: number, itemsPerPage: number = 5): Observable<QueryResponse> {
getItemsByHoldingsAndViewcode(
holdings: any, viewcode: string, page: number, itemsPerPage: number = 5): Observable<QueryResponse> {
const query = (holdings.metadata.holdings_type === 'serial')
? `holding.pid:${holdings.metadata.pid} AND issue.status:${IssueItemStatus.RECEIVED}`
: `holding.pid:${holdings.metadata.pid}`;
return this._recordService
.getRecords(
'items', `holding.pid:${holdingsPid}`, page, itemsPerPage, undefined,
{ view: viewcode }, this._headers, 'enumeration_chronology'
).pipe(map((response: Record) => response.hits));
.getRecords('items', query, page, itemsPerPage, undefined, { view: viewcode }, this._headers, 'enumeration_chronology')
.pipe(map((response: Record) => response.hits));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@
[hidden]="isCollapsed"
>
<div class="card-body p-2">
<public-search-items [holdingpid]="holding.metadata.pid" [viewcode]="viewcode" (eItemsCount)="eItemsCount($event)"></public-search-items>
<public-search-items [holding]="holding" [viewcode]="viewcode" (eItemsCount)="eItemsCount($event)"></public-search-items>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<public-search-item context="holding" [item]="item" [viewcode]="viewcode" [index]="index"></public-search-item>
</ng-container>
<ng-container *ngIf="isLinkShowMore">
<button type="button" id="show-more-{{ holdingpid }}" class="btn btn-link pr-1" (click)="showMore()">
<button type="button" id="show-more-{{ holding.metadata.pid }}" class="btn btn-link pr-1" (click)="showMore()">
<i class="fa fa-plus-square-o"></i> {{ 'Show more' | translate }}
</button>
<small>({{ hiddenItems }})</small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ describe('ItemComponent', () => {
hits: []
};

const holding = {
metadata: {
pid: '1',
holdings_type: 'regular'
}
};

const recordServiceSpy = jasmine.createSpyObj('ItemService', [
'getItemsByHoldingsPidAndViewcode'
'getItemsByHoldingsAndViewcode'
]);
recordServiceSpy.getItemsByHoldingsPidAndViewcode.and.returnValue(of(records));
recordServiceSpy.getItemsByHoldingsAndViewcode.and.returnValue(of(records));

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand All @@ -63,7 +70,7 @@ describe('ItemComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(ItemsComponent);
component = fixture.componentInstance;
component.holdingpid = '1';
component.holding = holding;
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
import { TranslateService } from '@ngx-translate/core';
import { Observable } from 'rxjs';
import { ItemApiService } from '../../../api/item-api.service';
import { QueryResponse } from '../../../record';

Expand All @@ -26,27 +27,26 @@ import { QueryResponse } from '../../../record';
})
export class ItemsComponent implements OnInit {

/** Holding pid */
@Input() holdingpid: string;

// COMPONENT ATTRIBUTE ====================================================
/** Holding */
@Input() holding: any;
/** View code */
@Input() viewcode: string;

/** Event items count */
@Output() eItemsCount: EventEmitter<number> = new EventEmitter<number>();

/** Items total */
itemsTotal = 0;

/** Items per page */
private itemsPerPage = 4;

/** Page */
page = 1;

/** Items records */
items = [];

/** Items per page */
private itemsPerPage = 4;


// GETTER & SETTER ========================================================
/**
* Is link show more
* @return boolean
Expand All @@ -71,6 +71,7 @@ export class ItemsComponent implements OnInit {
return this._translateService.instant(linkText, { counter: count });
}

// CONSTRUCTOR & HOOKS ====================================================
/**
* Constructor
* @param _itemApiService - ItemApiService
Expand All @@ -91,6 +92,7 @@ export class ItemsComponent implements OnInit {
});
}

// COMPONENT FUNCTIONS ==================================================
/** Show more */
showMore() {
this.page++;
Expand All @@ -104,8 +106,12 @@ export class ItemsComponent implements OnInit {
* @param page - number
* @return Observable
*/
private _ItemsQuery(page: number) {
return this._itemApiService
.getItemsByHoldingsPidAndViewcode(this.holdingpid, this.viewcode, page, this.itemsPerPage);
private _ItemsQuery(page: number): Observable<QueryResponse> {
return this._itemApiService.getItemsByHoldingsAndViewcode(
this.holding,
this.viewcode,
page,
this.itemsPerPage
);
}
}

0 comments on commit 8d43a87

Please sign in to comment.