From f5999c527649c94d5008644e0afdda45d6b28bf4 Mon Sep 17 00:00:00 2001 From: Manuel Friedli Date: Tue, 20 Sep 2016 22:34:31 +0200 Subject: [PATCH] added a wrapper service for the native libraries --- app/app.component.ts | 19 ++++++++++--------- app/converter/quotedprintabledecoder.ts | 8 ++++---- app/converter/quotedprintableencoder.ts | 8 ++++---- app/converterregistry.service.ts | 9 +++++---- app/inputarea.component.ts | 14 +++++++------- ...ce.ts => inputcomponentmanager.service.ts} | 3 ++- app/nativelibrarywrapper.service.ts | 15 +++++++++++++++ 7 files changed, 47 insertions(+), 29 deletions(-) rename app/{InputcomponentmanagerService.ts => inputcomponentmanager.service.ts} (95%) create mode 100644 app/nativelibrarywrapper.service.ts diff --git a/app/app.component.ts b/app/app.component.ts index 7cde15f..79d9816 100644 --- a/app/app.component.ts +++ b/app/app.component.ts @@ -1,25 +1,26 @@ import {Component, OnInit} from "@angular/core"; -import {ConverterregistryService} from "./converterregistry.service"; -import {InputcomponentmanagerService} from "./InputcomponentmanagerService"; +import {ConverterRegistryService} from "./converterregistry.service"; +import {InputComponentManagerService} from "./inputcomponentmanager.service"; import {Converter} from "./converter/converter"; +import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; @Component({ moduleId: module.id, selector: "den-app", templateUrl: "app.component.html", styleUrls: ["app.component.css"], - providers: [ConverterregistryService, InputcomponentmanagerService] + providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService] }) export class AppComponent extends OnInit { public steps:any[] = []; public converters:Converter[] = []; - constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) { + constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) { super(); } convert(step:any, $event:any):void { - step.selectedConverter = this.converterregistryService.getConverter($event.target.selectedOptions[0].id); + step.selectedConverter = this.converterRegistryService.getConverter($event.target.selectedOptions[0].id); this.update(step); } @@ -44,7 +45,7 @@ export class AppComponent extends OnInit { step.message = ""; step.error = false; if (result !== "") { - let nextComponent:any = this.inputcomponentmanagerService.getNext(step); + let nextComponent:any = this.inputComponentManagerService.getNext(step); nextComponent.content = result; this.update(nextComponent); } @@ -53,8 +54,8 @@ export class AppComponent extends OnInit { } ngOnInit():void { - this.converters = this.converterregistryService.getAllConverters(); - this.steps = this.inputcomponentmanagerService.getAllComponents(); - this.inputcomponentmanagerService.getFirst(); + this.converters = this.converterRegistryService.getAllConverters(); + this.steps = this.inputComponentManagerService.getAllComponents(); + this.inputComponentManagerService.getFirst(); } } diff --git a/app/converter/quotedprintabledecoder.ts b/app/converter/quotedprintabledecoder.ts index e34c238..6787ff1 100644 --- a/app/converter/quotedprintabledecoder.ts +++ b/app/converter/quotedprintabledecoder.ts @@ -1,9 +1,9 @@ import {Converter} from "./converter"; - -declare var utf8:any; -declare var quotedPrintable:any; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class QuotedPrintableDecoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { + } getDisplayname():string { return "Decode quoted printable"; @@ -14,6 +14,6 @@ export class QuotedPrintableDecoder implements Converter { } convert(input:string):string { - return utf8.decode(quotedPrintable.decode(input)); + return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); } } diff --git a/app/converter/quotedprintableencoder.ts b/app/converter/quotedprintableencoder.ts index 8f87109..048dbc6 100644 --- a/app/converter/quotedprintableencoder.ts +++ b/app/converter/quotedprintableencoder.ts @@ -1,9 +1,9 @@ import {Converter} from "./converter"; - -declare var utf8:any; -declare var quotedPrintable:any; +import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; export class QuotedPrintableEncoder implements Converter { + constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { + } getDisplayname():string { return "Encode quoted printable"; @@ -14,6 +14,6 @@ export class QuotedPrintableEncoder implements Converter { } convert(input:string):string { - return quotedPrintable.encode(utf8.encode(input)); + return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input)); } } diff --git a/app/converterregistry.service.ts b/app/converterregistry.service.ts index a3fa684..e5054a1 100644 --- a/app/converterregistry.service.ts +++ b/app/converterregistry.service.ts @@ -14,12 +14,13 @@ import {DecToBinConverter} from "./converter/dectobinconverter"; import {BinToDecConverter} from "./converter/bintodecconverter"; import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder"; import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; +import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; @Injectable() -export class ConverterregistryService { +export class ConverterRegistryService { private converters:Converter[] = []; - constructor() { + constructor(private wrapper:NativeLibraryWrapperService) { this.init(); } @@ -49,8 +50,8 @@ export class ConverterregistryService { this.registerConverter(new HexToDecConverter()); this.registerConverter(new DecToBinConverter()); this.registerConverter(new BinToDecConverter()); - this.registerConverter(new QuotedPrintableEncoder()); - this.registerConverter(new QuotedPrintableDecoder()); + this.registerConverter(new QuotedPrintableEncoder(this.wrapper)); + this.registerConverter(new QuotedPrintableDecoder(this.wrapper)); } private registerConverter(converter:Converter):void { diff --git a/app/inputarea.component.ts b/app/inputarea.component.ts index d3a3e1e..d6164ad 100644 --- a/app/inputarea.component.ts +++ b/app/inputarea.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit} from "@angular/core"; -import {ConverterregistryService} from "./converterregistry.service"; +import {ConverterRegistryService} from "./converterregistry.service"; import {Converter} from "./converter/converter"; -import {InputcomponentmanagerService} from "./InputcomponentmanagerService"; +import {InputComponentManagerService} from "./inputcomponentmanager.service"; @Component({ @@ -15,19 +15,19 @@ export class InputareaComponent extends OnInit { public content:string = ''; private selectedConverter:Converter; - constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) { + constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) { super(); } public convert(e):void { - this.selectedConverter = this.converterregistryService.getConverter(e.target.selectedOptions[0].id); + this.selectedConverter = this.converterRegistryService.getConverter(e.target.selectedOptions[0].id); this.update(); } public update():void { if (this.selectedConverter !== undefined) { let result:string = this.selectedConverter.convert(this.content); - let nextComponent:InputareaComponent = this.inputcomponentmanagerService.getNext(this); + let nextComponent:InputareaComponent = this.inputComponentManagerService.getNext(this); if (nextComponent !== undefined) { nextComponent.setContent(result); } @@ -40,8 +40,8 @@ export class InputareaComponent extends OnInit { } ngOnInit():void { - this.converters = this.converterregistryService.getAllConverters(); + this.converters = this.converterRegistryService.getAllConverters(); this.selectedConverter = undefined; - this.inputcomponentmanagerService.register(this); + this.inputComponentManagerService.register(this); } } diff --git a/app/InputcomponentmanagerService.ts b/app/inputcomponentmanager.service.ts similarity index 95% rename from app/InputcomponentmanagerService.ts rename to app/inputcomponentmanager.service.ts index a1717b8..a15b97c 100644 --- a/app/InputcomponentmanagerService.ts +++ b/app/inputcomponentmanager.service.ts @@ -1,6 +1,7 @@ import {Injectable} from "@angular/core"; + @Injectable() -export class InputcomponentmanagerService { +export class InputComponentManagerService { private components:any[] = []; public constructor() { diff --git a/app/nativelibrarywrapper.service.ts b/app/nativelibrarywrapper.service.ts new file mode 100644 index 0000000..6a7d840 --- /dev/null +++ b/app/nativelibrarywrapper.service.ts @@ -0,0 +1,15 @@ +import {Injectable} from "@angular/core"; + +declare var utf8:any; +declare var quotedPrintable:any; + +@Injectable() +export class NativeLibraryWrapperService { + public utf8:any; + public quotedPrintable:any; + + constructor() { + this.utf8 = utf8; + this.quotedPrintable = quotedPrintable; + } +} \ No newline at end of file