added a wrapper service for the native libraries

This commit is contained in:
Manuel Friedli 2016-09-20 22:34:31 +02:00
parent 9e95797211
commit f5999c5276
7 changed files with 47 additions and 29 deletions

View file

@ -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();
}
}

View file

@ -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));
}
}

View file

@ -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));
}
}

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -1,6 +1,7 @@
import {Injectable} from "@angular/core";
@Injectable()
export class InputcomponentmanagerService {
export class InputComponentManagerService {
private components:any[] = [];
public constructor() {

View file

@ -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;
}
}