From df2d5399bf619a5a740e6482f85d1da4bd2f639b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 13 Aug 2018 13:12:01 -0400 Subject: [PATCH] LP#1775466 Admin page grid content translator Signed-off-by: Bill Erickson --- .../src/app/share/grid/grid-toolbar.component.html | 2 +- .../share/admin-page/admin-page.component.html | 6 +++ .../staff/share/admin-page/admin-page.component.ts | 59 +++++++++++++++++++++- .../staff/share/translate/translate.component.html | 16 +++++- .../staff/share/translate/translate.component.ts | 19 ++++++- 5 files changed, 96 insertions(+), 6 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html index 442bab1d14..ae24021381 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html +++ b/Open-ILS/src/eg2/src/app/share/grid/grid-toolbar.component.html @@ -7,7 +7,7 @@
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 5f0eadded3..194f06b515 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 @@ -38,11 +38,17 @@
+ + + + + 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 afe9e97857..febfe35fe9 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 @@ -2,6 +2,7 @@ import {Component, Input, OnInit, TemplateRef, ViewChild} from '@angular/core'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {GridDataSource} from '@eg/share/grid/grid'; import {GridComponent} from '@eg/share/grid/grid.component'; +import {TranslateComponent} from '@eg/staff/share/translate/translate.component'; import {ToastService} from '@eg/share/toast/toast.service'; import {Pager} from '@eg/share/util/pager'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -65,12 +66,19 @@ export class AdminPageComponent implements OnInit { @ViewChild('editDialog') editDialog: FmRecordEditorComponent; @ViewChild('successString') successString: StringComponent; @ViewChild('createString') createString: StringComponent; + @ViewChild('translator') translator: TranslateComponent; idlClassDef: any; pkeyField: string; createNew: () => void; deleteSelected: (rows: IdlObject[]) => void; + // True if any columns on the object support translations + translateRowIdx: number; + translateFieldIdx: number; + translatableFields: string[]; + translate: () => void; + contextOrg: IdlObject; orgFieldLabel: string; viewPerms: string; @@ -83,7 +91,9 @@ export class AdminPageComponent implements OnInit { private pcrud: PcrudService, private perm: PermService, private toast: ToastService - ) {} + ) { + this.translatableFields = []; + } applyOrgValues() { @@ -113,6 +123,9 @@ export class AdminPageComponent implements OnInit { this.idlClassDef = this.idl.classes[this.idlClass]; this.pkeyField = this.idlClassDef.pkey || 'id'; + this.translatableFields = + this.idlClassDef.fields.filter(f => f.i18n).map(f => f.name); + if (!this.persistKey) { this.persistKey = 'admin.' + @@ -171,6 +184,50 @@ export class AdminPageComponent implements OnInit { () => this.grid.reload() ); }; + + // Open the field translation dialog. + // Link the next/previous actions to cycle through each translatable + // field on each row. + this.translate = () => { + this.translateRowIdx = 0; + this.translateFieldIdx = 0; + this.translator.fieldName = this.translatableFields[this.translateFieldIdx]; + this.translator.idlObject = this.dataSource.data[this.translateRowIdx]; + + this.translator.nextString = () => { + + if (this.translateFieldIdx < this.translatableFields.length - 1) { + this.translateFieldIdx++; + + } else if (this.translateRowIdx < this.dataSource.data.length - 1) { + this.translateRowIdx++; + this.translateFieldIdx = 0; + } + + this.translator.idlObject = + this.dataSource.data[this.translateRowIdx]; + this.translator.fieldName = + this.translatableFields[this.translateFieldIdx]; + } + + this.translator.prevString = () => { + + if (this.translateFieldIdx > 0) { + this.translateFieldIdx--; + + } else if (this.translateRowIdx > 0) { + this.translateRowIdx--; + this.translateFieldIdx = 0; + } + + this.translator.idlObject = + this.dataSource.data[this.translateRowIdx]; + this.translator.fieldName = + this.translatableFields[this.translateFieldIdx]; + } + + this.translator.open({size:'lg'}); + } } checkCreatePerms() { diff --git a/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.html b/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.html index a57ca17164..7aa59b46c3 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.html +++ b/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.html @@ -1,8 +1,7 @@ diff --git a/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.ts b/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.ts index a165afee50..1d3b0a5fe4 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/translate/translate.component.ts @@ -21,6 +21,13 @@ export class TranslateComponent translatedValue: string; existingTranslation: IdlObject; + // These actions should update the idlObject and/or fieldName values, + // forcing the dialog to load a new string to translate. When set, + // applying a translation in the dialog will leave the dialog window open + // so the next/prev buttons can be used to fetch the next string. + nextString: () => void; + prevString: () => void; + idlObj: IdlObject; @Input() set idlObject(o: IdlObject) { if (o) { @@ -105,7 +112,11 @@ export class TranslateComponent entry.string(this.translatedValue); this.pcrud.update(entry).toPromise().then( - ok => this.close('Translation updated'), + ok => { + if (!this.nextString) { + this.close('Translation updated'); + } + }, err => console.error(err) ); @@ -119,7 +130,11 @@ export class TranslateComponent entry.string(this.translatedValue); this.pcrud.create(entry).toPromise().then( - ok => this.close('Translation created'), + ok => { + if (!this.nextString) { + this.close('Translation created'); + } + }, err => console.error('Translation creation failed') ); } -- 2.11.0