From 5e4b580191c6f6d2b779a4f7716b36352ab97411 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 18 May 2020 15:37:46 -0400 Subject: [PATCH] LP1879335 Manage Authorities Angular WIP Signed-off-by: Bill Erickson --- .../app/staff/cat/authority/authority.module.ts | 2 + .../app/staff/cat/authority/browse.component.html | 26 +++++- .../app/staff/cat/authority/browse.component.ts | 104 +++++++++++---------- .../src/app/staff/cat/authority/browse.service.ts | 81 ++++++++++++++++ .../app/staff/cat/authority/manage.component.html | 11 +++ .../app/staff/cat/authority/manage.component.ts | 18 ---- .../staff/share/bib-list/bib-list.component.html | 19 +++- .../app/staff/share/bib-list/bib-list.component.ts | 15 +-- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 15 +++ .../upgrade/XXXX.data.manage-authority-grids.sql | 20 ++++ 10 files changed, 231 insertions(+), 80 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/cat/authority/browse.service.ts create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.data.manage-authority-grids.sql diff --git a/Open-ILS/src/eg2/src/app/staff/cat/authority/authority.module.ts b/Open-ILS/src/eg2/src/app/staff/cat/authority/authority.module.ts index ef2acbe770..8686b1aa5c 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/authority/authority.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/authority/authority.module.ts @@ -6,6 +6,7 @@ import {MarcEditModule} from '@eg/staff/share/marc-edit/marc-edit.module'; import {AuthorityMarcEditComponent} from './marc-edit.component'; import {BrowseAuthorityComponent} from './browse.component'; import {ManageAuthorityComponent} from './manage.component'; +import {BrowseService} from './browse.service'; import {BibListModule} from '@eg/staff/share/bib-list/bib-list.module'; @NgModule({ @@ -22,6 +23,7 @@ import {BibListModule} from '@eg/staff/share/bib-list/bib-list.module'; BibListModule ], providers: [ + BrowseService ] }) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.component.html b/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.component.html index 6c0794a018..237a844b2e 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.component.html @@ -1,6 +1,8 @@ + +
@@ -9,7 +11,8 @@
+ (change)="search()" + (keyup.enter)="search()" [(ngModel)]="browse.searchTerm">
@@ -18,9 +21,15 @@ Authority Type
+ [entries]="browse.authorityAxes" (onChange)="search(0, $event)"> +
@@ -29,7 +38,7 @@ + [(ngModel)]="browse.searchOffset" id="offset-input" (change)="search()"/>
@@ -43,7 +52,18 @@ + + + + + + + GridRowFlairEntry; + @ViewChild('grid', {static: false}) grid: GridComponent; + @ViewChild('axisCbox', {static: false}) axisCbox: ComboboxComponent; + @ViewChild('rowSelected', {static: false}) rowSelected: StringComponent; constructor( private net: NetService, private org: OrgService, - private pcrud: PcrudService - ) { - } + private pcrud: PcrudService, + private browse: BrowseService + ) {} ngOnInit() { + this.browse.fetchAxes(); + this.setupGrid(); + } - this.pcrud.retrieveAll('aba', {}, {atomic: true}) - .subscribe(axes => { - this.authorityAxes = axes - .map(axis => ({id: axis.code(), label: axis.name()})) - .sort((a1, a2) => a1.label < a2.label ? -1 : 1); - }); - + setupGrid() { this.dataSource = new GridDataSource(); - this.dataSource.getRows = (pager: Pager, sort: any): Observable => { - return this.loadAuthorities(); + this.dataSource.getRows = + (pager: Pager, sort: any): Observable => { + + if (this.authorityAxis) { + this.browse.authorityAxis = this.authorityAxis.id; + + } else { + if (this.browse.authorityAxis) { + this.axisCbox.selectedId = this.browse.authorityAxis; + this.authorityAxis = this.axisCbox.selected; + } else { + return empty(); + } + } + + return this.browse.loadAuthorities(); } this.cellTextGenerator = { heading: row => row.heading } - } - loadAuthorities(): Observable { - - if (!this.searchTerm || !this.authorityAxis.id) { - return empty(); + this.rowFlairCallback = (row: any): GridRowFlairEntry => { + const flair = {icon: null, title: null}; + if (this.browse.markedForMerge[row.authority.id()]) { + flair.icon = 'merge_type'; + flair.title = this.rowSelected.text; + } + return flair; } + } - return this.net.request( - 'open-ils.supercat', - 'open-ils.supercat.authority.browse.by_axis', - this.authorityAxis.id, this.searchTerm, - this.pageSize, this.searchOffset - - ).pipe(switchMap(authIds => { - - return this.net.request( - 'open-ils.search', - 'open-ils.search.authority.main_entry', authIds - ); - })).pipe(map(authMeta => { + markForMerge(rows: any[]) { + rows.forEach(row => + this.browse.markedForMerge[row.authority.id()] = true); + } - const oOrg = this.org.get(authMeta.authority.owner()); + unMarkForMerge(rows: any[]) { + rows.forEach(row => + delete this.browse.markedForMerge[row.authority.id()]); + } - return { - authority: authMeta.authority, - link_count: authMeta.linked_bibs.length, - heading: authMeta.heading, - thesaurus: authMeta.thesaurus, - thesaurus_code: authMeta.thesaurus_code, - owner: oOrg ? oOrg.shortname() : '' - }; - })); + clearMergeSelection() { + this.browse.markedForMerge = {}; } search(offset?: number) { - if (offset) { this.searchOffset += offset; } - + if (offset) { + this.browse.searchOffset += offset; + } this.grid.reload(); } } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.service.ts new file mode 100644 index 0000000000..83701c1a25 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/cat/authority/browse.service.ts @@ -0,0 +1,81 @@ +import {Injectable} from '@angular/core'; +import {Observable, empty} from 'rxjs'; +import {map, switchMap} from 'rxjs/operators'; +import {IdlObject} from '@eg/core/idl.service'; +import {Pager} from '@eg/share/util/pager'; +import {NetService} from '@eg/core/net.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {OrgService} from '@eg/core/org.service'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; + +/* Browse APIS and state maintenance */ + +@Injectable() +export class BrowseService { + + // Grid paging is disabled in this UI to support browsing in + // both directions. Define our own paging trackers. + pageSize = 15; + searchOffset = 0; + + searchTerm: string; + authorityAxis: string; + authorityAxes: ComboboxEntry[]; + markedForMerge: {[id: number]: boolean} = {}; + + constructor( + private net: NetService, + private org: OrgService, + private pcrud: PcrudService + ) {} + + fetchAxes(): Promise { + if (this.authorityAxes) { + return Promise.resolve(this.authorityAxes); + } + + this.pcrud.retrieveAll('aba', {}, {atomic: true}) + .pipe(map(axes => { + this.authorityAxes = axes + .map(axis => ({id: axis.code(), label: axis.name()})) + .sort((a1, a2) => a1.label < a2.label ? -1 : 1); + })).toPromise(); + + } + + loadAuthorities(): Observable { + + if (!this.searchTerm || !this.authorityAxis) { + return empty(); + } + + return this.net.request( + 'open-ils.supercat', + 'open-ils.supercat.authority.browse.by_axis', + this.authorityAxis, this.searchTerm, + this.pageSize, this.searchOffset + + ).pipe(switchMap(authIds => { + + return this.net.request( + 'open-ils.search', + 'open-ils.search.authority.main_entry', authIds + ); + + })).pipe(map(authMeta => { + + const oOrg = this.org.get(authMeta.authority.owner()); + + return { + authority: authMeta.authority, + link_count: authMeta.linked_bibs.length, + heading: authMeta.heading, + thesaurus: authMeta.thesaurus, + thesaurus_code: authMeta.thesaurus_code, + owner: oOrg ? oOrg.shortname() : '' + }; + })); + } +} + + diff --git a/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.html b/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.html index 6fa633fb2a..2eb475964b 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.html @@ -1,6 +1,17 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.ts index 7ddf38ae49..1234e76e0e 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/authority/manage.component.ts @@ -8,8 +8,6 @@ import {Pager} from '@eg/share/util/pager'; import {NetService} from '@eg/core/net.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {OrgService} from '@eg/core/org.service'; -import {GridComponent} from '@eg/share/grid/grid.component'; -import {GridContext, GridDataSource} from '@eg/share/grid/grid'; import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; /* Find, merge, and edit authority records */ @@ -23,9 +21,6 @@ export class ManageAuthorityComponent implements OnInit { authTab = 'bibs'; authMeta: any; - bibsDataSource: GridDataSource; - @ViewChild('bibsGrid', {static: false}) bibsGrid: GridComponent; - constructor( private router: Router, private route: ActivatedRoute, @@ -36,13 +31,6 @@ export class ManageAuthorityComponent implements OnInit { } ngOnInit() { - - this.bibsDataSource = new GridDataSource(); - - this.bibsDataSource.getRows = (pager: Pager, sort: any): Observable => { - return this.loadLinkedBibs(); - } - this.route.paramMap.subscribe((params: ParamMap) => { this.authTab = params.get('tab') || 'bibs'; const id = +params.get('id'); @@ -74,12 +62,6 @@ export class ManageAuthorityComponent implements OnInit { `/staff/cat/authority/manage/${this.authId}/${this.authTab}`; this.router.navigate([url]); } - - - loadLinkedBibs(): Observable { - - return empty(); - } } diff --git a/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.html b/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.html index df01a5c31e..6c0ffca6ae 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.html @@ -6,11 +6,26 @@ + [cellTextGenerator]="cellTextGenerator" [persistKey]="gridPersistKey" + [showDeclaredFieldsOnly]="true"> + + + label="Title" i18n-label flex="3"> + + + + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.ts b/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.ts index 84d8a37544..8c6b7fcc01 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/bib-list/bib-list.component.ts @@ -11,7 +11,7 @@ import {GridContext, GridDataSource, GridCellTextGenerator} from '@eg/share/grid import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; -/* List of bib records and associated actions */ +/* Grid of bib records and associated actions. */ @Component({ templateUrl: 'bib-list.component.html', @@ -21,9 +21,6 @@ export class BibListComponent implements OnInit { // Display bibs linked to this authority record. @Input() bibIds: number[]; - - @Input() bucketId: number; // TODO - @Input() gridPersistKey: string; dataSource: GridDataSource; @@ -51,6 +48,7 @@ export class BibListComponent implements OnInit { } this.cellTextGenerator = { + title: row => row.title }; } @@ -59,13 +57,18 @@ export class BibListComponent implements OnInit { return empty(); } + const orderBy: any = {rmsr: 'title'}; + if (sort.length) { + orderBy.rmsr = sort[0].name + ' ' + sort[0].dir; + } + return this.pcrud.search('rmsr', {id: this.bibIds}, { - order_by: {}, /* todo */ + order_by: orderBy, limit: pager.limit, offset: pager.offset, flesh: 2, flesh_fields: { - rmsr: ['bib_record'], + rmsr: ['biblio_record'], bre: ['creator', 'editor'] } }); diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index b6959bb20e..d6a989e888 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -20414,4 +20414,19 @@ VALUES ( ) ); +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.grid.cat.authority.browse', 'gui', 'object', + oils_i18n_gettext( + 'eg.grid.cat.authority.browse', + 'Grid Config: eg.grid.cat.authority.browse', + 'cwst', 'label') +), ( + 'eg.grid.cat.authority.manage.bibs', 'gui', 'object', + oils_i18n_gettext( + 'eg.grid.cat.authority.manage.bibs', + 'Grid Config: eg.grid.cat.authority.manage.bibs', + 'cwst', 'label') +); + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.data.manage-authority-grids.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.manage-authority-grids.sql new file mode 100644 index 0000000000..4236704eef --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.data.manage-authority-grids.sql @@ -0,0 +1,20 @@ +BEGIN; + +-- SELECT evergreen.upgrade_deps_block_check('TODO', :eg_version); + +INSERT INTO config.workstation_setting_type (name, grp, datatype, label) +VALUES ( + 'eg.grid.cat.authority.browse', 'gui', 'object', + oils_i18n_gettext( + 'eg.grid.cat.authority.browse', + 'Grid Config: eg.grid.cat.authority.browse', + 'cwst', 'label') +), ( + 'eg.grid.cat.authority.manage.bibs', 'gui', 'object', + oils_i18n_gettext( + 'eg.grid.cat.authority.manage.bibs', + 'Grid Config: eg.grid.cat.authority.manage.bibs', + 'cwst', 'label') +); + +COMMIT; -- 2.11.0