aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/search
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-23 14:10:17 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-06-23 16:00:49 +0200
commit67ed6552b831df66713bac9e672738796128d33f (patch)
tree59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/search
parent0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff)
downloadPeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz
PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst
PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip
Reorganize client shared modules
Diffstat (limited to 'client/src/app/search')
-rw-r--r--client/src/app/search/advanced-search.model.ts3
-rw-r--r--client/src/app/search/highlight.pipe.ts54
-rw-r--r--client/src/app/search/search-filters.component.ts6
-rw-r--r--client/src/app/search/search.component.ts19
-rw-r--r--client/src/app/search/search.module.ts22
-rw-r--r--client/src/app/search/search.service.ts14
6 files changed, 85 insertions, 33 deletions
diff --git a/client/src/app/search/advanced-search.model.ts b/client/src/app/search/advanced-search.model.ts
index 643cc9a29..516854a8c 100644
--- a/client/src/app/search/advanced-search.model.ts
+++ b/client/src/app/search/advanced-search.model.ts
@@ -1,5 +1,4 @@
1import { SearchTargetType } from '@shared/models/search/search-target-query.model' 1import { NSFWQuery, SearchTargetType } from '@shared/models'
2import { NSFWQuery } from '../../../../shared/models/search'
3 2
4export class AdvancedSearch { 3export class AdvancedSearch {
5 startDate: string // ISO 8601 4 startDate: string // ISO 8601
diff --git a/client/src/app/search/highlight.pipe.ts b/client/src/app/search/highlight.pipe.ts
new file mode 100644
index 000000000..50ee5c1bd
--- /dev/null
+++ b/client/src/app/search/highlight.pipe.ts
@@ -0,0 +1,54 @@
1import { PipeTransform, Pipe } from '@angular/core'
2import { SafeHtml } from '@angular/platform-browser'
3
4// Thanks https://gist.github.com/adamrecsko/0f28f474eca63e0279455476cc11eca7#gistcomment-2917369
5@Pipe({ name: 'highlight' })
6export class HighlightPipe implements PipeTransform {
7 /* use this for single match search */
8 static SINGLE_MATCH = 'Single-Match'
9 /* use this for single match search with a restriction that target should start with search string */
10 static SINGLE_AND_STARTS_WITH_MATCH = 'Single-And-StartsWith-Match'
11 /* use this for global search */
12 static MULTI_MATCH = 'Multi-Match'
13
14 transform (
15 contentString: string = null,
16 stringToHighlight: string = null,
17 option = 'Single-And-StartsWith-Match',
18 caseSensitive = false,
19 highlightStyleName = 'search-highlight'
20 ): SafeHtml {
21 if (stringToHighlight && contentString && option) {
22 let regex: any = ''
23 const caseFlag: string = !caseSensitive ? 'i' : ''
24
25 switch (option) {
26 case 'Single-Match': {
27 regex = new RegExp(stringToHighlight, caseFlag)
28 break
29 }
30 case 'Single-And-StartsWith-Match': {
31 regex = new RegExp('^' + stringToHighlight, caseFlag)
32 break
33 }
34 case 'Multi-Match': {
35 regex = new RegExp(stringToHighlight, 'g' + caseFlag)
36 break
37 }
38 default: {
39 // default will be a global case-insensitive match
40 regex = new RegExp(stringToHighlight, 'gi')
41 }
42 }
43
44 const replaced = contentString.replace(
45 regex,
46 (match) => `<span class="${highlightStyleName}">${match}</span>`
47 )
48
49 return replaced
50 } else {
51 return contentString
52 }
53 }
54}
diff --git a/client/src/app/search/search-filters.component.ts b/client/src/app/search/search-filters.component.ts
index af76260a7..14a5d0484 100644
--- a/client/src/app/search/search-filters.component.ts
+++ b/client/src/app/search/search-filters.component.ts
@@ -1,10 +1,10 @@
1import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core' 1import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
2import { ValidatorFn } from '@angular/forms' 2import { ValidatorFn } from '@angular/forms'
3import { VideoValidatorsService } from '@app/shared'
4import { ServerService } from '@app/core' 3import { ServerService } from '@app/core'
5import { I18n } from '@ngx-translate/i18n-polyfill'
6import { AdvancedSearch } from '@app/search/advanced-search.model' 4import { AdvancedSearch } from '@app/search/advanced-search.model'
7import { ServerConfig, VideoConstant } from '../../../../shared' 5import { VideoValidatorsService } from '@app/shared/shared-forms'
6import { I18n } from '@ngx-translate/i18n-polyfill'
7import { ServerConfig, VideoConstant } from '@shared/models'
8 8
9@Component({ 9@Component({
10 selector: 'my-search-filters', 10 selector: 'my-search-filters',
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index 6486085be..83b06e0ce 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -1,20 +1,15 @@
1import { forkJoin, of, Subscription } from 'rxjs' 1import { forkJoin, of, Subscription } from 'rxjs'
2import { Component, OnDestroy, OnInit } from '@angular/core' 2import { Component, OnDestroy, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { AuthService, Notifier, ServerService } from '@app/core' 4import { AuthService, ComponentPagination, HooksService, Notifier, ServerService, User, UserService } from '@app/core'
5import { HooksService } from '@app/core/plugins/hooks.service' 5import { immutableAssign } from '@app/helpers'
6import { AdvancedSearch } from '@app/search/advanced-search.model' 6import { Video, VideoChannel } from '@app/shared/shared-main'
7import { SearchService } from '@app/search/search.service' 7import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
8import { User, UserService } from '@app/shared'
9import { immutableAssign } from '@app/shared/misc/utils'
10import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
11import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
12import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
13import { Video } from '@app/shared/video/video.model'
14import { MetaService } from '@ngx-meta/core' 8import { MetaService } from '@ngx-meta/core'
15import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
16import { ServerConfig } from '@shared/models' 10import { SearchTargetType, ServerConfig } from '@shared/models'
17import { SearchTargetType } from '@shared/models/search/search-target-query.model' 11import { AdvancedSearch } from './advanced-search.model'
12import { SearchService } from './search.service'
18 13
19@Component({ 14@Component({
20 selector: 'my-search', 15 selector: 'my-search',
diff --git a/client/src/app/search/search.module.ts b/client/src/app/search/search.module.ts
index df5459802..65c954de8 100644
--- a/client/src/app/search/search.module.ts
+++ b/client/src/app/search/search.module.ts
@@ -1,11 +1,15 @@
1import { TagInputModule } from 'ngx-chips' 1import { TagInputModule } from 'ngx-chips'
2import { NgModule } from '@angular/core' 2import { NgModule } from '@angular/core'
3import { SearchFiltersComponent } from '@app/search/search-filters.component' 3import { SharedFormModule } from '@app/shared/shared-forms'
4import { SearchRoutingModule } from '@app/search/search-routing.module' 4import { SharedMainModule } from '@app/shared/shared-main'
5import { SearchComponent } from '@app/search/search.component' 5import { SharedUserSubscriptionModule } from '@app/shared/shared-user-subscription'
6import { SearchService } from '@app/search/search.service' 6import { SharedVideoMiniatureModule } from '@app/shared/shared-video-miniature'
7import { SharedModule } from '../shared'
8import { ChannelLazyLoadResolver } from './channel-lazy-load.resolver' 7import { ChannelLazyLoadResolver } from './channel-lazy-load.resolver'
8import { HighlightPipe } from './highlight.pipe'
9import { SearchFiltersComponent } from './search-filters.component'
10import { SearchRoutingModule } from './search-routing.module'
11import { SearchComponent } from './search.component'
12import { SearchService } from './search.service'
9import { VideoLazyLoadResolver } from './video-lazy-load.resolver' 13import { VideoLazyLoadResolver } from './video-lazy-load.resolver'
10 14
11@NgModule({ 15@NgModule({
@@ -13,7 +17,10 @@ import { VideoLazyLoadResolver } from './video-lazy-load.resolver'
13 TagInputModule, 17 TagInputModule,
14 18
15 SearchRoutingModule, 19 SearchRoutingModule,
16 SharedModule 20 SharedMainModule,
21 SharedFormModule,
22 SharedUserSubscriptionModule,
23 SharedVideoMiniatureModule
17 ], 24 ],
18 25
19 declarations: [ 26 declarations: [
@@ -29,7 +36,8 @@ import { VideoLazyLoadResolver } from './video-lazy-load.resolver'
29 providers: [ 36 providers: [
30 SearchService, 37 SearchService,
31 VideoLazyLoadResolver, 38 VideoLazyLoadResolver,
32 ChannelLazyLoadResolver 39 ChannelLazyLoadResolver,
40 HighlightPipe
33 ] 41 ]
34}) 42})
35export class SearchModule { } 43export class SearchModule { }
diff --git a/client/src/app/search/search.service.ts b/client/src/app/search/search.service.ts
index fdb12ea2c..36342034f 100644
--- a/client/src/app/search/search.service.ts
+++ b/client/src/app/search/search.service.ts
@@ -2,17 +2,13 @@ import { Observable } from 'rxjs'
2import { catchError, map, switchMap } from 'rxjs/operators' 2import { catchError, map, switchMap } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 3import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 4import { Injectable } from '@angular/core'
5import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core'
6import { peertubeLocalStorage } from '@app/helpers'
5import { AdvancedSearch } from '@app/search/advanced-search.model' 7import { AdvancedSearch } from '@app/search/advanced-search.model'
6import { RestExtractor, RestPagination, RestService } from '@app/shared' 8import { Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
7import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage' 9import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '@shared/models'
8import { ComponentPaginationLight } from '@app/shared/rest/component-pagination.model'
9import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
10import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
11import { Video } from '@app/shared/video/video.model'
12import { VideoService } from '@app/shared/video/video.service'
13import { ResultList, Video as VideoServerModel, VideoChannel as VideoChannelServerModel } from '../../../../shared'
14import { environment } from '../../environments/environment'
15import { SearchTargetType } from '@shared/models/search/search-target-query.model' 10import { SearchTargetType } from '@shared/models/search/search-target-query.model'
11import { environment } from '../../environments/environment'
16 12
17@Injectable() 13@Injectable()
18export class SearchService { 14export class SearchService {