Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/admin/src/app/service/holdings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('HoldingsService', () => {
});

it('should return true on the possibility of making a request', () => {
httpClientSpy.get.and.returnValue(of(true));
service.canRequest('pid').subscribe((result: any) => expect(result).toBeTrue());
httpClientSpy.get.and.returnValue(of({ can: true, reasons: {} }));
service.canRequest('pid').subscribe((result: any) => expect(result.can).toBeTrue());
});

it('should return a list of pickup locations', () => {
Expand Down
4 changes: 2 additions & 2 deletions projects/admin/src/app/service/items.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ describe('ItemsService', () => {
});

it('canRequest', () => {
httpClientSpy.get.and.returnValue(of(true));
service.canRequest('1').subscribe((result: boolean) => expect(result).toBeTrue());
httpClientSpy.get.and.returnValue(of({ can: true, reasons: {} }));
service.canRequest('1').subscribe((result: any) => expect(result.can).toBeTrue());
});

it('needCallout', () => {
Expand Down
4 changes: 2 additions & 2 deletions projects/public-holdings-items/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { HoldingsComponent } from 'projects/public-search/src/app/document-detai
import { ItemsComponent } from 'projects/public-search/src/app/document-detail/holdings/items/items.component';
import { ItemComponent } from 'projects/public-search/src/app/document-detail/item/item.component';
import { PickupLocationComponent } from 'projects/public-search/src/app/document-detail/request/pickup-location/pickup-location.component';
import { RequestComponent } from 'projects/public-search/src/app/document-detail/request/request.component';
import { HoldingsRequestComponent } from 'projects/public-search/src/app/document-detail/request/holdings-request.component';
import { AppConfigService } from './app-config-service.service';
import { AppInitializerService } from './app-initializer.service';
import { ItemRequestComponent } from 'projects/public-search/src/app/document-detail/item/item-request.component';
Expand Down Expand Up @@ -88,7 +88,7 @@ import { ItemRequestComponent } from 'projects/public-search/src/app/document-de
ItemComponent,
ItemsComponent,
PickupLocationComponent,
RequestComponent,
HoldingsRequestComponent,
DocumentDetailViewComponent,
ElectronicHoldingsComponent,
ItemRequestComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('ItemService', () => {

const canRequest = {
can: true,
reasons: []
reasons: {}
};

const request = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('LoanApiService', () => {

const canExtend = {
can: true,
reasons: []
reasons: {}
};

const renew = {
Expand Down
8 changes: 4 additions & 4 deletions projects/public-search/src/app/api/loan-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import { LoanOverduePreview } from '@app/admin/classes/loans';
import { ApiService, Error, Record, RecordService } from '@rero/ng-core';
import { ApiService, Error, Record as EsRecord, RecordService } from '@rero/ng-core';
import { BaseApi } from '@rero/shared';
import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
Expand All @@ -43,7 +43,7 @@ export class LoanApiService extends BaseApi {
patronPid: string, page: number,
itemsPerPage = 20, headers = BaseApi.reroJsonheaders,
sort?: string
): Observable<Record | Error> {
): Observable<EsRecord | Error> {
const loanStates = ['ITEM_ON_LOAN'];
return this.recordService.getRecords(
'loans', this._patronStateQuery(patronPid, loanStates), page, itemsPerPage,
Expand All @@ -62,7 +62,7 @@ export class LoanApiService extends BaseApi {
getRequest(
patronPid: string, page: number,
itemsPerPage = 10, headers = BaseApi.reroJsonheaders
): Observable<Record | Error> {
): Observable<EsRecord | Error> {
const requestStates = ['PENDING', 'ITEM_AT_DESK', 'ITEM_IN_TRANSIT_FOR_PICKUP'];
return this.recordService.getRecords(
'loans', this._patronStateQuery(patronPid, requestStates), page, itemsPerPage,
Expand Down Expand Up @@ -141,5 +141,5 @@ export class LoanApiService extends BaseApi {

export type CanExtend = {
can: boolean;
reasons: string[];
reasons: Record<string, string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ import { ButtonDirective } from 'primeng/button';
import { Message } from 'primeng/message';
import { Ripple } from 'primeng/ripple';
import { HoldingsApiService } from '../../api/holdings-api.service';
import { RequestComponent } from '../request/request.component';
import { HoldingsRequestComponent } from '../request/holdings-request.component';
import { HoldingsStore } from '../store/holdings-store';
import { ItemsComponent } from './items/items.component';
import { MultiSelect } from 'primeng/multiselect';

@Component({
selector: 'public-search-holdings',
templateUrl: './holdings.component.html',
imports: [Message, Accordion, AccordionPanel, Ripple, AccordionHeader, SharedModule, TranslateDirective, AccordionContent, ItemsComponent, RequestComponent, NgClass, ButtonDirective, I18nPluralPipe, TranslatePipe, CoreModule, MultiSelect],
imports: [Message, Accordion, AccordionPanel, Ripple, AccordionHeader, SharedModule, TranslateDirective, AccordionContent, ItemsComponent, HoldingsRequestComponent, NgClass, ButtonDirective, I18nPluralPipe, TranslatePipe, CoreModule, MultiSelect],
providers: [HoldingsStore]
})
export class HoldingsComponent implements OnInit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { canRequest } from '../model/can-request-model';
<p-button
class="ui:pointer-events-auto"
outlined
[hidden]="!canRequest().can"
[hidden]="!hiddenRequestButton()"
[disabled]="!canRequest().can"
[tooltipDisabled]="canRequest().can"
[pTooltip]="tooltip()"
Expand All @@ -52,9 +52,23 @@ export class ItemRequestComponent implements OnInit {

canRequest = signal<canRequest>({ can: false });

tooltip = computed(() => this.canRequest().reasons?.map(
(reason: string) => this.translateService.instant(reason)
).join('\n\n'));
reasonsToDisplay = [
"patron_type_overdue_items_limit",
"patron_type_fee_amount_limit",
"patron_type_unpaid_subscription",
"patron_type_request_limits"
]

allReasonsDisplayable = computed(() =>
this.canRequest().reasons &&
Object.keys(this.canRequest().reasons).every(key => this.reasonsToDisplay.includes(key))
);

hiddenRequestButton = computed(() => this.canRequest().can || this.allReasonsDisplayable());

tooltip = computed(() => Object.values(this.canRequest().reasons || {}).map(
(reason: string) => "- " + this.translateService.instant(reason)
).join('\n'));

private _patron: IPatron;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
*/
export type canRequest = {
can: boolean;
reasons?: string[];
reasons?: Record<string, string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
id="record-{{ record.metadata.pid }}-request-button"
outlined
(onClick)="showRequestDialog()"
[hidden]="!canRequest?.can"
[hidden]="!hiddenRequestButton()"
[disabled]="!canRequest().can"
[tooltipDisabled]="canRequest().can"
[pTooltip]="tooltip()"
tooltipPosition="top"
>
<i class="fa fa-cart-arrow-down ui:mr-2"></i>
@if (recordType === 'item') {
{{ 'Request' | translate }}
@if (holdingsItemsCount > 0) {
{{ 'Request another issue' | translate }}
} @else {
@if (holdingsItemsCount > 0) {
{{ 'Request another issue' | translate }}
} @else {
{{ 'Request an issue' | translate }}
}
{{ 'Request an issue' | translate }}
}
</p-button>
} @else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
* 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, EventEmitter, inject, Input, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, inject, Input, OnInit, Output, signal, computed } from '@angular/core';
import { IPatron, UserService, SharedModule } from '@rero/shared';
import { ItemApiService } from '../../api/item-api.service';
import { HoldingsApiService } from '../../api/holdings-api.service';
import { Button } from 'primeng/button';
import { Tooltip } from 'primeng/tooltip';
import { PickupLocationComponent } from './pickup-location/pickup-location.component';
import { TranslatePipe } from '@ngx-translate/core';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { canRequest } from '../model/can-request-model';

@Component({
selector: 'public-search-request',
templateUrl: './request.component.html',
templateUrl: './holdings-request.component.html',
imports: [Button, Tooltip, PickupLocationComponent, TranslatePipe, SharedModule]
})
export class RequestComponent implements OnInit {
export class HoldingsRequestComponent implements OnInit {

private itemApiService: ItemApiService = inject(ItemApiService);
private holdingsApiService: HoldingsApiService = inject(HoldingsApiService);
private userService: UserService = inject(UserService);
private translateService: TranslateService = inject(TranslateService);

/** Record: item or holding */
@Input() record: any;
Expand All @@ -47,10 +49,25 @@ export class RequestComponent implements OnInit {
@Input() holdingsItemsCount: number;

/** Item Can request with reason(s) */
canRequest = {
can: false,
reasons: []
};
canRequest = signal<canRequest>({ can: false, reasons: {} });

reasonsToDisplay = [
"patron_type_overdue_items_limit",
"patron_type_fee_amount_limit",
"patron_type_unpaid_subscription",
"patron_type_request_limits"
]

allReasonsDisplayable = computed(() =>
this.canRequest().reasons &&
Object.keys(this.canRequest().reasons).every(key => this.reasonsToDisplay.includes(key))
);

hiddenRequestButton = computed(() => this.canRequest().can || this.allReasonsDisplayable());

tooltip = computed(() => Object.values(this.canRequest().reasons || {}).map(
(reason: string) => "- " + this.translateService.instant(reason)
).join('\n'));

/** Request dialog */
requestDialog = false;
Expand Down Expand Up @@ -84,7 +101,7 @@ export class RequestComponent implements OnInit {
this.record.metadata.pid,
this.record.metadata.library.pid,
this._patron.patron.barcode[0],
).subscribe((can: any) => this.canRequest = can);
).subscribe((can: canRequest) => this.canRequest.set(can));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<p-button
size="small"
class="ui:pointer-events-auto"
[pTooltip]="canExtend.reasons | arrayTranslate | join:' / '"
[pTooltip]="reasons | arrayTranslate | join:' / '"
tooltipPosition="top"
[tooltipDisabled]="canExtend.can"
(onClick)="renew()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class PatronProfileLoanComponent implements OnInit {
/** Loan can extend */
canExtend = {
can: false,
reasons: []
reasons: {}
};
/** Fees */
fees = 0;
Expand All @@ -76,6 +76,11 @@ export class PatronProfileLoanComponent implements OnInit {
: DateTime.fromISO(this.record.metadata.due_soon_date) <= DateTime.now();
}

/** Get the cannot extend reasons messages as an array for template pipes */
get reasons(): string[] {
return Object.values(this.canExtend?.reasons || {});
}

/** OnInit hook */
ngOnInit(): void {
this.loanApiService
Expand Down
Loading