Skip to content

Commit

Permalink
request: allow cancellation when item is at desk
Browse files Browse the repository at this point in the history
* Updates cancel request permissions.
* Adds method to update the item detailed view after a cancel request.
* Adds a flash message to inform the user about item status.
* Closes rero/rero-ils#1293.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger committed Oct 20, 2020
1 parent 3f8806a commit 6d158ee
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ <h3 translate>Issue data</h3>
</section>

<!-- TRANSACTIONS -->
<admin-item-transactions [item]="record"></admin-item-transactions>
<admin-item-transactions [item]="record" (updateItem)="updateItem()"></admin-item-transactions>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, OnDestroy, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { extractIdOnRef, RecordService } from '@rero/ng-core';
import { DetailRecord } from '@rero/ng-core/lib/record/detail/view/detail-record';
import { ToastrService } from 'ngx-toastr';
import { forkJoin, Observable, Subscription } from 'rxjs';
import { IssueItemStatus } from '../../../class/items';
import { ItemsService } from '../../../service/items.service';
import { LoanService } from '../../../service/loan.service';

@Component({
Expand Down Expand Up @@ -54,32 +57,43 @@ export class ItemDetailViewComponent implements DetailRecord, OnInit, OnDestroy

/**
* Constructor
* @param recordService - RecordService
* @param loanService - LoanService
* @param _recordService - RecordService
* @param _loanService - loanService
* @param _itemService - ItemsService
*/
constructor(
private recordService: RecordService,
private loanService: LoanService
private _recordService: RecordService,
private _loanService: LoanService,
private _itemService: ItemsService
) {}

ngOnInit() {
this._recordObs = this.record$.subscribe( record => {
this.record = record;
const numberOfRequest$ = this.loanService.numberOfRequests$(record.metadata.pid);
const locationRecord$ = this.recordService.getRecord('locations', record.metadata.location.pid);
forkJoin([numberOfRequest$, locationRecord$]).subscribe(
([numberOfRequest, location]) => {
this.numberOfRequests = numberOfRequest;
this.location = location;
this.recordService.getRecord('libraries', extractIdOnRef(location.metadata.library.$ref)).subscribe(
library => this.library = library
);
}
);
this._recordObs = this.record$.subscribe(record => {
this._loadInfo(record);
});
this._itemService.updateItem$.subscribe((itemPid: string) => {
this._recordService.getRecord('items', itemPid, 1).subscribe((record: any) => {
this._loadInfo(record);
});
});
}

ngOnDestroy() {
this._recordObs.unsubscribe();
}

private _loadInfo(record) {
this.record = record;
const numberOfRequest$ = this._loanService.numberOfRequests$(record.metadata.pid);
const locationRecord$ = this._recordService.getRecord('locations', record.metadata.location.pid);
forkJoin([numberOfRequest$, locationRecord$]).subscribe(
([numberOfRequest, location]) => {
this.numberOfRequests = numberOfRequest;
this.location = location;
this._recordService.getRecord('libraries', extractIdOnRef(location.metadata.library.$ref)).subscribe(
library => this.library = library
);
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
*/
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { DialogService, RecordService } from '@rero/ng-core';
import { DialogService } from '@rero/ng-core';
import { ToastrService } from 'ngx-toastr';
import { LoanState } from 'projects/admin/src/app/class/items';
import { LoanService } from 'projects/admin/src/app/service/loan.service';
import { UserService } from 'projects/admin/src/app/service/user.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { ItemsService } from 'projects/admin/src/app/service/items.service';

Expand Down Expand Up @@ -141,7 +140,8 @@ export class ItemTransactionComponent implements OnInit, OnDestroy {
// No permission API in backend
// Allowed when loan state is PENDING or ITEM_IN_TRANSIT_FOR_PICKUP according to actions.md
return this.transaction.metadata.state === LoanState.PENDING
|| this.transaction.metadata.state === LoanState.ITEM_IN_TRANSIT_FOR_PICKUP;
|| this.transaction.metadata.state === LoanState.ITEM_IN_TRANSIT_FOR_PICKUP
|| this.transaction.metadata.state === LoanState.ITEM_AT_DESK;
}

/**
Expand Down Expand Up @@ -189,6 +189,12 @@ export class ItemTransactionComponent implements OnInit, OnDestroy {
)
.subscribe((itemData: any) => {
this.removeRequest.emit(true);
this._itemService.updateItem$.next(itemData.pid);
console.log(itemData);
this._toastrService.warning(
this._translateService.instant('The item is ' + itemData.status),
this._translateService.instant('Request')
);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* 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, Input, OnInit } from '@angular/core';
import { Component, Input, OnInit, Output } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { LoanService } from 'projects/admin/src/app/service/loan.service';
import { Observable } from 'rxjs';
import { Observable, Subject } from 'rxjs';
import { first } from 'rxjs/operators';
import { ItemRequestComponent } from '../../document-detail-view/item-request/item-request.component';

Expand Down
7 changes: 6 additions & 1 deletion projects/admin/src/app/service/items.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { Observable, of } from 'rxjs';
import { Observable, of, Subject } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { Item, ItemAction, ItemNoteType, ItemStatus } from '../class/items';
import { UserService } from './user.service';
Expand All @@ -28,6 +28,11 @@ import { UserService } from './user.service';
})
export class ItemsService {

/**
* Informs parent component to update item
*/
updateItem$ = new Subject();

/**
* constructor
* @param _http - HttpClient
Expand Down

0 comments on commit 6d158ee

Please sign in to comment.