LP1901930 SIP account admin UI WIP
authorBill Erickson <berickxx@gmail.com>
Tue, 10 Nov 2020 17:04:39 +0000 (12:04 -0500)
committerBill Erickson <berickxx@gmail.com>
Tue, 10 Nov 2020 17:04:39 +0000 (12:04 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account-list.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/sip/account-list.component.ts
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 a0aa755..ad1357a 100644 (file)
@@ -4,15 +4,8 @@
 
 <eg-grid #grid idlClass="sipacc" [dataSource]="gridSource" 
   [stickyHeader]="true" [sortable]="true" (onRowActivate)="openAccount($event)">
-  <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected">
+  <eg-grid-toolbar-action label="Delete Selected" i18n-label 
+    (onClick)="deleteSelected($event)">
   </eg-grid-toolbar-action>
-  <!--
-  <eg-grid-column name="test" [cellTemplate]="cellTmpl" 
-    [cellContext]="btGridTestContext" [sortable]="false">
-  </eg-grid-column>
-  <eg-grid-column [sortable]="false" path="owner.name"></eg-grid-column>
-  <eg-grid-column [sortable]="false" path="datetime_test" 
-    datatype="timestamp" [datePlusTime]="true"></eg-grid-column>
-    -->
 </eg-grid>
 
index 0188990..adea861 100644 (file)
@@ -52,5 +52,9 @@ export class SipAccountListComponent implements OnInit {
     openAccount(row: any) {
         this.router.navigate([`/staff/admin/server/sip/account/${row.id()}`]);
     }
+
+    deleteSelected(rows: any[]) {
+        // TODO
+    }
 }
 
index a395f1e..ae35b9a 100644 (file)
@@ -1,2 +1,20 @@
+<eg-staff-banner bannerText="SIP Account" i18n-bannerText></eg-staff-banner>
+
+<div class="row" *ngIf="account">
+  <div class="col-lg-6">
+
+    <ng-template #usrTemplate>
+      <eg-combobox #usrCbox [entries]="usrCboxEntries" 
+        [selectedId]="usrId" [asyncDataSource]="usrCboxSource">
+      </eg-combobox>
+    </ng-template>
+
+    <eg-fm-record-editor #editor
+      idlClass="sipacc" mode="update" hiddenFields="id" displayMode="inline"
+      fieldOrder="sip_username,setting_group,usr,workstation,transient,activity_who,enabled"
+      [fieldOptions]="{usr:{customTemplate:{template:usrTemplate}}}"
+      (recordSaved)="accountSaved()" [recordId]="accountId">
+    </eg-fm-record-editor>
+  </div>
+</div>
 
-<b>account</b>
index 5e17854..32584d4 100644 (file)
@@ -1,4 +1,7 @@
 import {Component, Input, ViewChild, OnInit} from '@angular/core';
+import {ActivatedRoute} from '@angular/router';
+import {Observable, of} from 'rxjs';
+import {map} 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';
@@ -8,14 +11,60 @@ import {StringComponent} from '@eg/share/string/string.component';
 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} from '@eg/share/combobox/combobox.component';
+import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.component';
 
 @Component({
     templateUrl: './account.component.html'
 })
 export class SipAccountComponent implements OnInit {
 
+    accountId: number;
+    account: IdlObject;
+    usrCboxSource: (term: string) => Observable<ComboboxEntry>;
+    usrCboxEntries: ComboboxEntry[];
+    usrId: number;
+
+    //@ViewChild() usrCbox: ComboboxComponent;
+
+    constructor(
+        private route: ActivatedRoute,
+        private pcrud: PcrudService
+    ) {}
+
     ngOnInit() {
+        this.route.paramMap.subscribe(map => {
+            this.accountId = Number(map.get('id'));
+            this.loadAccount();
+        });
+
+        this.usrCboxSource = term => {
+            return this.pcrud.search('au',
+                {   '-or': [
+                        {id: this.account.usr().id()},
+                        {usrname: {'ilike': `%${term}%`}}
+                    ],
+                },
+                {order_by: {au: 'usrname'}}
+            ).pipe(map(user => {
+                return {id: user.id(), label: user.usrname()};
+            }));
+        };
+    }
+
+    loadAccount() {
+        this.pcrud.retrieve('sipacc', this.accountId, {
+            flesh: 1,
+            flesh_fields: {sipacc: ['usr', 'setting_group', 'workstation']}
+        }).subscribe(acc => {
+            this.account = acc;
+            this.usrId = acc.usr().id();
+            this.usrCboxEntries =
+                [{id: acc.usr().id(), label: acc.usr().usrname()}];
+        });
+    }
+
+    accountSaved() {
+        this.loadAccount();
     }
 }