Skip to content

Commit

Permalink
add default trending page choice, revert comments count for hot strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelk committed Jan 26, 2021
1 parent 8bbb090 commit 699bccb
Show file tree
Hide file tree
Showing 30 changed files with 254 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,16 +269,33 @@ <h1 class="sr-only" i18n>Configuration</h1>
<div class="peertube-select-container">
<select id="instanceDefaultClientRoute" formControlName="defaultClientRoute" class="form-control">
<option i18n value="/videos/overview">Discover videos</option>
<option i18n value="/videos/trending">Trending videos</option>
<option i18n value="/videos/hot">Hot videos</option>
<option i18n value="/videos/most-liked">Most liked videos</option>
<optgroup i18n-label label="Trending pages">
<option i18n value="/videos/trending">Default trending page</option>
<option i18n value="/videos/hot" *ngIf="isTrendingHotEnabled()">Hot videos</option>
<option i18n value="/videos/hot" *ngIf="!isTrendingHotEnabled()" disabled>Hot videos</option>
<option i18n value="/videos/most-viewed">Most viewed videos</option>
<option i18n value="/videos/most-liked">Most liked videos</option>
</optgroup>
<option i18n value="/videos/recently-added">Recently added videos</option>
<option i18n value="/videos/local">Local videos</option>
</select>
</div>
<div *ngIf="formErrors.instance.defaultClientRoute" class="form-error">{{ formErrors.instance.defaultClientRoute }}</div>
</div>

<div class="form-group" formGroupName="instance">
<label i18n for="instanceDefaultTrendingRoute">Default trending page</label>
<div class="peertube-select-container">
<select id="instanceDefaultTrendingRoute" formControlName="defaultTrendingRoute" class="form-control">
<option i18n value="/videos/hot" *ngIf="isTrendingHotEnabled()">Hot videos</option>
<option i18n value="/videos/hot" *ngIf="!isTrendingHotEnabled()" disabled>Hot videos</option>
<option i18n value="/videos/trending">Most viewed videos</option>
<option i18n value="/videos/most-liked">Most liked videos</option>
</select>
</div>
<div *ngIf="formErrors.instance.defaultTrendingRoute" class="form-error">{{ formErrors.instance.defaultTrendingRoute }}</div>
</div>

</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A
languages: null,

defaultClientRoute: null,
defaultTrendingRoute: null,
pages: {
hot: {
enabled: null
}
},

customizations: {
javascript: null,
Expand Down Expand Up @@ -364,6 +370,10 @@ export class EditCustomConfigComponent extends FormReactive implements OnInit, A
return this.form.value['followings']['instance']['autoFollowIndex']['enabled'] === true
}

isTrendingHotEnabled () {
return this.form.value['instance']['pages']['hot']['enabled'] === true
}

async formValidated () {
const value: CustomConfig = this.form.getRawValue()

Expand Down
2 changes: 1 addition & 1 deletion client/src/app/+videos/video-list/trending/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './video-trending-header.component'
export * from './video-trending.component'
export * from './video-most-viewed.component'
export * from './video-hot.component'
export * from './video-most-liked.component'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" [(ngModel)]="data.model" (ngModelChange)="setSort()">
<label *ngFor="let button of buttons" ngbButtonLabel class="btn-light" placement="bottom" [ngbTooltip]="button.tooltip" container="body">
<label *ngFor="let button of visibleButtons" ngbButtonLabel class="btn-light" placement="bottom" [ngbTooltip]="button.tooltip" container="body">
<my-global-icon [iconName]="button.iconName"></my-global-icon>
<input ngbButton type="radio" [value]="button.value"> {{ button.label }}
</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Component, Inject } from '@angular/core'
import { Component, Inject, OnInit } from '@angular/core'
import { Router } from '@angular/router'
import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
import { GlobalIconName } from '@app/shared/shared-icons'
import { VideoSortField } from '@shared/models'
import { ServerService } from '@app/core/server/server.service'

interface VideoTrendingHeaderItem {
label: string
iconName: GlobalIconName
value: VideoSortField
path: string
tooltip?: string
hidden?: boolean
}

@Component({
Expand All @@ -18,12 +20,13 @@ interface VideoTrendingHeaderItem {
styleUrls: [ './video-trending-header.component.scss' ],
templateUrl: './video-trending-header.component.html'
})
export class VideoTrendingHeaderComponent extends VideoListHeaderComponent {
export class VideoTrendingHeaderComponent extends VideoListHeaderComponent implements OnInit {
buttons: VideoTrendingHeaderItem[]

constructor (
@Inject('data') public data: any,
private router: Router
private router: Router,
private serverService: ServerService
) {
super(data)

Expand All @@ -34,16 +37,17 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent {
value: '-hot',
path: 'hot',
tooltip: $localize`Videos totalizing the most interactions for recent videos`,
hidden: true
},
{
label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
iconName: 'trending',
value: '-trending',
path: 'trending',
path: 'most-viewed',
tooltip: $localize`Videos totalizing the most views during the last 24 hours`,
},
{
label: $localize`:a variant of Trending videos based on the number of likes:Likes`,
label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
iconName: 'like',
value: '-likes',
path: 'most-liked',
Expand All @@ -52,6 +56,21 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent {
]
}

ngOnInit () {
this.serverService.getConfig()
.subscribe(config => {
// don't filter if auto-blacklist is not enabled as this will be the only list
if (config.instance.pages.hot.enabled) {
const index = this.buttons.findIndex(b => b.path === 'hot')
this.buttons[index].hidden = false
}
})
}

get visibleButtons () {
return this.buttons.filter(b => !b.hidden)
}

setSort () {
const path = this.buttons.find(b => b.value === this.data.model).path
this.router.navigate([ `/videos/${path}` ])
Expand Down

This file was deleted.

22 changes: 13 additions & 9 deletions client/src/app/+videos/videos-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NgModule } from '@angular/core'
import { RouterModule, Routes } from '@angular/router'
import { LoginGuard } from '@app/core'
import { LoginGuard, TrendingGuard } from '@app/core'
import { MetaGuard } from '@ngx-meta/core'
import { VideoOverviewComponent } from './video-list/overview/video-overview.component'
import { VideoHotComponent } from './video-list/trending/video-hot.component'
import { VideoMostLikedComponent } from './video-list/trending/video-most-liked.component'
import { VideoTrendingComponent } from './video-list/trending/video-trending.component'
import { VideoMostViewedComponent } from './video-list/trending/video-most-viewed.component'
import { VideoLocalComponent } from './video-list/video-local.component'
import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component'
import { VideoUserSubscriptionsComponent } from './video-list/video-user-subscriptions.component'
Expand All @@ -28,27 +28,31 @@ const videosRoutes: Routes = [
},
{
path: 'trending',
component: VideoTrendingComponent,
canActivate: [ TrendingGuard ]
},
{
path: 'hot',
component: VideoHotComponent,
data: {
meta: {
title: $localize`Trending videos`
title: $localize`Hot videos`
},
reuse: {
enabled: true,
key: 'trending-videos-list'
key: 'hot-videos-list'
}
}
},
{
path: 'hot',
component: VideoHotComponent,
path: 'most-viewed',
component: VideoMostViewedComponent,
data: {
meta: {
title: $localize`Hot videos`
title: $localize`Most viewed videos`
},
reuse: {
enabled: true,
key: 'hot-videos-list'
key: 'most-viewed-videos-list'
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/+videos/videos.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OverviewService } from './video-list'
import { VideoOverviewComponent } from './video-list/overview/video-overview.component'
import { VideoTrendingHeaderComponent } from './video-list/trending/video-trending-header.component'
import { VideoHotComponent } from './video-list/trending/video-hot.component'
import { VideoTrendingComponent } from './video-list/trending/video-trending.component'
import { VideoMostViewedComponent } from './video-list/trending/video-most-viewed.component'
import { VideoMostLikedComponent } from './video-list/trending/video-most-liked.component'
import { VideoLocalComponent } from './video-list/video-local.component'
import { VideoRecentlyAddedComponent } from './video-list/video-recently-added.component'
Expand All @@ -32,7 +32,7 @@ import { VideosComponent } from './videos.component'
VideosComponent,

VideoTrendingHeaderComponent,
VideoTrendingComponent,
VideoMostViewedComponent,
VideoHotComponent,
VideoMostLikedComponent,
VideoRecentlyAddedComponent,
Expand Down
4 changes: 2 additions & 2 deletions client/src/app/core/core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { PeerTubeSocket } from '@app/core/notification/peertube-socket.service'
import { HooksService } from '@app/core/plugins/hooks.service'
import { PluginService } from '@app/core/plugins/plugin.service'
import { UnloggedGuard } from '@app/core/routing/unlogged-guard.service'
import { AuthService } from './auth'
import { ConfirmService } from './confirm'
import { CheatSheetComponent } from './hotkeys'
Expand All @@ -16,7 +15,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard'
import { Notifier } from './notification'
import { HtmlRendererService, LinkifierService, MarkdownService } from './renderer'
import { RestExtractor, RestService } from './rest'
import { LoginGuard, RedirectService, UserRightGuard } from './routing'
import { LoginGuard, RedirectService, UserRightGuard, UnloggedGuard, TrendingGuard } from './routing'
import { CanDeactivateGuard } from './routing/can-deactivate-guard.service'
import { ServerConfigResolver } from './routing/server-config-resolver.service'
import { ScopedTokensService } from './scoped-tokens'
Expand Down Expand Up @@ -57,6 +56,7 @@ import { LocalStorageService, ScreenService, SessionStorageService } from './wra
LoginGuard,
UserRightGuard,
UnloggedGuard,
TrendingGuard,

PluginService,
HooksService,
Expand Down
1 change: 1 addition & 0 deletions client/src/app/core/routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './redirect.service'
export * from './server-config-resolver.service'
export * from './unlogged-guard.service'
export * from './user-right-guard.service'
export * from './trending-guard.service'
Loading

0 comments on commit 699bccb

Please sign in to comment.