From: Bill Erickson Date: Tue, 19 Jun 2018 15:21:57 +0000 (-0400) Subject: LP#1775466 Retracting dynamic component for now X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bc8c7ff3c00c6d323371a8652f3c1625a0962807;p=working%2FEvergreen.git LP#1775466 Retracting dynamic component for now Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/common.module.ts b/Open-ILS/src/eg2/src/app/common.module.ts index 89fef3573d..e04e00309e 100644 --- a/Open-ILS/src/eg2/src/app/common.module.ts +++ b/Open-ILS/src/eg2/src/app/common.module.ts @@ -6,7 +6,6 @@ import {NgModule, ModuleWithProviders} from '@angular/core'; import {RouterModule} from '@angular/router'; import {FormsModule} from '@angular/forms'; import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; -import {HttpClientModule} from '@angular/common/http'; import {EventService} from '@eg/core/event.service'; import {StoreService} from '@eg/core/store.service'; @@ -27,38 +26,30 @@ import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; import {PromptDialogComponent} from '@eg/share/dialog/prompt.component'; import {ProgressDialogComponent} from '@eg/share/dialog/progress.component'; -// DynamicComponent only works in JIT compilation mode. -// Leaving for now as reference while considering alternatives -import {DynamicComponent} from '@eg/share/util/dynamic.component'; - @NgModule({ declarations: [ PrintComponent, DialogComponent, ConfirmDialogComponent, PromptDialogComponent, - ProgressDialogComponent, - DynamicComponent + ProgressDialogComponent ], imports: [ CommonModule, FormsModule, RouterModule, - HttpClientModule, NgbModule ], exports: [ CommonModule, RouterModule, - HttpClientModule, NgbModule, FormsModule, PrintComponent, DialogComponent, ConfirmDialogComponent, PromptDialogComponent, - ProgressDialogComponent, - DynamicComponent + ProgressDialogComponent ] }) diff --git a/Open-ILS/src/eg2/src/app/share/print/print.component.ts b/Open-ILS/src/eg2/src/app/share/print/print.component.ts index 0270a8bb64..53762d6263 100644 --- a/Open-ILS/src/eg2/src/app/share/print/print.component.ts +++ b/Open-ILS/src/eg2/src/app/share/print/print.component.ts @@ -1,6 +1,5 @@ import {Component, OnInit, TemplateRef, ElementRef} from '@angular/core'; // See dynamic.component for details on why it's commented out. -//import {DynamicComponent} from '@eg/share/util/dynamic.component'; import {PrintService, PrintRequest} from './print.service'; @Component({ diff --git a/Open-ILS/src/eg2/src/app/share/util/dynamic.component.ts b/Open-ILS/src/eg2/src/app/share/util/dynamic.component.ts deleted file mode 100644 index 2f67671ee5..0000000000 --- a/Open-ILS/src/eg2/src/app/share/util/dynamic.component.ts +++ /dev/null @@ -1,109 +0,0 @@ -/** - * WARNING: This component only works when using the JIT compiler. - * Compiling --aot prevents the JitCompiler from working. - */ -import {Component, OnInit, ViewChild, Input, Output, TemplateRef} from '@angular/core'; -import {Compiler, ViewContainerRef, NgModule, EventEmitter} from '@angular/core'; -import {HttpClient} from '@angular/common/http'; - -/** - * Render HTML content derived from a string or a URL path, - * interpolating the provided context data along the way. - * - * Content text or URL values may be provided as Inputs or passed - * directly to component build* methods. - */ - -@Component({ - selector: 'eg-dynamic-component', - template: '' -}) - -export class DynamicComponent implements OnInit { - - @ViewChild('container', {read: ViewContainerRef}) - private container: ViewContainerRef; - - @Input() content: string; - @Input() contentUrl: string; - @Input() contextData: any; - - // Emits true if the content was render-able, false otherwise - @Output() onComplete: EventEmitter; - - constructor( - private compiler: Compiler, - private http: HttpClient - ) { - console.warn("DynamicComponent only works in JIT compilation mode"); - this.onComplete = new EventEmitter(); - } - - ngOnInit() { - if (this.contentUrl) { - this.buildFromUrl(this.contentUrl, this.contextData); - } else if (this.content) { - this.buildFromString(this.content, this.contextData); - } - } - - buildFromString(template: string, context: any = {}) { - try { - this.addComponent(template, context); - } catch (err) { - console.error(`Error rendering dynamic content: ${err}`); - this.onComplete.emit(false); - return; - } - - this.onComplete.emit(true); - } - - // Returns a promise which resolves if the requested URL - // was found and was render-able, rejected otherwise. - buildFromUrl(url: string, context: any = {}): Promise { - return this.http.get(url, {responseType: 'text'}).toPromise() - .then( - html => { - console.debug(`Loaded dynamic content from: ${url}`); - try { - this.addComponent(html, context); - } catch (err) { - const msg = `Error rendering dynamic content: ${url}`; - console.error(msg); - this.onComplete.emit(false); - return Promise.reject(msg); - } - this.onComplete.emit(true); - }, - notFound => { - console.debug( - `Unable to fetch dynamic component URL: ${url}`, notFound); - this.onComplete.emit(false); - } - ) - } - - // Method below taken practically verbatim from - // https://stackoverflow.com/a/39507831 - private addComponent(template: string, context: any) { - @Component({template}) class TemplateComponent {} - @NgModule({declarations: [TemplateComponent]}) class TemplateModule {} - - const mod = - this.compiler.compileModuleAndAllComponentsSync(TemplateModule); - - const factory = mod.componentFactories.find(comp => - comp.componentType === TemplateComponent - ); - - const component = this.container.createComponent(factory); - Object.assign(component.instance, context); - - // If context changes at a later stage, the change detection - // may need to be triggered manually: - // component.changeDetectorRef.detectChanges(); - } - -} - diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index b96a7ce504..dbea15aad7 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -72,30 +72,6 @@ Hello, {{context.world}}! - - -

diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index 46f2bd57a7..eb0fdb035f 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -13,7 +13,6 @@ import {OrgService} from '@eg/core/org.service'; import {Pager} from '@eg/share/util/pager'; import {DateSelectComponent} from '@eg/share/date-select/date-select.component'; import {PrintService} from '@eg/share/print/print.service'; -//import {DynamicComponent} from '@eg/share/util/dynamic.component'; @Component({ templateUrl: 'sandbox.component.html' @@ -29,9 +28,6 @@ export class SandboxComponent implements OnInit { @ViewChild('printTemplate') private printTemplate: TemplateRef; - //@ViewChild('dynamic') private dynamic: DynamicComponent; - //@ViewChild('dynamicUrl') private dynamicUrl: DynamicComponent; - // @ViewChild('helloStr') private helloStr: StringComponent; gridDataSource: GridDataSource = new GridDataSource(); @@ -85,15 +81,6 @@ export class SandboxComponent implements OnInit { return cbt; })); }; - - /* - this.dynamic.buildFromString( - 'HELLO {{world}}', {world: this.world}); - - // Assumes a file on the server at this URL - this.dynamicUrl.buildFromUrl( - '/test-template.html', {world: this.world}); - */ } doPrint() { @@ -104,16 +91,6 @@ export class SandboxComponent implements OnInit { }); } - doDynamicPrint() { - /* - this.printer.print({ - templateString: 'DYNAMIC HELLO {{world}}', - contextData: {world : this.world}, - printContext: 'default' - }); - */ - } - changeDate(date) { console.log('HERE WITH ' + date); this.testDate = date;