From 406f8692cb11c76eb7e00680b9a6789d5d0ba06c Mon Sep 17 00:00:00 2001 From: Zavier Banks Date: Thu, 24 Oct 2019 18:26:40 +0000 Subject: [PATCH] LP#1849212 Course List Ui Added a grid component that displays the available data, specified by the class, while also modifying the routing, so the admin splash page links to the created component. Signed-off-by: Zavier Banks Signed-off-by: Jane Sandberg Signed-off-by: Michele Morgan Signed-off-by: Galen Charlton --- .../server/admin-server-splash.component.html | 2 + .../course-list.component.html | 30 ++++ .../course-reserves/course-list.component.ts | 149 ++++++++++++++++++ .../course-reserves/course-reserves.module.ts | 23 +++ .../server/course-reserves/routing.module.ts | 15 ++ .../app/staff/admin/server/routing.module.ts | 3 + 6 files changed, 222 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-list.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-list.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-reserves.module.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/routing.module.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html index de399d6517..df5b9ef490 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/admin-server-splash.component.html @@ -39,6 +39,8 @@ routerLink="/staff/admin/server/config/circ_modifier"> + + + + + + + + + +
+ + + + + + + + +
+ + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-list.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-list.component.ts new file mode 100644 index 0000000000..9e4bb40878 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-list.component.ts @@ -0,0 +1,149 @@ +import {Component, Input, ViewChild, OnInit} from '@angular/core'; +import {IdlObject} from '@eg/core/idl.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {GridComponent} from '@eg/share/grid/grid.component'; +import {Pager} from '@eg/share/util/pager'; +import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid'; +import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; + +@Component({ + templateUrl: './course-list.component.html' +}) + +export class CourseListComponent implements OnInit { + + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('grid', { static: true }) grid: GridComponent; + @ViewChild('successString', { static: true }) successString: StringComponent; + @ViewChild('createString', { static: false }) createString: StringComponent; + @ViewChild('createErrString', { static: false }) createErrString: StringComponent; + @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent; + @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent; + @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent; + @ViewChild('flairTooltip', { static: true }) private flairTooltip: StringComponent; + rowFlairCallback: (row: any) => GridRowFlairEntry; + @Input() sort_field: string; + @Input() idl_class = "acmc"; + @Input() dialog_size: 'sm' | 'lg' = 'lg'; + @Input() table_name = "Course"; + grid_source: GridDataSource = new GridDataSource(); + search_value = ''; + + constructor( + private pcrud: PcrudService, + private toast: ToastService, + ){} + + ngOnInit() { + this.getSource(); + this.rowFlair(); + } + + /** + * Gets the data, specified by the class, that is available. + */ + getSource() { + this.grid_source.getRows = (pager: Pager, sort: any[]) => { + const orderBy: any = {}; + if (sort.length) { + // Sort specified from grid + orderBy[this.idl_class] = sort[0].name + ' ' + sort[0].dir; + } else if (this.sort_field) { + // Default sort field + orderBy[this.idl_class] = this.sort_field; + } + const searchOps = { + offset: pager.offset, + limit: pager.limit, + order_by: orderBy + }; + return this.pcrud.retrieveAll(this.idl_class, searchOps, {fleshSelectors: true}); + }; + } + + rowFlair() { + this.rowFlairCallback = (row: any): GridRowFlairEntry => { + const flair = {icon: null, title: null}; + if (row.id() < 100) { + flair.icon = 'not_interested'; + flair.title = this.flairTooltip.text; + } + return flair; + }; + } + + gridCellClassCallback = (row: any, col: GridColumn): string => { + if (col.name === 'id' && row.a[0] < 100) { + return 'text-danger'; + } + return ''; + } + + showEditDialog(standingPenalty: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = standingPenalty['id'](); + return new Promise((resolve, reject) => { + this.editDialog.open({size: this.dialog_size}).subscribe( + result => { + this.successString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + resolve(result); + }, + error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + reject(error); + } + ); + }); + } + + createNew() { + this.editDialog.mode = 'create'; + this.editDialog.recordId = null; + this.editDialog.record = null; + this.editDialog.open({size: this.dialog_size}).subscribe( + ok => { + this.createString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } + + editSelected(fields: IdlObject[]) { + // Edit each IDL thing one at a time + const editOneThing = (field_object: IdlObject) => { + if (!field_object) { return; } + this.showEditDialog(field_object).then( + () => editOneThing(fields.shift())); + }; + editOneThing(fields.shift()); + } + + deleteSelected(idl_object: IdlObject[]) { + idl_object.forEach(idl_object => idl_object.isdeleted(true)); + this.pcrud.autoApply(idl_object).subscribe( + val => { + console.debug('deleted: ' + val); + this.deleteSuccessString.current() + .then(str => this.toast.success(str)); + }, + err => { + this.deleteFailedString.current() + .then(str => this.toast.danger(str)); + }, + () => this.grid.reload() + ); + }; +} + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-reserves.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-reserves.module.ts new file mode 100644 index 0000000000..1702ba861e --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/course-reserves.module.ts @@ -0,0 +1,23 @@ +import {NgModule} from '@angular/core'; +import {TreeModule} from '@eg/share/tree/tree.module'; +import {AdminCommonModule} from '@eg/staff/admin/common.module'; +import {CourseListComponent} from './course-list.component'; +import {CourseReservesRoutingModule} from './routing.module'; + +@NgModule({ + declarations: [ + CourseListComponent + ], + imports: [ + AdminCommonModule, + CourseReservesRoutingModule, + TreeModule + ], + exports: [ + ], + providers: [ + ] +}) + +export class CourseReservesModule { +} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/routing.module.ts new file mode 100644 index 0000000000..84e74ff881 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/course-reserves/routing.module.ts @@ -0,0 +1,15 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {CourseListComponent} from './course-list.component'; + +const routes: Routes = [{ + path: '', + component: CourseListComponent +}]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) + +export class CourseReservesRoutingModule {} \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts index 194a979052..fe4d35463f 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/routing.module.ts @@ -22,6 +22,9 @@ const routes: Routes = [{ }, { path: 'permission/grp_tree', component: PermGroupTreeComponent +}, { + path: 'asset/course_list', + loadChildren: '@eg/staff/admin/server/course-reserves/course-reserves.module#CourseReservesModule' }, { path: 'actor/org_unit', loadChildren: () => -- 2.43.2