From 7395d1ce56f1a780809af1db2b1df4a92919247d Mon Sep 17 00:00:00 2001 From: Kyle Huckins Date: Wed, 8 Jan 2020 18:04:11 +0000 Subject: [PATCH] lp1857910 Field Documentation Port - Port grid UI allowing the creation and editing of Field Documentation from DOJO to Angular Signed-off-by: Kyle Huckins Changes to be committed: modified: Open-ILS/src/eg2/src/app/staff/admin/local/admin-local-splash.component.html new file: Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.html new file: Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.ts new file: Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.module.ts new file: Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/routing.module.ts modified: Open-ILS/src/eg2/src/app/staff/admin/local/routing.module.ts Signed-off-by: Bill Erickson Signed-off-by: Jason Etheridge Signed-off-by: Jane Sandberg --- .../admin/local/admin-local-splash.component.html | 4 +- .../field-documentation.component.html | 52 ++++++ .../field-documentation.component.ts | 183 +++++++++++++++++++++ .../field-documentation.module.ts | 18 ++ .../local/field-documentation/routing.module.ts | 14 ++ .../src/app/staff/admin/local/routing.module.ts | 3 + 6 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.module.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/routing.module.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local-splash.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local-splash.component.html index 41f19dcf71..9188bde149 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local-splash.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local-splash.component.html @@ -30,8 +30,8 @@ - + + + +
+
+
+
+
Class
+ + + +
+
+
+ +
+ +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.ts new file mode 100644 index 0000000000..a8ff1ec95a --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.component.ts @@ -0,0 +1,183 @@ +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 {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {GridDataSource} from '@eg/share/grid/grid'; +import {GridComponent} from '@eg/share/grid/grid.component'; +import {Pager} from '@eg/share/util/pager'; +import {AuthService} from '@eg/core/auth.service'; +import {IdlObject, IdlService} from '@eg/core/idl.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; + +@Component({ + templateUrl: './field-documentation.component.html' +}) + +export class FieldDocumentationComponent implements OnInit { + + idlEntries: any[] = []; + fieldOptions: any = {}; + @Input() selectedClass: any; + @Input() fields: [] = []; + gridDataSource: GridDataSource; + @ViewChild('fieldClassSelector', {static: true}) fieldClassSelector: any; + @ViewChild('fieldSelector', {static: true}) fieldSelector: any; + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('fieldDocGrid', { static: true }) fieldDocGrid: GridComponent; + @ViewChild('updateSuccessString', { static: true }) updateSuccessString: StringComponent; + @ViewChild('createSuccessString', { static: false }) createSuccessString: StringComponent; + @ViewChild('createFailedString', { static: false }) createFailedString: StringComponent; + @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent; + + constructor( + private auth: AuthService, + private idl: IdlService, + private pcrud: PcrudService, + private toast: ToastService + ) {} + + ngOnInit() { + this.gridDataSource = new GridDataSource(); + Object.values(this.idl.classes).forEach(idlClass => { + let fields = []; + Object.values(idlClass['field_map']).forEach(field => { + // We can safely ignore virtual fields... + if (!field['virtual']) { + fields.push({ + id: field['name'], + label: field['label'] ? field['label'] : field['name'] + }); + } + }); + if (idlClass['label']) { + this.idlEntries.push({ + label: idlClass['label'], + id: idlClass['name'], + fields: fields + }); + } + }); + this.idlEntries.sort((a, b) => { + let textA = a.label.toUpperCase(); + let textB = b.label.toUpperCase(); + return (textA < textB) ? -1 : (textA > textB) ? 1 : 0; + }); + if (this.selectedClass) this.setGrid(); + this.fieldDocGrid.onRowActivate.subscribe((fieldDoc: IdlObject) => { + this.showEditDialog(fieldDoc); + }); + + this.fieldOptions = { + fm_class: { + customTemplate: { + template:this.fieldClassSelector, + context: { + fieldentries: this.idlEntries, + selectedEntry: this.selectedClass + } + } + }, + field: { + customTemplate: { + template: this.fieldSelector, + context: { + selectedEntry: null + } + } + } + } + } + + setClass(idlClass, entry?) { + if (this.editDialog.record) this.editDialog.record.fm_class(idlClass.id); + this.fieldOptions.fm_class.customTemplate.context.selectedEntry = idlClass; + this.fields = idlClass.fields; + + if (entry && entry.field()) this.setField( + idlClass.fields.find(o => o.id == entry.field()), + ); + } + + setField(entry) { + if (this.editDialog.record) this.editDialog.record.field(entry.id); + this.fieldOptions.field.customTemplate.context.selectedEntry = entry; + } + + setGrid() { + this.gridDataSource.data = []; + this.setCurrentFieldDoc(); + } + + setCurrentFieldDoc() { + if (this.selectedClass) { + this.fields = this.selectedClass.fields; + this.pcrud.search('fdoc', + {fm_class: this.selectedClass.id} + ).subscribe(fdocs => { + this.gridDataSource.data.push(fdocs); + }); + } + } + + setFieldOptions(field) { + field.owner(this.auth.user().ws_ou()); + this.fieldOptions.fm_class.customTemplate.context.selectedEntry = this.selectedClass; + this.fieldOptions.field.customTemplate.context.fields = this.selectedClass ? this.selectedClass.fields : []; + this.fieldOptions.field.customTemplate.context.record = field; + if (this.selectedClass) { + this.setClass(this.selectedClass, field); + } + } + + showEditDialog(field: IdlObject): Promise { + this.editDialog.mode = 'update'; + this.editDialog.recordId = field.id(); + this.setFieldOptions(field); + return new Promise((resolve, reject) => { + this.editDialog.open({size: 'lg'}).subscribe(result => { + this.updateSuccessString.current() + .then(str => this.toast.success(str)); + this.setGrid(); + resolve(result); + }, error => { + this.updateFailedString.current() + .then(str => this.toast.danger(str)); + }); + }); + } + + editSelected(fields: IdlObject[]) { + const editOneFieldDoc = (fieldDoc: IdlObject) => { + if (!fieldDoc) return; + + this.showEditDialog(fieldDoc).then( + () => editOneFieldDoc(fields.shift()) + ); + } + + editOneFieldDoc(fields.shift()); + } + + createNew() { + this.editDialog.mode = 'create'; + this.editDialog.recordId = null; + this.editDialog.record = this.idl.create('fdoc'); + this.setFieldOptions(this.editDialog.record); + this.editDialog.open({size: 'lg'}).subscribe( + ok => { + this.createSuccessString.current() + .then(str => this.toast.success(str)); + this.setGrid(); + }, + rejection => { + if (!rejection.dismissed) { + this.createFailedString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } +} \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.module.ts new file mode 100644 index 0000000000..0fc12667ab --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/field-documentation.module.ts @@ -0,0 +1,18 @@ +import {NgModule} from '@angular/core'; +import {AdminCommonModule} from '@eg/staff/admin/common.module'; +import {FieldDocumentationComponent} from './field-documentation.component'; +import {FieldDocumentationRoutingModule} from './routing.module'; + +@NgModule({ + declarations: [ + FieldDocumentationComponent + ], + imports: [ + AdminCommonModule, + FieldDocumentationRoutingModule + ], + exports: [], + providers: [] +}) + +export class FieldDocumentationModule {} \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/routing.module.ts new file mode 100644 index 0000000000..e9e2f27a40 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/field-documentation/routing.module.ts @@ -0,0 +1,14 @@ +import {NgModule} from '@angular/core'; +import {RouterModule, Routes} from '@angular/router'; +import {FieldDocumentationComponent} from './field-documentation.component'; +const routes: Routes = [{ + path: '', + component: FieldDocumentationComponent +}]; + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) + +export class FieldDocumentationRoutingModule {} \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/routing.module.ts index c87c51795d..f3ff4e8f1d 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/routing.module.ts @@ -66,6 +66,9 @@ const routes: Routes = [{ loadChildren: () => import('./triggers/triggers.module').then(m => m.TriggersModule) }, { + path: 'config/idl_field_doc', + loadChildren: '@eg/staff/admin/local/field-documentation/field-documentation.module#FieldDocumentationModule' +}, { path: ':schema/:table', component: BasicAdminPageComponent }]; -- 2.11.0