aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/components/list/video-miniature.component.ts
blob: 383c2c609d79f11db8d19b4e5e4193d01d55aaa8 (plain) (blame)
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
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { DatePipe } from '@angular/common';
import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';

import { Video } from '../../video';
import { VideosService } from '../../videos.service';
import { User } from '../../../users/models/user';

@Component({
  selector: 'my-video-miniature',
  styleUrls: [ 'app/angular/videos/components/list/video-miniature.component.css' ],
  templateUrl: 'app/angular/videos/components/list/video-miniature.component.html',
  directives: [ ROUTER_DIRECTIVES ],
  pipes: [ DatePipe ]
})

export class VideoMiniatureComponent {
  @Output() removed = new EventEmitter<any>();

  @Input() video: Video;
  @Input() user: User;

  hovering: boolean = false;

  constructor(private _videosService: VideosService) {}

  onHover() {
    this.hovering = true;
  }

  onBlur() {
    this.hovering = false;
  }

  displayRemoveIcon(): boolean {
    return this.hovering && this.video.isRemovableBy(this.user);
  }

  removeVideo(id: string) {
    if (confirm('Do you really want to remove this video?')) {
      this._videosService.removeVideo(id).subscribe(
        status => this.removed.emit(true),
        error => alert(error)
      );
    }
  }
}