diff options
Diffstat (limited to 'client/src')
10 files changed, 69 insertions, 27 deletions
diff --git a/client/src/app/shared/video/recommendation-info.model.ts b/client/src/app/shared/video/recommendation-info.model.ts new file mode 100644 index 000000000..0233563bb --- /dev/null +++ b/client/src/app/shared/video/recommendation-info.model.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export interface RecommendationInfo { | ||
2 | uuid: string | ||
3 | tags?: string[] | ||
4 | } | ||
diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.html b/client/src/app/videos/+video-edit/shared/video-edit.component.html index 26c9e977e..69f306519 100644 --- a/client/src/app/videos/+video-edit/shared/video-edit.component.html +++ b/client/src/app/videos/+video-edit/shared/video-edit.component.html | |||
@@ -14,7 +14,8 @@ | |||
14 | </div> | 14 | </div> |
15 | 15 | ||
16 | <div class="form-group"> | 16 | <div class="form-group"> |
17 | <label i18n class="label-tags">Tags</label> <span i18n>(press Enter to add)</span> | 17 | <label i18n class="label-tags">Tags</label> |
18 | <my-help i18n-preHtml preHtml="Tags could be used to suggest relevant recommendations.</br>Press Enter to add a new tag."></my-help> | ||
18 | <tag-input | 19 | <tag-input |
19 | [validators]="tagValidators" [errorMessages]="tagValidatorsMessages" | 20 | [validators]="tagValidators" [errorMessages]="tagValidatorsMessages" |
20 | formControlName="tags" maxItems="5" modelAsStrings="true" | 21 | formControlName="tags" maxItems="5" modelAsStrings="true" |
@@ -223,4 +224,4 @@ | |||
223 | 224 | ||
224 | <my-video-caption-add-modal | 225 | <my-video-caption-add-modal |
225 | #videoCaptionAddModal [existingCaptions]="existingCaptions" (captionAdded)="onCaptionAdded($event)" | 226 | #videoCaptionAddModal [existingCaptions]="existingCaptions" (captionAdded)="onCaptionAdded($event)" |
226 | ></my-video-caption-add-modal> \ No newline at end of file | 227 | ></my-video-caption-add-modal> |
diff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.html index 937f25eb6..3b6b5d8ed 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html | |||
@@ -200,8 +200,7 @@ | |||
200 | <my-video-comments [video]="video" [user]="user"></my-video-comments> | 200 | <my-video-comments [video]="video" [user]="user"></my-video-comments> |
201 | </div> | 201 | </div> |
202 | <my-recommended-videos class="col-12 col-lg-3" | 202 | <my-recommended-videos class="col-12 col-lg-3" |
203 | [inputVideo]="video" [user]="user"></my-recommended-videos> | 203 | [inputRecommendation]="{ uuid: video.uuid, tags: video.tags }" [user]="user"></my-recommended-videos> |
204 | </div> | ||
205 | </div> | 204 | </div> |
206 | 205 | ||
207 | <div class="privacy-concerns" *ngIf="hasAlreadyAcceptedPrivacyConcern === false"> | 206 | <div class="privacy-concerns" *ngIf="hasAlreadyAcceptedPrivacyConcern === false"> |
diff --git a/client/src/app/videos/recommendations/recent-videos-recommendation.service.spec.ts b/client/src/app/videos/recommendations/recent-videos-recommendation.service.spec.ts index f9055b82c..698b2e27b 100644 --- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.spec.ts +++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.spec.ts | |||
@@ -21,7 +21,7 @@ describe('"Recent Videos" Recommender', () => { | |||
21 | { uuid: 'uuid2' } | 21 | { uuid: 'uuid2' } |
22 | ] | 22 | ] |
23 | getVideosMock.mockReturnValueOnce(of({ videos: vids })) | 23 | getVideosMock.mockReturnValueOnce(of({ videos: vids })) |
24 | const result = await service.getRecommendations('uuid1').toPromise() | 24 | const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise() |
25 | const uuids = result.map(v => v.uuid) | 25 | const uuids = result.map(v => v.uuid) |
26 | expect(uuids).toEqual(['uuid2']) | 26 | expect(uuids).toEqual(['uuid2']) |
27 | done() | 27 | done() |
@@ -36,7 +36,7 @@ describe('"Recent Videos" Recommender', () => { | |||
36 | { uuid: 'uuid7' } | 36 | { uuid: 'uuid7' } |
37 | ] | 37 | ] |
38 | getVideosMock.mockReturnValueOnce(of({ videos: vids })) | 38 | getVideosMock.mockReturnValueOnce(of({ videos: vids })) |
39 | const result = await service.getRecommendations('uuid1').toPromise() | 39 | const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise() |
40 | expect(result.length).toEqual(5) | 40 | expect(result.length).toEqual(5) |
41 | done() | 41 | done() |
42 | }) | 42 | }) |
@@ -51,12 +51,12 @@ describe('"Recent Videos" Recommender', () => { | |||
51 | ] | 51 | ] |
52 | getVideosMock | 52 | getVideosMock |
53 | .mockReturnValueOnce(of({ videos: vids })) | 53 | .mockReturnValueOnce(of({ videos: vids })) |
54 | const result = await service.getRecommendations('uuid1').toPromise() | 54 | const result = await service.getRecommendations({ uuid: 'uuid1' }).toPromise() |
55 | expect(result.length).toEqual(5) | 55 | expect(result.length).toEqual(5) |
56 | done() | 56 | done() |
57 | }) | 57 | }) |
58 | it('should fetch an extra result in case the given UUID is in the list', async (done) => { | 58 | it('should fetch an extra result in case the given UUID is in the list', async (done) => { |
59 | await service.getRecommendations('uuid1').toPromise() | 59 | await service.getRecommendations({ uuid: 'uuid1' }).toPromise() |
60 | let expectedSize = service.pageSize + 1 | 60 | let expectedSize = service.pageSize + 1 |
61 | let params = { currentPage: jasmine.anything(), itemsPerPage: expectedSize } | 61 | let params = { currentPage: jasmine.anything(), itemsPerPage: expectedSize } |
62 | expect(getVideosMock).toHaveBeenCalledWith(params, jasmine.anything()) | 62 | expect(getVideosMock).toHaveBeenCalledWith(params, jasmine.anything()) |
diff --git a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts index 708d67699..4723f7fd0 100644 --- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts +++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts | |||
@@ -1,9 +1,12 @@ | |||
1 | import { Inject, Injectable } from '@angular/core' | 1 | import { Inject, Injectable } from '@angular/core' |
2 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' | 2 | import { RecommendationService } from '@app/videos/recommendations/recommendations.service' |
3 | import { Video } from '@app/shared/video/video.model' | 3 | import { Video } from '@app/shared/video/video.model' |
4 | import { VideoService, VideosProvider } from '@app/shared/video/video.service' | 4 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' |
5 | import { VideoService } from '@app/shared/video/video.service' | ||
5 | import { map } from 'rxjs/operators' | 6 | import { map } from 'rxjs/operators' |
6 | import { Observable } from 'rxjs' | 7 | import { Observable } from 'rxjs' |
8 | import { SearchService } from '@app/search/search.service' | ||
9 | import { AdvancedSearch } from '@app/search/advanced-search.model' | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * Provides "recommendations" by providing the most recently uploaded videos. | 12 | * Provides "recommendations" by providing the most recently uploaded videos. |
@@ -14,26 +17,40 @@ export class RecentVideosRecommendationService implements RecommendationService | |||
14 | readonly pageSize = 5 | 17 | readonly pageSize = 5 |
15 | 18 | ||
16 | constructor ( | 19 | constructor ( |
17 | @Inject(VideoService) private videos: VideosProvider | 20 | private videos: VideoService, |
21 | private searchService: SearchService | ||
18 | ) { | 22 | ) { |
19 | } | 23 | } |
20 | 24 | ||
21 | getRecommendations (uuid: string): Observable<Video[]> { | 25 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { |
22 | return this.fetchPage(1) | 26 | return this.fetchPage(1, recommendation) |
23 | .pipe( | 27 | .pipe( |
24 | map(vids => { | 28 | map(vids => { |
25 | const otherVideos = vids.filter(v => v.uuid !== uuid) | 29 | const otherVideos = vids.filter(v => v.uuid !== recommendation.uuid) |
26 | return otherVideos.slice(0, this.pageSize) | 30 | return otherVideos.slice(0, this.pageSize) |
27 | }) | 31 | }) |
28 | ) | 32 | ) |
29 | } | 33 | } |
30 | 34 | ||
31 | private fetchPage (page: number): Observable<Video[]> { | 35 | private fetchPage (page: number, recommendation: RecommendationInfo): Observable<Video[]> { |
32 | let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } | 36 | let pagination = { currentPage: page, itemsPerPage: this.pageSize + 1 } |
33 | return this.videos.getVideos(pagination, '-createdAt') | 37 | if (!recommendation.tags) { |
34 | .pipe( | 38 | return this.videos.getVideos(pagination, '-createdAt') |
35 | map(v => v.videos) | 39 | .pipe( |
36 | ) | 40 | map(v => v.videos) |
41 | ) | ||
42 | } | ||
43 | if (recommendation.tags.length === 0) { | ||
44 | return this.videos.getVideos(pagination, '-createdAt') | ||
45 | .pipe( | ||
46 | map(v => v.videos) | ||
47 | ) | ||
48 | } | ||
49 | return this.searchService.searchVideos('', | ||
50 | pagination, | ||
51 | new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' }) | ||
52 | ).pipe( | ||
53 | map(v => v.videos) | ||
54 | ) | ||
37 | } | 55 | } |
38 | |||
39 | } | 56 | } |
diff --git a/client/src/app/videos/recommendations/recommendations.service.ts b/client/src/app/videos/recommendations/recommendations.service.ts index 44cbda9b7..114a808b5 100644 --- a/client/src/app/videos/recommendations/recommendations.service.ts +++ b/client/src/app/videos/recommendations/recommendations.service.ts | |||
@@ -1,8 +1,9 @@ | |||
1 | import { Video } from '@app/shared/video/video.model' | 1 | import { Video } from '@app/shared/video/video.model' |
2 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | ||
2 | import { Observable } from 'rxjs' | 3 | import { Observable } from 'rxjs' |
3 | 4 | ||
4 | export type UUID = string | 5 | export type UUID = string |
5 | 6 | ||
6 | export interface RecommendationService { | 7 | export interface RecommendationService { |
7 | getRecommendations (uuid: UUID): Observable<Video[]> | 8 | getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> |
8 | } | 9 | } |
diff --git a/client/src/app/videos/recommendations/recommended-videos.component.ts b/client/src/app/videos/recommendations/recommended-videos.component.ts index aa4dd0ee2..c6c1d9e5d 100644 --- a/client/src/app/videos/recommendations/recommended-videos.component.ts +++ b/client/src/app/videos/recommendations/recommended-videos.component.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Component, Input, OnChanges } from '@angular/core' | 1 | import { Component, Input, OnChanges } from '@angular/core' |
2 | import { Observable } from 'rxjs' | 2 | import { Observable } from 'rxjs' |
3 | import { Video } from '@app/shared/video/video.model' | 3 | import { Video } from '@app/shared/video/video.model' |
4 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | ||
4 | import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' | 5 | import { RecommendedVideosStore } from '@app/videos/recommendations/recommended-videos.store' |
5 | import { User } from '@app/shared' | 6 | import { User } from '@app/shared' |
6 | 7 | ||
@@ -9,7 +10,7 @@ import { User } from '@app/shared' | |||
9 | templateUrl: './recommended-videos.component.html' | 10 | templateUrl: './recommended-videos.component.html' |
10 | }) | 11 | }) |
11 | export class RecommendedVideosComponent implements OnChanges { | 12 | export class RecommendedVideosComponent implements OnChanges { |
12 | @Input() inputVideo: Video | 13 | @Input() inputRecommendation: RecommendationInfo |
13 | @Input() user: User | 14 | @Input() user: User |
14 | 15 | ||
15 | readonly hasVideos$: Observable<boolean> | 16 | readonly hasVideos$: Observable<boolean> |
@@ -23,8 +24,8 @@ export class RecommendedVideosComponent implements OnChanges { | |||
23 | } | 24 | } |
24 | 25 | ||
25 | public ngOnChanges (): void { | 26 | public ngOnChanges (): void { |
26 | if (this.inputVideo) { | 27 | if (this.inputRecommendation) { |
27 | this.store.requestNewRecommendations(this.inputVideo.uuid) | 28 | this.store.requestNewRecommendations(this.inputRecommendation) |
28 | } | 29 | } |
29 | } | 30 | } |
30 | 31 | ||
diff --git a/client/src/app/videos/recommendations/recommended-videos.store.ts b/client/src/app/videos/recommendations/recommended-videos.store.ts index 689adeb1f..eb5c9867f 100644 --- a/client/src/app/videos/recommendations/recommended-videos.store.ts +++ b/client/src/app/videos/recommendations/recommended-videos.store.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { Inject, Injectable } from '@angular/core' | 1 | import { Inject, Injectable } from '@angular/core' |
2 | import { Observable, ReplaySubject } from 'rxjs' | 2 | import { Observable, ReplaySubject } from 'rxjs' |
3 | import { Video } from '@app/shared/video/video.model' | 3 | import { Video } from '@app/shared/video/video.model' |
4 | import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' | ||
4 | import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service' | 5 | import { RecentVideosRecommendationService } from '@app/videos/recommendations/recent-videos-recommendation.service' |
5 | import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service' | 6 | import { RecommendationService, UUID } from '@app/videos/recommendations/recommendations.service' |
6 | import { map, switchMap, take } from 'rxjs/operators' | 7 | import { map, switchMap, take } from 'rxjs/operators' |
@@ -12,13 +13,13 @@ import { map, switchMap, take } from 'rxjs/operators' | |||
12 | export class RecommendedVideosStore { | 13 | export class RecommendedVideosStore { |
13 | public readonly recommendations$: Observable<Video[]> | 14 | public readonly recommendations$: Observable<Video[]> |
14 | public readonly hasRecommendations$: Observable<boolean> | 15 | public readonly hasRecommendations$: Observable<boolean> |
15 | private readonly requestsForLoad$$ = new ReplaySubject<UUID>(1) | 16 | private readonly requestsForLoad$$ = new ReplaySubject<RecommendationInfo>(1) |
16 | 17 | ||
17 | constructor ( | 18 | constructor ( |
18 | @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService | 19 | @Inject(RecentVideosRecommendationService) private recommendations: RecommendationService |
19 | ) { | 20 | ) { |
20 | this.recommendations$ = this.requestsForLoad$$.pipe( | 21 | this.recommendations$ = this.requestsForLoad$$.pipe( |
21 | switchMap(requestedUUID => recommendations.getRecommendations(requestedUUID) | 22 | switchMap(requestedRecommendation => recommendations.getRecommendations(requestedRecommendation) |
22 | .pipe(take(1)) | 23 | .pipe(take(1)) |
23 | )) | 24 | )) |
24 | this.hasRecommendations$ = this.recommendations$.pipe( | 25 | this.hasRecommendations$ = this.recommendations$.pipe( |
@@ -26,7 +27,7 @@ export class RecommendedVideosStore { | |||
26 | ) | 27 | ) |
27 | } | 28 | } |
28 | 29 | ||
29 | requestNewRecommendations (videoUUID: string) { | 30 | requestNewRecommendations (recommend: RecommendationInfo) { |
30 | this.requestsForLoad$$.next(videoUUID) | 31 | this.requestsForLoad$$.next(recommend) |
31 | } | 32 | } |
32 | } | 33 | } |
diff --git a/client/src/setupJest.ts b/client/src/setupJest.ts new file mode 100644 index 000000000..8d88704e8 --- /dev/null +++ b/client/src/setupJest.ts | |||
@@ -0,0 +1 @@ | |||
import 'jest-preset-angular'; | |||
diff --git a/client/src/tsconfig.spec.json b/client/src/tsconfig.spec.json new file mode 100644 index 000000000..cefee1781 --- /dev/null +++ b/client/src/tsconfig.spec.json | |||
@@ -0,0 +1,17 @@ | |||
1 | { | ||
2 | "extends": "../tsconfig.json", | ||
3 | "compilerOptions": { | ||
4 | "outDir": "../out-tsc/spec", | ||
5 | "module": "commonjs", | ||
6 | "target": "es5", | ||
7 | "baseUrl": "", | ||
8 | "allowJs": true | ||
9 | }, | ||
10 | "files": [ | ||
11 | "test.ts" | ||
12 | ], | ||
13 | "include": [ | ||
14 | "**/*.spec.ts", | ||
15 | "**/*.d.ts" | ||
16 | ] | ||
17 | } | ||