lpxxx Angular holdings maintenance wip
authorBill Erickson <berickxx@gmail.com>
Wed, 20 Mar 2019 22:03:24 +0000 (18:03 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 20 Mar 2019 22:03:24 +0000 (18:03 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html
Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts

index ba20df3..808f247 100644 (file)
@@ -46,6 +46,7 @@
 
 <eg-mark-damaged-dialog #markDamagedDialog></eg-mark-damaged-dialog>
 <eg-mark-missing-dialog #markMissingDialog></eg-mark-missing-dialog>
+<eg-copy-alerts-dialog #copyAlertsDialog></eg-copy-alerts-dialog>
 
 <!-- holdings grid -->
 <div class='eg-copies w-100 mt-3'>
       i18n-group group="Add" i18n-label label="Add Call Numbers and Items"
       (onClick)="openVolCopyEdit($event, true, true)">
     </eg-grid-toolbar-action>
+
+    <eg-grid-toolbar-action
+      i18n-group group="Add" i18n-label label="Add Items Notes"
+      (onClick)="openItemNotes($event, 'create')">
+    </eg-grid-toolbar-action>
     
     <!-- row actions : Show -->
 
index e2e6340..c47d7a6 100644 (file)
@@ -18,6 +18,7 @@ import {MarkMissingDialogComponent
     } from '@eg/staff/share/holdings/mark-missing-dialog.component';
 import {AnonCacheService} from '@eg/share/util/anon-cache.service';
 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
+import {CopyAlertsDialogComponent} from '@eg/staff/share/holdings/copy-alerts-dialog.component';
 
 
 // The holdings grid models a single HoldingsTree, composed of HoldingsTreeNodes
@@ -82,6 +83,8 @@ export class HoldingsMaintenanceComponent implements OnInit {
         private markDamagedDialog: MarkDamagedDialogComponent;
     @ViewChild('markMissingDialog')
         private markMissingDialog: MarkMissingDialogComponent;
+    @ViewChild('copyAlertsDialog')
+        private copyAlertsDialog: CopyAlertsDialogComponent;
 
     holdingsTree: HoldingsTree;
 
@@ -723,4 +726,21 @@ export class HoldingsMaintenanceComponent implements OnInit {
                 this.recordId, null, entries, !addCopies);
         }
     }
+
+    openItemNotes(rows: HoldingsEntry[], mode: string) {
+        const copyIds = this.selectedCopyIds(rows);
+        if (copyIds.length === 0) { return; }
+
+        this.copyAlertsDialog.copyIds = copyIds;
+        this.copyAlertsDialog.mode = mode;
+        this.copyAlertsDialog.open({}).then(
+            modified => {
+                if (modified) {
+                    this.hardRefresh();
+                }
+            },
+            dismissed => {}
+        )
+    }
+
 }
diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.html
new file mode 100644 (file)
index 0000000..f76e9fd
--- /dev/null
@@ -0,0 +1,28 @@
+<eg-string #successMsg text="Successfully Modified Copy Alerts" i18n-text></eg-string>
+<eg-string #errorMsg text="Failed To Modify Copy Alerts" i18n-text></eg-string>
+
+<ng-template #dialogContent>
+  <div class="modal-header bg-info">
+    <h4 class="modal-title">
+      <span i18n>Manage Copy Alerts</span>
+    </h4>
+    <button type="button" class="close" 
+      i18n-aria-label aria-label="Close" (click)="dismiss('cross_click')">
+      <span aria-hidden="true">&times;</span>
+    </button>
+  </div>
+  <div class="modal-body">
+    <ng-container *ngIf="mode == 'create'">
+      <span i18n>Adding alerts for {{copies.length}} item(s).</span>
+    </ng-container>
+    <ng-container *ngIf="mode == 'manage'">
+      <span i18n>Managing alerts for item {{copies[0].barcode()}}</span>
+    </ng-container>
+  </div>
+  <div class="modal-footer">
+    <button type="button" class="btn btn-warning" 
+      (click)="dismiss('canceled')" i18n>Cancel</button>
+    <button class="btn btn-info mr-2" 
+      (click)="save()" i18n>Apply Changes</button>
+  </div>
+</ng-template>
diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts
new file mode 100644 (file)
index 0000000..72ec0c5
--- /dev/null
@@ -0,0 +1,110 @@
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {NetService} from '@eg/core/net.service';
+import {IdlObject} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
+import {ToastService} from '@eg/share/toast/toast.service';
+import {AuthService} from '@eg/core/auth.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {OrgService} from '@eg/core/org.service';
+import {StringComponent} from '@eg/share/string/string.component';
+import {DialogComponent} from '@eg/share/dialog/dialog.component';
+import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
+import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
+
+/**
+ * Dialog for managing copy alerts.
+ */
+
+@Component({
+  selector: 'eg-copy-alerts-dialog',
+  templateUrl: 'copy-alerts-dialog.component.html'
+})
+
+export class CopyAlertsDialogComponent
+    extends DialogComponent implements OnInit {
+
+    _copyIds: number[];
+    @Input() set copyIds(ids: number[]) {
+        this._copyIds = [].concat(ids);
+    }
+    get copyIds(): number[] {
+        return this._copyIds;
+    }
+
+    _mode: string;
+    @Input() set mode(m: string) {
+        this._mode = m;
+    }
+    get mode(): string {
+        return this._mode;
+    }
+
+    copies: IdlObject[];
+    alertTypes: IdlObject[];
+
+    @ViewChild('successMsg') private successMsg: StringComponent;
+    @ViewChild('errorMsg') private errorMsg: StringComponent;
+
+    constructor(
+        private modal: NgbModal, // required for passing to parent
+        private toast: ToastService,
+        private net: NetService,
+        private evt: EventService,
+        private pcrud: PcrudService,
+        private org: OrgService,
+        private auth: AuthService) {
+        super(modal); // required for subclassing
+        this.copyIds = [];
+        this.copies = [];
+    }
+
+    ngOnInit() {}
+
+    /**
+     * Fetch the item/record, then open the dialog.
+     * Dialog promise resolves with true/false indicating whether
+     * the mark-damanged action occured or was dismissed.
+     */
+    async open(args: NgbModalOptions): Promise<boolean> {
+        this.copies = [];
+
+        if (this.copyIds.length === 0) {
+            return Promise.reject('copy ID required');
+        }
+
+        // In manage mode, we can only manage a single copy.
+        // But in create mode, we can add alerts to multiple copies.
+
+        if (this.mode === 'manage') {
+            if (this.copyIds.length > 1) {
+                console.warn('Attempt to manage alerts for multiple copies.');
+                this.copyIds = [this.copyIds[0]];
+            }
+        }
+
+        if (!this.alertTypes) {
+            await this.getAlertTypes();
+        }
+
+        await this.getCopies();
+        return super.open(args);
+    }
+
+    async getAlertTypes(): Promise<any> {
+        return this.pcrud.retrieveAll('aca', {}, {atomic: true})
+        .toPromise().then(alerts => this.alertTypes = alerts);
+    }
+
+    async getCopies(): Promise<any> {
+        return this.pcrud.search('acp',
+            {id: this.copyIds},
+            {flesh: 1, flesh_fields: {acp: ['call_number', 'copy_alerts']}},
+            {atomic: true}
+        ).toPromise().then(copies => this.copies = copies);
+    }
+
+    save() {
+        this.close(false);
+    }
+}
+
index 382e906..e5789f6 100644 (file)
@@ -3,18 +3,21 @@ import {StaffCommonModule} from '@eg/staff/common.module';
 import {HoldingsService} from './holdings.service';
 import {MarkDamagedDialogComponent} from './mark-damaged-dialog.component';
 import {MarkMissingDialogComponent} from './mark-missing-dialog.component';
+import {CopyAlertsDialogComponent} from './copy-alerts-dialog.component';
 
 @NgModule({
     declarations: [
       MarkDamagedDialogComponent,
-      MarkMissingDialogComponent
+      MarkMissingDialogComponent,
+      CopyAlertsDialogComponent
     ],
     imports: [
         StaffCommonModule
     ],
     exports: [
       MarkDamagedDialogComponent,
-      MarkMissingDialogComponent
+      MarkMissingDialogComponent,
+      CopyAlertsDialogComponent
     ],
     providers: [
         HoldingsService