Fixed delay tab error

This commit is contained in:
NejcZdovc
2016-10-17 14:35:16 +02:00
committed by József Farkas
parent 9369b956d8
commit 51c33cec3c
2 changed files with 17 additions and 12 deletions

View File

@@ -12,15 +12,15 @@
max="1000" max="1000"
step="0.1" step="0.1"
placeholder="Delay amount" placeholder="Delay amount"
class="form-control" class="form-control"
[(ngModel)]="delay" [attr.value]="delay"
(ngModelChange)="setDelay($event)"> (change)="setDelay($event)">
</div> </div>
</div> </div>
<div class="row macro-delay__presets"> <div class="row macro-delay__presets">
<div class="col-xs-12"> <div class="col-xs-12">
<h6>Choose a preset</h6> <h6>Choose a preset</h6>
<button *ngFor="let delay of presets" class="btn btn-sm btn-default"(click)="setDelay(delay)">{{delay}}s</button> <button *ngFor="let delay of presets" class="btn btn-sm btn-default" (click)="setDelay(delay)">{{delay}}s</button>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,4 +1,11 @@
import { AfterViewInit, Component, ElementRef, Input, OnInit, Renderer, ViewChild } from '@angular/core'; import {
ChangeDetectionStrategy,
Component,
ElementRef,
Input,
OnInit,
ViewChild
} from '@angular/core';
import { EditableMacroAction } from '../../../../../config-serializer/config-items/macro-action'; import { EditableMacroAction } from '../../../../../config-serializer/config-items/macro-action';
@@ -8,26 +15,24 @@ const INITIAL_DELAY = 0.5; // In seconds
selector: 'macro-delay-tab', selector: 'macro-delay-tab',
template: require('./macro-delay.component.html'), template: require('./macro-delay.component.html'),
styles: [require('./macro-delay.component.scss')], styles: [require('./macro-delay.component.scss')],
host: { 'class': 'macro__delay' } host: { 'class': 'macro__delay' },
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class MacroDelayTabComponent implements AfterViewInit, OnInit { export class MacroDelayTabComponent implements OnInit {
@Input() macroAction: EditableMacroAction; @Input() macroAction: EditableMacroAction;
@ViewChild('macroDelayInput') input: ElementRef; @ViewChild('macroDelayInput') input: ElementRef;
private delay: number; private delay: number;
/* tslint:disable:no-unused-variable: It is used in the template. */ /* tslint:disable:no-unused-variable: It is used in the template. */
private presets: number[] = [0.3, 0.5, 0.8, 1, 2, 3, 4, 5]; private presets: number[] = [0.3, 0.5, 0.8, 1, 2, 3, 4, 5];
/* tslint:enable:no-unused-variable */ /* tslint:enable:no-unused-variable */
constructor(private renderer: Renderer) { } constructor() { }
ngOnInit() { ngOnInit() {
this.delay = this.macroAction.delay > 0 ? this.macroAction.delay / 1000 : INITIAL_DELAY; this.delay = this.macroAction.delay > 0 ? this.macroAction.delay / 1000 : INITIAL_DELAY;
} }
ngAfterViewInit() {
this.renderer.invokeElementMethod(this.input.nativeElement, 'focus');
}
setDelay(value: number): void { setDelay(value: number): void {
this.delay = value; this.delay = value;
this.macroAction.delay = this.delay * 1000; this.macroAction.delay = this.delay * 1000;