LP1901930 SIP account admin UI WIP
authorBill Erickson <berickxx@gmail.com>
Fri, 13 Nov 2020 15:29:13 +0000 (10:29 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 30 Nov 2020 16:38:26 +0000 (08:38 -0800)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account.component.ts

index a13caa8..82e5989 100644 (file)
   hiddenFields="id" fieldOrder="label,institution">
 </eg-fm-record-editor>
 
+<eg-fm-record-editor #settingDialog idlClass="sipset" mode="update" 
+  hiddenFields="id,setting_group" fieldOrder="name,description,value"
+  [fieldOptions]="{name:{isReadonly:true}}">
+</eg-fm-record-editor>
+
 <div class="row mt-2" *ngIf="account">
   <div class="col-lg-6">
 
       <span class="font-weight-bold">{{account.setting_group().label()}}</span>
     </h4>
 
-    <eg-grid idlClass="sipset" [dataSource]="settingsSource" [sortable]="true"
+    <span class="font-italic mt-2 mb-2" i18n>
+      Setting values must be entered as valid JSON.
+    </span>
+
+    <eg-grid #settingGrid idlClass="sipset" [dataSource]="settingsSource" 
+      [sortable]="true" (onRowActivate)="editSetting($event)"
       persistKey="admin.server.sip.account.settings" hideFields="id,setting_group">
+      <eg-grid-toolbar-action label="Edit Selected" i18n-label 
+        (onClick)="editFirstSetting($event)">
+      </eg-grid-toolbar-action>
     </eg-grid>
   </div>
 </div>
index b43dce7..e1c204e 100644 (file)
@@ -1,7 +1,7 @@
 import {Component, Input, ViewChild, OnInit} from '@angular/core';
 import {ActivatedRoute} from '@angular/router';
 import {Observable, of} from 'rxjs';
-import {map, switchMap} from 'rxjs/operators';
+import {map, tap, switchMap, catchError} from 'rxjs/operators';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {AuthService} from '@eg/core/auth.service';
@@ -12,6 +12,7 @@ import {StringService} from '@eg/share/string/string.service';
 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.component';
+import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {Pager} from '@eg/share/util/pager';
 
@@ -28,6 +29,8 @@ export class SipAccountComponent implements OnInit {
     settingsSource: GridDataSource = new GridDataSource();
 
     @ViewChild('cloneDialog') cloneDialog: FmRecordEditorComponent;
+    @ViewChild('settingDialog') settingDialog: FmRecordEditorComponent;
+    @ViewChild('settingGrid') settingGrid: GridComponent;
 
     constructor(
         private route: ActivatedRoute,
@@ -36,9 +39,10 @@ export class SipAccountComponent implements OnInit {
     ) {}
 
     ngOnInit() {
+
         this.route.paramMap.subscribe(map => {
             this.accountId = Number(map.get('id'));
-            this.loadAccount();
+            this.loadAccount().toPromise(); // force it to run
         });
 
         this.usrCboxSource = term => {
@@ -74,19 +78,19 @@ export class SipAccountComponent implements OnInit {
         }
     }
 
-    loadAccount() {
-        this.pcrud.retrieve('sipacc', this.accountId, {
+    loadAccount(): Observable<any> {
+        return this.pcrud.retrieve('sipacc', this.accountId, {
             flesh: 2,
             flesh_fields: {
                 sipacc: ['usr', 'setting_group', 'workstation'],
                 sipsetg: ['settings']
             }}, {authoritative: true}
-        ).subscribe(acc => {
+        ).pipe(tap(acc => {
             this.account = acc;
             this.usrId = acc.usr().id();
             this.usrCboxEntries =
                 [{id: acc.usr().id(), label: acc.usr().usrname()}];
-        });
+        }));
     }
 
     grpChanged(entry: ComboboxEntry) {
@@ -126,5 +130,29 @@ export class SipAccountComponent implements OnInit {
     accountSaved() {
         this.loadAccount();
     }
+
+    editFirstSetting(rows: any) {
+        if (rows.length > 0) {
+            this.editSetting(rows[0]);
+        }
+    }
+
+    editSetting(row: any) {
+        this.settingDialog.record = this.idl.clone(row);
+        this.settingDialog.open().subscribe(
+            ok => {
+                // Easier to simply refresh the whole account.
+                // After refresh, force a grid reload.
+                this.loadAccount().subscribe(ok2 => {
+                    setTimeout(() => {
+                        if (this.settingGrid) {
+                            this.settingGrid.reload();
+                        }
+                    });
+                });
+            },
+            err => {} // todo toast
+        );
+    }
 }