|
| 1 | +import { Component, EventEmitter, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'; |
| 2 | +import { IgxButtonGroupComponent, IgxSliderComponent, |
| 3 | +} from 'igniteui-angular'; |
| 4 | +import { timer } from 'rxjs'; |
| 5 | +import { debounce } from 'rxjs/operators'; |
| 6 | + |
| 7 | +@Component({ |
| 8 | + selector: 'app-finjs-controllers', |
| 9 | + styleUrls: ['./controllers.component.scss'], |
| 10 | + templateUrl: './controllers.component.html' |
| 11 | +}) |
| 12 | +export class ControllerComponent implements OnInit, OnDestroy { |
| 13 | + @ViewChild('buttonGroup1', { static: true }) public buttonGroup1: IgxButtonGroupComponent; |
| 14 | + @ViewChild('buttonGroup2', { static: true }) public buttonGroup2: IgxButtonGroupComponent; |
| 15 | + @ViewChild('slider1', { static: true }) public volumeSlider: IgxSliderComponent; |
| 16 | + @ViewChild('slider2', { static: true }) public intervalSlider: IgxSliderComponent; |
| 17 | + |
| 18 | + @Output() public switchChanged = new EventEmitter<any>(); |
| 19 | + @Output() public volumeChanged = new EventEmitter<any>(); |
| 20 | + @Output() public frequencyChanged = new EventEmitter<any>(); |
| 21 | + @Output() public playAction = new EventEmitter<any>(); |
| 22 | + |
| 23 | + public selectionMode = 'multiple'; |
| 24 | + public theme = false; |
| 25 | + public volume = 1000; |
| 26 | + public frequency = 500; |
| 27 | + public grouped = true; |
| 28 | + public controls = [ |
| 29 | + { |
| 30 | + disabled: false, |
| 31 | + icon: 'update', |
| 32 | + label: 'LIVE PRICES', |
| 33 | + selected: false |
| 34 | + }, |
| 35 | + { |
| 36 | + disabled: false, |
| 37 | + icon: 'update', |
| 38 | + label: 'LIVE ALL PRICES', |
| 39 | + selected: false |
| 40 | + }, |
| 41 | + { |
| 42 | + disabled: true, |
| 43 | + icon: 'stop', |
| 44 | + label: 'Stop', |
| 45 | + selected: false |
| 46 | + } |
| 47 | + ]; |
| 48 | + |
| 49 | + private subscription; |
| 50 | + private selectedButton; |
| 51 | + private volumeChanged$; |
| 52 | + |
| 53 | + public ngOnInit() { |
| 54 | + this.volumeChanged$ = this.volumeSlider.onValueChange.pipe(debounce(() => timer(200))); |
| 55 | + this.volumeChanged$.subscribe(x => this.volumeChanged.emit(this.volumeSlider.value)); |
| 56 | + } |
| 57 | + |
| 58 | + public onButtonSelected(event: any) { |
| 59 | + switch (event.index) { |
| 60 | + case 0: { |
| 61 | + this.disableOtherButtons(event.index, true); |
| 62 | + this.playAction.emit({ action: 'playRandom'} ); |
| 63 | + break; |
| 64 | + } |
| 65 | + case 1: { |
| 66 | + this.disableOtherButtons(event.index, true); |
| 67 | + this.playAction.emit({ action: 'playAll'} ); |
| 68 | + break; |
| 69 | + } |
| 70 | + case 2: { |
| 71 | + this.disableOtherButtons(event.index, false); |
| 72 | + this.playAction.emit({ action: 'stop'} ); |
| 73 | + break; |
| 74 | + } |
| 75 | + case 3: { |
| 76 | + this.disableOtherButtons(event.index, true); |
| 77 | + break; |
| 78 | + } |
| 79 | + default: |
| 80 | + { |
| 81 | + break; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public onChange(action: string, event: any) { |
| 87 | + this.switchChanged.emit({action, value: event.checked }); |
| 88 | + } |
| 89 | + |
| 90 | + private disableOtherButtons(ind: number, disableButtons: boolean) { |
| 91 | + if (this.subscription) { |
| 92 | + this.subscription.unsubscribe(); |
| 93 | + } |
| 94 | + this.volumeSlider.disabled = disableButtons; |
| 95 | + this.intervalSlider.disabled = disableButtons; |
| 96 | + this.selectedButton = ind; |
| 97 | + this.buttonGroup1.buttons.forEach((button, index) => { |
| 98 | + if (index === 2) { button.disabled = !disableButtons; } else { |
| 99 | + this.buttonGroup1.buttons[0].disabled = disableButtons; |
| 100 | + this.buttonGroup1.buttons[1].disabled = disableButtons; |
| 101 | + } |
| 102 | + }); |
| 103 | + } |
| 104 | + |
| 105 | + get buttonSelected(): number { |
| 106 | + return this.selectedButton || this.selectedButton === 0 ? this.selectedButton : -1; |
| 107 | + } |
| 108 | + |
| 109 | + public ngOnDestroy() { |
| 110 | + this.volumeChanged$.unsubscribe(); |
| 111 | + } |
| 112 | +} |
0 commit comments