<ngb-tab title="Template" i18n-title id='template'>
<ng-template ngbTabContent>
<div class="row">
- <div class="col-lg-6 mt-3">
- <button class="btn btn-success" (click)="openEditDialog()" i18n>
+ <div class="col-lg-12 mt-3 d-flex">
+ <button class="btn btn-info" (click)="openEditDialog()" i18n>
Edit Template Attributes
</button>
- <button class="btn btn-info ml-2" (click)="applyChanges()" i18n>
- Save Template and Refresh Preview
+ <button class="btn btn-success ml-2" (click)="applyChanges()" i18n>
+ Save Template Changes
+ </button>
+ <button class="btn btn-info ml-2" (click)="cloneTemplate()" i18n>
+ Clone Template
+ </button>
+ <div class="flex-1"> </div>
+ <button class="btn btn-danger ml-2" (click)="deleteTemplate()" i18n>
+ Delete Template
</button>
<span *ngIf="invalidJson" class="badge badge-danger ml-2" i18n>
Invalid Sample JSON!
<div class="row mt-2">
<div class="col-lg-6">
<h4 i18n>
- Template for "{{template.label()}}"
+ Template for "{{template.label()}} ({{getOwnerName(template.id())}})"
<span class="pl-2 text-warning" *ngIf="template.active() == 'f'">
(Inactive)
</span>
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';
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();
}
//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;
}
}
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<IdlObject> {
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 {
}
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()];
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));
+ });
}
}