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>
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';
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';
settingsSource: GridDataSource = new GridDataSource();
@ViewChild('cloneDialog') cloneDialog: FmRecordEditorComponent;
+ @ViewChild('settingDialog') settingDialog: FmRecordEditorComponent;
+ @ViewChild('settingGrid') settingGrid: GridComponent;
constructor(
private route: ActivatedRoute,
) {}
ngOnInit() {
+
this.route.paramMap.subscribe(map => {
this.accountId = Number(map.get('id'));
- this.loadAccount();
+ this.loadAccount().toPromise(); // force it to run
});
this.usrCboxSource = term => {
}
}
- 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) {
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
+ );
+ }
}