LP1910145 Hold notes and notifications WIP
authorBill Erickson <berickxx@gmail.com>
Mon, 4 Jan 2021 21:12:50 +0000 (16:12 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 4 Jan 2021 21:12:50 +0000 (16:12 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.html
Open-ILS/src/eg2/src/app/staff/share/holds/detail.component.ts
Open-ILS/src/eg2/src/styles.css

index bc7e4f6..616acc6 100644 (file)
@@ -1,11 +1,8 @@
-
-<eg-staff-banner bannerText="Hold Details (#{{hold.id}})" i18n-bannerText>
-</eg-staff-banner>
-
 <div class="row">
-  <div class="col-lg-3">
+  <div class="col-lg-2">
     <button (click)="showListView()" class="btn btn-info" i18n>List View</button>
   </div>
+  <div class="col-lg-3 font-weight-bold" i18n><h4>Hold #{{holdId}}</h4></div>
 </div>
 
 <div class="well-table">
   </div>
 </div>
 
+<div class="row mt-2">
+  <div class="col-lg-12">
+    <ul ngbNav #detailNav="ngbNav" class="nav-tabs" [activeId]="detailTab">
+      <li ngbNavItem="notes">
+        <a ngbNavLink i18n>Notes</a>
+        <ng-template ngbNavContent>
+          <button class="btn btn-outline-dark mt-3" (click)="newNote()" i18n>New Note</button>
+          <div class="mt-3" *ngFor="let note of notes">
+            <div class="d-flex">
+              <div class="font-weight-bold">{{note.title()}}</div>
+              <div class="flex-1"></div>
+              <div>
+                <span *ngIf="note.slip() == 't'" 
+                  class="ml-2 badge badge-info">Print on Slip</span>
+                <span *ngIf="note.pub() == 't'" 
+                  class="ml-2 badge badge-warning">Patron Visible</span>
+                <span *ngIf="note.staff() == 't'" 
+                  class="ml-2 badge badge-info">Staff Create</span>
+              </div>
+            </div>
+            <div class="well-table">
+              <div class="well-row">
+                <div class="well-value">{{note.body()}}</div>
+                <div class="well-label-no-flex">
+                  <button class="btn btn-warning" 
+                    (click)="deleteNote(note)" i18n>Delete</button>
+                </div>
+              </div>
+            </div>
+          </div>
+        </ng-template>
+      </li>
+      <li ngbNavItem="notifications">
+        <a ngbNavLink i18n>Staff Notifications</a>
+        <ng-template ngbNavContent>
+          NOTIFY
+        </ng-template>
+      </li>
+    </ul>
+    <div [ngbNavOutlet]="detailNav"></div>
+  </div>
+</div>
index 67b3801..5a1ebbf 100644 (file)
@@ -1,6 +1,9 @@
 import {Component, OnInit, Input, Output, ViewChild, EventEmitter} from '@angular/core';
 import {Observable, Observer, of} from 'rxjs';
+import {tap} from 'rxjs/operators';
+import {IdlObject} from '@eg/core/idl.service';
 import {NetService} from '@eg/core/net.service';
+import {PcrudService} from '@eg/core/pcrud.service';
 import {OrgService} from '@eg/core/org.service';
 import {AuthService} from '@eg/core/auth.service';
 
@@ -11,25 +14,39 @@ import {AuthService} from '@eg/core/auth.service';
   templateUrl: 'detail.component.html'
 })
 export class HoldDetailComponent implements OnInit {
+    detailTab = 'notes';
+    notes: IdlObject[] = [];
+    notifies: IdlObject[] = [];
 
-    _holdId: number;
+    private _holdId: number;
     @Input() set holdId(id: number) {
-        this._holdId = id;
-        if (this.initDone) {
-            this.fetchHold();
+        if (this._holdId !== id) {
+            this._holdId = id;
+            if (this.initDone) {
+                this.fetchHold();
+            }
         }
     }
 
+    get holdId(): number {
+        return this._holdId;
+    }
+
     hold: any; // wide hold reference
     @Input() set wideHold(wh: any) {
         this.hold = wh;
     }
 
+    get wideHold(): any {
+        return this.hold;
+    }
+
     initDone: boolean;
     @Output() onShowList: EventEmitter<any>;
 
     constructor(
         private net: NetService,
+        private pcrud: PcrudService,
         private org: OrgService,
         private auth: AuthService,
     ) {
@@ -42,15 +59,37 @@ export class HoldDetailComponent implements OnInit {
     }
 
     fetchHold() {
-        if (!this._holdId) { return; }
+        if (!this.holdId && !this.hold) { return; }
+
+        const promise = this.hold ? Promise.resolve(this.hold) :
+            this.net.request(
+                'open-ils.circ',
+                'open-ils.circ.hold.wide_hash.stream',
+                this.auth.token(), {id: this.holdId}
+            ).toPromise();
 
-        this.net.request(
-            'open-ils.circ',
-            'open-ils.circ.hold.wide_hash.stream',
-            this.auth.token(), {id: this._holdId}
-        ).subscribe(wideHold => {
+        return promise.then(wideHold => {
             this.hold = wideHold;
-        });
+            // avoid this.holdId = since it re-fires this fetch.
+            this._holdId = wideHold.id;
+        })
+        .then(_ => this.getNotes())
+        .then(_ => this.getNotifies());
+    }
+
+    getNotes(): Promise<any> {
+        this.notes = [];
+        return this.pcrud.search('ahrn', {hold: this.holdId})
+        .pipe(tap(note => this.notes.push(note))).toPromise()
+    }
+
+    getNotifies(): Promise<any> {
+        this.notifies = [];
+
+        return this.pcrud.search('ahn',
+            {hold: this.holdId},
+            {order_by: {ahn: 'notify_time DESC'}}
+        ).pipe(tap(notify => this.notifies.push(notify))).toPromise();
     }
 
     getOrgName(id: number) {
@@ -62,6 +101,11 @@ export class HoldDetailComponent implements OnInit {
     showListView() {
         this.onShowList.emit();
     }
+
+    deleteNote(note: IdlObject) {
+        this.pcrud.remove(note).toPromise()
+        .then(ok => { if (ok) { this.getNotes(); } });
+    }
 }
 
 
index 9ec9f67..5ff572a 100644 (file)
@@ -63,6 +63,14 @@ h5 {font-size: .95rem}
   min-height: 40px;
 }
 
+.well-table .well-label-no-flex {
+  display: flex;
+  align-items: center;
+  margin: 4px;
+  padding: 4px;
+  min-height: 40px;
+}
+
 .well-table .well-value {
   flex: 1;
   display: flex;