diff options
Diffstat (limited to 'client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts')
-rw-r--r-- | client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts new file mode 100644 index 000000000..fdd5ec76e --- /dev/null +++ b/client/src/app/+admin/moderation/video-comment-list/video-comment-list.component.ts | |||
@@ -0,0 +1,111 @@ | |||
1 | import { SortMeta } from 'primeng/api' | ||
2 | import { filter } from 'rxjs/operators' | ||
3 | import { AfterViewInit, Component, OnInit } from '@angular/core' | ||
4 | import { DomSanitizer } from '@angular/platform-browser' | ||
5 | import { ActivatedRoute, Params, Router } from '@angular/router' | ||
6 | import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' | ||
7 | import { DropdownAction, VideoService } from '@app/shared/shared-main' | ||
8 | import { VideoCommentAdmin, VideoCommentService } from '@app/shared/shared-video-comment' | ||
9 | |||
10 | @Component({ | ||
11 | selector: 'my-video-comment-list', | ||
12 | templateUrl: './video-comment-list.component.html', | ||
13 | styleUrls: [ './video-comment-list.component.scss' ] | ||
14 | }) | ||
15 | export class VideoCommentListComponent extends RestTable implements OnInit, AfterViewInit { | ||
16 | comments: VideoCommentAdmin[] | ||
17 | totalRecords = 0 | ||
18 | sort: SortMeta = { field: 'createdAt', order: -1 } | ||
19 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | ||
20 | |||
21 | videoCommentActions: DropdownAction<VideoCommentAdmin>[][] = [] | ||
22 | |||
23 | constructor ( | ||
24 | private notifier: Notifier, | ||
25 | private serverService: ServerService, | ||
26 | private confirmService: ConfirmService, | ||
27 | private videoCommentService: VideoCommentService, | ||
28 | private markdownRenderer: MarkdownService, | ||
29 | private sanitizer: DomSanitizer, | ||
30 | private videoService: VideoService, | ||
31 | private route: ActivatedRoute, | ||
32 | private router: Router | ||
33 | ) { | ||
34 | super() | ||
35 | |||
36 | this.videoCommentActions = [ | ||
37 | [ | ||
38 | |||
39 | // remove this comment, | ||
40 | |||
41 | // remove all comments of this account | ||
42 | |||
43 | ] | ||
44 | ] | ||
45 | } | ||
46 | |||
47 | ngOnInit () { | ||
48 | this.initialize() | ||
49 | |||
50 | this.route.queryParams | ||
51 | .pipe(filter(params => params.search !== undefined && params.search !== null)) | ||
52 | .subscribe(params => { | ||
53 | this.search = params.search | ||
54 | this.setTableFilter(params.search) | ||
55 | this.loadData() | ||
56 | }) | ||
57 | } | ||
58 | |||
59 | ngAfterViewInit () { | ||
60 | if (this.search) this.setTableFilter(this.search) | ||
61 | } | ||
62 | |||
63 | onSearch (event: Event) { | ||
64 | this.onSearch(event) | ||
65 | this.setQueryParams((event.target as HTMLInputElement).value) | ||
66 | } | ||
67 | |||
68 | setQueryParams (search: string) { | ||
69 | const queryParams: Params = {} | ||
70 | |||
71 | if (search) Object.assign(queryParams, { search }) | ||
72 | this.router.navigate([ '/admin/moderation/video-comments/list' ], { queryParams }) | ||
73 | } | ||
74 | |||
75 | resetTableFilter () { | ||
76 | this.setTableFilter('') | ||
77 | this.setQueryParams('') | ||
78 | this.resetSearch() | ||
79 | } | ||
80 | /* END Table filter functions */ | ||
81 | |||
82 | getIdentifier () { | ||
83 | return 'VideoCommentListComponent' | ||
84 | } | ||
85 | |||
86 | toHtml (text: string) { | ||
87 | return this.markdownRenderer.textMarkdownToHTML(text) | ||
88 | } | ||
89 | |||
90 | protected loadData () { | ||
91 | this.videoCommentService.getAdminVideoComments({ | ||
92 | pagination: this.pagination, | ||
93 | sort: this.sort, | ||
94 | search: this.search | ||
95 | }).subscribe( | ||
96 | async resultList => { | ||
97 | this.totalRecords = resultList.total | ||
98 | |||
99 | this.comments = [] | ||
100 | |||
101 | for (const c of resultList.data) { | ||
102 | this.comments.push( | ||
103 | new VideoCommentAdmin(c, await this.toHtml(c.text)) | ||
104 | ) | ||
105 | } | ||
106 | }, | ||
107 | |||
108 | err => this.notifier.error(err.message) | ||
109 | ) | ||
110 | } | ||
111 | } | ||