diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-history')
3 files changed, 233 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-history/my-account-history.component.html b/client/src/app/+my-account/my-account-history/my-account-history.component.html new file mode 100644 index 000000000..d42af37d4 --- /dev/null +++ b/client/src/app/+my-account/my-account-history/my-account-history.component.html | |||
@@ -0,0 +1,27 @@ | |||
1 | <div class="top-buttons"> | ||
2 | <div class="history-switch"> | ||
3 | <p-inputSwitch [(ngModel)]="videosHistoryEnabled" (ngModelChange)="onVideosHistoryChange()"></p-inputSwitch> | ||
4 | <label i18n>History enabled</label> | ||
5 | </div> | ||
6 | |||
7 | <div class="delete-history"> | ||
8 | <button (click)="deleteHistory()" i18n>Delete history</button> | ||
9 | </div> | ||
10 | </div> | ||
11 | |||
12 | |||
13 | <div class="no-history" i18n *ngIf="pagination.totalItems === 0">You don't have videos history yet.</div> | ||
14 | |||
15 | <div myInfiniteScroller (nearOfBottom)="onNearOfBottom()" class="videos" #videosElement> | ||
16 | <div *ngFor="let videos of videoPages;" class="videos-page"> | ||
17 | <div class="video" *ngFor="let video of videos"> | ||
18 | <my-video-thumbnail [video]="video"></my-video-thumbnail> | ||
19 | |||
20 | <div class="video-info"> | ||
21 | <a tabindex="-1" class="video-info-name" [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name">{{ video.name }}</a> | ||
22 | <span i18n class="video-info-date-views">{{ video.views | myNumberFormatter }} views</span> | ||
23 | <a tabindex="-1" class="video-info-account" [routerLink]="[ '/accounts', video.byAccount ]">{{ video.byAccount }}</a> | ||
24 | </div> | ||
25 | </div> | ||
26 | </div> | ||
27 | </div> | ||
diff --git a/client/src/app/+my-account/my-account-history/my-account-history.component.scss b/client/src/app/+my-account/my-account-history/my-account-history.component.scss new file mode 100644 index 000000000..e7c6863f1 --- /dev/null +++ b/client/src/app/+my-account/my-account-history/my-account-history.component.scss | |||
@@ -0,0 +1,99 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | .no-history { | ||
5 | display: flex; | ||
6 | justify-content: center; | ||
7 | margin-top: 50px; | ||
8 | font-weight: $font-semibold; | ||
9 | font-size: 16px; | ||
10 | } | ||
11 | |||
12 | .top-buttons { | ||
13 | margin-bottom: 20px; | ||
14 | display: flex; | ||
15 | |||
16 | .history-switch { | ||
17 | display: flex; | ||
18 | flex-grow: 1; | ||
19 | |||
20 | label { | ||
21 | margin: 0 0 0 5px; | ||
22 | } | ||
23 | } | ||
24 | |||
25 | .delete-history { | ||
26 | font-size: 15px; | ||
27 | |||
28 | button { | ||
29 | @include peertube-button; | ||
30 | @include grey-button; | ||
31 | } | ||
32 | } | ||
33 | } | ||
34 | |||
35 | .video { | ||
36 | @include row-blocks; | ||
37 | |||
38 | my-video-thumbnail { | ||
39 | margin-right: 10px; | ||
40 | } | ||
41 | |||
42 | .video-info { | ||
43 | flex-grow: 1; | ||
44 | |||
45 | .video-info-name { | ||
46 | @include disable-default-a-behaviour; | ||
47 | |||
48 | color: var(--mainForegroundColor); | ||
49 | display: block; | ||
50 | width: fit-content; | ||
51 | font-size: 18px; | ||
52 | font-weight: $font-semibold; | ||
53 | } | ||
54 | |||
55 | .video-info-date-views { | ||
56 | font-size: 14px; | ||
57 | } | ||
58 | |||
59 | .video-info-account { | ||
60 | @include disable-default-a-behaviour; | ||
61 | |||
62 | display: block; | ||
63 | width: fit-content; | ||
64 | overflow: hidden; | ||
65 | text-overflow: ellipsis; | ||
66 | white-space: nowrap; | ||
67 | font-size: 14px; | ||
68 | color: $grey-foreground-color; | ||
69 | |||
70 | &:hover { | ||
71 | color: $grey-foreground-hover-color; | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | @media screen and (max-width: $small-view) { | ||
78 | .video { | ||
79 | flex-direction: column; | ||
80 | height: auto; | ||
81 | text-align: center; | ||
82 | |||
83 | .video-info-name { | ||
84 | margin: auto; | ||
85 | } | ||
86 | |||
87 | input[type=checkbox] { | ||
88 | display: none; | ||
89 | } | ||
90 | |||
91 | my-video-thumbnail { | ||
92 | margin-right: 0; | ||
93 | } | ||
94 | |||
95 | .video-buttons { | ||
96 | margin-top: 10px; | ||
97 | } | ||
98 | } | ||
99 | } | ||
diff --git a/client/src/app/+my-account/my-account-history/my-account-history.component.ts b/client/src/app/+my-account/my-account-history/my-account-history.component.ts new file mode 100644 index 000000000..394091bad --- /dev/null +++ b/client/src/app/+my-account/my-account-history/my-account-history.component.ts | |||
@@ -0,0 +1,107 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { Location } from '@angular/common' | ||
4 | import { immutableAssign } from '@app/shared/misc/utils' | ||
5 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | ||
6 | import { AuthService } from '../../core/auth' | ||
7 | import { ConfirmService } from '../../core/confirm' | ||
8 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
9 | import { VideoService } from '../../shared/video/video.service' | ||
10 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
11 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
12 | import { UserHistoryService } from '@app/shared/users/user-history.service' | ||
13 | import { UserService } from '@app/shared' | ||
14 | import { Notifier } from '@app/core' | ||
15 | |||
16 | @Component({ | ||
17 | selector: 'my-account-history', | ||
18 | templateUrl: './my-account-history.component.html', | ||
19 | styleUrls: [ './my-account-history.component.scss' ] | ||
20 | }) | ||
21 | export class MyAccountHistoryComponent extends AbstractVideoList implements OnInit, OnDestroy { | ||
22 | titlePage: string | ||
23 | currentRoute = '/my-account/history/videos' | ||
24 | pagination: ComponentPagination = { | ||
25 | currentPage: 1, | ||
26 | itemsPerPage: 5, | ||
27 | totalItems: null | ||
28 | } | ||
29 | videosHistoryEnabled: boolean | ||
30 | |||
31 | protected baseVideoWidth = -1 | ||
32 | protected baseVideoHeight = 155 | ||
33 | |||
34 | constructor ( | ||
35 | protected router: Router, | ||
36 | protected route: ActivatedRoute, | ||
37 | protected authService: AuthService, | ||
38 | protected userService: UserService, | ||
39 | protected notifier: Notifier, | ||
40 | protected location: Location, | ||
41 | protected screenService: ScreenService, | ||
42 | protected i18n: I18n, | ||
43 | private confirmService: ConfirmService, | ||
44 | private videoService: VideoService, | ||
45 | private userHistoryService: UserHistoryService | ||
46 | ) { | ||
47 | super() | ||
48 | |||
49 | this.titlePage = this.i18n('My videos history') | ||
50 | } | ||
51 | |||
52 | ngOnInit () { | ||
53 | super.ngOnInit() | ||
54 | |||
55 | this.videosHistoryEnabled = this.authService.getUser().videosHistoryEnabled | ||
56 | } | ||
57 | |||
58 | ngOnDestroy () { | ||
59 | super.ngOnDestroy() | ||
60 | } | ||
61 | |||
62 | getVideosObservable (page: number) { | ||
63 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
64 | |||
65 | return this.userHistoryService.getUserVideosHistory(newPagination) | ||
66 | } | ||
67 | |||
68 | generateSyndicationList () { | ||
69 | throw new Error('Method not implemented.') | ||
70 | } | ||
71 | |||
72 | onVideosHistoryChange () { | ||
73 | this.userService.updateMyProfile({ videosHistoryEnabled: this.videosHistoryEnabled }) | ||
74 | .subscribe( | ||
75 | () => { | ||
76 | const message = this.videosHistoryEnabled === true ? | ||
77 | this.i18n('Videos history is enabled') : | ||
78 | this.i18n('Videos history is disabled') | ||
79 | |||
80 | this.notifier.success(message) | ||
81 | |||
82 | this.authService.refreshUserInformation() | ||
83 | }, | ||
84 | |||
85 | err => this.notifier.error(err.message) | ||
86 | ) | ||
87 | } | ||
88 | |||
89 | async deleteHistory () { | ||
90 | const title = this.i18n('Delete videos history') | ||
91 | const message = this.i18n('Are you sure you want to delete all your videos history?') | ||
92 | |||
93 | const res = await this.confirmService.confirm(message, title) | ||
94 | if (res !== true) return | ||
95 | |||
96 | this.userHistoryService.deleteUserVideosHistory() | ||
97 | .subscribe( | ||
98 | () => { | ||
99 | this.notifier.success(this.i18n('Videos history deleted')) | ||
100 | |||
101 | this.reloadVideos() | ||
102 | }, | ||
103 | |||
104 | err => this.notifier.error(err.message) | ||
105 | ) | ||
106 | } | ||
107 | } | ||