1
0
Fork 0

Use search client scope

This commit is contained in:
Chocobozzz 2019-07-22 16:04:44 +02:00 committed by Chocobozzz
parent 93cae47925
commit e8f902c05c
8 changed files with 25 additions and 16 deletions

View File

@ -28,6 +28,7 @@ export class PluginService implements ClientHook {
pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = { pluginsLoaded: { [ scope in PluginClientScope ]: ReplaySubject<boolean> } = {
common: new ReplaySubject<boolean>(1), common: new ReplaySubject<boolean>(1),
search: new ReplaySubject<boolean>(1),
'video-watch': new ReplaySubject<boolean>(1) 'video-watch': new ReplaySubject<boolean>(1)
} }
@ -109,7 +110,11 @@ export class PluginService implements ClientHook {
if (!isReload) this.loadedScopes.push(scope) if (!isReload) this.loadedScopes.push(scope)
const toLoad = this.scopes[ scope ] const toLoad = this.scopes[ scope ]
if (!Array.isArray(toLoad)) return if (!Array.isArray(toLoad)) {
this.pluginsLoaded[scope].next(true)
return
}
const promises: Promise<any>[] = [] const promises: Promise<any>[] = []
for (const pluginInfo of toLoad) { for (const pluginInfo of toLoad) {

View File

@ -11,6 +11,7 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
import { immutableAssign } from '@app/shared/misc/utils' import { immutableAssign } from '@app/shared/misc/utils'
import { Video } from '@app/shared/video/video.model' import { Video } from '@app/shared/video/video.model'
import { HooksService } from '@app/core/plugins/hooks.service' import { HooksService } from '@app/core/plugins/hooks.service'
import { PluginService } from '@app/core/plugins/plugin.service'
@Component({ @Component({
selector: 'my-search', selector: 'my-search',
@ -43,7 +44,8 @@ export class SearchComponent implements OnInit, OnDestroy {
private notifier: Notifier, private notifier: Notifier,
private searchService: SearchService, private searchService: SearchService,
private authService: AuthService, private authService: AuthService,
private hooks: HooksService private hooks: HooksService,
private pluginService: PluginService
) { } ) { }
get user () { get user () {
@ -51,6 +53,8 @@ export class SearchComponent implements OnInit, OnDestroy {
} }
ngOnInit () { ngOnInit () {
this.pluginService.loadPluginsByScope('search')
this.subActivatedRoute = this.route.queryParams.subscribe( this.subActivatedRoute = this.route.queryParams.subscribe(
queryParams => { queryParams => {
const querySearch = queryParams['search'] const querySearch = queryParams['search']
@ -175,7 +179,7 @@ export class SearchComponent implements OnInit, OnDestroy {
return this.hooks.wrapObsFun( return this.hooks.wrapObsFun(
this.searchService.searchVideos.bind(this.searchService), this.searchService.searchVideos.bind(this.searchService),
params, params,
'common', 'search',
'filter:api.search.videos.list.params', 'filter:api.search.videos.list.params',
'filter:api.search.videos.list.result' 'filter:api.search.videos.list.result'
) )
@ -190,7 +194,7 @@ export class SearchComponent implements OnInit, OnDestroy {
return this.hooks.wrapObsFun( return this.hooks.wrapObsFun(
this.searchService.searchVideoChannels.bind(this.searchService), this.searchService.searchVideoChannels.bind(this.searchService),
params, params,
'common', 'search',
'filter:api.search.video-channels.list.params', 'filter:api.search.video-channels.list.params',
'filter:api.search.video-channels.list.result' 'filter:api.search.video-channels.list.result'
) )

View File

@ -52,7 +52,7 @@ export class VideoCommentService {
videoId: number | string, videoId: number | string,
componentPagination: ComponentPagination, componentPagination: ComponentPagination,
sort: VideoSortField sort: VideoSortField
}): Observable<{ comments: VideoComment[], totalComments: number}> { }): Observable<ResultList<VideoComment>> {
const { videoId, componentPagination, sort } = parameters const { videoId, componentPagination, sort } = parameters
const pagination = this.restService.componentPaginationToRestPagination(componentPagination) const pagination = this.restService.componentPaginationToRestPagination(componentPagination)
@ -61,10 +61,9 @@ export class VideoCommentService {
params = this.restService.addRestGetParams(params, pagination, sort) params = this.restService.addRestGetParams(params, pagination, sort)
const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads' const url = VideoCommentService.BASE_VIDEO_URL + videoId + '/comment-threads'
return this.authHttp return this.authHttp.get<ResultList<VideoComment>>(url, { params })
.get(url, { params })
.pipe( .pipe(
map(this.extractVideoComments), map(result => this.extractVideoComments(result)),
catchError(err => this.restExtractor.handleError(err)) catchError(err => this.restExtractor.handleError(err))
) )
} }
@ -136,7 +135,7 @@ export class VideoCommentService {
comments.push(new VideoComment(videoCommentJson)) comments.push(new VideoComment(videoCommentJson))
} }
return { comments, totalComments } return { data: comments, total: totalComments }
} }
private extractVideoCommentTree (tree: VideoCommentThreadTree) { private extractVideoCommentTree (tree: VideoCommentThreadTree) {

View File

@ -122,8 +122,8 @@ export class VideoCommentsComponent implements OnInit, OnChanges, OnDestroy {
obs.subscribe( obs.subscribe(
res => { res => {
this.comments = this.comments.concat(res.comments) this.comments = this.comments.concat(res.data)
this.componentPagination.totalItems = res.totalComments this.componentPagination.totalItems = res.total
}, },
err => this.notifier.error(err.message) err => this.notifier.error(err.message)

View File

@ -103,7 +103,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
} }
async ngOnInit () { async ngOnInit () {
await this.pluginService.loadPluginsByScope('video-watch') this.pluginService.loadPluginsByScope('video-watch')
this.configSub = this.serverService.configLoaded this.configSub = this.serverService.configLoaded
.subscribe(() => { .subscribe(() => {

View File

@ -1 +1 @@
export type PluginClientScope = 'common' | 'video-watch' export type PluginClientScope = 'common' | 'video-watch' | 'search'

View File

@ -1,6 +1,8 @@
import { PluginClientScope } from './plugin-client-scope.type'
export type ClientScript = { export type ClientScript = {
script: string, script: string,
scopes: string[] scopes: PluginClientScope[]
} }
export type PluginPackageJson = { export type PluginPackageJson = {

View File

@ -1,12 +1,11 @@
import { NSFWPolicyType } from '../videos/nsfw-policy.type' import { NSFWPolicyType } from '../videos/nsfw-policy.type'
import { ClientScript } from '../plugins/plugin-package-json.model' import { ClientScript } from '../plugins/plugin-package-json.model'
import { PluginClientScope } from '../plugins/plugin-scope.type'
export interface ServerConfigPlugin { export interface ServerConfigPlugin {
name: string name: string
version: string version: string
description: string description: string
clientScripts: { [name in PluginClientScope]: ClientScript } clientScripts: { [name: string]: ClientScript }
} }
export interface ServerConfigTheme extends ServerConfigPlugin { export interface ServerConfigTheme extends ServerConfigPlugin {