LPXXX volcopy autsave prefs; lint
authorBill Erickson <berickxx@gmail.com>
Fri, 17 Jul 2020 15:03:04 +0000 (11:03 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 17 Jul 2020 15:03:04 +0000 (11:03 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/config.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/config.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts

index 02bc4a1..22e75b1 100644 (file)
@@ -1,10 +1,9 @@
-<div class="row d-flex">
+<div class="d-flex">
+  <h3 class="mt-3" i18n>Holdings Preferences</h3>
   <div class="flex-1"></div>
-  <button class="btn btn-outline-dark" (click)="save()" i18n>Save Preferences</button>
+  <div i18n class="font-italic">Changes are saved automatically.</div>
 </div>
 
-<h3 class="mt-3" i18n>Holdings Preferences</h3>
-
 <div class="row">
   <div class="col-lg-6">
     <div class="row">
   from the Item Attributes Form.
 </span>
 
-<div class="row d-flex">
+<div class="row d-flex pb-5">
 
   <!-- COLUMN 1 -->
   <div class="flex-1 p-1">
   </div>
 </div>
 
-<div class="row d-flex">
-  <div class="flex-1"></div>
-  <button class="btn btn-outline-dark" (click)="save()" i18n>Save Preferences</button>
-</div>
-
-
index 5716f9e..f5d648f 100644 (file)
@@ -1,53 +1,57 @@
-import {Component, Input, OnInit, AfterViewInit, ViewChild, Renderer2} from '@angular/core';
+import {Component, Input, OnInit, ViewChild, DoCheck} from '@angular/core';
 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
 import {tap} from 'rxjs/operators';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
-import {EventService} from '@eg/core/event.service';
-import {OrgService} from '@eg/core/org.service';
-import {StoreService} from '@eg/core/store.service';
-import {NetService} from '@eg/core/net.service';
-import {AuthService} from '@eg/core/auth.service';
-import {PcrudService} from '@eg/core/pcrud.service';
-import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
 import {VolCopyContext} from './volcopy';
 import {VolCopyService} from './volcopy.service';
-import {FormatService} from '@eg/core/format.service';
-import {StringComponent} from '@eg/share/string/string.component';
-import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
 
 @Component({
   selector: 'eg-volcopy-config',
   templateUrl: 'config.component.html'
 })
-export class VolCopyConfigComponent implements OnInit, AfterViewInit {
+export class VolCopyConfigComponent implements OnInit, DoCheck {
 
     @Input() context: VolCopyContext;
 
+    defaultsCopy: any;
+
     constructor(
         private router: Router,
         private route: ActivatedRoute,
-        private renderer: Renderer2,
-        private evt: EventService,
         private idl: IdlService,
-        private org: OrgService,
-        private net: NetService,
-        private auth: AuthService,
-        private pcrud: PcrudService,
-        private holdings: HoldingsService,
-        private format: FormatService,
-        private store: StoreService,
         public  volcopy: VolCopyService
-    ) { }
+    ) {}
 
     ngOnInit() {
-        console.log('DEFAULTS', this.volcopy.defaults);
+        console.debug('DEFAULTS', this.volcopy.defaults);
+
+        // Not an IDL object, but clones just the same
+        this.defaultsCopy = this.idl.clone(this.volcopy.defaults);
     }
 
-    ngAfterViewInit() {
+    // Watch for changes in the form and auto-save them.
+    ngDoCheck() {
+        const hidden = this.volcopy.defaults.hidden;
+        for (const key in hidden) {
+            if (hidden[key] !== this.defaultsCopy.hidden[key]) {
+                this.save();
+                return;
+            }
+        }
+
+        const values = this.volcopy.defaults.values;
+        for (const key in values) {
+            if (values[key] !== this.defaultsCopy.values[key]) {
+                this.save();
+                return;
+            }
+        }
     }
 
     save() {
-        this.volcopy.saveDefaults();
+        this.volcopy.saveDefaults().then(_ =>
+            this.defaultsCopy = this.idl.clone(this.volcopy.defaults)
+        );
     }
 }
 
index 91cae6f..25743a9 100644 (file)
@@ -381,7 +381,6 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
                 entry = this.idl.create('asce');
                 entry.stat_cat(catId);
                 copy.stat_cat_entries().push(entry);
-                console.log('1', entry);
             }
 
             entry.id(entryId);
@@ -413,7 +412,6 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
     openCopyTags() {
         this.copyTagsDialog.inPlaceMode = true;
         this.copyTagsDialog.copyIds = this.context.copyList().map(c => c.id());
-        console.log('IDS', this.copyTagsDialog.copyIds);
 
         this.copyTagsDialog.open({size: 'lg'}).subscribe(newTags => {
             if (!newTags || newTags.length === 0) { return; }
index 983cdd4..35ee7db 100644 (file)
@@ -93,7 +93,6 @@ export class VolEditComponent implements OnInit {
 
     // Column width (flex:x) for column by column number.
     flexAt(column: number): number {
-        //return this.flexSettings[column];
         return this.flexSpan(column, column);
     }
 
index 3ca7101..1d15c9c 100644 (file)
@@ -364,7 +364,6 @@ export class VolCopyComponent implements OnInit {
             let vol = volumes.filter(v => v.id() === copyVol.id())[0];
 
             if (vol) {
-                console.log('Adding deleted copy to vol deleted=' + vol.isdeleted());
                 vol.copies().push(cloneCopy);
             } else {
                 vol = this.idl.clone(copyVol);