LP1846552 Shelving location Order handle new locations
authorBill Erickson <berickxx@gmail.com>
Wed, 15 Sep 2021 14:21:25 +0000 (10:21 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 16 Mar 2022 20:41:23 +0000 (16:41 -0400)
Ensure that copy locations added since the last time location order
entries were saved are displayed.

Show when a location is "unsaved" in the UI.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/local/copy-loc-order/copy-loc-order.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/copy-loc-order/copy-loc-order.component.ts

index c37cf0a..6c42172 100644 (file)
@@ -27,7 +27,7 @@
         class="mr-2 btn btn-sm btn-outline-dark .mat-icon-shrunk-in-button">
         <span class="material-icons">vertical_align_bottom</span>
       </button>
-      <span class="ml-2 font-italic" *ngIf="selectedEntry">
+      <span class="ml-2 font-italic" *ngIf="selected()">
         Selected: {{selected().location().name()}} 
           ({{orgSn(selected().location().owning_lib())}})
       </span>
@@ -52,6 +52,7 @@
           [ngClass]="{'border border-primary rounded': selectedEntry == entry.id()}">
           {{entry.location().name()}} ({{orgSn(entry.location().owning_lib())}})
         </span>
+        <span *ngIf="entry.isnew()" class="ml-2 font-italic text-info">(unsaved)</span>
       </div>
     </div>
   </li>
index 56e9b1a..fb9eb4e 100644 (file)
@@ -70,21 +70,27 @@ export class CopyLocOrderComponent implements OnInit {
 
         .then(_ => {
 
-            if (this.entries.length > 0) { return; }
-
-            // If we have no position entries, create some now so they
-            // can become the basis of our new list.
+            // Ensure we have an entry for every in-range copy location.
 
             const locs = Object.values(this.locations)
                 .sort((o1, o2) => o1.name() < o2.name() ? -1 : 1);
 
-            let pos = 1;
+            let pos = this.entries.length;
+
             locs.forEach(loc => {
-                const entry = this.idl.create('acplo');
+                pos++;
+
+                let entry = this.entries.filter(e => e.location().id() === loc.id())[0];
+                if (entry) { return; }
+
+                // Either we have no entries or we encountered a new copy
+                // location added since the last time entries were saved.
+
+                entry = this.idl.create('acplo');
                 entry.isnew(true);
-                entry.id(-pos); // avoid using '0' as an ID
+                entry.id(-pos); // local temp ID
                 entry.location(loc);
-                entry.position(pos++);
+                entry.position(pos);
                 entry.org(this.contextOrg);
                 this.entries.push(entry);
             });