aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-library/my-videos
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+my-library/my-videos')
-rw-r--r--client/src/app/+my-library/my-videos/modals/video-change-ownership.component.html33
-rw-r--r--client/src/app/+my-library/my-videos/modals/video-change-ownership.component.scss10
-rw-r--r--client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts69
-rw-r--r--client/src/app/+my-library/my-videos/my-videos.component.html58
-rw-r--r--client/src/app/+my-library/my-videos/my-videos.component.scss138
-rw-r--r--client/src/app/+my-library/my-videos/my-videos.component.ts178
6 files changed, 486 insertions, 0 deletions
diff --git a/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.html b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.html
new file mode 100644
index 000000000..c7c5a0b69
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.html
@@ -0,0 +1,33 @@
1<ng-template #modal let-close="close" let-dismiss="dismiss">
2 <div class="modal-header">
3 <h4 i18n class="modal-title">Change ownership</h4>
4
5 <my-global-icon iconName="cross" aria-label="Close" role="button" (click)="dismiss()"></my-global-icon>
6 </div>
7
8 <div class="modal-body" [formGroup]="form">
9 <div class="form-group">
10 <label i18n for="next-ownership-username">Select the next owner</label>
11 <p-autoComplete formControlName="username" [suggestions]="usernamePropositions"
12 (completeMethod)="search($event)" id="next-ownership-username"></p-autoComplete>
13 <div *ngIf="formErrors.username" class="form-error">
14 {{ formErrors.username }}
15 </div>
16 </div>
17 </div>
18
19 <div class="modal-footer">
20 <div class="form-group inputs">
21 <input
22 type="button" role="button" i18n-value value="Cancel" class="action-button action-button-cancel"
23 (click)="dismiss()" (key.enter)="dismiss()"
24 >
25
26 <input
27 type="submit" i18n-value value="Submit" class="action-button-submit"
28 [disabled]="!form.valid"
29 (click)="close()"
30 />
31 </div>
32 </div>
33</ng-template>
diff --git a/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.scss b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.scss
new file mode 100644
index 000000000..a79fec179
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.scss
@@ -0,0 +1,10 @@
1@import '_variables';
2@import '_mixins';
3
4p-autocomplete {
5 display: block;
6}
7
8.form-group {
9 margin: 20px 0;
10} \ No newline at end of file
diff --git a/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts
new file mode 100644
index 000000000..84237dee1
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/modals/video-change-ownership.component.ts
@@ -0,0 +1,69 @@
1import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'
2import { Notifier, UserService } from '@app/core'
3import { OWNERSHIP_CHANGE_USERNAME_VALIDATOR } from '@app/shared/form-validators/video-ownership-change-validators'
4import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
5import { Video, VideoOwnershipService } from '@app/shared/shared-main'
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
7
8@Component({
9 selector: 'my-video-change-ownership',
10 templateUrl: './video-change-ownership.component.html',
11 styleUrls: [ './video-change-ownership.component.scss' ]
12})
13export class VideoChangeOwnershipComponent extends FormReactive implements OnInit {
14 @ViewChild('modal', { static: true }) modal: ElementRef
15
16 usernamePropositions: string[]
17
18 error: string = null
19
20 private video: Video | undefined = undefined
21
22 constructor (
23 protected formValidatorService: FormValidatorService,
24 private videoOwnershipService: VideoOwnershipService,
25 private notifier: Notifier,
26 private userService: UserService,
27 private modalService: NgbModal
28 ) {
29 super()
30 }
31
32 ngOnInit () {
33 this.buildForm({
34 username: OWNERSHIP_CHANGE_USERNAME_VALIDATOR
35 })
36 this.usernamePropositions = []
37 }
38
39 show (video: Video) {
40 this.video = video
41 this.modalService
42 .open(this.modal, { centered: true })
43 .result
44 .then(() => this.changeOwnership())
45 .catch((_) => _) // Called when closing (cancel) the modal without validating, do nothing
46 }
47
48 search (event: { query: string }) {
49 const query = event.query
50 this.userService.autocomplete(query)
51 .subscribe(
52 usernames => this.usernamePropositions = usernames,
53
54 err => this.notifier.error(err.message)
55 )
56 }
57
58 changeOwnership () {
59 const username = this.form.value['username']
60
61 this.videoOwnershipService
62 .changeOwnership(this.video.id, username)
63 .subscribe(
64 () => this.notifier.success($localize`Ownership change request sent.`),
65
66 err => this.notifier.error(err.message)
67 )
68 }
69}
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.html b/client/src/app/+my-library/my-videos/my-videos.component.html
new file mode 100644
index 000000000..977f7b03b
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/my-videos.component.html
@@ -0,0 +1,58 @@
1<h1>
2 <span>
3 <my-global-icon iconName="videos" aria-hidden="true"></my-global-icon>
4 <ng-container i18n>My videos</ng-container>
5 <span class="badge badge-secondary"> {{ pagination.totalItems }}</span>
6 </span>
7
8 <div>
9 <a routerLink="/my-library/video-imports" class="button-link">
10 <my-global-icon iconName="cloud-download" aria-hidden="true"></my-global-icon>
11 <ng-container i18n>My imports</ng-container>
12 </a>
13
14 <a routerLink="/my-library/ownership" class="button-link">
15 <my-global-icon iconName="users" aria-hidden="true"></my-global-icon>
16 <ng-container i18n>Ownership changes</ng-container>
17 </a>
18 </div>
19</h1>
20
21<div class="videos-header d-flex justify-content-between">
22 <div class="has-feedback has-clear">
23 <input type="text" placeholder="Search your videos" i18n-placeholder [(ngModel)]="videosSearch"
24 (ngModelChange)="onVideosSearchChanged()" />
25 <a class="glyphicon glyphicon-remove-sign form-control-feedback form-control-clear" (click)="resetSearch()"></a>
26 <span class="sr-only" i18n>Clear filters</span>
27 </div>
28</div>
29
30<my-videos-selection
31 [pagination]="pagination"
32 [(selection)]="selection"
33 [(videosModel)]="videos"
34 [miniatureDisplayOptions]="miniatureDisplayOptions"
35 [titlePage]="titlePage"
36 [getVideosObservableFunction]="getVideosObservableFunction"
37 [ownerDisplayType]="ownerDisplayType"
38 #videosSelection
39>
40 <ng-template ptTemplate="globalButtons">
41 <span class="action-button action-button-delete-selection" (click)="deleteSelectedVideos()">
42 <my-global-icon iconName="delete" aria-hidden="true"></my-global-icon>
43 <ng-container i18n>Delete</ng-container>
44 </span>
45 </ng-template>
46
47 <ng-template ptTemplate="rowButtons" let-video>
48 <div class="action-button">
49 <my-edit-button label [routerLink]="[ '/videos', 'update', video.uuid ]"></my-edit-button>
50
51 <my-action-dropdown [actions]="videoActions" [entry]="{ video: video }"></my-action-dropdown>
52 </div>
53 </ng-template>
54</my-videos-selection>
55
56
57<my-video-change-ownership #videoChangeOwnershipModal></my-video-change-ownership>
58<my-live-stream-information #liveStreamInformationModal></my-live-stream-information>
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.scss b/client/src/app/+my-library/my-videos/my-videos.component.scss
new file mode 100644
index 000000000..59fc5fe80
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/my-videos.component.scss
@@ -0,0 +1,138 @@
1@import '_variables';
2@import '_mixins';
3
4input[type=text] {
5 @include peertube-input-text(300px);
6}
7
8h1 {
9 display: flex;
10 justify-content: space-between;
11
12 .button-link {
13 @include peertube-button-link;
14 @include grey-button;
15 @include button-with-icon(18px, 3px, -1px);
16
17 &:not(:last-child) {
18 margin-right: 10px;
19 }
20 }
21}
22
23.action-button-delete-selection {
24 display: inline-block;
25
26 @include peertube-button;
27 @include orange-button;
28 @include button-with-icon(21px);
29
30 my-global-icon {
31 @include apply-svg-color(#fff);
32 }
33}
34
35::ng-deep {
36 .video {
37 flex-wrap: wrap;
38 }
39
40 .action-button span {
41 white-space: nowrap;
42 }
43
44 .video-miniature {
45 &.display-as-row {
46 // width: min-content !important;
47 width: 100% !important;
48
49 .video-bottom .video-miniature-information {
50 width: max-content !important;
51 min-width: unset !important;
52 }
53 }
54
55 .video-bottom {
56 max-width: 350px;
57 }
58 }
59}
60
61.action-button {
62 display: flex;
63 margin-left: 55px;
64 margin-top: 10px;
65 align-self: flex-end;
66}
67
68my-edit-button {
69 margin-right: 10px;
70}
71
72@media screen and (max-width: $small-view) {
73 h1 {
74 flex-direction: column;
75
76 > span,
77 .button-link {
78 margin-bottom: 10px;
79 }
80 }
81
82 .action-button {
83 flex-direction: column;
84 align-self: center;
85 align-items: center;
86 margin-left: 0px;
87 }
88
89 my-edit-button {
90 margin: 15px 0 5px 0;
91 width: 100%;
92 text-align: center;
93
94 ::ng-deep {
95 .action-button {
96 /* same width than a.video-thumbnail */
97 width: $video-thumbnail-width;
98 }
99 }
100 }
101
102 ::ng-deep {
103 .video-miniature {
104 align-items: center;
105
106 .video-bottom,
107 .video-bottom .video-miniature-information {
108 /* same width than a.video-thumbnail */
109 max-width: $video-thumbnail-width !important;
110 }
111 }
112 }
113}
114
115// Adapt my-video-miniature on small screens with menu
116@media screen and (min-width: $small-view) and (max-width: #{breakpoint(lg) + ($not-expanded-horizontal-margins / 3) * 2}) {
117 :host-context(.main-col:not(.expanded)) {
118 ::ng-deep {
119 .video-miniature {
120 flex-direction: column;
121
122 .video-miniature-name {
123 max-width: $video-thumbnail-width;
124 }
125 }
126 }
127 }
128}
129
130@media screen and (max-width: $mobile-view) {
131 .videos-header {
132 flex-direction: column;
133
134 input[type=text] {
135 width: 100% !important;
136 }
137 }
138}
diff --git a/client/src/app/+my-library/my-videos/my-videos.component.ts b/client/src/app/+my-library/my-videos/my-videos.component.ts
new file mode 100644
index 000000000..e89bb12e1
--- /dev/null
+++ b/client/src/app/+my-library/my-videos/my-videos.component.ts
@@ -0,0 +1,178 @@
1import { concat, Observable, Subject } from 'rxjs'
2import { debounceTime, tap, toArray } from 'rxjs/operators'
3import { Component, OnInit, ViewChild } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, ComponentPagination, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core'
6import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
7import { immutableAssign } from '@app/helpers'
8import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
9import { LiveStreamInformationComponent } from '@app/shared/shared-video-live'
10import { MiniatureDisplayOptions, OwnerDisplayType, SelectionType, VideosSelectionComponent } from '@app/shared/shared-video-miniature'
11import { VideoSortField } from '@shared/models'
12import { VideoChangeOwnershipComponent } from './modals/video-change-ownership.component'
13
14@Component({
15 templateUrl: './my-videos.component.html',
16 styleUrls: [ './my-videos.component.scss' ]
17})
18export class MyVideosComponent implements OnInit, DisableForReuseHook {
19 @ViewChild('videosSelection', { static: true }) videosSelection: VideosSelectionComponent
20 @ViewChild('videoChangeOwnershipModal', { static: true }) videoChangeOwnershipModal: VideoChangeOwnershipComponent
21 @ViewChild('liveStreamInformationModal', { static: true }) liveStreamInformationModal: LiveStreamInformationComponent
22
23 titlePage: string
24 selection: SelectionType = {}
25 pagination: ComponentPagination = {
26 currentPage: 1,
27 itemsPerPage: 10,
28 totalItems: null
29 }
30 miniatureDisplayOptions: MiniatureDisplayOptions = {
31 date: true,
32 views: true,
33 by: true,
34 privacyLabel: false,
35 privacyText: true,
36 state: true,
37 blacklistInfo: true
38 }
39 ownerDisplayType: OwnerDisplayType = 'videoChannel'
40
41 videoActions: DropdownAction<{ video: Video }>[] = []
42
43 videos: Video[] = []
44 videosSearch: string
45 videosSearchChanged = new Subject<string>()
46 getVideosObservableFunction = this.getVideosObservable.bind(this)
47
48 constructor (
49 protected router: Router,
50 protected serverService: ServerService,
51 protected route: ActivatedRoute,
52 protected authService: AuthService,
53 protected notifier: Notifier,
54 protected screenService: ScreenService,
55 private confirmService: ConfirmService,
56 private videoService: VideoService
57 ) {
58 this.titlePage = $localize`My videos`
59 }
60
61 ngOnInit () {
62 this.buildActions()
63
64 this.videosSearchChanged
65 .pipe(debounceTime(500))
66 .subscribe(() => {
67 this.videosSelection.reloadVideos()
68 })
69 }
70
71 resetSearch () {
72 this.videosSearch = ''
73 this.onVideosSearchChanged()
74 }
75
76 onVideosSearchChanged () {
77 this.videosSearchChanged.next()
78 }
79
80 disableForReuse () {
81 this.videosSelection.disableForReuse()
82 }
83
84 enabledForReuse () {
85 this.videosSelection.enabledForReuse()
86 }
87
88 getVideosObservable (page: number, sort: VideoSortField) {
89 const newPagination = immutableAssign(this.pagination, { currentPage: page })
90
91 return this.videoService.getMyVideos(newPagination, sort, this.videosSearch)
92 .pipe(
93 tap(res => this.pagination.totalItems = res.total)
94 )
95 }
96
97 async deleteSelectedVideos () {
98 const toDeleteVideosIds = Object.keys(this.selection)
99 .filter(k => this.selection[ k ] === true)
100 .map(k => parseInt(k, 10))
101
102 const res = await this.confirmService.confirm(
103 $localize`Do you really want to delete ${toDeleteVideosIds.length} videos?`,
104 $localize`Delete`
105 )
106 if (res === false) return
107
108 const observables: Observable<any>[] = []
109 for (const videoId of toDeleteVideosIds) {
110 const o = this.videoService.removeVideo(videoId)
111 .pipe(tap(() => this.removeVideoFromArray(videoId)))
112
113 observables.push(o)
114 }
115
116 concat(...observables)
117 .pipe(toArray())
118 .subscribe(
119 () => {
120 this.notifier.success($localize`${toDeleteVideosIds.length} videos deleted.`)
121 this.selection = {}
122 },
123
124 err => this.notifier.error(err.message)
125 )
126 }
127
128 async deleteVideo (video: Video) {
129 const res = await this.confirmService.confirm(
130 $localize`Do you really want to delete ${video.name}?`,
131 $localize`Delete`
132 )
133 if (res === false) return
134
135 this.videoService.removeVideo(video.id)
136 .subscribe(
137 () => {
138 this.notifier.success($localize`Video ${video.name} deleted.`)
139 this.removeVideoFromArray(video.id)
140 },
141
142 error => this.notifier.error(error.message)
143 )
144 }
145
146 changeOwnership (video: Video) {
147 this.videoChangeOwnershipModal.show(video)
148 }
149
150 displayLiveInformation (video: Video) {
151 this.liveStreamInformationModal.show(video)
152 }
153
154 private removeVideoFromArray (id: number) {
155 this.videos = this.videos.filter(v => v.id !== id)
156 }
157
158 private buildActions () {
159 this.videoActions = [
160 {
161 label: $localize`Display live information`,
162 handler: ({ video }) => this.displayLiveInformation(video),
163 isDisplayed: ({ video }) => video.isLive,
164 iconName: 'live'
165 },
166 {
167 label: $localize`Change ownership`,
168 handler: ({ video }) => this.changeOwnership(video),
169 iconName: 'ownership-change'
170 },
171 {
172 label: $localize`Delete`,
173 handler: ({ video }) => this.deleteVideo(video),
174 iconName: 'delete'
175 }
176 ]
177 }
178}