From bbe0f0645ca958d33a3f409b15166609733b663f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 15 Jun 2018 16:52:15 +0200 Subject: Add ability to schedule video publication --- client/src/app/shared/video/abstract-video-list.ts | 5 ++-- client/src/app/shared/video/video-edit.model.ts | 32 ++++++++++++++++++++-- .../app/shared/video/video-thumbnail.component.ts | 6 ++-- client/src/app/shared/video/video.model.ts | 3 ++ client/src/app/shared/video/video.service.ts | 3 +- 5 files changed, 42 insertions(+), 7 deletions(-) (limited to 'client/src/app/shared/video') diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 1c84573da..a468d3231 100644 --- a/client/src/app/shared/video/abstract-video-list.ts +++ b/client/src/app/shared/video/abstract-video-list.ts @@ -2,7 +2,6 @@ import { debounceTime } from 'rxjs/operators' import { ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { Location } from '@angular/common' -import { isInMobileView } from '@app/shared/misc/utils' import { InfiniteScrollerDirective } from '@app/shared/video/infinite-scroller.directive' import { NotificationsService } from 'angular2-notifications' import { fromEvent, Observable, Subscription } from 'rxjs' @@ -11,6 +10,7 @@ import { ComponentPagination } from '../rest/component-pagination.model' import { VideoSortField } from './sort-field.type' import { Video } from './video.model' import { I18n } from '@ngx-translate/i18n-polyfill' +import { ScreenService } from '@app/shared/misc/screen.service' export abstract class AbstractVideoList implements OnInit, OnDestroy { private static LINES_PER_PAGE = 4 @@ -41,6 +41,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { protected abstract authService: AuthService protected abstract router: Router protected abstract route: ActivatedRoute + protected abstract screenService: ScreenService protected abstract i18n: I18n protected abstract location: Location protected abstract currentRoute: string @@ -199,7 +200,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy { } private calcPageSizes () { - if (isInMobileView() || this.baseVideoWidth === -1) { + if (this.screenService.isInMobileView() || this.baseVideoWidth === -1) { this.pagination.itemsPerPage = 5 // Video takes all the width diff --git a/client/src/app/shared/video/video-edit.model.ts b/client/src/app/shared/video/video-edit.model.ts index f045a3acd..78aed4f9f 100644 --- a/client/src/app/shared/video/video-edit.model.ts +++ b/client/src/app/shared/video/video-edit.model.ts @@ -1,8 +1,11 @@ import { VideoDetails } from './video-details.model' import { VideoPrivacy } from '../../../../../shared/models/videos/video-privacy.enum' import { VideoUpdate } from '../../../../../shared/models/videos' +import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' export class VideoEdit implements VideoUpdate { + static readonly SPECIAL_SCHEDULED_PRIVACY = -1 + category: number licence: number language: string @@ -21,6 +24,7 @@ export class VideoEdit implements VideoUpdate { previewUrl: string uuid?: string id?: number + scheduleUpdate?: VideoScheduleUpdate constructor (videoDetails?: VideoDetails) { if (videoDetails) { @@ -40,6 +44,8 @@ export class VideoEdit implements VideoUpdate { this.support = videoDetails.support this.thumbnailUrl = videoDetails.thumbnailUrl this.previewUrl = videoDetails.previewUrl + + this.scheduleUpdate = videoDetails.scheduledUpdate } } @@ -47,10 +53,22 @@ export class VideoEdit implements VideoUpdate { Object.keys(values).forEach((key) => { this[ key ] = values[ key ] }) + + // If schedule publication, the video is private and will be changed to public privacy + if (values['schedulePublicationAt']) { + const updateAt = (values['schedulePublicationAt'] as Date) + updateAt.setSeconds(0) + + this.privacy = VideoPrivacy.PRIVATE + this.scheduleUpdate = { + updateAt: updateAt.toISOString(), + privacy: VideoPrivacy.PUBLIC + } + } } - toJSON () { - return { + toFormPatch () { + const json = { category: this.category, licence: this.licence, language: this.language, @@ -64,5 +82,15 @@ export class VideoEdit implements VideoUpdate { channelId: this.channelId, privacy: this.privacy } + + // Special case if we scheduled an update + if (this.scheduleUpdate) { + Object.assign(json, { + privacy: VideoEdit.SPECIAL_SCHEDULED_PRIVACY, + schedulePublicationAt: new Date(this.scheduleUpdate.updateAt.toString()) + }) + } + + return json } } diff --git a/client/src/app/shared/video/video-thumbnail.component.ts b/client/src/app/shared/video/video-thumbnail.component.ts index e52f7dfb0..86d8f6f74 100644 --- a/client/src/app/shared/video/video-thumbnail.component.ts +++ b/client/src/app/shared/video/video-thumbnail.component.ts @@ -1,6 +1,6 @@ import { Component, Input } from '@angular/core' -import { isInMobileView } from '@app/shared/misc/utils' import { Video } from './video.model' +import { ScreenService } from '@app/shared/misc/screen.service' @Component({ selector: 'my-video-thumbnail', @@ -11,10 +11,12 @@ export class VideoThumbnailComponent { @Input() video: Video @Input() nsfw = false + constructor (private screenService: ScreenService) {} + getImageUrl () { if (!this.video) return '' - if (isInMobileView()) { + if (this.screenService.isInMobileView()) { return this.video.previewUrl } diff --git a/client/src/app/shared/video/video.model.ts b/client/src/app/shared/video/video.model.ts index 48a4b4260..7f421dbbb 100644 --- a/client/src/app/shared/video/video.model.ts +++ b/client/src/app/shared/video/video.model.ts @@ -6,6 +6,7 @@ import { getAbsoluteAPIUrl } from '../misc/utils' import { ServerConfig } from '../../../../../shared/models' import { Actor } from '@app/shared/actor/actor.model' import { peertubeTranslate } from '@app/shared/i18n/i18n-utils' +import { VideoScheduleUpdate } from '../../../../../shared/models/videos/video-schedule-update.model' export class Video implements VideoServerModel { by: string @@ -38,6 +39,7 @@ export class Video implements VideoServerModel { waitTranscoding?: boolean state?: VideoConstant + scheduledUpdate?: VideoScheduleUpdate account: { id: number @@ -109,6 +111,7 @@ export class Video implements VideoServerModel { this.language.label = peertubeTranslate(this.language.label, translations) this.privacy.label = peertubeTranslate(this.privacy.label, translations) + this.scheduledUpdate = hash.scheduledUpdate if (this.state) this.state.label = peertubeTranslate(this.state.label, translations) } diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts index d63915ad2..3af90e7ad 100644 --- a/client/src/app/shared/video/video.service.ts +++ b/client/src/app/shared/video/video.service.ts @@ -83,7 +83,8 @@ export class VideoService { waitTranscoding: video.waitTranscoding, commentsEnabled: video.commentsEnabled, thumbnailfile: video.thumbnailfile, - previewfile: video.previewfile + previewfile: video.previewfile, + scheduleUpdate: video.scheduleUpdate || undefined } const data = objectToFormData(body) -- cgit v1.2.3