]>
Commit | Line | Data |
---|---|---|
501bc6c2 C |
1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; |
2 | import { DatePipe } from '@angular/common'; | |
3 | import { ROUTER_DIRECTIVES } from '@angular/router-deprecated'; | |
4 | ||
5 | import { Video } from '../../video'; | |
6 | import { VideosService } from '../../videos.service'; | |
7 | import { User } from '../../../users/models/user'; | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-video-miniature', | |
11 | styleUrls: [ 'app/angular/videos/components/list/video-miniature.component.css' ], | |
12 | templateUrl: 'app/angular/videos/components/list/video-miniature.component.html', | |
13 | directives: [ ROUTER_DIRECTIVES ], | |
14 | pipes: [ DatePipe ] | |
15 | }) | |
16 | ||
17 | export class VideoMiniatureComponent { | |
18 | @Output() removed = new EventEmitter<any>(); | |
19 | ||
20 | @Input() video: Video; | |
21 | @Input() user: User; | |
22 | ||
23 | hovering: boolean = false; | |
24 | ||
25 | constructor(private _videosService: VideosService) {} | |
26 | ||
27 | onHover() { | |
28 | this.hovering = true; | |
29 | } | |
30 | ||
31 | onBlur() { | |
32 | this.hovering = false; | |
33 | } | |
34 | ||
35 | displayRemoveIcon(): boolean { | |
36 | return this.hovering && this.video.isRemovableBy(this.user); | |
37 | } | |
38 | ||
39 | removeVideo(id: string) { | |
40 | if (confirm('Do you really want to remove this video?')) { | |
41 | this._videosService.removeVideo(id).subscribe( | |
42 | status => this.removed.emit(true), | |
43 | error => alert(error) | |
44 | ); | |
45 | } | |
46 | } | |
47 | } |