LPXXX volcopy batch edit select specific
authorBill Erickson <berickxx@gmail.com>
Tue, 14 Jul 2020 21:15:04 +0000 (17:15 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 14 Jul 2020 21:15:04 +0000 (17:15 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/batch-item-attr.component.html
Open-ILS/src/eg2/src/app/staff/share/holdings/batch-item-attr.component.ts

index 736de9d..5e13cff 100644 (file)
@@ -24,7 +24,7 @@
     [editTemplate]="template"
     [labelCounts]="itemAttrCounts(field)"
     (valueCleared)="applyCopyValue(field, null)"
-    (changesSaved)="applyCopyValue(field)">
+    (changesSaved)="applyCopyValue(field, undefined, $event)">
   </eg-batch-item-attr>
 </ng-template>
 
index 6bdda44..91cae6f 100644 (file)
@@ -20,7 +20,8 @@ import {CopyAlertsDialogComponent
 import {CopyTagsDialogComponent
     } from '@eg/staff/share/holdings/copy-tags-dialog.component';
 import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
-import {BatchItemAttrComponent} from '@eg/staff/share/holdings/batch-item-attr.component';
+import {BatchItemAttrComponent, BatchChangeSelection
+    } from '@eg/staff/share/holdings/batch-item-attr.component';
 import {FileExportService} from '@eg/share/util/file-export.service';
 
 @Component({
@@ -247,7 +248,13 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
         return value;
     }
 
-    applyCopyValue(field: string, value?: any) {
+    copyWantsChange(copy: IdlObject, field: string,
+            changeSelection: BatchChangeSelection): boolean {
+        const disValue = this.getFieldDisplayValue(field, copy);
+        return changeSelection[disValue] === true;
+    }
+
+    applyCopyValue(field: string, value?: any, changeSelection?: BatchChangeSelection) {
         if (value === undefined) {
             value = this.values[field];
         } else {
@@ -255,18 +262,26 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
         }
 
         if (field === 'owning_lib') {
-            return this.owningLibChanged(value);
+            return this.owningLibChanged(value, changeSelection);
         }
 
         this.context.copyList().forEach(copy => {
-            if (copy[field] && copy[field]() !== value) {
-                copy[field](value);
-                copy.ischanged(true);
+            if (!copy[field] || copy[field]() === value) { return; }
+
+            // Change selection indicates which items should be modified
+            // based on the display value for the selected field at
+            // time of editing.
+            if (changeSelection &&
+                !this.copyWantsChange(copy, field, changeSelection)) {
+                return;
             }
+
+            copy[field](value);
+            copy.ischanged(true);
         });
     }
 
-    owningLibChanged(orgId: number) {
+    owningLibChanged(orgId: number, changeSelection?: BatchChangeSelection) {
         if (!orgId) { return; }
 
         // Map existing vol IDs to their replacments.
@@ -274,6 +289,11 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
 
         this.context.copyList().forEach(copy => {
 
+            if (changeSelection &&
+                !this.copyWantsChange(copy, 'owning_lib', changeSelection)) {
+                return;
+            }
+
             // Change the copy circ lib to match the new owning lib
             // if configured to do so.
             if (this.volcopy.defaults.values.circ_lib_mod_with_owning_lib) {
index e126ca9..cc660d6 100644 (file)
       </a>
     </ng-container>
   </div>
-  <div *ngIf="!editing" tabindex="0" class="p-2"
-    [ngClass]="{'has-changes': hasChanged}" (keyup.enter)="toggleEditMode()" 
-      (click)="toggleEditMode()">
+  <div tabindex="0" class="p-2" *ngIf="!editing || multiValue()"
+    [ngClass]="{'has-changes': hasChanged}">
     <div class="d-flex" 
       *ngFor="let count of labelCounts | keyvalue; let idx = index">
-      <ng-container *ngIf="!expanded && idx === defaultDisplayCount">
+      <ng-container *ngIf="!expanded && !editing && idx === defaultDisplayCount">
         <span class="text-info" i18n>...</span>
       </ng-container>
-      <ng-container *ngIf="expanded || idx < defaultDisplayCount">
-        <div class="flex-1">
+      <ng-container *ngIf="expanded || editing || idx < defaultDisplayCount">
+        <ng-container *ngIf="editing">
+          <div class="ml-4 mr-2">
+            <input type="checkbox" class="form-check-input" 
+              [(ngModel)]="editValues[count.key]"/>
+          </div>
+        </ng-container>
+        <div class="flex-1"
+          (click)="toggleEditMode()" (keyup.enter)="toggleEditMode()">
           <ng-container *ngIf="displayAs == 'bool'">
             <span *ngIf="count.key == 't'" i18n>Yes</span>
             <span *ngIf="count.key == 'f'" i18n>No</span>
@@ -41,7 +47,9 @@
             <ng-template #default>{{count.key}}</ng-template>
           </ng-container>
         </div>
-        <div i18n>{{count.value}} copies</div>
+        <div (click)="toggleEditMode()" (keyup.enter)="toggleEditMode()" i18n>
+          {{count.value}} copies
+        </div>
       </ng-container>
     </div>
   </div>
index 55519df..e970e2d 100644 (file)
@@ -7,6 +7,13 @@ import {StringComponent} from '@eg/share/string/string.component';
  * updates to batches of items.
  */
 
+
+// Map of display value to boolean indicating whether a given item
+// should be modified.
+export interface BatchChangeSelection {
+    [value: string]: boolean;
+}
+
 @Component({
   selector: 'eg-batch-item-attr',
   templateUrl: 'batch-item-attr.component.html',
@@ -50,7 +57,9 @@ export class BatchItemAttrComponent {
     // and expandy.
     @Input() defaultDisplayCount = 7;
 
-    @Output() changesSaved: EventEmitter<void> = new EventEmitter<void>();
+    @Output() changesSaved: EventEmitter<BatchChangeSelection> =
+        new EventEmitter<BatchChangeSelection>();
+
     @Output() changesCanceled: EventEmitter<void> = new EventEmitter<void>();
     @Output() valueCleared: EventEmitter<void> = new EventEmitter<void>();
 
@@ -62,12 +71,15 @@ export class BatchItemAttrComponent {
     // Showing all entries?
     expanded = false;
 
+    // Indicate which display values the user wants to modify.
+    editValues: BatchChangeSelection = {};
+
     constructor() {}
 
     save() {
         this.hasChanged = true;
         this.editing = false;
-        this.changesSaved.emit();
+        this.changesSaved.emit(this.editValues);
     }
 
     cancel() {
@@ -85,6 +97,10 @@ export class BatchItemAttrComponent {
         return Object.keys(this.labelCounts).length > this.defaultDisplayCount;
     }
 
+    multiValue(): boolean {
+        return Object.keys(this.labelCounts).length > 1;
+    }
+
     toggleEditMode() {
         if (this.readOnly) { return; }
 
@@ -92,11 +108,17 @@ export class BatchItemAttrComponent {
 
         // Avoid using selectRootElement to focus.
         // https://stackoverflow.com/a/36059595
-        if (this.editing && this.editInputDomId) {
-            setTimeout(() => {
-                const node = document.getElementById(this.editInputDomId);
-                if (node) { node.focus(); }
-            });
+        if (this.editing) {
+
+            Object.keys(this.labelCounts).forEach(
+                key => this.editValues[key] = true);
+
+            if (this.editInputDomId) {
+                setTimeout(() => {
+                    const node = document.getElementById(this.editInputDomId);
+                    if (node) { node.focus(); }
+                });
+            }
         }
     }
 }