all files / controls/vg-time-display/ vg-time-display.ts

58.82% Statements 30/51
42.86% Branches 6/14
50% Functions 5/10
58.7% Lines 27/46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126                                                                                                                                                                                                      
import { Component, Input, ElementRef, OnInit, PipeTransform, Pipe, ViewEncapsulation, OnDestroy } from '@angular/core';
import { VgAPI } from '../../core/services/vg-api';
import { Subscription } from 'rxjs/Subscription';
 
// Workaround until we can use UTC with Angular Date Pipe
 
export class VgUtcPipe implements PipeTransform {
    transform(value: number, format: string): string {
        let date = new Date(value);
        let result = format;
        let ss: string|number = date.getUTCSeconds();
        let mm: string|number = date.getUTCMinutes();
        let hh: string|number = date.getUTCHours();
 
        if (ss < 10) {
            ss = '0' + ss;
        }
        if (mm < 10) {
            mm = '0' + mm;
        }
        if (hh < 10) {
            hh = '0' + hh;
        }
 
        result = result.replace(/ss/g, <string>ss);
        result = result.replace(/mm/g, <string>mm);
        result = result.replace(/hh/g, <string>hh);
 
        return result;
    }
static decorators: DecoratorInvocation[] = [
{ type: Pipe, args: [{ name: 'vgUtc' }, ] },
];
/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
];
}
 
 
export class VgTimeDisplay implements OnInit, OnDestroy {
     vgFor: string;
     vgProperty: string = 'current';
     vgFormat: string = 'mm:ss';
 
    elem: HTMLElement;
    target: any;
 
    subscriptions: Subscription[] = [];
 
    constructor(ref: ElementRef, public API: VgAPI) {
        this.elem = ref.nativeElement;
    }
 
    ngOnInit() {
        if (this.API.isPlayerReady) {
            this.onPlayerReady();
        }
        else {
            this.subscriptions.push(this.API.playerReadyEvent.subscribe(() => this.onPlayerReady()));
        }
    }
 
    onPlayerReady() {
        this.target = this.API.getMediaById(this.vgFor);
    }
 
    getTime() {
        let t = 0;
 
        if (this.target) {
            t = Math.round(this.target.time[ this.vgProperty ]);
            t = isNaN(t) || this.target.isLive ? 0 : t;
        }
 
        return t;
    }
 
    ngOnDestroy() {
        this.subscriptions.forEach(s => s.unsubscribe());
    }
static decorators: DecoratorInvocation[] = [
{ type: Component, args: [{
    selector: 'vg-time-display',
    encapsulation: ViewEncapsulation.None,
    template: `
        <span *ngIf="target?.isLive">LIVE</span>
        <span *ngIf="!target?.isLive">{{ getTime() | vgUtc:vgFormat }}</span>
        <ng-content></ng-content>
    `,
    styles: [ `
        vg-time-display {
            -webkit-touch-callout: none;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            display: flex;
            justify-content: center;
            height: 50px;
            width: 60px;
            cursor: pointer;
            color: white;
            line-height: 50px;
            pointer-events: none;
            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
        }
    ` ]
}, ] },
];
/** @nocollapse */
static ctorParameters: ({type: any, decorators?: DecoratorInvocation[]}|null)[] = [
{type: ElementRef, },
{type: VgAPI, },
];
static propDecorators: {[key: string]: DecoratorInvocation[]} = {
'vgFor': [{ type: Input },],
'vgProperty': [{ type: Input },],
'vgFormat': [{ type: Input },],
};
}
 
interface DecoratorInvocation {
  type: Function;
  args?: any[];
}