From 886ba54fa622277740aa78c5eec813812e724a65 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 12 Jul 2019 12:38:17 -0400 Subject: [PATCH] LP1825851 print config uses org family Signed-off-by: Bill Erickson --- .../admin/server/print-template.component.html | 28 ++++++----- .../staff/admin/server/print-template.component.ts | 55 ++++++++++++++++------ 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.html b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.html index 9a95f61234..d5d06e13c8 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.html @@ -9,24 +9,25 @@
-
-
-
- Owner -
- - -
+
+ +
Template
- + {{r.label}} ({{getOwnerName(r.id)}}) + +
@@ -55,6 +56,9 @@ + + Invalid Sample JSON! +
diff --git a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts index 5a38c989a9..700d084628 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/server/print-template.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, ViewChild, TemplateRef} from '@angular/core'; +import {Component, OnInit, ViewChild, TemplateRef} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -11,6 +11,7 @@ import {LocaleService} from '@eg/core/locale.service'; import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; import {SampleDataService} from '@eg/share/util/sample-data.service'; +import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component'; /** * Print Template Admin Page @@ -22,13 +23,16 @@ import {SampleDataService} from '@eg/share/util/sample-data.service'; export class PrintTemplateComponent implements OnInit { - contextOrg: IdlObject; entries: ComboboxEntry[]; template: IdlObject; sampleJson: string; + invalidJson = false; localeCode: string; localeEntries: ComboboxEntry[]; compiledContent: string; + templateCache: {[id: number]: IdlObject} = {}; + initialOrg: number; + selectedOrgs: number[]; @ViewChild('templateSelector') templateSelector: ComboboxComponent; @ViewChild('tabs') tabs: NgbTabset; @@ -57,7 +61,8 @@ export class PrintTemplateComponent implements OnInit { } ngOnInit() { - this.contextOrg = this.org.get(this.auth.user().ws_ou()); + this.initialOrg = this.auth.user().ws_ou(); + this.selectedOrgs = [this.initialOrg]; this.localeCode = this.locale.currentLocaleCode(); this.locale.supportedLocales().subscribe( l => this.localeEntries.push({id: l.code(), label: l.name()})); @@ -111,11 +116,29 @@ export class PrintTemplateComponent implements OnInit { return document.getElementById('template-preview-pane'); } - orgOnChange(org: IdlObject) { - this.contextOrg = org; + //orgOnChange(org: IdlObject) { + orgOnChange(family: OrgFamily) { + console.log('existing = ', this.selectedOrgs); + console.log('new = ', family.orgIds); + if (this.arrayEquals(this.selectedOrgs, family.orgIds)) { + return; + } + this.selectedOrgs = family.orgIds; this.setTemplateInfo(); } + arrayEquals(arr1: any[], arr2: any[]): boolean { + if (arr1.length !== arr2.length) { + return false; + } + for (var i = 0; i < arr1.length; i++) { // exit on first failure. + if (!arr2.includes(arr1[i])) { + return false; + } + } + return true; + } + localeOnChange(code: string) { if (code) { this.localeCode = code; @@ -133,16 +156,22 @@ export class PrintTemplateComponent implements OnInit { this.pcrud.search('cpt', { - owner: this.contextOrg.id(), + owner: this.selectedOrgs, locale: this.localeCode }, { - select: {cpt: ['id', 'label']}, + select: {cpt: ['id', 'label', 'owner']}, order_by: {cpt: 'label'} } - ).subscribe(tmpl => + ).subscribe(tmpl => { + this.templateCache[tmpl.id()] = tmpl; this.entries.push({id: tmpl.id(), label: tmpl.label()}) - ); + console.log('entry count = ', this.entries.length); + }); + } + + getOwnerName(id: number): string { + return this.org.get(this.templateCache[id].owner()).shortname(); } selectTemplate(id: number) { @@ -163,9 +192,9 @@ export class PrintTemplateComponent implements OnInit { let data; try { data = JSON.parse(this.sampleJson); + this.invalidJson = false; } catch (E) { - // TODO: i18n/AlertDialog - alert('Invalid Sample Data JSON'); + this.invalidJson = true; } this.printer.compileRemoteTemplate({ @@ -192,9 +221,7 @@ export class PrintTemplateComponent implements OnInit { } openEditDialog() { - // TODO: PENDING EXTERNAL FIXES - //this.editDialog.record = this.template; - this.editDialog.recordId = this.template.id(); + this.editDialog.setRecord(this.template); this.editDialog.mode = 'update'; this.editDialog.open({size: 'lg'}); } -- 2.11.0