First usable version based on AngularJS 2! Almost no converters yet, though.
This commit is contained in:
parent
8acddfe548
commit
4197bca299
13 changed files with 155 additions and 66 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ node_modules/
|
||||||
typings/
|
typings/
|
||||||
app/**/*.js
|
app/**/*.js
|
||||||
app/**/*.js.map
|
app/**/*.js.map
|
||||||
|
npm-debug.log
|
||||||
|
|
41
app/InputcomponentmanagerService.ts
Normal file
41
app/InputcomponentmanagerService.ts
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import {Injectable} from "@angular/core";
|
||||||
|
@Injectable()
|
||||||
|
export class InputcomponentmanagerService {
|
||||||
|
private components:any[] = [];
|
||||||
|
|
||||||
|
public constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public register(component:any):void {
|
||||||
|
this.components.push(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getAllComponents():any[] {
|
||||||
|
return this.components;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getNext(component:any):any {
|
||||||
|
let index:number = component.index;
|
||||||
|
if (index == this.components.length - 1) {
|
||||||
|
this.addComponent();
|
||||||
|
}
|
||||||
|
return this.components[index + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
public getFirst():any {
|
||||||
|
if (this.components.length == 0) {
|
||||||
|
this.addComponent();
|
||||||
|
}
|
||||||
|
return this.components[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private addComponent():void {
|
||||||
|
this.register({
|
||||||
|
content: "",
|
||||||
|
selectedConverter: undefined,
|
||||||
|
index: this.components.length,
|
||||||
|
error: false,
|
||||||
|
message: ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,9 @@
|
||||||
<div>
|
<div *ngFor="let step of steps" class="wrapper">
|
||||||
<den-inputarea></den-inputarea>
|
<textarea class="input" (change)="update(step)" placeholder="Please enter your input ..."
|
||||||
|
[(ngModel)]="step.content">{{step.content}}</textarea>
|
||||||
|
<select class="conversion" (change)="convert(step, $event)">
|
||||||
|
<option id="-1">Select conversion ...</option>
|
||||||
|
<option *ngFor="let c of converters" id="{{c.getId()}}">{{c.getDisplayname()}}</option>
|
||||||
|
</select>
|
||||||
|
<div class="message" *ngIf="step.error">{{step.message}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,26 +1,57 @@
|
||||||
import {Component} from "@angular/core";
|
import {Component, OnInit} from "@angular/core";
|
||||||
import {OnInit}from "@angular/core";
|
|
||||||
|
|
||||||
import {ConverterregistryService} from "./converterregistry.service";
|
import {ConverterregistryService} from "./converterregistry.service";
|
||||||
import {Converter} from "./converter";
|
import {InputcomponentmanagerService} from "./InputcomponentmanagerService";
|
||||||
|
import {Converter} from "./converter/converter";
|
||||||
|
|
||||||
@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]
|
providers: [ConverterregistryService, InputcomponentmanagerService]
|
||||||
})
|
})
|
||||||
export class AppComponent extends OnInit {
|
export class AppComponent extends OnInit {
|
||||||
constructor(private converterregistryService:ConverterregistryService) {
|
public steps:any[] = [];
|
||||||
|
public converters:Converter[] = [];
|
||||||
|
|
||||||
|
constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit():void {
|
convert(step:any, $event:any):void {
|
||||||
let converters:Converter[] = this.converterregistryService.getConverters();
|
step.selectedConverter = this.converterregistryService.getConverter($event.target.selectedOptions[0].id);
|
||||||
console.log("Number of registered converters: " + converters.length);
|
this.update(step);
|
||||||
for (let i = 0; i < converters.length; i++) {
|
}
|
||||||
console.log("Converter " + converters[i].getId() + ": " + converters[i].getDisplayname());
|
|
||||||
|
update(step:any):void {
|
||||||
|
let converter:Converter = step.selectedConverter;
|
||||||
|
|
||||||
|
if (converter !== undefined) {
|
||||||
|
let content:string = step.content;
|
||||||
|
let result:string;
|
||||||
|
try {
|
||||||
|
result = converter.convert(content);
|
||||||
|
} catch (error) {
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
if (result === null) {
|
||||||
|
step.message = "Error converting. Not applicable?";
|
||||||
|
step.error = true;
|
||||||
|
} else {
|
||||||
|
step.message = "";
|
||||||
|
step.error = false;
|
||||||
|
if (result !== "") {
|
||||||
|
let nextComponent:any = this.inputcomponentmanagerService.getNext(step);
|
||||||
|
nextComponent.content = result;
|
||||||
|
this.update(nextComponent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit():void {
|
||||||
|
this.converters = this.converterregistryService.getAllConverters();
|
||||||
|
this.steps = this.inputcomponentmanagerService.getAllComponents();
|
||||||
|
this.inputcomponentmanagerService.getFirst();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import {NgModule} from '@angular/core'
|
import {NgModule} from "@angular/core";
|
||||||
import {BrowserModule} from '@angular/platform-browser'
|
import {BrowserModule} from "@angular/platform-browser";
|
||||||
import {FormsModule} from '@angular/forms'
|
import {FormsModule} from "@angular/forms";
|
||||||
|
import {AppComponent} from "./app.component";
|
||||||
import {AppComponent} from './app.component'
|
|
||||||
import {InputareaComponent} from "./inputarea.component";
|
import {InputareaComponent} from "./inputarea.component";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {Converter} from './converter';
|
import {Converter} from "./converter";
|
||||||
|
|
||||||
export class Base64Decoder implements Converter {
|
export class Base64Decoder implements Converter {
|
||||||
getDisplayname():string {
|
getDisplayname():string {
|
|
@ -1,4 +1,4 @@
|
||||||
import {Converter} from './converter';
|
import {Converter} from "./converter";
|
||||||
|
|
||||||
export class Base64Encoder implements Converter {
|
export class Base64Encoder implements Converter {
|
||||||
getDisplayname():string {
|
getDisplayname():string {
|
|
@ -1,8 +1,7 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from "@angular/core";
|
||||||
|
import {Converter} from "./converter/converter";
|
||||||
import {Converter} from './converter';
|
import {Base64Encoder} from "./converter/base64encoder";
|
||||||
import {Base64Encoder} from "./base64encoder";
|
import {Base64Decoder} from "./converter/base64decoder";
|
||||||
import {Base64Decoder} from "./base64decoder";
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConverterregistryService {
|
export class ConverterregistryService {
|
||||||
|
@ -12,7 +11,7 @@ export class ConverterregistryService {
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConverters():Converter[] {
|
public getAllConverters():Converter[] {
|
||||||
return this.converters;
|
return this.converters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,15 @@
|
||||||
<div id="wrapper-{{index}}" class="wrapper">
|
<!--<div id="wrapper-{{index}}" class="wrapper">-->
|
||||||
<textarea id="input-{{index}}" class="input" (change)="update()" placeholder="Please enter your input ..."
|
<!--<textarea id="input-{{index}}" class="input" (change)="update()" placeholder="Please enter your input ..."-->
|
||||||
[(ngModel)]="conversion.content">{{conversion.content}}</textarea>
|
<!--[(ngModel)]="conversion.content">{{conversion.content}}</textarea>-->
|
||||||
<select id="type-{{index}}" class="conversion" (change)="convert($event)">
|
<!--<select id="type-{{index}}" class="conversion" (change)="convert($event)">-->
|
||||||
<option id="-1">Select conversion ...</option>
|
<!--<option id="-1">Select conversion ...</option>-->
|
||||||
<option *ngFor="let c of conversions" id="{{c}}">Type {{ConversionType[c]}}</option>
|
<!--<option *ngFor="let c of conversions" id="{{c}}">Type {{ConversionType[c]}}</option>-->
|
||||||
</select>
|
<!--</select>-->
|
||||||
</div>
|
<!--</div>-->
|
||||||
|
|
||||||
|
<textarea class="input" (change)="update()" placeholder="Please enter your input ..."
|
||||||
|
[(ngModel)]="content">{{content}}</textarea>
|
||||||
|
<select class="conversion" (change)="convert($event)">
|
||||||
|
<option id="-1">Select conversion ...</option>
|
||||||
|
<option *ngFor="let c of converters" id="{{c.getId()}}">{{c.getDisplayname()}}</option>
|
||||||
|
</select>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {Component} from "@angular/core";
|
import {Component, OnInit} from "@angular/core";
|
||||||
import {ConversionInput} from "./conversioninput";
|
import {ConverterregistryService} from "./converterregistry.service";
|
||||||
import {ConversionType} from "./conversiontype";
|
import {Converter} from "./converter/converter";
|
||||||
|
import {InputcomponentmanagerService} from "./InputcomponentmanagerService";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
@ -9,40 +10,38 @@ import {ConversionType} from "./conversiontype";
|
||||||
templateUrl: "inputarea.component.html",
|
templateUrl: "inputarea.component.html",
|
||||||
styleUrls: ["inputarea.component.css"]
|
styleUrls: ["inputarea.component.css"]
|
||||||
})
|
})
|
||||||
export class InputareaComponent {
|
export class InputareaComponent extends OnInit {
|
||||||
public index:number = 0;
|
public converters:Converter[] = [];
|
||||||
public conversions:ConversionType[] = [ConversionType.ENCODE_BASE64, ConversionType.DECODE_BASE64];
|
public content:string = '';
|
||||||
private conversion:ConversionInput;
|
private selectedConverter:Converter;
|
||||||
// private ConversionType:ConversionType = ConversionType;
|
|
||||||
|
|
||||||
constructor() {
|
constructor(private converterregistryService:ConverterregistryService, private inputcomponentmanagerService:InputcomponentmanagerService) {
|
||||||
console.log("Aloha, " + this.index);
|
super();
|
||||||
this.conversion = new ConversionInput();
|
|
||||||
this.conversion.content = "";
|
|
||||||
this.conversion.type = ConversionType.DECODE_BASE64;
|
|
||||||
}
|
|
||||||
|
|
||||||
public update():void {
|
|
||||||
console.log(this.conversion.content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public convert(e):void {
|
public convert(e):void {
|
||||||
this.conversion.type = ConversionType.of(+e.target.selectedOptions[0].id);
|
this.selectedConverter = this.converterregistryService.getConverter(e.target.selectedOptions[0].id);
|
||||||
console.log(this.conversion.type);
|
this.update();
|
||||||
switch (this.conversion.type) {
|
}
|
||||||
case ConversionType.DECODE_BASE64:
|
|
||||||
this.conversion.content = "Base64 decode";
|
public update():void {
|
||||||
break;
|
if (this.selectedConverter !== undefined) {
|
||||||
case ConversionType.ENCODE_BASE64:
|
let result:string = this.selectedConverter.convert(this.content);
|
||||||
this.conversion.content = "Base64 encode";
|
let nextComponent:InputareaComponent = this.inputcomponentmanagerService.getNext(this);
|
||||||
break;
|
if (nextComponent !== undefined) {
|
||||||
default:
|
nextComponent.setContent(result);
|
||||||
this.conversion.content = "Unknown: " + this.conversion.type;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public setIndex(index:number):void {
|
public setContent(content:string):void {
|
||||||
this.index = index;
|
this.content = content;
|
||||||
|
this.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit():void {
|
||||||
|
this.converters = this.converterregistryService.getAllConverters();
|
||||||
|
this.selectedConverter = undefined;
|
||||||
|
this.inputcomponentmanagerService.register(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
|
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
|
||||||
|
|
||||||
import {AppModule} from "./app.module";
|
import {AppModule} from "./app.module";
|
||||||
|
|
||||||
platformBrowserDynamic().bootstrapModule(AppModule);
|
platformBrowserDynamic().bootstrapModule(AppModule);
|
||||||
|
|
|
@ -59,6 +59,13 @@ div.wrapper {
|
||||||
padding: 0.5em;
|
padding: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.wrapper div.message {
|
||||||
|
display: inline-block;
|
||||||
|
color: #f00;
|
||||||
|
background-color: #fff;
|
||||||
|
border: 1px solid #f00;
|
||||||
|
}
|
||||||
|
|
||||||
textarea.input {
|
textarea.input {
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
|
|
Loading…
Reference in a new issue