Merge branch '11-convert-any-input-data-holder-to-a-class' into 'develop'
created class for the input stuff Closes #11 See merge request !7
This commit is contained in:
commit
f2940b2cb0
3 changed files with 24 additions and 16 deletions
|
@ -3,6 +3,7 @@ import {ConverterRegistryService} from "./converterregistry.service";
|
||||||
import {InputComponentManagerService} from "./inputcomponentmanager.service";
|
import {InputComponentManagerService} from "./inputcomponentmanager.service";
|
||||||
import {Converter} from "./converter/converter";
|
import {Converter} from "./converter/converter";
|
||||||
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
||||||
|
import {Step} from "./step";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
|
@ -12,19 +13,19 @@ import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
||||||
providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService]
|
providers: [ConverterRegistryService, InputComponentManagerService, NativeLibraryWrapperService]
|
||||||
})
|
})
|
||||||
export class AppComponent extends OnInit {
|
export class AppComponent extends OnInit {
|
||||||
public steps:any[] = [];
|
public steps:Step[] = [];
|
||||||
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:Step, $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);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(step:any):void {
|
update(step:Step):void {
|
||||||
let converter:Converter = step.selectedConverter;
|
let converter:Converter = step.selectedConverter;
|
||||||
|
|
||||||
if (converter !== undefined) {
|
if (converter !== undefined) {
|
||||||
|
@ -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:Step = this.inputComponentManagerService.getNext(step);
|
||||||
nextComponent.content = result;
|
nextComponent.content = result;
|
||||||
this.update(nextComponent);
|
this.update(nextComponent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import {Injectable} from "@angular/core";
|
import {Injectable} from "@angular/core";
|
||||||
|
import {Step} from "./step";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InputComponentManagerService {
|
export class InputComponentManagerService {
|
||||||
private components:any[] = [];
|
private components:Step[] = [];
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public register(component:any):void {
|
public register(component:Step):void {
|
||||||
this.components.push(component);
|
this.components.push(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllComponents():any[] {
|
public getAllComponents():Step[] {
|
||||||
return this.components;
|
return this.components;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getNext(component:any):any {
|
public getNext(component:Step):Step {
|
||||||
let index:number = component.index;
|
let index:number = component.index;
|
||||||
if (index == this.components.length - 1) {
|
if (index == this.components.length - 1) {
|
||||||
this.addComponent();
|
this.addComponent();
|
||||||
|
@ -23,7 +24,7 @@ export class InputComponentManagerService {
|
||||||
return this.components[index + 1];
|
return this.components[index + 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFirst():any {
|
public getFirst():Step {
|
||||||
if (this.components.length == 0) {
|
if (this.components.length == 0) {
|
||||||
this.addComponent();
|
this.addComponent();
|
||||||
}
|
}
|
||||||
|
@ -31,12 +32,6 @@ export class InputComponentManagerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private addComponent():void {
|
private addComponent():void {
|
||||||
this.register({
|
this.register(new Step(this.components.length));
|
||||||
content: "",
|
|
||||||
selectedConverter: undefined,
|
|
||||||
index: this.components.length,
|
|
||||||
error: false,
|
|
||||||
message: ""
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
12
app/step.ts
Normal file
12
app/step.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import {Converter} from "./converter/converter";
|
||||||
|
export class Step {
|
||||||
|
public content:string = "";
|
||||||
|
public selectedConverter:Converter = undefined;
|
||||||
|
public index:number;
|
||||||
|
public error:boolean = false;
|
||||||
|
public message:string = "";
|
||||||
|
|
||||||
|
constructor(index:number) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue