From 27c346a64e0a55984b16b1218c204e28de2cec52 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 4 Dec 2019 15:52:23 -0500 Subject: [PATCH] LP1840287 Floating group admin minor code tweaks * Added grid sorting to both group and group member grids. * Avoid using the defaultNewRecord in fm-editor directly, by cloning it as needed, so that subsequent new records (within a single parent component instance) do not pick up values from the previously created record. * Renamed the eg-admin-page @Input() 'hideFields' to 'hideGridFields' to better explain how the value will be passed along. * Replace access of fieldmapper innards (thing.a[0]) with field names (thing.id()) * Remove unused entries. * Avoid unnecessary newlines in translatable strings. * Remove unused @Inputs() and unnecessary functions * Remove unneccessary TreeModule import * Removed a redundant -- will set the title when present. * Various 'ng lint' repairs. Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg --- .../src/app/share/fm-editor/fm-editor.component.ts | 12 +++++- .../edit-floating-group.component.html | 12 ++---- .../edit-floating-group.component.ts | 30 +++++++++------ .../floating-group/floating-group.component.html | 18 ++++----- .../floating-group/floating-group.component.ts | 44 +++++++++++----------- .../server/floating-group/floating-group.module.ts | 6 +-- .../share/admin-page/admin-page.component.html | 2 +- .../staff/share/admin-page/admin-page.component.ts | 2 +- 8 files changed, 66 insertions(+), 60 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index d95646589a..e809b7d72d 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -359,8 +359,16 @@ export class FmRecordEditorComponent // // Create a new record from the stub record provided by the // caller or a new from-scratch record - // Set this._record (not this.record) to avoid loop in initRecord() - this._record = this.defaultNewRecord || this.record || this.idl.create(this.idlClass); + if (!this.record) { + // NOTE: Set this._record (not this.record) to avoid + // loop in initRecord() + if (this.defaultNewRecord) { + // Clone to avoid polluting the stub record + this._record = this.idl.clone(this.defaultNewRecord); + } else { + this._record = this.idl.create(this.idlClass); + } + } this._recordId = null; // avoid future confusion return this.getFieldList(); diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.html index 00fda10854..48d8dfedd3 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.html @@ -8,17 +8,11 @@ - - - - - - - - \ No newline at end of file + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.ts index 805e3e2f0c..e6785e8397 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.ts @@ -1,19 +1,17 @@ -import {Component, Input} from '@angular/core'; +import {Component, Input, OnInit} from '@angular/core'; import {Router, ActivatedRoute} from '@angular/router'; import {GridDataSource} from '@eg/share/grid/grid'; import {Pager} from '@eg/share/util/pager'; import {PcrudService} from '@eg/core/pcrud.service'; import {IdlObject, IdlService } from '@eg/core/idl.service'; - @Component({ - templateUrl: './edit-floating-group.component.html' - }) +@Component({ + templateUrl: './edit-floating-group.component.html' +}) - export class EditFloatingGroupComponent { +export class EditFloatingGroupComponent implements OnInit { - @Input() sortField: string; - @Input() dataSource: GridDataSource; - @Input() dialogSize: 'sm' | 'lg' = 'lg'; + dataSource: GridDataSource; // defaultNewRecord is used when creating a new entry to give a default floating_group defaultNewRecord: IdlObject; @@ -29,17 +27,25 @@ import {IdlObject, IdlService } from '@eg/core/idl.service'; } ngOnInit() { - this.currentId = parseInt(this.route.snapshot.paramMap.get('id')); + this.currentId = parseInt(this.route.snapshot.paramMap.get('id'), 10); this.defaultNewRecord = this.idl.create('cfgm'); this.defaultNewRecord.floating_group(this.currentId); this.dataSource = new GridDataSource(); + this.dataSource.getRows = (pager: Pager, sort: any[]) => { + const orderBy: any = {}; + if (sort.length) { + orderBy.cfgm = sort[0].name + ' ' + sort[0].dir; + } + const searchOps = { offset: pager.offset, limit: pager.limit, - order_by: {} + order_by: orderBy }; - return this.pcrud.search("cfgm", {floating_group: this.currentId}, searchOps); + + return this.pcrud.search('cfgm', + {floating_group: this.currentId}, searchOps); }; } - } \ No newline at end of file +} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.html index 1895293ebb..66084e5686 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.html @@ -1,19 +1,17 @@ - - + - - - + + + - + + label="New Floating Group" i18n-label (onClick)="createNew()"> diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.ts index fa639ee829..da84179689 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.component.ts @@ -1,6 +1,6 @@ import {Pager} from '@eg/share/util/pager'; -import {Component, Input, ViewChild} from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; +import {Component, Input, ViewChild, OnInit} from '@angular/core'; +import {Router, ActivatedRoute} from '@angular/router'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {GridDataSource} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; @@ -9,20 +9,18 @@ import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; import {PermService} from '@eg/core/perm.service'; import {AuthService} from '@eg/core/auth.service'; -import { AdminPageComponent } from '../../../share/admin-page/admin-page.component'; +import {AdminPageComponent} from '../../../share/admin-page/admin-page.component'; - @Component({ - templateUrl: './floating-group.component.html' - }) +@Component({ + templateUrl: './floating-group.component.html' +}) - export class FloatingGroupComponent extends AdminPageComponent { +export class FloatingGroupComponent extends AdminPageComponent implements OnInit { idlClass = 'cfg'; - @Input() sortField: string; - @Input() dialogSize: 'sm' | 'lg' = 'lg'; gridDataSource: GridDataSource = new GridDataSource(); - + @ViewChild('grid', {static: true}) grid: GridComponent; constructor( @@ -33,7 +31,7 @@ import { AdminPageComponent } from '../../../share/admin-page/admin-page.compone pcrud: PcrudService, perm: PermService, toast: ToastService, - private router:Router + private router: Router ) { super(route, idl, org, auth, pcrud, perm, toast); } @@ -41,27 +39,31 @@ import { AdminPageComponent } from '../../../share/admin-page/admin-page.compone ngOnInit() { super.ngOnInit(); this.gridDataSource.getRows = (pager: Pager, sort: any[]) => { + + const orderBy: any = {}; + if (sort.length) { + orderBy.cfg = sort[0].name + ' ' + sort[0].dir; + } + const searchOps = { offset: pager.offset, limit: pager.limit, - order_by: {} + order_by: orderBy }; - return this.pcrud.retrieveAll("cfg", searchOps); + + return this.pcrud.retrieveAll('cfg', searchOps); }; + this.grid.onRowActivate.subscribe( (idlThing: IdlObject) => { - let idToEdit = idlThing.a[0]; + const idToEdit = idlThing.id(); this.navigateToEditPage(idToEdit); } ); } - createNew = () => { - super.createNew(); - }; - editSelected = (floatingGroups: IdlObject[]) => { - let idToEdit = floatingGroups[0].a[0]; + const idToEdit = floatingGroups[0].id(); this.navigateToEditPage(idToEdit); } @@ -70,7 +72,7 @@ import { AdminPageComponent } from '../../../share/admin-page/admin-page.compone } navigateToEditPage(id: any) { - this.router.navigate(["/staff/admin/server/config/floating_group/" + id]); + this.router.navigate(['/staff/admin/server/config/floating_group/' + id]); } // this was left mostly blank to ensure a modal does not open for edits @@ -78,4 +80,4 @@ import { AdminPageComponent } from '../../../share/admin-page/admin-page.compone return; } - } \ No newline at end of file + } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.module.ts index a52febc342..ff267653df 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/floating-group.module.ts @@ -1,6 +1,5 @@ import {NgModule} from '@angular/core'; import {AdminCommonModule} from '@eg/staff/admin/common.module'; -import {TreeModule} from '@eg/share/tree/tree.module'; import {FloatingGroupComponent} from './floating-group.component'; import {EditFloatingGroupComponent} from './edit-floating-group.component'; import {FloatingGroupRoutingModule} from './floating-group-routing.module'; @@ -12,8 +11,7 @@ import {FloatingGroupRoutingModule} from './floating-group-routing.module'; ], imports: [ AdminCommonModule, - FloatingGroupRoutingModule, - TreeModule + FloatingGroupRoutingModule ], exports: [ ], @@ -22,4 +20,4 @@ import {FloatingGroupRoutingModule} from './floating-group-routing.module'; }) export class FloatingGroupModule { -} \ No newline at end of file +} diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html index 285d9c9fc4..e0ae6c3b03 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html @@ -33,7 +33,7 @@ - diff --git a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts index db5c9be25c..cb52da7f1d 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts @@ -45,7 +45,7 @@ export class AdminPageComponent implements OnInit { // comma-separated list of fields to hide. // This does not imply all other fields should be visible, only that // the selected fields will be hidden. - @Input() hideFields: string; + @Input() hideGridFields: string; // If an org unit field is specified, an org unit filter // is added to the top of the page. -- 2.11.0