LP1936233 Circ history list
authorBill Erickson <berickxx@gmail.com>
Wed, 14 Jul 2021 16:24:36 +0000 (12:24 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 24 Oct 2022 15:03:11 +0000 (11:03 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/item/item.module.ts
Open-ILS/src/eg2/src/app/staff/cat/item/status.component.html
Open-ILS/src/eg2/src/app/staff/share/circ/circ.service.ts

diff --git a/Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.html b/Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.html
new file mode 100644 (file)
index 0000000..24eb48a
--- /dev/null
@@ -0,0 +1,2 @@
+
+<b>I have {{recentCircs.length}} recent circs</b>
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/item/circ-history.component.ts
new file mode 100644 (file)
index 0000000..c754936
--- /dev/null
@@ -0,0 +1,57 @@
+import {Component, Input, OnInit, AfterViewInit, ViewChild} from '@angular/core';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {AuthService} from '@eg/core/auth.service';
+import {NetService} from '@eg/core/net.service';
+import {OrgService} from '@eg/core/org.service';
+import {PrintService} from '@eg/share/print/print.service';
+import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
+import {EventService} from '@eg/core/event.service';
+import {PermService} from '@eg/core/perm.service';
+import {PatronPenaltyDialogComponent} from '@eg/staff/share/patron/penalty-dialog.component';
+import {BarcodeSelectComponent} from '@eg/staff/share/barcodes/barcode-select.component';
+import {CatalogService} from '@eg/share/catalog/catalog.service';
+import {CircService, ItemCircInfo} from '@eg/staff/share/circ/circ.service';
+import {CopyAlertsDialogComponent
+    } from '@eg/staff/share/holdings/copy-alerts-dialog.component';
+import {FormatService} from '@eg/core/format.service';
+
+@Component({
+  selector: 'eg-item-circ-history',
+  templateUrl: 'circ-history.component.html'
+})
+
+export class ItemCircHistoryComponent implements OnInit {
+
+    @Input() item: IdlObject;
+    recentCircs: IdlObject[] = [];
+
+    loading = false;
+
+    constructor(
+        private router: Router,
+        private route: ActivatedRoute,
+        private net: NetService,
+        private org: OrgService,
+        private printer: PrintService,
+        private pcrud: PcrudService,
+        private auth: AuthService,
+        private perms: PermService,
+        private idl: IdlService,
+        private evt: EventService,
+        private cat: CatalogService,
+        private holdings: HoldingsService,
+        private circs: CircService,
+        public  format: FormatService
+    ) { }
+
+    ngOnInit() {
+        this.loading = true;
+        this.circs.getRecentCircs(this.item)
+        .then(circs => this.recentCircs = circs)
+        .then(_ => this.loading = false);
+    }
+}
+
+
index f104689..5bad3bc 100644 (file)
@@ -10,13 +10,15 @@ import {BarcodesModule} from '@eg/staff/share/barcodes/barcodes.module';
 import {CircModule} from '@eg/staff/share/circ/circ.module';
 import {ItemSummaryComponent} from './summary.component';
 import {ItemRecentHistoryComponent} from './recent-history.component';
+import {ItemCircHistoryComponent} from './circ-history.component';
 
 @NgModule({
   declarations: [
     MarkItemMissingPiecesComponent,
     ItemSummaryComponent,
     ItemStatusComponent,
-    ItemRecentHistoryComponent
+    ItemRecentHistoryComponent,
+    ItemCircHistoryComponent
   ],
   imports: [
     StaffCommonModule,
index ea75b82..6a619b5 100644 (file)
         <eg-item-recent-history [item]="item"></eg-item-recent-history>
       </ng-template>
     </li>
+    <li ngbNavItem="circ-history">
+      <a ngbNavLink i18n>Circ History List</a>
+      <ng-template ngbNavContent>
+        <eg-item-circ-history [item]="item"></eg-item-circ-history>
+      </ng-template>
+    </li>
   </ul>
   <div [ngbNavOutlet]="itemNav"></div>
 
index 6a99685..1bd5f24 100644 (file)
@@ -1348,7 +1348,13 @@ export class CircService {
         ).toPromise();
     }
 
-    getLatestCirc(copyId: number, ops?: PcrudQueryOps): Promise<IdlObject> {
+    getLatestCirc(item: IdlObject, ops?: PcrudQueryOps): Promise<IdlObject> {
+        return this.getRecentCircs(item, ops, 1)
+        .then(circs => circs[0]);
+    }
+
+    getRecentCircs(item: IdlObject,
+        ops?: PcrudQueryOps, count?: number): Promise<IdlObject[]> {
 
         if (!ops) {
             ops = {
@@ -1368,9 +1374,35 @@ export class CircService {
         }
 
         ops.order_by = {aacs: 'xact_start desc'};
-        ops.limit = 1;
 
-        return this.pcrud.search('aacs', {target_copy : copyId}, ops).toPromise();
+        let promise = count ?
+            Promise.resolve(count) : this.getMaxCircDisplayCount(item);
+
+        return promise.then(count => {
+            ops.limit = count;
+            return this.pcrud.search('aacs',
+                {target_copy : item.id()}, ops, {atomic: true}).toPromise();
+        });
+    }
+
+    getMaxCircDisplayCount(item: IdlObject): Promise<number> {
+
+        const copyOrg: number =
+            item.call_number().id() === -1 ?
+            item.circ_lib().id() :
+            item.call_number().owning_lib().id();
+
+        return this.perms.hasWorkPermAt(['VIEW_COPY_CHECKOUT_HISTORY'], true)
+        .then(hasPerm => {
+            if (hasPerm['VIEW_COPY_CHECKOUT_HISTORY'].includes(copyOrg)) {
+                return this.org.settings('circ.item_checkout_history.max')
+                .then(sets => {
+                    return sets['circ.item_checkout_history.max'] || 4;
+                });
+            } else {
+                return 0;
+            }
+        });
     }
 
     getItemCircInfo(item: IdlObject): Promise<ItemCircInfo> {
@@ -1382,10 +1414,6 @@ export class CircService {
             circsPrevYear: 0
         };
 
-        const copyOrg: number =
-            item.call_number().id() === -1 ?
-            item.circ_lib().id() :
-            item.call_number().owning_lib().id();
 
         return this.pcrud.search('circbyyr',
             {copy : item.id()}, null, {atomic : true}).toPromise()
@@ -1405,20 +1433,9 @@ export class CircService {
                 }
             });
         })
-        .then(_ => this.perms.hasWorkPermAt(['VIEW_COPY_CHECKOUT_HISTORY'], true))
-        .then(hasPerm => {
-            if (hasPerm['VIEW_COPY_CHECKOUT_HISTORY'].includes(copyOrg)) {
-                return this.org.settings('circ.item_checkout_history.max')
-                .then(sets => {
-                    response.maxHistoryCount = sets['circ.item_checkout_history.max'] || 4;
-                });
-            } else {
-                response.maxHistoryCount = 0;
-            }
-        })
-
-        .then(_ => this.getLatestCirc(item.id()))
-
+        .then(_ => this.getMaxCircDisplayCount(item))
+        .then(count => response.maxHistoryCount = count)
+        .then(_ => this.getLatestCirc(item))
         .then(circ => {
 
             if (!circ) { return response; }