LP1839341: Small tweaks to org unit settings UI
authorJane Sandberg <sandbej@linnbenton.edu>
Fri, 11 Sep 2020 00:24:22 +0000 (17:24 -0700)
committerJane Sandberg <sandbergja@gmail.com>
Thu, 13 Oct 2022 16:04:00 +0000 (09:04 -0700)
* Changes Edit link into a button so that the modal opens
* Adds [flex] widths to grid columns
* Removes some unnecessary @Import statements
* Fixes lint errors

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/edit-org-unit-setting-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-history-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-setting-json-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings-routing.module.ts
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/org-unit-settings/org-unit-settings.module.ts

index 81f79fe..13ef179 100644 (file)
@@ -1,11 +1,7 @@
-import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
+import {Component} from '@angular/core';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
-import {AuthService} from '@eg/core/auth.service';
-import {NetService} from '@eg/core/net.service';
-import {OrgService} from '@eg/core/org.service';
 import {IdlObject} from '@eg/core/idl.service';
-import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
-import {OrgUnitSetting} from '@eg/staff/admin/local/org-unit-settings/org-unit-settings.component';
+import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
 
 @Component({
   selector: 'eg-admin-edit-org-unit-setting-dialog',
@@ -21,9 +17,6 @@ export class EditOuSettingDialogComponent extends DialogComponent {
     linkedFieldOptions: IdlObject[];
 
     constructor(
-        private auth: AuthService,
-        private net: NetService,
-        private org: OrgService,
         private modal: NgbModal
     ) {
         super(modal);
index 62823d3..200c25b 100644 (file)
@@ -1,33 +1,26 @@
-import {Component, Input, ViewChild, OnInit, TemplateRef} from '@angular/core';
-import {Observable, Observer, of} from 'rxjs';
+import {Component, OnInit, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
-import {AuthService} from '@eg/core/auth.service';
-import {NetService} from '@eg/core/net.service';
 import {OrgService} from '@eg/core/org.service';
 import {Pager} from '@eg/share/util/pager';
 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {GridComponent} from '@eg/share/grid/grid.component';
-import {GridToolbarCheckboxComponent
-    } from '@eg/share/grid/grid-toolbar-checkbox.component';
-import {OrgUnitSetting} from '@eg/staff/admin/local/org-unit-settings/org-unit-settings.component';
 
 @Component({
     selector: 'eg-admin-ou-setting-history-dialog',
     templateUrl: './org-unit-setting-history-dialog.component.html'
 })
 
-export class OuSettingHistoryDialogComponent extends DialogComponent {
+export class OuSettingHistoryDialogComponent extends DialogComponent implements OnInit {
 
     entry: any = {};
     history: any[] = [];
     gridDataSource: GridDataSource;
-    @ViewChild('historyGrid', { static:true }) historyGrid: GridComponent;
+    @ViewChild('historyGrid', { static: true }) historyGrid: GridComponent;
 
 
     constructor(
-        private auth: AuthService,
-        private net: NetService,
         private org: OrgService,
         private modal: NgbModal
     ) {
@@ -50,9 +43,9 @@ export class OuSettingHistoryDialogComponent extends DialogComponent {
 
     revert(log) {
         if (log) {
-            var intTypes = ["integer", "currency", "link"];
+            const intTypes = ['integer', 'currency', 'link'];
             if (intTypes.includes(this.entry.dataType)) {
-                log.new_value = parseInt(log.new_value);
+                log.new_value = Number(log.new_value);
             } else {
                 log.new_value = log.new_value.replace(/^"(.*)"$/, '$1');
             }
@@ -64,4 +57,4 @@ export class OuSettingHistoryDialogComponent extends DialogComponent {
             this.gridDataSource.data = null;
         }
     }
-}
\ No newline at end of file
+}
index f2eb3aa..adb8cb9 100644 (file)
@@ -1,7 +1,6 @@
-import {Component, Input, ViewChild, TemplateRef} from '@angular/core';
+import {Component, Input} from '@angular/core';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
-import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
-import {OrgUnitSetting} from '@eg/staff/admin/local/org-unit-settings/org-unit-settings.component';
+import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
 
 @Component({
   selector: 'eg-admin-ou-setting-json-dialog',
@@ -25,4 +24,4 @@ export class OuSettingJsonDialogComponent extends DialogComponent {
             jsonData: this.jsonData
         });
     }
-}
\ No newline at end of file
+}
index 8c1e88d..533c975 100644 (file)
@@ -44,7 +44,7 @@
         (click)="showJsonDialog(false)" i18n>Import</button>
     </div>
   </div>
-  
+
 </div>
 <!-- Org Unit Settings Grid -->
 <div class='w-11 mt-3'>
     [sortable]="false" [showDeclaredFieldsOnly]="true"
     persistKey="admin.actor.org_unit_settings">
 
-    <eg-grid-column i18n-label label="Edit" name="edit"
+    <eg-grid-column i18n-label label="Edit" name="edit" [flex]="1"
       [cellTemplate]="editCellTemplate"></eg-grid-column>
-    <eg-grid-column i18n-label label="History" name="history"
+    <eg-grid-column i18n-label label="History" name="history" [flex]="1"
       [cellTemplate]="historyCellTemplate"></eg-grid-column>
-    <eg-grid-column path="name" label="Name" i18n-label [hidden]="true"></eg-grid-column>
-    <eg-grid-column path="grp" label="Group" i18n-label></eg-grid-column>
-    <eg-grid-column path="label" label="Setting" [index]="true" i18n-label></eg-grid-column>
-    <eg-grid-column path="context.shortname()" label="Context" i18n-label></eg-grid-column>
-    <eg-grid-column path="value_str" label="Value" i18n-label></eg-grid-column>
-    
+    <eg-grid-column path="name" label="Name" i18n-label [hidden]="true" [flex]="3"></eg-grid-column>
+    <eg-grid-column path="grp" label="Group" i18n-label [flex]="1"></eg-grid-column>
+    <eg-grid-column path="label" label="Setting" [index]="true" i18n-label [flex]="4"></eg-grid-column>
+    <eg-grid-column path="context.shortname()" label="Context" i18n-label [flex]="1"></eg-grid-column>
+    <eg-grid-column path="value_str" label="Value" i18n-label [flex]="1"></eg-grid-column>
+
   </eg-grid>
 </div>
 
 <ng-template #editCellTemplate let-entry="row">
   <span>
-    <a
-      (click)="showEditSettingValueDialog(entry)" class="pl-1"
-      [routerLink]="" i18n>
+    <button (click)="showEditSettingValueDialog(entry)"
+      class="btn btn-primary" i18n>
       Edit
-    </a>
+    </button>
   </span>
 </ng-template>
 
@@ -84,4 +83,4 @@
       History
     </a>
   </span>
-</ng-template>
\ No newline at end of file
+</ng-template>
index 60451ed..d0b1092 100644 (file)
@@ -1,8 +1,5 @@
-import {Component, OnInit, Input, ViewChild, ViewEncapsulation
-    } from '@angular/core';
-import {Router} from '@angular/router';
-import {Observable, Observer, of} from 'rxjs';
-import {map} from 'rxjs/operators';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {Observable, Observer} from 'rxjs';
 import {Pager} from '@eg/share/util/pager';
 import {IdlObject, IdlService} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
@@ -11,10 +8,6 @@ import {AuthService} from '@eg/core/auth.service';
 import {NetService} from '@eg/core/net.service';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {GridComponent} from '@eg/share/grid/grid.component';
-import {GridToolbarCheckboxComponent
-    } from '@eg/share/grid/grid-toolbar-checkbox.component';
-import {StoreService} from '@eg/core/store.service';
-import {ServerStoreService} from '@eg/core/server-store.service';
 import {ToastService} from '@eg/share/toast/toast.service';
 
 import {EditOuSettingDialogComponent
@@ -44,7 +37,7 @@ export class OrgUnitSetting {
     templateUrl: './org-unit-settings.component.html'
 })
 
-export class OrgUnitSettingsComponent {
+export class OrgUnitSettingsComponent implements OnInit {
 
     contextOrg: IdlObject;
 
@@ -55,13 +48,13 @@ export class OrgUnitSettingsComponent {
     currentHistory: any[];
     currentOptions: any[];
     jsonFieldData: {};
-    @ViewChild('orgUnitSettingsGrid', { static:true }) orgUnitSettingsGrid: GridComponent;
+    @ViewChild('orgUnitSettingsGrid', { static: true }) orgUnitSettingsGrid: GridComponent;
 
-    @ViewChild('editOuSettingDialog', { static:true })
+    @ViewChild('editOuSettingDialog', { static: true })
         private editOuSettingDialog: EditOuSettingDialogComponent;
-    @ViewChild('orgUnitSettingHistoryDialog', { static:true })
+    @ViewChild('orgUnitSettingHistoryDialog', { static: true })
         private orgUnitSettingHistoryDialog: OuSettingHistoryDialogComponent;
-    @ViewChild('ouSettingJsonDialog', { static:true })
+    @ViewChild('ouSettingJsonDialog', { static: true })
         private ouSettingJsonDialog: OuSettingJsonDialogComponent;
 
     refreshSettings: boolean;
@@ -72,13 +65,9 @@ export class OrgUnitSettingsComponent {
     @Input() filterString: string;
 
     constructor(
-        private router: Router,
         private org: OrgService,
-        private idl: IdlService,
         private pcrud: PcrudService,
         private auth: AuthService,
-        private store: ServerStoreService,
-        private localStore: StoreService,
         private toast: ToastService,
         private net: NetService,
     ) {
@@ -95,7 +84,7 @@ export class OrgUnitSettingsComponent {
         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
             return this.fetchSettingTypes(pager);
         };
-        this.orgUnitSettingsGrid.onRowActivate.subscribe((setting:OrgUnitSetting) => {
+        this.orgUnitSettingsGrid.onRowActivate.subscribe((setting: OrgUnitSetting) => {
             this.showEditSettingValueDialog(setting);
         });
     }
@@ -129,17 +118,17 @@ export class OrgUnitSettingsComponent {
                  this.contextOrg.id(), settingNames, this.auth.token()
             ).subscribe(
                 blob => {
-                    let settingVals = Object.keys(blob).map(key => {
-                        return {'name': key, 'setting': blob[key]}
+                    const settingVals = Object.keys(blob).map(key => {
+                        return {'name': key, 'setting': blob[key]};
                     });
                     settingVals.forEach(key => {
                         if (key.setting) {
-                            let settingsObj = this.settingTypeArr.filter(
-                                setting => setting.name == key.name
+                            const settingsObj = this.settingTypeArr.filter(
+                                setting => setting.name === key.name
                             )[0];
                             settingsObj.value = key.setting.value;
                             settingsObj.value_str = settingsObj.value;
-                            if (settingsObj.dataType == 'link' && (key.setting.value || key.setting.value == 0)) {
+                            if (settingsObj.dataType === 'link' && (key.setting.value || key.setting.value === 0)) {
                                 this.fetchLinkedField(settingsObj.fmClass, key.setting.value, settingsObj.value_str).then(res => {
                                     settingsObj.value_str = res;
                                 });
@@ -165,13 +154,13 @@ export class OrgUnitSettingsComponent {
     }
 
     fetchHistory(setting): Promise<any> {
-        let name = setting.name;
+        const name = setting.name;
         return new Promise((resolve, reject) => {
             this.net.request(
                 'open-ils.actor',
                 'open-ils.actor.org_unit.settings.history.retrieve',
                 this.auth.token(), name, this.contextOrg.id()
-            ).subscribe(res=> {
+            ).subscribe(res => {
                 this.currentHistory = [];
                 if (!Array.isArray(res)) {
                     res = [res];
@@ -180,20 +169,20 @@ export class OrgUnitSettingsComponent {
                     log.org = this.org.get(log.org);
                     log.new_value_str = log.new_value;
                     log.original_value_str = log.original_value;
-                    if (setting.dataType == "link") {
+                    if (setting.dataType === 'link') {
                         if (log.new_value) {
-                            this.fetchLinkedField(setting.fmClass, parseInt(log.new_value), log.new_value_str).then(val => {
+                            this.fetchLinkedField(setting.fmClass, Number(log.new_value), log.new_value_str).then(val => {
                                 log.new_value_str = val;
                             });
                         }
                         if (log.original_value) {
-                            this.fetchLinkedField(setting.fmClass, parseInt(log.original_value), log.original_value_str).then(val => {
+                            this.fetchLinkedField(setting.fmClass, Number(log.original_value), log.original_value_str).then(val => {
                                 log.original_value_str = val;
                             });
                         }
                     }
-                    if (log.new_value_str) log.new_value_str = log.new_value_str.replace(/^"(.*)"$/, '$1');
-                    if (log.original_value_str) log.original_value_str = log.original_value_str.replace(/^"(.*)"$/, '$1');
+                    if (log.new_value_str) { log.new_value_str = log.new_value_str.replace(/^"(.*)"$/, '$1'); }
+                    if (log.original_value_str) { log.original_value_str = log.original_value_str.replace(/^"(.*)"$/, '$1'); }
                 });
                 this.currentHistory = res;
                 this.currentHistory.sort((a, b) => {
@@ -201,21 +190,22 @@ export class OrgUnitSettingsComponent {
                 });
 
                 resolve(this.currentHistory);
-            }, err=>{reject(err);});
+            }, err => {reject(err); });
         });
     }
 
     allocateSettingTypes(coust: IdlObject) {
-        let entry = new OrgUnitSetting();
+        const entry = new OrgUnitSetting();
         entry.name = coust.name();
         entry.label = coust.label();
         entry.dataType = coust.datatype();
-        if (coust.fm_class()) entry.fmClass = coust.fm_class();
-        if (coust.description()) entry.description = coust.description();
+        if (coust.fm_class()) { entry.fmClass = coust.fm_class(); }
+        if (coust.description()) { entry.description = coust.description(); }
         // For some reason some setting types don't have a grp, should look into this...
-        if (coust.grp()) entry.grp = coust.grp().label();
-        if (coust.view_perm()) 
+        if (coust.grp()) { entry.grp = coust.grp().label(); }
+        if (coust.view_perm()) {
             entry.view_perm = coust.view_perm().code();
+        }
 
         this.settingTypeArr.push(entry);
     }
@@ -230,20 +220,20 @@ export class OrgUnitSettingsComponent {
     }
 
     applyFilter(clear?: boolean) {
-        if (clear) this.filterString = '';
+        if (clear) { this.filterString = ''; }
         this.updateGrid(this.contextOrg);
     }
-    
+
     updateSetting(obj, entry) {
         this.net.request(
             'open-ils.actor',
             'open-ils.actor.org_unit.settings.update',
             this.auth.token(), obj.context.id(), obj.setting
-        ).toPromise().then(res=> {
-            this.toast.success(entry.label + " Updated.");
+        ).toPromise().then(res => {
+            this.toast.success(entry.label + ' Updated.');
             if (!obj.setting[entry.name]) {
-                let settingsObj = this.settingTypeArr.filter(
-                    setting => setting.name == entry.name
+                const settingsObj = this.settingTypeArr.filter(
+                    setting => setting.name === entry.name
                 )[0];
                 settingsObj.value = null;
                 settingsObj.value_str = null;
@@ -253,7 +243,7 @@ export class OrgUnitSettingsComponent {
             this.mergeSettingValues();
         },
         err => {
-            this.toast.danger(entry.label + " failed to update: " + err.desc);
+            this.toast.danger(entry.label + ' failed to update: ' + err.desc);
         });
     }
 
@@ -281,38 +271,39 @@ export class OrgUnitSettingsComponent {
                         }
                     });
                 }
-            )
+            );
         }
     }
 
     showJsonDialog(isExport: boolean) {
         this.ouSettingJsonDialog.isExport = isExport;
-        this.ouSettingJsonDialog.jsonData = "";
+        this.ouSettingJsonDialog.jsonData = '';
         if (isExport) {
-            this.ouSettingJsonDialog.jsonData = "{";
+            this.ouSettingJsonDialog.jsonData = '{';
             this.gridDataSource.data.forEach(entry => {
                 this.ouSettingJsonDialog.jsonData +=
-                    "\"" + entry.name + "\": {\"org\": \"" +
-                    this.contextOrg.id() + "\", \"value\": ";
+                    '"' + entry.name + '": {"org": "' +
+                    this.contextOrg.id() + '", "value": ';
                 if (entry.value) {
-                    this.ouSettingJsonDialog.jsonData += "\"" + entry.value + "\"";
+                    this.ouSettingJsonDialog.jsonData += '"' + entry.value + '"';
                 } else {
-                    this.ouSettingJsonDialog.jsonData += "null";
+                    this.ouSettingJsonDialog.jsonData += 'null';
+                }
+                this.ouSettingJsonDialog.jsonData += '}';
+                if (this.gridDataSource.data.indexOf(entry) !== (this.gridDataSource.data.length - 1)) {
+                    this.ouSettingJsonDialog.jsonData += ',';
                 }
-                this.ouSettingJsonDialog.jsonData += "}";
-                if (this.gridDataSource.data.indexOf(entry) != (this.gridDataSource.data.length - 1))
-                    this.ouSettingJsonDialog.jsonData += ",";
             });
-            this.ouSettingJsonDialog.jsonData += "}";
+            this.ouSettingJsonDialog.jsonData += '}';
         }
 
         this.ouSettingJsonDialog.open({size: 'lg'}).subscribe(res => {
             if (res.apply && res.jsonData) {
-                let jsonSettings = JSON.parse(res.jsonData);
+                const jsonSettings = JSON.parse(res.jsonData);
                 Object.entries(jsonSettings).forEach((fields) => {
-                    let entry = this.settingTypeArr.find(x => x.name == fields[0]);
-                    let obj = {setting: {}, context: {}};
-                    let val = this.parseValType(fields[1]['value'], entry.dataType);
+                    const entry = this.settingTypeArr.find(x => x.name === fields[0]);
+                    const obj = {setting: {}, context: {}};
+                    const val = this.parseValType(fields[1]['value'], entry.dataType);
                     obj.setting[fields[0]] = val;
                     obj.context = this.org.get(fields[1]['org']);
                     this.updateSetting(obj, entry);
@@ -322,23 +313,23 @@ export class OrgUnitSettingsComponent {
     }
 
     parseValType(value, dataType) {
-        if (dataType == "integer" || "currency" || "link") {
+        if (dataType === 'integer' || 'currency' || 'link') {
             return Number(value);
-        } else if (dataType == "bool") {
+        } else if (dataType === 'bool') {
             return (value === 'true');
         } else {
             return value;
         }
     }
-    
+
     filterCoust() {
-        if (this.filterString != this.prevFilter) {
+        if (this.filterString !== this.prevFilter) {
             this.prevFilter = this.filterString;
             if (this.filterString) {
                 this.gridDataSource.data = [];
-                let tempGrid = this.settingTypeArr;
+                const tempGrid = this.settingTypeArr;
                 tempGrid.forEach(row => {
-                    let containsString =
+                    const containsString =
                          row.name.includes(this.filterString) ||
                          row.label.includes(this.filterString) ||
                          (row.grp && row.grp.includes(this.filterString)) ||
@@ -354,16 +345,16 @@ export class OrgUnitSettingsComponent {
     }
 
     updateGrid(org) {
-        if (this.contextOrg != org) {
+        if (this.contextOrg !== org) {
             this.contextOrg = org;
             this.refreshSettings = true;
         }
 
-        if (this.filterString != this.prevFilter) {
+        if (this.filterString !== this.prevFilter) {
             this.refreshSettings = true;
         }
 
-        if (this.refreshSettings) { 
+        if (this.refreshSettings) {
             this.mergeSettingValues().then(
                 res => this.filterCoust()
             );