]>
Commit | Line | Data |
---|---|---|
1 | import { SortMeta } from 'primeng/api' | |
2 | import { Component, OnInit } from '@angular/core' | |
3 | import { Notifier, RestPagination, RestTable } from '@app/core' | |
4 | import { Video, VideoImportService } from '@app/shared/shared-main' | |
5 | import { VideoImport, VideoImportState } from '@shared/models' | |
6 | ||
7 | @Component({ | |
8 | templateUrl: './my-video-imports.component.html', | |
9 | styleUrls: [ './my-video-imports.component.scss' ] | |
10 | }) | |
11 | export class MyVideoImportsComponent extends RestTable implements OnInit { | |
12 | videoImports: VideoImport[] = [] | |
13 | totalRecords = 0 | |
14 | sort: SortMeta = { field: 'createdAt', order: 1 } | |
15 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
16 | ||
17 | constructor ( | |
18 | private notifier: Notifier, | |
19 | private videoImportService: VideoImportService | |
20 | ) { | |
21 | super() | |
22 | } | |
23 | ||
24 | ngOnInit () { | |
25 | this.initialize() | |
26 | } | |
27 | ||
28 | getIdentifier () { | |
29 | return 'MyVideoImportsComponent' | |
30 | } | |
31 | ||
32 | getVideoImportStateClass (state: VideoImportState) { | |
33 | switch (state) { | |
34 | case VideoImportState.FAILED: | |
35 | return 'badge-red' | |
36 | ||
37 | case VideoImportState.REJECTED: | |
38 | return 'badge-banned' | |
39 | ||
40 | case VideoImportState.PENDING: | |
41 | return 'badge-yellow' | |
42 | ||
43 | case VideoImportState.PROCESSING: | |
44 | return 'badge-blue' | |
45 | ||
46 | default: | |
47 | return 'badge-green' | |
48 | } | |
49 | } | |
50 | ||
51 | isVideoImportSuccess (videoImport: VideoImport) { | |
52 | return videoImport.state.id === VideoImportState.SUCCESS | |
53 | } | |
54 | ||
55 | isVideoImportPending (videoImport: VideoImport) { | |
56 | return videoImport.state.id === VideoImportState.PENDING | |
57 | } | |
58 | ||
59 | isVideoImportFailed (videoImport: VideoImport) { | |
60 | return videoImport.state.id === VideoImportState.FAILED | |
61 | } | |
62 | ||
63 | isVideoImportCancelled (videoImport: VideoImport) { | |
64 | return videoImport.state.id === VideoImportState.CANCELLED | |
65 | } | |
66 | ||
67 | getVideoUrl (video: { uuid: string }) { | |
68 | return Video.buildWatchUrl(video) | |
69 | } | |
70 | ||
71 | getEditVideoUrl (video: { uuid: string }) { | |
72 | return Video.buildUpdateUrl(video) | |
73 | } | |
74 | ||
75 | deleteImport (videoImport: VideoImport) { | |
76 | this.videoImportService.deleteVideoImport(videoImport) | |
77 | .subscribe({ | |
78 | next: () => this.reloadData(), | |
79 | ||
80 | error: err => this.notifier.error(err.message) | |
81 | }) | |
82 | } | |
83 | ||
84 | cancelImport (videoImport: VideoImport) { | |
85 | this.videoImportService.cancelVideoImport(videoImport) | |
86 | .subscribe({ | |
87 | next: () => this.reloadData(), | |
88 | ||
89 | error: err => this.notifier.error(err.message) | |
90 | }) | |
91 | } | |
92 | ||
93 | protected reloadDataInternal () { | |
94 | this.videoImportService.getMyVideoImports(this.pagination, this.sort, this.search) | |
95 | .subscribe({ | |
96 | next: resultList => { | |
97 | this.videoImports = resultList.data | |
98 | this.totalRecords = resultList.total | |
99 | }, | |
100 | ||
101 | error: err => this.notifier.error(err.message) | |
102 | }) | |
103 | } | |
104 | } |