Add KeyboardModule Component

This commit is contained in:
József Farkas
2016-04-09 21:58:50 +02:00
parent f8bcf2ef94
commit 4ccf06efc5
3 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import { Component, OnInit, Input, DynamicComponentLoader, ElementRef, ComponentRef } from 'angular2/core';
import {KeyboardButton} from './keyboard-button.model';
import {KeyboardButtonGroupComponent} from './keyboard-button-group.component';
@Component({
selector: 'module',
template:
`
<div #row></div>
`,
styles:
[`
:host {
display: flex;
height: 100%;
width: 100%;
flex-direction: column;
}
`]
})
export class ModuleComponent implements OnInit {
@Input() case: any;
@Input() keyboardButtons: KeyboardButton[];
@Input() fill: string;
constructor(private dcl: DynamicComponentLoader, private elementRef: ElementRef) {
this.keyboardButtons = [];
}
ngOnInit() {
this.getButtonGroups().forEach(buttonGroup => {
this.dcl.loadIntoLocation(KeyboardButtonGroupComponent, this.elementRef, "row").then((bttnComponentRef: ComponentRef) => {
var group: KeyboardButtonGroupComponent = bttnComponentRef.instance;
group.keyboardButtons = buttonGroup;
// console.log(keyboardButtonComponent);
});
});
}
private getButtonGroups(): KeyboardButton[][] {
var buttonGroups: KeyboardButton[][] = [];
var buttonGroup: KeyboardButton[] = [];
this.keyboardButtons.forEach((keyboardButton, index) => {
if (buttonGroup.length > 0 && buttonGroup[buttonGroup.length - 1].y !== keyboardButton.y) {
buttonGroups.push(buttonGroup);
buttonGroup = [];
}
buttonGroup.push(keyboardButton);
});
//console.log(buttonGroups, buttonGroup, this.keyboardButtons);
return buttonGroups;
}
}

View File

@@ -0,0 +1,12 @@
import {KeyboardButton} from './keyboard-button.model';
export class Module {
private case: any;
private keyboardButtons: KeyboardButton[];
constructor(obj: { rect: any[], path: any[] }, fill?: string) {
this.keyboardButtons = obj.rect.map(obj => obj.$);
this.keyboardButtons.forEach(keyboardButton => keyboardButton.fill = fill ? fill : 'black');
this.case = obj.path[0].$;
}
}

3
src/components/module.ts Normal file
View File

@@ -0,0 +1,3 @@
import {Module} from './module.model';
import {ModuleComponent} from './module.component';
export {Module, ModuleComponent};