Commit 758ce9f03e64cb94b05a328008cf21f1bea82fd5

Authored by Vladyslav_Prykhodko
1 parent c1223b0c

UI: Fixed bug trip animation widget after change speed or change time to the time slider

@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 <mat-icon class="material-icons" [ngStyle]="{'color': settings.buttonColor}">skip_previous</mat-icon> 24 <mat-icon class="material-icons" [ngStyle]="{'color': settings.buttonColor}">skip_previous</mat-icon>
25 </button> 25 </button>
26 <div fxLayout="column" fxFlex="100"> 26 <div fxLayout="column" fxFlex="100">
27 - <mat-slider [(ngModel)]="index" [min]="minTimeIndex" [max]="maxTimeIndex" (change)="changeIndex()"> 27 + <mat-slider [(ngModel)]="index" [min]="minTimeIndex" [max]="maxTimeIndex" (input)="changeIndex($event.value)">
28 </mat-slider> 28 </mat-slider>
29 <div class="panel-timer"> 29 <div class="panel-timer">
30 <span *ngIf="this.currentTime">{{ this.currentTime | date:'medium'}}</span> 30 <span *ngIf="this.currentTime">{{ this.currentTime | date:'medium'}}</span>
@@ -47,8 +47,8 @@ @@ -47,8 +47,8 @@
47 pause_circle_outline 47 pause_circle_outline
48 </mat-icon> 48 </mat-icon>
49 </button> 49 </button>
50 - <mat-select [(ngModel)]="speed" (selectionChange)="reeneble()" class="speed-select" aria-label="Speed selector"> 50 + <mat-select [(ngModel)]="speed" (selectionChange)="reInit()" class="speed-select" aria-label="Speed selector">
51 <mat-option [value]="speedValue" *ngFor="let speedValue of speeds">{{speedValue}} </mat-option> 51 <mat-option [value]="speedValue" *ngFor="let speedValue of speeds">{{speedValue}} </mat-option>
52 </mat-select> 52 </mat-select>
53 </div> 53 </div>
54 -</div>  
  54 +</div>
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; 17 +import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
18 import { interval } from 'rxjs'; 18 import { interval } from 'rxjs';
19 import { filter } from 'rxjs/operators'; 19 import { filter } from 'rxjs/operators';
20 import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/maps/map-models'; 20 import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/maps/map-models';
@@ -24,9 +24,9 @@ import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/m @@ -24,9 +24,9 @@ import { HistorySelectSettings } from '@app/modules/home/components/widget/lib/m
24 templateUrl: './history-selector.component.html', 24 templateUrl: './history-selector.component.html',
25 styleUrls: ['./history-selector.component.scss'] 25 styleUrls: ['./history-selector.component.scss']
26 }) 26 })
27 -export class HistorySelectorComponent implements OnInit, OnChanges { 27 +export class HistorySelectorComponent implements OnChanges {
28 28
29 - @Input() settings: HistorySelectSettings 29 + @Input() settings: HistorySelectSettings;
30 @Input() minTime: number; 30 @Input() minTime: number;
31 @Input() maxTime: number; 31 @Input() maxTime: number;
32 @Input() step = 1000; 32 @Input() step = 1000;
@@ -47,9 +47,6 @@ export class HistorySelectorComponent implements OnInit, OnChanges { @@ -47,9 +47,6 @@ export class HistorySelectorComponent implements OnInit, OnChanges {
47 47
48 constructor(private cd: ChangeDetectorRef) { } 48 constructor(private cd: ChangeDetectorRef) { }
49 49
50 - ngOnInit(): void {  
51 - }  
52 -  
53 ngOnChanges() { 50 ngOnChanges() {
54 this.maxTimeIndex = Math.ceil((this.maxTime - this.minTime) / this.step); 51 this.maxTimeIndex = Math.ceil((this.maxTime - this.minTime) / this.step);
55 this.currentTime = this.minTime === Infinity ? null : this.minTime; 52 this.currentTime = this.minTime === Infinity ? null : this.minTime;
@@ -57,34 +54,34 @@ export class HistorySelectorComponent implements OnInit, OnChanges { @@ -57,34 +54,34 @@ export class HistorySelectorComponent implements OnInit, OnChanges {
57 54
58 play() { 55 play() {
59 this.playing = true; 56 this.playing = true;
60 - if (!this.interval) 57 + if (!this.interval) {
61 this.interval = interval(1000 / this.speed) 58 this.interval = interval(1000 / this.speed)
62 .pipe( 59 .pipe(
63 - filter(() => this.playing)).subscribe(() => {  
64 - this.index++;  
65 - this.currentTime = this.minTime + this.index * this.step;  
66 - if (this.index <= this.maxTimeIndex) {  
67 - this.cd.detectChanges();  
68 - this.timeUpdated.emit(this.currentTime);  
69 - }  
70 - else {  
71 - this.interval.complete();  
72 - }  
73 - }, err => {  
74 - console.error(err);  
75 - }, () => {  
76 - this.currentTime = this.index = this.minTimeIndex; 60 + filter(() => this.playing)
  61 + ).subscribe(() => {
  62 + this.index++;
  63 + this.currentTime = this.minTime + this.index * this.step;
  64 + if (this.index <= this.maxTimeIndex) {
  65 + this.cd.detectChanges();
  66 + this.timeUpdated.emit(this.currentTime);
  67 + } else {
77 this.playing = false; 68 this.playing = false;
78 - this.interval = null; 69 + this.interval.complete();
79 this.cd.detectChanges(); 70 this.cd.detectChanges();
80 - }); 71 + }
  72 + }, err => {
  73 + console.error(err);
  74 + }, () => {
  75 + this.interval = null;
  76 + });
  77 + }
81 } 78 }
82 79
83 - reeneble() {  
84 - if (this.playing) {  
85 - const position = this.index; 80 + reInit() {
  81 + if (this.interval) {
86 this.interval.complete(); 82 this.interval.complete();
87 - this.index = position; 83 + }
  84 + if (this.playing) {
88 this.play(); 85 this.play();
89 } 86 }
90 } 87 }
@@ -138,8 +135,9 @@ export class HistorySelectorComponent implements OnInit, OnChanges { @@ -138,8 +135,9 @@ export class HistorySelectorComponent implements OnInit, OnChanges {
138 this.pause(); 135 this.pause();
139 } 136 }
140 137
141 - changeIndex() {  
142 - this.currentTime = this.minTime + this.index * this.step; 138 + changeIndex(index: number) {
  139 + this.index = index;
  140 + this.currentTime = this.minTime + index * this.step;
143 this.timeUpdated.emit(this.currentTime); 141 this.timeUpdated.emit(this.currentTime);
144 } 142 }
145 } 143 }