added a wrapper service for the native libraries
This commit is contained in:
		
							parent
							
								
									9e95797211
								
							
						
					
					
						commit
						f5999c5276
					
				
					 7 changed files with 47 additions and 29 deletions
				
			
		|  | @ -1,25 +1,26 @@ | ||||||
| import {Component, OnInit} from "@angular/core"; | import {Component, OnInit} from "@angular/core"; | ||||||
| import {ConverterregistryService} from "./converterregistry.service"; | import {ConverterRegistryService} from "./converterregistry.service"; | ||||||
| import {InputcomponentmanagerService} from "./InputcomponentmanagerService"; | import {InputComponentManagerService} from "./inputcomponentmanager.service"; | ||||||
| import {Converter} from "./converter/converter"; | import {Converter} from "./converter/converter"; | ||||||
|  | import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|     moduleId: module.id, |     moduleId: module.id, | ||||||
|     selector: "den-app", |     selector: "den-app", | ||||||
|     templateUrl: "app.component.html", |     templateUrl: "app.component.html", | ||||||
|     styleUrls: ["app.component.css"], |     styleUrls: ["app.component.css"], | ||||||
|     providers: [ConverterregistryService, InputcomponentmanagerService] |     providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService] | ||||||
| }) | }) | ||||||
| export class AppComponent extends OnInit { | export class AppComponent extends OnInit { | ||||||
|     public steps:any[] = []; |     public steps:any[] = []; | ||||||
|     public converters:Converter[] = []; |     public converters:Converter[] = []; | ||||||
| 
 | 
 | ||||||
|     constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) { |     constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) { | ||||||
|         super(); |         super(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     convert(step:any, $event:any):void { |     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); |         this.update(step); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -44,7 +45,7 @@ export class AppComponent extends OnInit { | ||||||
|                 step.message = ""; |                 step.message = ""; | ||||||
|                 step.error = false; |                 step.error = false; | ||||||
|                 if (result !== "") { |                 if (result !== "") { | ||||||
|                     let nextComponent:any = this.inputcomponentmanagerService.getNext(step); |                     let nextComponent:any = this.inputComponentManagerService.getNext(step); | ||||||
|                     nextComponent.content = result; |                     nextComponent.content = result; | ||||||
|                     this.update(nextComponent); |                     this.update(nextComponent); | ||||||
|                 } |                 } | ||||||
|  | @ -53,8 +54,8 @@ export class AppComponent extends OnInit { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ngOnInit():void { |     ngOnInit():void { | ||||||
|         this.converters = this.converterregistryService.getAllConverters(); |         this.converters = this.converterRegistryService.getAllConverters(); | ||||||
|         this.steps = this.inputcomponentmanagerService.getAllComponents(); |         this.steps = this.inputComponentManagerService.getAllComponents(); | ||||||
|         this.inputcomponentmanagerService.getFirst(); |         this.inputComponentManagerService.getFirst(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| import {Converter} from "./converter"; | import {Converter} from "./converter"; | ||||||
| 
 | import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; | ||||||
| declare var utf8:any; |  | ||||||
| declare var quotedPrintable:any; |  | ||||||
| 
 | 
 | ||||||
| export class QuotedPrintableDecoder implements Converter { | export class QuotedPrintableDecoder implements Converter { | ||||||
|  |     constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     getDisplayname():string { |     getDisplayname():string { | ||||||
|         return "Decode quoted printable"; |         return "Decode quoted printable"; | ||||||
|  | @ -14,6 +14,6 @@ export class QuotedPrintableDecoder implements Converter { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     convert(input:string):string { |     convert(input:string):string { | ||||||
|         return utf8.decode(quotedPrintable.decode(input)); |         return this.nativeLibraryWrapperService.utf8.decode(this.nativeLibraryWrapperService.quotedPrintable.decode(input)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,9 +1,9 @@ | ||||||
| import {Converter} from "./converter"; | import {Converter} from "./converter"; | ||||||
| 
 | import {NativeLibraryWrapperService} from "../nativelibrarywrapper.service"; | ||||||
| declare var utf8:any; |  | ||||||
| declare var quotedPrintable:any; |  | ||||||
| 
 | 
 | ||||||
| export class QuotedPrintableEncoder implements Converter { | export class QuotedPrintableEncoder implements Converter { | ||||||
|  |     constructor(private nativeLibraryWrapperService:NativeLibraryWrapperService) { | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     getDisplayname():string { |     getDisplayname():string { | ||||||
|         return "Encode quoted printable"; |         return "Encode quoted printable"; | ||||||
|  | @ -14,6 +14,6 @@ export class QuotedPrintableEncoder implements Converter { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     convert(input:string):string { |     convert(input:string):string { | ||||||
|         return quotedPrintable.encode(utf8.encode(input)); |         return this.nativeLibraryWrapperService.quotedPrintable.encode(this.nativeLibraryWrapperService.utf8.encode(input)); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,12 +14,13 @@ import {DecToBinConverter} from "./converter/dectobinconverter"; | ||||||
| import {BinToDecConverter} from "./converter/bintodecconverter"; | import {BinToDecConverter} from "./converter/bintodecconverter"; | ||||||
| import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder"; | import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder"; | ||||||
| import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; | import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder"; | ||||||
|  | import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service"; | ||||||
| 
 | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class ConverterregistryService { | export class ConverterRegistryService { | ||||||
|     private converters:Converter[] = []; |     private converters:Converter[] = []; | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor(private wrapper:NativeLibraryWrapperService) { | ||||||
|         this.init(); |         this.init(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -49,8 +50,8 @@ export class ConverterregistryService { | ||||||
|         this.registerConverter(new HexToDecConverter()); |         this.registerConverter(new HexToDecConverter()); | ||||||
|         this.registerConverter(new DecToBinConverter()); |         this.registerConverter(new DecToBinConverter()); | ||||||
|         this.registerConverter(new BinToDecConverter()); |         this.registerConverter(new BinToDecConverter()); | ||||||
|         this.registerConverter(new QuotedPrintableEncoder()); |         this.registerConverter(new QuotedPrintableEncoder(this.wrapper)); | ||||||
|         this.registerConverter(new QuotedPrintableDecoder()); |         this.registerConverter(new QuotedPrintableDecoder(this.wrapper)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private registerConverter(converter:Converter):void { |     private registerConverter(converter:Converter):void { | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import {Component, OnInit} from "@angular/core"; | import {Component, OnInit} from "@angular/core"; | ||||||
| import {ConverterregistryService} from "./converterregistry.service"; | import {ConverterRegistryService} from "./converterregistry.service"; | ||||||
| import {Converter} from "./converter/converter"; | import {Converter} from "./converter/converter"; | ||||||
| import {InputcomponentmanagerService} from "./InputcomponentmanagerService"; | import {InputComponentManagerService} from "./inputcomponentmanager.service"; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|  | @ -15,19 +15,19 @@ export class InputareaComponent extends OnInit { | ||||||
|     public content:string = ''; |     public content:string = ''; | ||||||
|     private selectedConverter:Converter; |     private selectedConverter:Converter; | ||||||
| 
 | 
 | ||||||
|     constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) { |     constructor(private converterRegistryService:ConverterRegistryService, private inputComponentManagerService:InputComponentManagerService) { | ||||||
|         super(); |         super(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public convert(e):void { |     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(); |         this.update(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public update():void { |     public update():void { | ||||||
|         if (this.selectedConverter !== undefined) { |         if (this.selectedConverter !== undefined) { | ||||||
|             let result:string = this.selectedConverter.convert(this.content); |             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) { |             if (nextComponent !== undefined) { | ||||||
|                 nextComponent.setContent(result); |                 nextComponent.setContent(result); | ||||||
|             } |             } | ||||||
|  | @ -40,8 +40,8 @@ export class InputareaComponent extends OnInit { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     ngOnInit():void { |     ngOnInit():void { | ||||||
|         this.converters = this.converterregistryService.getAllConverters(); |         this.converters = this.converterRegistryService.getAllConverters(); | ||||||
|         this.selectedConverter = undefined; |         this.selectedConverter = undefined; | ||||||
|         this.inputcomponentmanagerService.register(this); |         this.inputComponentManagerService.register(this); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| import {Injectable} from "@angular/core"; | import {Injectable} from "@angular/core"; | ||||||
|  | 
 | ||||||
| @Injectable() | @Injectable() | ||||||
| export class InputcomponentmanagerService { | export class InputComponentManagerService { | ||||||
|     private components:any[] = []; |     private components:any[] = []; | ||||||
| 
 | 
 | ||||||
|     public constructor() { |     public constructor() { | ||||||
							
								
								
									
										15
									
								
								app/nativelibrarywrapper.service.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/nativelibrarywrapper.service.ts
									
										
									
									
									
										Normal 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; | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue