Skip to content

Commit

Permalink
fix(timeline): fix bug of get set properity do not work when typescri…
Browse files Browse the repository at this point in the history
…pt less than 3.7
  • Loading branch information
LennonReid committed Jul 28, 2020
1 parent e84616f commit b4df5f5
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 104 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { TimelineModule } from 'projects/timeline/src/lib/timeline.module';
import { NgxVideoTimelineModule } from 'projects/timeline/src/lib/timeline.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
TimelineModule
NgxVideoTimelineModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
4 changes: 2 additions & 2 deletions projects/timeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { TimelineModule } from 'projects/timeline/src/lib/timeline.module';
import { NgxVideoTimelineModule } from 'projects/timeline/src/lib/timeline.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
TimelineModule
NgxVideoTimelineModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
2 changes: 1 addition & 1 deletion projects/timeline/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-video-timeline",
"version": "0.0.7",
"version": "0.1.0",
"peerDependencies": {
"@angular/common": "^9.1.12",
"@angular/core": "^9.1.12"
Expand Down
123 changes: 42 additions & 81 deletions projects/timeline/src/lib/timeline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,97 +48,30 @@ export interface VideoCellType {
templateUrl: './timeline.component.html',
styleUrls: ['./timeline.component.scss']
})
export class TimelineComponent implements OnInit, OnChanges {
export class NgxVideoTimelineComponent implements OnInit, OnChanges {

// Canvas scale is adjusted according to outer height
private _scale = 20;
get scale(): number {
return (this.canvasHeight / 4.55);
}

// The height of the outer canvas
private _canvasHeight = 50;
get canvasHeight(): number {
return this._canvasHeight;
}
@Input() canvasHeight = 50;

@Input()
set canvasHeight(value: number) {
this._canvasHeight = value;
}
// Canvas scale is adjusted according to outer height
scale = this.canvasHeight / 4.55;

// Video playback time
private _playTime = new Date().getTime();
get playTime(): number | string | Date {
return this._playTime;
}

@Input()
set playTime(value: number | string | Date) {
if (value instanceof String) {
this._playTime = new Date(value).getTime();
} else if (value instanceof Date) {
this._playTime = value.getTime();
} else if (typeof value === 'number') {
this._playTime = Number(value);
}
}
@Input() playTime: number | string | Date;

// The video plays at twice the speed
private _speed = 1;
get speed(): number {
return 1 / this._speed * 1000;
}

@Input()
set speed(value: number) {
this._speed = value;
}
@Input() speed: number;

// Video fast forward value
private _forWardValue = 5;
get forWardValue(): number {
return this._forWardValue * 1000;
}

@Input()
set forWardValue(value: number) {
this._forWardValue = value;
}
@Input() forWardValue: number;

// Start time limit: Timestamp
private _startTimeThreshold = new Date().getTime() - 1 * 12 * 3600 * 1000;
get startTimeThreshold(): number | string | Date {
return this._startTimeThreshold;
}

@Input()
set startTimeThreshold(value: number | string | Date) {
if (value instanceof String) {
this._startTimeThreshold = new Date(value).getTime();
} else if (value instanceof Date) {
this._startTimeThreshold = value.getTime();
} else if (typeof value === 'number') {
this._startTimeThreshold = Number(value);
}
}
@Input() startTimeThreshold: number | string | Date;

// End time limit: Timestamp
private _endTimeThreshold = new Date().getTime() + 1 * 12 * 3600 * 1000;
get endTimeThreshold(): number | string | Date {
return this._endTimeThreshold;
}
@Input() endTimeThreshold: number | string | Date;

@Input()
set endTimeThreshold(value: number | string | Date) {
if (value instanceof String) {
this._endTimeThreshold = new Date(value).getTime();
} else if (value instanceof Date) {
this._endTimeThreshold = value.getTime();
} else if (typeof value === 'number') {
this._endTimeThreshold = Number(value);
}
}
// relation to Css Start

// color of canvas border
Expand Down Expand Up @@ -262,6 +195,11 @@ export class TimelineComponent implements OnInit, OnChanges {
constructor() {
// this.startTimeThreshold = new Date().getTime() - 1 * 0.5 * 3600 * 1000;
// this.endTimeThreshold = new Date().getTime() + 1 * 1 * 3600 * 1000;
this.forWardValue = 5000;
this.speed = 1000;
this.playTime = new Date().getTime();
this.startTimeThreshold = new Date().getTime() - 1 * 12 * 3600 * 1000;
this.endTimeThreshold = new Date().getTime() + 1 * 12 * 3600 * 1000;
this.playClick = new EventEmitter<any>();
this.mouseUp = new EventEmitter<any>();
this.mouseDown = new EventEmitter<any>();
Expand Down Expand Up @@ -486,7 +424,14 @@ export class TimelineComponent implements OnInit, OnChanges {
// this.drawPalyBar();
}
if (changes.startTimeThreshold) {
this.startTimeThreshold = changes.startTimeThreshold.currentValue;
const value = changes.startTimeThreshold.currentValue;
if (changes.startTimeThreshold.currentValue instanceof String) {
this.startTimeThreshold = new Date(value).getTime();
} else if (value instanceof Date) {
this.startTimeThreshold = value.getTime();
} else if (typeof value === 'number') {
this.startTimeThreshold = Number(value);
}

this.hoursPerRuler = Math.ceil((Number(this.endTimeThreshold) - Number(this.startTimeThreshold)) / 1000 / 3600) < 24
? Math.ceil((Number(this.endTimeThreshold) - Number(this.startTimeThreshold)) / 1000 / 3600)
Expand All @@ -496,14 +441,29 @@ export class TimelineComponent implements OnInit, OnChanges {
// this.init(this.startTimestamp, this.timecell, false);
}
if (changes.endTimeThreshold) {
this.endTimeThreshold = changes.endTimeThreshold.currentValue;
const value = changes.endTimeThreshold.currentValue;
if (changes.endTimeThreshold.currentValue instanceof String) {
this.endTimeThreshold = new Date(value).getTime();
} else if (value instanceof Date) {
this.endTimeThreshold = value.getTime();
} else if (typeof value === 'number') {
this.endTimeThreshold = Number(value);
}
this.hoursPerRuler = Math.ceil((Number(this.endTimeThreshold) - Number(this.startTimeThreshold)) / 1000 / 3600) < 24
? Math.ceil((Number(this.endTimeThreshold) - Number(this.startTimeThreshold)) / 1000 / 3600)
: 24;

}
if (changes.playTime) {
this.playTime = changes.playTime.currentValue;

const value = changes.playTime.currentValue;
if (changes.playTime.currentValue instanceof String) {
this.playTime = new Date(value).getTime();
} else if (value instanceof Date) {
this.playTime = value.getTime();
} else if (typeof value === 'number') {
this.playTime = Number(value);
}

// use SetTimeOut Timer to make it asynchronous
setTimeout(() => {
Expand All @@ -513,12 +473,13 @@ export class TimelineComponent implements OnInit, OnChanges {
}
if (changes.speed) {

this.speed = changes.speed.currentValue;
this.speed = Number(changes.speed.currentValue) * 1000;
}
if (changes.forWardValue) {

this.forWardValue = changes.forWardValue.currentValue;
this.forWardValue = Number(changes.forWardValue.currentValue) * 1000;
}

if (changes.isPlayClick) {
if (changes.isPlayClick.currentValue) {
this.onPlayClick();
Expand Down
14 changes: 7 additions & 7 deletions projects/timeline/src/lib/timeline.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { NgModule } from '@angular/core';
import { TimelineComponent } from './timeline.component';
import { NgxVideoTimelineComponent } from './timeline.component';
import {CommonModule} from '@angular/common';



@NgModule({
declarations: [TimelineComponent],
imports: [
CommonModule
],
exports: [TimelineComponent]
declarations: [NgxVideoTimelineComponent],
imports: [
CommonModule
],
exports: [NgxVideoTimelineComponent]
})
export class TimelineModule { }
export class NgxVideoTimelineModule { }
6 changes: 3 additions & 3 deletions projects/timeline/src/lib/timeline.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';

import { TimelineService } from './timeline.service';
import { NgxVideoTimelineService } from './timeline.service';

describe('TimelineService', () => {
let service: TimelineService;
let service: NgxVideoTimelineService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TimelineService);
service = TestBed.inject(NgxVideoTimelineService);
});

it('should be created', () => {
Expand Down
2 changes: 1 addition & 1 deletion projects/timeline/src/lib/timeline.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TimelineService {
export class NgxVideoTimelineService {

constructor() { }
}
10 changes: 5 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export class AppComponent implements OnInit {

speed: number;
canvasHeight: number;
startTimeThreshold: number;
endTimeThreshold: number;
startTimeThreshold: number | string | Date;
endTimeThreshold: number | string | Date;
videoCells: VideoCellType[];
playTime: Date;
isPlayClick: boolean;

constructor() {
this.speed = 10;
this.speed = 1;
this.isPlayClick = false;
this.canvasHeight = 80;
this.startTimeThreshold = new Date().getTime() - 1 * 3600 * 1000;
this.endTimeThreshold = new Date().getTime() + 1 * 3600 * 1000;
this.startTimeThreshold = new Date('2020-07-27 00:00:00');
this.endTimeThreshold = new Date('2020-07-29 00:00:00');
this.videoCells = [];
this.playTime = new Date();
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { TimelineModule } from 'projects/timeline/src/lib/timeline.module';
import { NgxVideoTimelineModule } from 'projects/timeline/src/lib/timeline.module';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
TimelineModule
NgxVideoTimelineModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
},
"compilerOptions": {
"skipLibCheck": true
}
}

0 comments on commit b4df5f5

Please sign in to comment.