diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-19 16:17:54 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-24 14:04:05 +0200 |
commit | 57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6 (patch) | |
tree | 87ebcd623c06445b9b25a237addefc98a2d64afa /client/src/app | |
parent | 7279b455811f4806dcb74a08d17b837bc22533c1 (diff) | |
download | PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.gz PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.tar.zst PeerTube-57c36b277e68b764dd34cb2e449f6e2ca3d1e9b6.zip |
Begin advanced search
Diffstat (limited to 'client/src/app')
-rw-r--r-- | client/src/app/app.module.ts | 2 | ||||
-rw-r--r-- | client/src/app/header/header.component.ts | 2 | ||||
-rw-r--r-- | client/src/app/search/index.ts | 3 | ||||
-rw-r--r-- | client/src/app/search/search-routing.module.ts | 23 | ||||
-rw-r--r-- | client/src/app/search/search.component.html | 19 | ||||
-rw-r--r-- | client/src/app/search/search.component.scss | 93 | ||||
-rw-r--r-- | client/src/app/search/search.component.ts | 93 | ||||
-rw-r--r-- | client/src/app/search/search.module.ts | 25 | ||||
-rw-r--r-- | client/src/app/search/search.service.ts | 46 | ||||
-rw-r--r-- | client/src/app/shared/shared.module.ts | 9 | ||||
-rw-r--r-- | client/src/app/shared/video/video-miniature.component.html | 2 | ||||
-rw-r--r-- | client/src/app/shared/video/video-thumbnail.component.html | 2 | ||||
-rw-r--r-- | client/src/app/shared/video/video.service.ts | 51 | ||||
-rw-r--r-- | client/src/app/videos/video-list/index.ts | 2 | ||||
-rw-r--r-- | client/src/app/videos/video-list/video-search.component.ts | 77 | ||||
-rw-r--r-- | client/src/app/videos/videos-routing.module.ts | 12 | ||||
-rw-r--r-- | client/src/app/videos/videos.module.ts | 4 |
17 files changed, 332 insertions, 133 deletions
diff --git a/client/src/app/app.module.ts b/client/src/app/app.module.ts index 48886fd4e..9d655c523 100644 --- a/client/src/app/app.module.ts +++ b/client/src/app/app.module.ts | |||
@@ -18,6 +18,7 @@ import { VideosModule } from './videos' | |||
18 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' | 18 | import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '../../../shared/models/i18n' |
19 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' | 19 | import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' |
20 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' | 20 | import { LanguageChooserComponent } from '@app/menu/language-chooser.component' |
21 | import { SearchModule } from '@app/search' | ||
21 | 22 | ||
22 | export function metaFactory (serverService: ServerService): MetaLoader { | 23 | export function metaFactory (serverService: ServerService): MetaLoader { |
23 | return new MetaStaticLoader({ | 24 | return new MetaStaticLoader({ |
@@ -52,6 +53,7 @@ export function metaFactory (serverService: ServerService): MetaLoader { | |||
52 | LoginModule, | 53 | LoginModule, |
53 | ResetPasswordModule, | 54 | ResetPasswordModule, |
54 | SignupModule, | 55 | SignupModule, |
56 | SearchModule, | ||
55 | SharedModule, | 57 | SharedModule, |
56 | VideosModule, | 58 | VideosModule, |
57 | 59 | ||
diff --git a/client/src/app/header/header.component.ts b/client/src/app/header/header.component.ts index 0e999fbb1..f73d40947 100644 --- a/client/src/app/header/header.component.ts +++ b/client/src/app/header/header.component.ts | |||
@@ -24,7 +24,7 @@ export class HeaderComponent implements OnInit { | |||
24 | } | 24 | } |
25 | 25 | ||
26 | doSearch () { | 26 | doSearch () { |
27 | this.router.navigate([ '/videos', 'search' ], { | 27 | this.router.navigate([ '/search' ], { |
28 | queryParams: { search: this.searchValue } | 28 | queryParams: { search: this.searchValue } |
29 | }) | 29 | }) |
30 | } | 30 | } |
diff --git a/client/src/app/search/index.ts b/client/src/app/search/index.ts new file mode 100644 index 000000000..40f4e021f --- /dev/null +++ b/client/src/app/search/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './search-routing.module' | ||
2 | export * from './search.component' | ||
3 | export * from './search.module' | ||
diff --git a/client/src/app/search/search-routing.module.ts b/client/src/app/search/search-routing.module.ts new file mode 100644 index 000000000..0ac9e6b57 --- /dev/null +++ b/client/src/app/search/search-routing.module.ts | |||
@@ -0,0 +1,23 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | import { RouterModule, Routes } from '@angular/router' | ||
3 | import { MetaGuard } from '@ngx-meta/core' | ||
4 | import { SearchComponent } from '@app/search/search.component' | ||
5 | |||
6 | const searchRoutes: Routes = [ | ||
7 | { | ||
8 | path: 'search', | ||
9 | component: SearchComponent, | ||
10 | canActivate: [ MetaGuard ], | ||
11 | data: { | ||
12 | meta: { | ||
13 | title: 'Search' | ||
14 | } | ||
15 | } | ||
16 | } | ||
17 | ] | ||
18 | |||
19 | @NgModule({ | ||
20 | imports: [ RouterModule.forChild(searchRoutes) ], | ||
21 | exports: [ RouterModule ] | ||
22 | }) | ||
23 | export class SearchRoutingModule {} | ||
diff --git a/client/src/app/search/search.component.html b/client/src/app/search/search.component.html new file mode 100644 index 000000000..b8c4d7dc5 --- /dev/null +++ b/client/src/app/search/search.component.html | |||
@@ -0,0 +1,19 @@ | |||
1 | <div i18n *ngIf="pagination.totalItems === 0" class="no-result"> | ||
2 | No results found | ||
3 | </div> | ||
4 | |||
5 | <div myInfiniteScroller [autoLoading]="true" (nearOfBottom)="onNearOfBottom()" class="search-result"> | ||
6 | <div i18n *ngIf="pagination.totalItems" class="results-counter"> | ||
7 | {{ pagination.totalItems | myNumberFormatter }} results for <span class="search-value">{{ currentSearch }}</span> | ||
8 | </div> | ||
9 | |||
10 | <div *ngFor="let video of videos" class="entry video"> | ||
11 | <my-video-thumbnail [video]="video"></my-video-thumbnail> | ||
12 | |||
13 | <div class="video-info"> | ||
14 | <a class="video-info-name" [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name">{{ video.name }}</a> | ||
15 | <span i18n class="video-info-date-views">{{ video.publishedAt | myFromNow }} - {{ video.views | myNumberFormatter }} views</span> | ||
16 | <a class="video-info-account" [routerLink]="[ '/accounts', video.by ]">{{ video.by }}</a> | ||
17 | </div> | ||
18 | </div> | ||
19 | </div> | ||
diff --git a/client/src/app/search/search.component.scss b/client/src/app/search/search.component.scss new file mode 100644 index 000000000..06e3c9542 --- /dev/null +++ b/client/src/app/search/search.component.scss | |||
@@ -0,0 +1,93 @@ | |||
1 | @import '_variables'; | ||
2 | @import '_mixins'; | ||
3 | |||
4 | .no-result { | ||
5 | height: 70vh; | ||
6 | display: flex; | ||
7 | align-items: center; | ||
8 | justify-content: center; | ||
9 | font-size: 16px; | ||
10 | font-weight: $font-semibold; | ||
11 | } | ||
12 | |||
13 | .search-result { | ||
14 | margin-left: 40px; | ||
15 | margin-top: 40px; | ||
16 | |||
17 | .results-counter { | ||
18 | font-size: 15px; | ||
19 | padding-bottom: 20px; | ||
20 | margin-bottom: 30px; | ||
21 | border-bottom: 1px solid #DADADA; | ||
22 | |||
23 | .search-value { | ||
24 | font-weight: $font-semibold; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | .entry { | ||
29 | display: flex; | ||
30 | min-height: 130px; | ||
31 | padding-bottom: 20px; | ||
32 | margin-bottom: 20px; | ||
33 | |||
34 | &.video { | ||
35 | |||
36 | my-video-thumbnail { | ||
37 | margin-right: 10px; | ||
38 | } | ||
39 | |||
40 | .video-info { | ||
41 | flex-grow: 1; | ||
42 | |||
43 | .video-info-name { | ||
44 | @include disable-default-a-behaviour; | ||
45 | |||
46 | color: #000; | ||
47 | display: block; | ||
48 | width: fit-content; | ||
49 | font-size: 18px; | ||
50 | font-weight: $font-semibold; | ||
51 | } | ||
52 | |||
53 | .video-info-date-views { | ||
54 | font-size: 14px; | ||
55 | } | ||
56 | |||
57 | .video-info-account { | ||
58 | @include disable-default-a-behaviour; | ||
59 | |||
60 | display: block; | ||
61 | width: fit-content; | ||
62 | overflow: hidden; | ||
63 | text-overflow: ellipsis; | ||
64 | white-space: nowrap; | ||
65 | font-size: 14px; | ||
66 | color: #585858; | ||
67 | |||
68 | &:hover { | ||
69 | color: #303030; | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | @media screen and (max-width: 800px) { | ||
78 | .entry { | ||
79 | flex-direction: column; | ||
80 | height: auto; | ||
81 | text-align: center; | ||
82 | |||
83 | &.video { | ||
84 | .video-info-name { | ||
85 | margin: auto; | ||
86 | } | ||
87 | |||
88 | my-video-thumbnail { | ||
89 | margin-right: 0; | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | } | ||
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts new file mode 100644 index 000000000..be1cb3689 --- /dev/null +++ b/client/src/app/search/search.component.ts | |||
@@ -0,0 +1,93 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute } from '@angular/router' | ||
3 | import { RedirectService } from '@app/core' | ||
4 | import { NotificationsService } from 'angular2-notifications' | ||
5 | import { Subscription } from 'rxjs' | ||
6 | import { SearchService } from '@app/search/search.service' | ||
7 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { Video } from '../../../../shared' | ||
10 | import { MetaService } from '@ngx-meta/core' | ||
11 | |||
12 | @Component({ | ||
13 | selector: 'my-search', | ||
14 | styleUrls: [ './search.component.scss' ], | ||
15 | templateUrl: './search.component.html' | ||
16 | }) | ||
17 | export class SearchComponent implements OnInit, OnDestroy { | ||
18 | videos: Video[] = [] | ||
19 | pagination: ComponentPagination = { | ||
20 | currentPage: 1, | ||
21 | itemsPerPage: 10, // It's per object type (so 10 videos, 10 video channels etc) | ||
22 | totalItems: null | ||
23 | } | ||
24 | |||
25 | private subActivatedRoute: Subscription | ||
26 | private currentSearch: string | ||
27 | |||
28 | constructor ( | ||
29 | private i18n: I18n, | ||
30 | private route: ActivatedRoute, | ||
31 | private metaService: MetaService, | ||
32 | private redirectService: RedirectService, | ||
33 | private notificationsService: NotificationsService, | ||
34 | private searchService: SearchService | ||
35 | ) { } | ||
36 | |||
37 | ngOnInit () { | ||
38 | this.subActivatedRoute = this.route.queryParams.subscribe( | ||
39 | queryParams => { | ||
40 | const querySearch = queryParams['search'] | ||
41 | |||
42 | if (!querySearch) return this.redirectService.redirectToHomepage() | ||
43 | if (querySearch === this.currentSearch) return | ||
44 | |||
45 | this.currentSearch = querySearch | ||
46 | this.updateTitle() | ||
47 | |||
48 | this.reload() | ||
49 | }, | ||
50 | |||
51 | err => this.notificationsService.error('Error', err.text) | ||
52 | ) | ||
53 | } | ||
54 | |||
55 | ngOnDestroy () { | ||
56 | if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() | ||
57 | } | ||
58 | |||
59 | search () { | ||
60 | return this.searchService.searchVideos(this.currentSearch, this.pagination) | ||
61 | .subscribe( | ||
62 | ({ videos, totalVideos }) => { | ||
63 | this.videos = this.videos.concat(videos) | ||
64 | this.pagination.totalItems = totalVideos | ||
65 | }, | ||
66 | |||
67 | error => { | ||
68 | this.notificationsService.error(this.i18n('Error'), error.message) | ||
69 | } | ||
70 | ) | ||
71 | } | ||
72 | |||
73 | onNearOfBottom () { | ||
74 | // Last page | ||
75 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | ||
76 | |||
77 | this.pagination.currentPage += 1 | ||
78 | this.search() | ||
79 | } | ||
80 | |||
81 | private reload () { | ||
82 | this.pagination.currentPage = 1 | ||
83 | this.pagination.totalItems = null | ||
84 | |||
85 | this.videos = [] | ||
86 | |||
87 | this.search() | ||
88 | } | ||
89 | |||
90 | private updateTitle () { | ||
91 | this.metaService.setTitle(this.i18n('Search') + ' ' + this.currentSearch) | ||
92 | } | ||
93 | } | ||
diff --git a/client/src/app/search/search.module.ts b/client/src/app/search/search.module.ts new file mode 100644 index 000000000..c6ec74d20 --- /dev/null +++ b/client/src/app/search/search.module.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { NgModule } from '@angular/core' | ||
2 | import { SharedModule } from '../shared' | ||
3 | import { SearchComponent } from '@app/search/search.component' | ||
4 | import { SearchService } from '@app/search/search.service' | ||
5 | import { SearchRoutingModule } from '@app/search/search-routing.module' | ||
6 | |||
7 | @NgModule({ | ||
8 | imports: [ | ||
9 | SearchRoutingModule, | ||
10 | SharedModule | ||
11 | ], | ||
12 | |||
13 | declarations: [ | ||
14 | SearchComponent | ||
15 | ], | ||
16 | |||
17 | exports: [ | ||
18 | SearchComponent | ||
19 | ], | ||
20 | |||
21 | providers: [ | ||
22 | SearchService | ||
23 | ] | ||
24 | }) | ||
25 | export class SearchModule { } | ||
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts new file mode 100644 index 000000000..02d5f5915 --- /dev/null +++ b/client/src/app/search/search.service.ts | |||
@@ -0,0 +1,46 @@ | |||
1 | import { catchError, switchMap } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { Observable } from 'rxjs' | ||
5 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | ||
6 | import { VideoService } from '@app/shared/video/video.service' | ||
7 | import { RestExtractor, RestService } from '@app/shared' | ||
8 | import { environment } from 'environments/environment' | ||
9 | import { ResultList, Video } from '../../../../shared' | ||
10 | import { Video as VideoServerModel } from '@app/shared/video/video.model' | ||
11 | |||
12 | export type SearchResult = { | ||
13 | videosResult: { totalVideos: number, videos: Video[] } | ||
14 | } | ||
15 | |||
16 | @Injectable() | ||
17 | export class SearchService { | ||
18 | static BASE_SEARCH_URL = environment.apiUrl + '/api/v1/search/' | ||
19 | |||
20 | constructor ( | ||
21 | private authHttp: HttpClient, | ||
22 | private restExtractor: RestExtractor, | ||
23 | private restService: RestService, | ||
24 | private videoService: VideoService | ||
25 | ) {} | ||
26 | |||
27 | searchVideos ( | ||
28 | search: string, | ||
29 | componentPagination: ComponentPagination | ||
30 | ): Observable<{ videos: Video[], totalVideos: number }> { | ||
31 | const url = SearchService.BASE_SEARCH_URL + 'videos' | ||
32 | |||
33 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
34 | |||
35 | let params = new HttpParams() | ||
36 | params = this.restService.addRestGetParams(params, pagination) | ||
37 | params = params.append('search', search) | ||
38 | |||
39 | return this.authHttp | ||
40 | .get<ResultList<VideoServerModel>>(url, { params }) | ||
41 | .pipe( | ||
42 | switchMap(res => this.videoService.extractVideos(res)), | ||
43 | catchError(err => this.restExtractor.handleError(err)) | ||
44 | ) | ||
45 | } | ||
46 | } | ||
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index fdfb90600..99df61cdb 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts | |||
@@ -37,9 +37,14 @@ import { I18n } from '@ngx-translate/i18n-polyfill' | |||
37 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | 37 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
38 | import { | 38 | import { |
39 | CustomConfigValidatorsService, | 39 | CustomConfigValidatorsService, |
40 | LoginValidatorsService, ReactiveFileComponent, | 40 | LoginValidatorsService, |
41 | ReactiveFileComponent, | ||
41 | ResetPasswordValidatorsService, | 42 | ResetPasswordValidatorsService, |
42 | UserValidatorsService, VideoAbuseValidatorsService, VideoChannelValidatorsService, VideoCommentValidatorsService, VideoValidatorsService | 43 | UserValidatorsService, |
44 | VideoAbuseValidatorsService, | ||
45 | VideoChannelValidatorsService, | ||
46 | VideoCommentValidatorsService, | ||
47 | VideoValidatorsService | ||
43 | } from '@app/shared/forms' | 48 | } from '@app/shared/forms' |
44 | import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' | 49 | import { I18nPrimengCalendarService } from '@app/shared/i18n/i18n-primeng-calendar' |
45 | import { ScreenService } from '@app/shared/misc/screen.service' | 50 | import { ScreenService } from '@app/shared/misc/screen.service' |
diff --git a/client/src/app/shared/video/video-miniature.component.html b/client/src/app/shared/video/video-miniature.component.html index 20020e2a8..3010e5ccc 100644 --- a/client/src/app/shared/video/video-miniature.component.html +++ b/client/src/app/shared/video/video-miniature.component.html | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | <div class="video-miniature-information"> | 4 | <div class="video-miniature-information"> |
5 | <a | 5 | <a |
6 | class="video-miniature-name" alt="" | 6 | class="video-miniature-name" |
7 | [routerLink]="[ '/videos/watch', video.uuid ]" [attr.title]="video.name" [ngClass]="{ 'blur-filter': isVideoBlur() }" | 7 | [routerLink]="[ '/videos/watch', video.uuid ]" [attr.title]="video.name" [ngClass]="{ 'blur-filter': isVideoBlur() }" |
8 | > | 8 | > |
9 | {{ video.name }} | 9 | {{ video.name }} |
diff --git a/client/src/app/shared/video/video-thumbnail.component.html b/client/src/app/shared/video/video-thumbnail.component.html index 971f352ba..4909cf3f1 100644 --- a/client/src/app/shared/video/video-thumbnail.component.html +++ b/client/src/app/shared/video/video-thumbnail.component.html | |||
@@ -2,7 +2,7 @@ | |||
2 | [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name" | 2 | [routerLink]="['/videos/watch', video.uuid]" [attr.title]="video.name" |
3 | class="video-thumbnail" | 3 | class="video-thumbnail" |
4 | > | 4 | > |
5 | <img [attr.src]="getImageUrl()" [ngClass]="{ 'blur-filter': nsfw }" /> | 5 | <img alt="" [attr.src]="getImageUrl()" [ngClass]="{ 'blur-filter': nsfw }" /> |
6 | 6 | ||
7 | <div class="video-thumbnail-overlay"> | 7 | <div class="video-thumbnail-overlay"> |
8 | {{ video.durationLabel }} | 8 | {{ video.durationLabel }} |
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index b4c1f10f9..f316d31ea 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts | |||
@@ -231,27 +231,6 @@ export class VideoService { | |||
231 | return this.buildBaseFeedUrls(params) | 231 | return this.buildBaseFeedUrls(params) |
232 | } | 232 | } |
233 | 233 | ||
234 | searchVideos ( | ||
235 | search: string, | ||
236 | videoPagination: ComponentPagination, | ||
237 | sort: VideoSortField | ||
238 | ): Observable<{ videos: Video[], totalVideos: number }> { | ||
239 | const url = VideoService.BASE_VIDEO_URL + 'search' | ||
240 | |||
241 | const pagination = this.restService.componentPaginationToRestPagination(videoPagination) | ||
242 | |||
243 | let params = new HttpParams() | ||
244 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
245 | params = params.append('search', search) | ||
246 | |||
247 | return this.authHttp | ||
248 | .get<ResultList<VideoServerModel>>(url, { params }) | ||
249 | .pipe( | ||
250 | switchMap(res => this.extractVideos(res)), | ||
251 | catchError(err => this.restExtractor.handleError(err)) | ||
252 | ) | ||
253 | } | ||
254 | |||
255 | removeVideo (id: number) { | 234 | removeVideo (id: number) { |
256 | return this.authHttp | 235 | return this.authHttp |
257 | .delete(VideoService.BASE_VIDEO_URL + id) | 236 | .delete(VideoService.BASE_VIDEO_URL + id) |
@@ -289,21 +268,7 @@ export class VideoService { | |||
289 | .pipe(catchError(err => this.restExtractor.handleError(err))) | 268 | .pipe(catchError(err => this.restExtractor.handleError(err))) |
290 | } | 269 | } |
291 | 270 | ||
292 | private setVideoRate (id: number, rateType: VideoRateType) { | 271 | extractVideos (result: ResultList<VideoServerModel>) { |
293 | const url = VideoService.BASE_VIDEO_URL + id + '/rate' | ||
294 | const body: UserVideoRateUpdate = { | ||
295 | rating: rateType | ||
296 | } | ||
297 | |||
298 | return this.authHttp | ||
299 | .put(url, body) | ||
300 | .pipe( | ||
301 | map(this.restExtractor.extractDataBool), | ||
302 | catchError(err => this.restExtractor.handleError(err)) | ||
303 | ) | ||
304 | } | ||
305 | |||
306 | private extractVideos (result: ResultList<VideoServerModel>) { | ||
307 | return this.serverService.localeObservable | 272 | return this.serverService.localeObservable |
308 | .pipe( | 273 | .pipe( |
309 | map(translations => { | 274 | map(translations => { |
@@ -319,4 +284,18 @@ export class VideoService { | |||
319 | }) | 284 | }) |
320 | ) | 285 | ) |
321 | } | 286 | } |
287 | |||
288 | private setVideoRate (id: number, rateType: VideoRateType) { | ||
289 | const url = VideoService.BASE_VIDEO_URL + id + '/rate' | ||
290 | const body: UserVideoRateUpdate = { | ||
291 | rating: rateType | ||
292 | } | ||
293 | |||
294 | return this.authHttp | ||
295 | .put(url, body) | ||
296 | .pipe( | ||
297 | map(this.restExtractor.extractDataBool), | ||
298 | catchError(err => this.restExtractor.handleError(err)) | ||
299 | ) | ||
300 | } | ||
322 | } | 301 | } |
diff --git a/client/src/app/videos/video-list/index.ts b/client/src/app/videos/video-list/index.ts index 5e7c7886c..5f7c8bd48 100644 --- a/client/src/app/videos/video-list/index.ts +++ b/client/src/app/videos/video-list/index.ts | |||
@@ -1,3 +1,3 @@ | |||
1 | export * from './video-local.component' | ||
1 | export * from './video-recently-added.component' | 2 | export * from './video-recently-added.component' |
2 | export * from './video-trending.component' | 3 | export * from './video-trending.component' |
3 | export * from './video-search.component' | ||
diff --git a/client/src/app/videos/video-list/video-search.component.ts b/client/src/app/videos/video-list/video-search.component.ts deleted file mode 100644 index 33ed3f00e..000000000 --- a/client/src/app/videos/video-list/video-search.component.ts +++ /dev/null | |||
@@ -1,77 +0,0 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { Location } from '@angular/common' | ||
4 | import { RedirectService } from '@app/core' | ||
5 | import { immutableAssign } from '@app/shared/misc/utils' | ||
6 | import { NotificationsService } from 'angular2-notifications' | ||
7 | import { Subscription } from 'rxjs' | ||
8 | import { AuthService } from '../../core/auth' | ||
9 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
10 | import { VideoService } from '../../shared/video/video.service' | ||
11 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
12 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-videos-search', | ||
16 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | ||
17 | templateUrl: '../../shared/video/abstract-video-list.html' | ||
18 | }) | ||
19 | export class VideoSearchComponent extends AbstractVideoList implements OnInit, OnDestroy { | ||
20 | titlePage: string | ||
21 | currentRoute = '/videos/search' | ||
22 | loadOnInit = false | ||
23 | |||
24 | protected otherRouteParams = { | ||
25 | search: '' | ||
26 | } | ||
27 | private subActivatedRoute: Subscription | ||
28 | |||
29 | constructor ( | ||
30 | protected router: Router, | ||
31 | protected route: ActivatedRoute, | ||
32 | protected notificationsService: NotificationsService, | ||
33 | protected authService: AuthService, | ||
34 | protected location: Location, | ||
35 | protected i18n: I18n, | ||
36 | protected screenService: ScreenService, | ||
37 | private videoService: VideoService, | ||
38 | private redirectService: RedirectService | ||
39 | ) { | ||
40 | super() | ||
41 | |||
42 | this.titlePage = i18n('Search') | ||
43 | } | ||
44 | |||
45 | ngOnInit () { | ||
46 | super.ngOnInit() | ||
47 | |||
48 | this.subActivatedRoute = this.route.queryParams.subscribe( | ||
49 | queryParams => { | ||
50 | const querySearch = queryParams['search'] | ||
51 | |||
52 | if (!querySearch) return this.redirectService.redirectToHomepage() | ||
53 | if (this.otherRouteParams.search === querySearch) return | ||
54 | |||
55 | this.otherRouteParams.search = querySearch | ||
56 | this.reloadVideos() | ||
57 | }, | ||
58 | |||
59 | err => this.notificationsService.error('Error', err.text) | ||
60 | ) | ||
61 | } | ||
62 | |||
63 | ngOnDestroy () { | ||
64 | super.ngOnDestroy() | ||
65 | |||
66 | if (this.subActivatedRoute) this.subActivatedRoute.unsubscribe() | ||
67 | } | ||
68 | |||
69 | getVideosObservable (page: number) { | ||
70 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
71 | return this.videoService.searchVideos(this.otherRouteParams.search, newPagination, this.sort) | ||
72 | } | ||
73 | |||
74 | generateSyndicationList () { | ||
75 | throw new Error('Search does not support syndication.') | ||
76 | } | ||
77 | } | ||
diff --git a/client/src/app/videos/videos-routing.module.ts b/client/src/app/videos/videos-routing.module.ts index da786c0f9..538a43c6d 100644 --- a/client/src/app/videos/videos-routing.module.ts +++ b/client/src/app/videos/videos-routing.module.ts | |||
@@ -1,8 +1,7 @@ | |||
1 | import { NgModule } from '@angular/core' | 1 | import { NgModule } from '@angular/core' |
2 | import { RouterModule, Routes, UrlSegment } from '@angular/router' | 2 | import { RouterModule, Routes } from '@angular/router' |
3 | import { VideoLocalComponent } from '@app/videos/video-list/video-local.component' | 3 | import { VideoLocalComponent } from '@app/videos/video-list/video-local.component' |
4 | import { MetaGuard } from '@ngx-meta/core' | 4 | import { MetaGuard } from '@ngx-meta/core' |
5 | import { VideoSearchComponent } from './video-list' | ||
6 | import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component' | 5 | import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component' |
7 | import { VideoTrendingComponent } from './video-list/video-trending.component' | 6 | import { VideoTrendingComponent } from './video-list/video-trending.component' |
8 | import { VideosComponent } from './videos.component' | 7 | import { VideosComponent } from './videos.component' |
@@ -46,15 +45,6 @@ const videosRoutes: Routes = [ | |||
46 | } | 45 | } |
47 | }, | 46 | }, |
48 | { | 47 | { |
49 | path: 'search', | ||
50 | component: VideoSearchComponent, | ||
51 | data: { | ||
52 | meta: { | ||
53 | title: 'Search videos' | ||
54 | } | ||
55 | } | ||
56 | }, | ||
57 | { | ||
58 | path: 'upload', | 48 | path: 'upload', |
59 | loadChildren: 'app/videos/+video-edit/video-add.module#VideoAddModule', | 49 | loadChildren: 'app/videos/+video-edit/video-add.module#VideoAddModule', |
60 | data: { | 50 | data: { |
diff --git a/client/src/app/videos/videos.module.ts b/client/src/app/videos/videos.module.ts index 7c3d457b3..c38257e08 100644 --- a/client/src/app/videos/videos.module.ts +++ b/client/src/app/videos/videos.module.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import { NgModule } from '@angular/core' | 1 | import { NgModule } from '@angular/core' |
2 | import { VideoLocalComponent } from '@app/videos/video-list/video-local.component' | 2 | import { VideoLocalComponent } from '@app/videos/video-list/video-local.component' |
3 | import { SharedModule } from '../shared' | 3 | import { SharedModule } from '../shared' |
4 | import { VideoSearchComponent } from './video-list' | ||
5 | import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component' | 4 | import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component' |
6 | import { VideoTrendingComponent } from './video-list/video-trending.component' | 5 | import { VideoTrendingComponent } from './video-list/video-trending.component' |
7 | import { VideosRoutingModule } from './videos-routing.module' | 6 | import { VideosRoutingModule } from './videos-routing.module' |
@@ -18,8 +17,7 @@ import { VideosComponent } from './videos.component' | |||
18 | 17 | ||
19 | VideoTrendingComponent, | 18 | VideoTrendingComponent, |
20 | VideoRecentlyAddedComponent, | 19 | VideoRecentlyAddedComponent, |
21 | VideoLocalComponent, | 20 | VideoLocalComponent |
22 | VideoSearchComponent | ||
23 | ], | 21 | ], |
24 | 22 | ||
25 | exports: [ | 23 | exports: [ |