diff options
Diffstat (limited to 'client/src/app/shared')
3 files changed, 49 insertions, 18 deletions
diff --git a/client/src/app/shared/form-validators/host-validators.ts b/client/src/app/shared/form-validators/host-validators.ts index d750113ef..6f410a50a 100644 --- a/client/src/app/shared/form-validators/host-validators.ts +++ b/client/src/app/shared/form-validators/host-validators.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { AbstractControl, ValidatorFn, Validators } from '@angular/forms' | 1 | import { AbstractControl, ValidatorFn, Validators } from '@angular/forms' |
2 | import { BuildFormValidator } from './form-validator.model' | 2 | import { BuildFormValidator } from './form-validator.model' |
3 | 3 | ||
4 | function validateHost (value: string) { | 4 | export function validateHost (value: string) { |
5 | // Thanks to http://stackoverflow.com/a/106223 | 5 | // Thanks to http://stackoverflow.com/a/106223 |
6 | const HOST_REGEXP = new RegExp( | 6 | const HOST_REGEXP = new RegExp( |
7 | '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' | 7 | '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' |
@@ -10,7 +10,7 @@ function validateHost (value: string) { | |||
10 | return HOST_REGEXP.test(value) | 10 | return HOST_REGEXP.test(value) |
11 | } | 11 | } |
12 | 12 | ||
13 | function validateHandle (value: string) { | 13 | export function validateHandle (value: string) { |
14 | if (!value) return false | 14 | if (!value) return false |
15 | 15 | ||
16 | return value.includes('@') | 16 | return value.includes('@') |
diff --git a/client/src/app/shared/shared-search/advanced-search.model.ts b/client/src/app/shared/shared-search/advanced-search.model.ts index 2c83f53b6..9c55f6cd8 100644 --- a/client/src/app/shared/shared-search/advanced-search.model.ts +++ b/client/src/app/shared/shared-search/advanced-search.model.ts | |||
@@ -1,4 +1,11 @@ | |||
1 | import { BooleanBothQuery, BooleanQuery, SearchTargetType, VideosSearchQuery } from '@shared/models' | 1 | import { |
2 | BooleanBothQuery, | ||
3 | BooleanQuery, | ||
4 | SearchTargetType, | ||
5 | VideoChannelsSearchQuery, | ||
6 | VideoPlaylistsSearchQuery, | ||
7 | VideosSearchQuery | ||
8 | } from '@shared/models' | ||
2 | 9 | ||
3 | export class AdvancedSearch { | 10 | export class AdvancedSearch { |
4 | startDate: string // ISO 8601 | 11 | startDate: string // ISO 8601 |
@@ -23,6 +30,8 @@ export class AdvancedSearch { | |||
23 | 30 | ||
24 | isLive: BooleanQuery | 31 | isLive: BooleanQuery |
25 | 32 | ||
33 | host: string | ||
34 | |||
26 | sort: string | 35 | sort: string |
27 | 36 | ||
28 | searchTarget: SearchTargetType | 37 | searchTarget: SearchTargetType |
@@ -45,6 +54,8 @@ export class AdvancedSearch { | |||
45 | 54 | ||
46 | isLive?: BooleanQuery | 55 | isLive?: BooleanQuery |
47 | 56 | ||
57 | host?: string | ||
58 | |||
48 | durationMin?: string | 59 | durationMin?: string |
49 | durationMax?: string | 60 | durationMax?: string |
50 | sort?: string | 61 | sort?: string |
@@ -68,6 +79,8 @@ export class AdvancedSearch { | |||
68 | this.durationMin = parseInt(options.durationMin, 10) | 79 | this.durationMin = parseInt(options.durationMin, 10) |
69 | this.durationMax = parseInt(options.durationMax, 10) | 80 | this.durationMax = parseInt(options.durationMax, 10) |
70 | 81 | ||
82 | this.host = options.host || undefined | ||
83 | |||
71 | this.searchTarget = options.searchTarget || undefined | 84 | this.searchTarget = options.searchTarget || undefined |
72 | 85 | ||
73 | if (isNaN(this.durationMin)) this.durationMin = undefined | 86 | if (isNaN(this.durationMin)) this.durationMin = undefined |
@@ -101,6 +114,7 @@ export class AdvancedSearch { | |||
101 | this.durationMin = undefined | 114 | this.durationMin = undefined |
102 | this.durationMax = undefined | 115 | this.durationMax = undefined |
103 | this.isLive = undefined | 116 | this.isLive = undefined |
117 | this.host = undefined | ||
104 | 118 | ||
105 | this.sort = '-match' | 119 | this.sort = '-match' |
106 | } | 120 | } |
@@ -120,12 +134,13 @@ export class AdvancedSearch { | |||
120 | durationMin: this.durationMin, | 134 | durationMin: this.durationMin, |
121 | durationMax: this.durationMax, | 135 | durationMax: this.durationMax, |
122 | isLive: this.isLive, | 136 | isLive: this.isLive, |
137 | host: this.host, | ||
123 | sort: this.sort, | 138 | sort: this.sort, |
124 | searchTarget: this.searchTarget | 139 | searchTarget: this.searchTarget |
125 | } | 140 | } |
126 | } | 141 | } |
127 | 142 | ||
128 | toAPIObject (): VideosSearchQuery { | 143 | toVideosAPIObject (): VideosSearchQuery { |
129 | let isLive: boolean | 144 | let isLive: boolean |
130 | if (this.isLive) isLive = this.isLive === 'true' | 145 | if (this.isLive) isLive = this.isLive === 'true' |
131 | 146 | ||
@@ -142,12 +157,27 @@ export class AdvancedSearch { | |||
142 | tagsAllOf: this.tagsAllOf, | 157 | tagsAllOf: this.tagsAllOf, |
143 | durationMin: this.durationMin, | 158 | durationMin: this.durationMin, |
144 | durationMax: this.durationMax, | 159 | durationMax: this.durationMax, |
160 | host: this.host, | ||
145 | isLive, | 161 | isLive, |
146 | sort: this.sort, | 162 | sort: this.sort, |
147 | searchTarget: this.searchTarget | 163 | searchTarget: this.searchTarget |
148 | } | 164 | } |
149 | } | 165 | } |
150 | 166 | ||
167 | toPlaylistAPIObject (): VideoPlaylistsSearchQuery { | ||
168 | return { | ||
169 | host: this.host, | ||
170 | searchTarget: this.searchTarget | ||
171 | } | ||
172 | } | ||
173 | |||
174 | toChannelAPIObject (): VideoChannelsSearchQuery { | ||
175 | return { | ||
176 | host: this.host, | ||
177 | searchTarget: this.searchTarget | ||
178 | } | ||
179 | } | ||
180 | |||
151 | size () { | 181 | size () { |
152 | let acc = 0 | 182 | let acc = 0 |
153 | 183 | ||
diff --git a/client/src/app/shared/shared-search/search.service.ts b/client/src/app/shared/shared-search/search.service.ts index ad258f5e5..2c26eb2e5 100644 --- a/client/src/app/shared/shared-search/search.service.ts +++ b/client/src/app/shared/shared-search/search.service.ts | |||
@@ -7,7 +7,6 @@ import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/sha | |||
7 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | 7 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
8 | import { | 8 | import { |
9 | ResultList, | 9 | ResultList, |
10 | SearchTargetType, | ||
11 | Video as VideoServerModel, | 10 | Video as VideoServerModel, |
12 | VideoChannel as VideoChannelServerModel, | 11 | VideoChannel as VideoChannelServerModel, |
13 | VideoPlaylist as VideoPlaylistServerModel | 12 | VideoPlaylist as VideoPlaylistServerModel |
@@ -33,8 +32,8 @@ export class SearchService { | |||
33 | } | 32 | } |
34 | 33 | ||
35 | searchVideos (parameters: { | 34 | searchVideos (parameters: { |
36 | search: string, | 35 | search: string |
37 | componentPagination?: ComponentPaginationLight, | 36 | componentPagination?: ComponentPaginationLight |
38 | advancedSearch?: AdvancedSearch | 37 | advancedSearch?: AdvancedSearch |
39 | }): Observable<ResultList<Video>> { | 38 | }): Observable<ResultList<Video>> { |
40 | const { search, componentPagination, advancedSearch } = parameters | 39 | const { search, componentPagination, advancedSearch } = parameters |
@@ -52,7 +51,7 @@ export class SearchService { | |||
52 | if (search) params = params.append('search', search) | 51 | if (search) params = params.append('search', search) |
53 | 52 | ||
54 | if (advancedSearch) { | 53 | if (advancedSearch) { |
55 | const advancedSearchObject = advancedSearch.toAPIObject() | 54 | const advancedSearchObject = advancedSearch.toVideosAPIObject() |
56 | params = this.restService.addObjectParams(params, advancedSearchObject) | 55 | params = this.restService.addObjectParams(params, advancedSearchObject) |
57 | } | 56 | } |
58 | 57 | ||
@@ -65,11 +64,11 @@ export class SearchService { | |||
65 | } | 64 | } |
66 | 65 | ||
67 | searchVideoChannels (parameters: { | 66 | searchVideoChannels (parameters: { |
68 | search: string, | 67 | search: string |
69 | searchTarget?: SearchTargetType, | 68 | advancedSearch?: AdvancedSearch |
70 | componentPagination?: ComponentPaginationLight | 69 | componentPagination?: ComponentPaginationLight |
71 | }): Observable<ResultList<VideoChannel>> { | 70 | }): Observable<ResultList<VideoChannel>> { |
72 | const { search, componentPagination, searchTarget } = parameters | 71 | const { search, advancedSearch, componentPagination } = parameters |
73 | 72 | ||
74 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' | 73 | const url = SearchService.BASE_SEARCH_URL + 'video-channels' |
75 | 74 | ||
@@ -82,8 +81,9 @@ export class SearchService { | |||
82 | params = this.restService.addRestGetParams(params, pagination) | 81 | params = this.restService.addRestGetParams(params, pagination) |
83 | params = params.append('search', search) | 82 | params = params.append('search', search) |
84 | 83 | ||
85 | if (searchTarget) { | 84 | if (advancedSearch) { |
86 | params = params.append('searchTarget', searchTarget as string) | 85 | const advancedSearchObject = advancedSearch.toChannelAPIObject() |
86 | params = this.restService.addObjectParams(params, advancedSearchObject) | ||
87 | } | 87 | } |
88 | 88 | ||
89 | return this.authHttp | 89 | return this.authHttp |
@@ -95,11 +95,11 @@ export class SearchService { | |||
95 | } | 95 | } |
96 | 96 | ||
97 | searchVideoPlaylists (parameters: { | 97 | searchVideoPlaylists (parameters: { |
98 | search: string, | 98 | search: string |
99 | searchTarget?: SearchTargetType, | 99 | advancedSearch?: AdvancedSearch |
100 | componentPagination?: ComponentPaginationLight | 100 | componentPagination?: ComponentPaginationLight |
101 | }): Observable<ResultList<VideoPlaylist>> { | 101 | }): Observable<ResultList<VideoPlaylist>> { |
102 | const { search, componentPagination, searchTarget } = parameters | 102 | const { search, advancedSearch, componentPagination } = parameters |
103 | 103 | ||
104 | const url = SearchService.BASE_SEARCH_URL + 'video-playlists' | 104 | const url = SearchService.BASE_SEARCH_URL + 'video-playlists' |
105 | 105 | ||
@@ -112,8 +112,9 @@ export class SearchService { | |||
112 | params = this.restService.addRestGetParams(params, pagination) | 112 | params = this.restService.addRestGetParams(params, pagination) |
113 | params = params.append('search', search) | 113 | params = params.append('search', search) |
114 | 114 | ||
115 | if (searchTarget) { | 115 | if (advancedSearch) { |
116 | params = params.append('searchTarget', searchTarget as string) | 116 | const advancedSearchObject = advancedSearch.toPlaylistAPIObject() |
117 | params = this.restService.addObjectParams(params, advancedSearchObject) | ||
117 | } | 118 | } |
118 | 119 | ||
119 | return this.authHttp | 120 | return this.authHttp |