From 7eef73802f55d852669cfaa75a69ffb57908ffc1 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 12 Jul 2019 14:16:10 -0400 Subject: [PATCH] LP1825851 UI continued Signed-off-by: Bill Erickson --- Open-ILS/examples/fm_IDL.xml | 2 +- .../admin/server/print-template.component.html | 17 ++++-- .../staff/admin/server/print-template.component.ts | 65 ++++++++++++++++------ 3 files changed, 60 insertions(+), 24 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index 462b28117a..91f75974e3 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -12817,7 +12817,7 @@ SELECT usr, oils_obj:fieldmapper="config::print_template" oils_persist:tablename="config.print_template" reporter:label="Print Templates"> - + 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 d5d06e13c8..da685c9dbe 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 @@ -49,12 +49,19 @@
-
- - + +
+ Invalid Sample JSON! @@ -64,7 +71,7 @@

- Template for "{{template.label()}}" + Template for "{{template.label()}} ({{getOwnerName(template.id())}})" (Inactive) 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 700d084628..b192469a14 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,6 @@ import {Component, OnInit, ViewChild, TemplateRef} from '@angular/core'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; import {ActivatedRoute} from '@angular/router'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -66,7 +68,7 @@ export class PrintTemplateComponent implements OnInit { this.localeCode = this.locale.currentLocaleCode(); this.locale.supportedLocales().subscribe( l => this.localeEntries.push({id: l.code(), label: l.name()})); - this.setTemplateInfo(); + this.setTemplateInfo().subscribe(); this.fleshSampleData(); } @@ -118,21 +120,18 @@ export class PrintTemplateComponent implements OnInit { //orgOnChange(org: IdlObject) { orgOnChange(family: OrgFamily) { - console.log('existing = ', this.selectedOrgs); - console.log('new = ', family.orgIds); - if (this.arrayEquals(this.selectedOrgs, family.orgIds)) { - return; + if (!this.arrayEquals(this.selectedOrgs, family.orgIds)) { + this.selectedOrgs = family.orgIds; + this.setTemplateInfo().subscribe(); } - 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])) { + for (var i = 0; i < arr1.length; i++) { + if (arr1[i] !== arr2[i]) { return false; } } @@ -142,32 +141,31 @@ export class PrintTemplateComponent implements OnInit { localeOnChange(code: string) { if (code) { this.localeCode = code; - this.setTemplateInfo(); + this.setTemplateInfo().subscribe(); } } // Fetch name/id for all templates in range. // Avoid fetching the template content until needed. - setTemplateInfo() { + setTemplateInfo(): Observable { this.entries = []; this.template = null; this.templateSelector.applyEntryId(null); this.compiledContent = ''; - this.pcrud.search('cpt', + return this.pcrud.search('cpt', { owner: this.selectedOrgs, locale: this.localeCode - }, - { + }, { select: {cpt: ['id', 'label', 'owner']}, order_by: {cpt: 'label'} } - ).subscribe(tmpl => { + ).pipe(map(tmpl => { this.templateCache[tmpl.id()] = tmpl; this.entries.push({id: tmpl.id(), label: tmpl.label()}) - console.log('entry count = ', this.entries.length); - }); + return tmpl; + })); } getOwnerName(id: number): string { @@ -175,6 +173,13 @@ export class PrintTemplateComponent implements OnInit { } selectTemplate(id: number) { + + if (id === null) { + this.template = null; + this.compiledContent = ''; + return; + } + this.pcrud.retrieve('cpt', id).subscribe(t => { this.template = t; const data = this.sampleData[t.name()]; @@ -223,7 +228,31 @@ export class PrintTemplateComponent implements OnInit { openEditDialog() { this.editDialog.setRecord(this.template); this.editDialog.mode = 'update'; - this.editDialog.open({size: 'lg'}); + this.editDialog.open({size: 'lg'}).subscribe(id => { + const selectedId = this.template.id(); + this.setTemplateInfo().toPromise().then( + _ => this.selectTemplate(selectedId) + ); + }); + } + + cloneTemplate() { + const tmpl = this.idl.clone(this.template); + tmpl.id(null); + this.editDialog.setRecord(tmpl); + this.editDialog.mode = 'create'; + this.editDialog.open({size: 'lg'}).subscribe(tmpl => { + this.setTemplateInfo().toPromise() + .then(_ => this.selectTemplate(tmpl.id())); + + }); + } + + deleteTemplate() { + this.pcrud.remove(this.template).subscribe(_ => { + this.setTemplateInfo().toPromise() + .then(_ => this.selectTemplate(null)); + }); } } -- 2.11.0