From cc1561f9f7b33d739d66b23bacae23ea49f2fa12 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Apr 2018 10:35:08 +0200 Subject: Simplify client syndications --- .../account-videos/account-videos.component.ts | 4 +- .../src/app/shared/video/abstract-video-list.scss | 5 +- client/src/app/shared/video/abstract-video-list.ts | 5 +- .../src/app/shared/video/video-feed.component.html | 9 ++- .../src/app/shared/video/video-feed.component.ts | 8 +-- client/src/app/shared/video/video.service.ts | 64 ++++++++++++---------- .../videos/+video-watch/video-watch.component.ts | 14 +---- .../app/videos/video-list/video-local.component.ts | 6 +- .../video-list/video-recently-added.component.ts | 6 +- .../videos/video-list/video-trending.component.ts | 8 +-- 10 files changed, 58 insertions(+), 71 deletions(-) (limited to 'client/src/app') diff --git a/client/src/app/account/account-videos/account-videos.component.ts b/client/src/app/account/account-videos/account-videos.component.ts index b9a3bea3f..07f5b7f0b 100644 --- a/client/src/app/account/account-videos/account-videos.component.ts +++ b/client/src/app/account/account-videos/account-videos.component.ts @@ -27,8 +27,6 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, totalItems: null } - syndicationItems = {} - protected baseVideoWidth = -1 protected baseVideoHeight = 155 @@ -43,6 +41,8 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit, ngOnInit () { super.ngOnInit() + + // this.generateSyndicationList() } ngOnDestroy () { diff --git a/client/src/app/shared/video/abstract-video-list.scss b/client/src/app/shared/video/abstract-video-list.scss index b75907dc9..913fcfe22 100644 --- a/client/src/app/shared/video/abstract-video-list.scss +++ b/client/src/app/shared/video/abstract-video-list.scss @@ -8,9 +8,12 @@ } } +.title-page.title-page-single { + margin-right: 5px; +} + my-video-feed { display: inline-block; - margin-left: -45px; } @media screen and (max-width: 500px) { diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 024834dfc..c1c07e628 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -3,7 +3,6 @@ import { ActivatedRoute, Router } from '@angular/router' import { isInMobileView } from '@app/shared/misc/utils' import { InfiniteScrollerDirective } from '@app/shared/video/infinite-scroller.directive' import { NotificationsService } from 'angular2-notifications' -import { PopoverModule } from 'ngx-bootstrap/popover' import 'rxjs/add/operator/debounceTime' import { Observable } from 'rxjs/Observable' import { fromEvent } from 'rxjs/observable/fromEvent' @@ -12,8 +11,6 @@ import { AuthService } from '../../core/auth' import { ComponentPagination } from '../rest/component-pagination.model' import { SortField } from './sort-field.type' import { Video } from './video.model' -import { FeedFormat } from '../../../../../shared' -import { VideoFeedComponent } from '@app/shared/video/video-feed.component' export abstract class AbstractVideoList implements OnInit, OnDestroy { private static LINES_PER_PAGE = 4 @@ -28,7 +25,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { } sort: SortField = '-createdAt' defaultSort: SortField = '-createdAt' - syndicationItems = {} + syndicationItems = [] loadOnInit = true pageHeight: number diff --git a/client/src/app/shared/video/video-feed.component.html b/client/src/app/shared/video/video-feed.component.html index 7733ef221..5ef13e1ed 100644 --- a/client/src/app/shared/video/video-feed.component.html +++ b/client/src/app/shared/video/video-feed.component.html @@ -1,14 +1,13 @@
- -
- {{ key }} +
+ {{ item.label }}
-
- \ No newline at end of file +
\ No newline at end of file diff --git a/client/src/app/shared/video/video-feed.component.ts b/client/src/app/shared/video/video-feed.component.ts index 41257ca99..6922153c0 100644 --- a/client/src/app/shared/video/video-feed.component.ts +++ b/client/src/app/shared/video/video-feed.component.ts @@ -1,14 +1,10 @@ -import { Component, Input, OnChanges, SimpleChanges } from '@angular/core' +import { Component, Input } from '@angular/core' @Component({ selector: 'my-video-feed', styleUrls: [ './video-feed.component.scss' ], templateUrl: './video-feed.component.html' }) -export class VideoFeedComponent implements OnChanges { +export class VideoFeedComponent { @Input() syndicationItems - - ngOnChanges (changes: SimpleChanges) { - this.syndicationItems = changes.syndicationItems.currentValue - } } diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index 009155410..4c19c3765 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -117,45 +117,53 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } - baseFeed () { - const feed = {} - - for (let item in FeedFormat) { - feed[FeedFormat[item]] = VideoService.BASE_FEEDS_URL + item.toLowerCase() - } - - return feed - } - - getFeed ( - filter?: VideoFilter - ) { + buildBaseFeedUrls () { + const feeds = [ + { + label: 'rss 2.0', + url: VideoService.BASE_FEEDS_URL + FeedFormat.RSS.toLowerCase() + }, + { + label: 'atom 1.0', + url: VideoService.BASE_FEEDS_URL + FeedFormat.ATOM.toLowerCase() + }, + { + label: 'json 1.0', + url: VideoService.BASE_FEEDS_URL + FeedFormat.JSON.toLowerCase() + } + ] + + return feeds + } + + getVideoFeedUrls (filter?: VideoFilter) { let params = this.restService.addRestGetParams(new HttpParams()) - const feed = this.baseFeed() + const feeds = this.buildBaseFeedUrls() - if (filter) { - params = params.set('filter', filter) - } - for (let item in feed) { - feed[item] = feed[item] + ((params.toString().length === 0) ? '' : '?') + params.toString() + if (filter) params = params.set('filter', filter) + + if (params.keys().length !== 0) { + for (let item of feeds) { + item.url += `?${params.toString()}` + } } - return feed + return feeds } - getAccountFeed ( - accountId: number, - host?: string - ) { + getAccountFeedUrls (accountId: number) { let params = this.restService.addRestGetParams(new HttpParams()) - const feed = this.baseFeed() + const feeds = this.buildBaseFeedUrls() params = params.set('accountId', accountId.toString()) - for (let item in feed) { - feed[item] = feed[item] + ((params.toString().length === 0) ? '' : '?') + params.toString() + + if (params.keys().length !== 0) { + for (let item of feeds) { + item.url += `?${params.toString()}` + } } - return feed + return feeds } searchVideos ( diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts index b3ebe3e4b..182703cdf 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild, OnChanges } from '@angular/core' +import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { RedirectService } from '@app/core/routing/redirect.service' import { peertubeLocalStorage } from '@app/shared/misc/peertube-local-storage' @@ -9,20 +9,18 @@ import { Subscription } from 'rxjs/Subscription' import * as videojs from 'video.js' import 'videojs-hotkeys' import * as WebTorrent from 'webtorrent' -import { UserVideoRateType, VideoRateType, FeedFormat } from '../../../../../shared' +import { UserVideoRateType, VideoRateType } from '../../../../../shared' import '../../../assets/player/peertube-videojs-plugin' import { AuthService, ConfirmService } from '../../core' import { VideoBlacklistService } from '../../shared' import { Account } from '../../shared/account/account.model' import { VideoDetails } from '../../shared/video/video-details.model' -import { VideoFeedComponent } from '../../shared/video/video-feed.component' import { Video } from '../../shared/video/video.model' import { VideoService } from '../../shared/video/video.service' import { MarkdownService } from '../shared' import { VideoDownloadComponent } from './modal/video-download.component' import { VideoReportComponent } from './modal/video-report.component' import { VideoShareComponent } from './modal/video-share.component' -import { environment } from '../../../environments/environment' import { getVideojsOptions } from '../../../assets/player/peertube-player' @Component({ @@ -248,13 +246,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { } generateSyndicationList () { - const feeds = this.videoService.getAccountFeed( - this.video.account.id, - (this.video.isLocal) ? environment.apiUrl : this.video.account.host - ) - this.syndicationItems['rss 2.0'] = feeds[FeedFormat.RSS] - this.syndicationItems['atom 1.0'] = feeds[FeedFormat.ATOM] - this.syndicationItems['json 1.0'] = feeds[FeedFormat.JSON] + this.syndicationItems = this.videoService.getAccountFeedUrls(this.video.account.id) } isVideoRemovable () { diff --git a/client/src/app/videos/video-list/video-local.component.ts b/client/src/app/videos/video-list/video-local.component.ts index 9d626abd1..90eb96afe 100644 --- a/client/src/app/videos/video-list/video-local.component.ts +++ b/client/src/app/videos/video-list/video-local.component.ts @@ -30,6 +30,7 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On ngOnInit () { super.ngOnInit() + this.generateSyndicationList() } @@ -44,9 +45,6 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On } generateSyndicationList () { - const feeds = this.videoService.getFeed('local') - this.syndicationItems['rss 2.0'] = feeds[FeedFormat.RSS] - this.syndicationItems['atom 1.0'] = feeds[FeedFormat.ATOM] - this.syndicationItems['json 1.0'] = feeds[FeedFormat.JSON] + this.syndicationItems = this.videoService.getVideoFeedUrls('local') } } diff --git a/client/src/app/videos/video-list/video-recently-added.component.ts b/client/src/app/videos/video-list/video-recently-added.component.ts index 2bdc20d92..3b8108b00 100644 --- a/client/src/app/videos/video-list/video-recently-added.component.ts +++ b/client/src/app/videos/video-list/video-recently-added.component.ts @@ -29,6 +29,7 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On ngOnInit () { super.ngOnInit() + this.generateSyndicationList() } @@ -43,9 +44,6 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On } generateSyndicationList () { - const feeds = this.videoService.getFeed('local') - this.syndicationItems['rss 2.0'] = feeds[FeedFormat.RSS] - this.syndicationItems['atom 1.0'] = feeds[FeedFormat.ATOM] - this.syndicationItems['json 1.0'] = feeds[FeedFormat.JSON] + this.syndicationItems = this.videoService.getVideoFeedUrls() } } diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts index 905c75ab0..6358ef91f 100644 --- a/client/src/app/videos/video-list/video-trending.component.ts +++ b/client/src/app/videos/video-list/video-trending.component.ts @@ -6,8 +6,6 @@ import { AuthService } from '../../core/auth' import { AbstractVideoList } from '../../shared/video/abstract-video-list' import { SortField } from '../../shared/video/sort-field.type' import { VideoService } from '../../shared/video/video.service' -import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum' -import * as url from 'url' @Component({ selector: 'my-videos-trending', @@ -29,6 +27,7 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, ngOnInit () { super.ngOnInit() + this.generateSyndicationList() } @@ -42,9 +41,6 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit, } generateSyndicationList () { - const feeds = this.videoService.getFeed('local') - this.syndicationItems['rss 2.0'] = feeds[FeedFormat.RSS] - this.syndicationItems['atom 1.0'] = feeds[FeedFormat.ATOM] - this.syndicationItems['json 1.0'] = feeds[FeedFormat.JSON] + this.syndicationItems = this.videoService.getVideoFeedUrls() } } -- cgit v1.2.3