]>
Commit | Line | Data |
---|---|---|
f3aaa9a9 | 1 | import { Component, OnInit } from '@angular/core' |
be447678 | 2 | import { ActivatedRoute, Router } from '@angular/router' |
202f6b6c | 3 | import { NotificationsService } from 'angular2-notifications' |
332542bc | 4 | import { ConfirmService } from '../../core/confirm' |
be447678 | 5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' |
332542bc | 6 | import { Video } from '../../shared/video/video.model' |
202f6b6c C |
7 | import { VideoService } from '../../shared/video/video.service' |
8 | ||
9 | @Component({ | |
10 | selector: 'my-account-videos', | |
11 | templateUrl: './account-videos.component.html', | |
12 | styleUrls: [ './account-videos.component.scss' ] | |
13 | }) | |
f3aaa9a9 | 14 | export class AccountVideosComponent extends AbstractVideoList implements OnInit { |
202f6b6c C |
15 | titlePage = 'My videos' |
16 | currentRoute = '/account/videos' | |
17 | ||
18 | constructor (protected router: Router, | |
19 | protected route: ActivatedRoute, | |
20 | protected notificationsService: NotificationsService, | |
332542bc | 21 | protected confirmService: ConfirmService, |
202f6b6c C |
22 | private videoService: VideoService) { |
23 | super() | |
24 | } | |
25 | ||
26 | ngOnInit () { | |
27 | super.ngOnInit() | |
28 | } | |
29 | ||
202f6b6c C |
30 | getVideosObservable () { |
31 | return this.videoService.getMyVideos(this.pagination, this.sort) | |
32 | } | |
332542bc C |
33 | |
34 | deleteVideo (video: Video) { | |
35 | this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe( | |
36 | res => { | |
37 | if (res === false) return | |
38 | ||
39 | this.videoService.removeVideo(video.id) | |
40 | .subscribe( | |
41 | status => { | |
42 | this.notificationsService.success('Success', `Video ${video.name} deleted.`) | |
43 | const index = this.videos.findIndex(v => v.id === video.id) | |
44 | this.videos.splice(index, 1) | |
45 | }, | |
46 | ||
47 | error => this.notificationsService.error('Error', error.text) | |
48 | ) | |
49 | } | |
50 | ) | |
51 | } | |
202f6b6c | 52 | } |