--- /dev/null
+import { FormReactive } from '@app/shared'
+import { OnInit } from '@angular/core'
+import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
+import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
+import { VideoConstant, VideoPrivacy } from '../../../../../../shared/models/videos'
+import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
+import { LoadingBarService } from '@ngx-loading-bar/core'
+import { NotificationsService } from 'angular2-notifications'
+import { AuthService, ServerService } from '@app/core'
+import { VideoService } from '@app/shared/video/video.service'
+import { VideoCaptionService } from '@app/shared/video-caption'
+import { catchError, switchMap, tap } from 'rxjs/operators'
+import { VideoEdit } from '@app/shared/video/video-edit.model'
+
+export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate {
+
+ userVideoChannels: { id: number, label: string, support: string }[] = []
+ videoPrivacies: VideoConstant<string>[] = []
+ videoCaptions: VideoCaptionEdit[] = []
+
+ firstStepPrivacyId = 0
+ firstStepChannelId = 0
+
+ protected abstract readonly DEFAULT_VIDEO_PRIVACY: VideoPrivacy
+
+ protected loadingBar: LoadingBarService
+ protected notificationsService: NotificationsService
+ protected authService: AuthService
+ protected serverService: ServerService
+ protected videoService: VideoService
+ protected videoCaptionService: VideoCaptionService
+
+ abstract canDeactivate ()
+
+ ngOnInit () {
+ this.buildForm({})
+
+ populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
+ .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
+
+ this.serverService.videoPrivaciesLoaded
+ .subscribe(
+ () => {
+ this.videoPrivacies = this.serverService.getVideoPrivacies()
+
+ this.firstStepPrivacyId = this.DEFAULT_VIDEO_PRIVACY
+ })
+ }
+
+ checkForm () {
+ this.forceCheck()
+
+ return this.form.valid
+ }
+
+ protected updateVideoAndCaptions (video: VideoEdit) {
+ this.loadingBar.start()
+
+ return this.videoService.updateVideo(video)
+ .pipe(
+ // Then update captions
+ switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions)),
+ tap(() => this.loadingBar.complete()),
+ catchError(err => {
+ this.loadingBar.complete()
+ throw err
+ })
+ )
+ }
+}
<tabset class="video-add-tabset root-tabset bootstrap" [ngClass]="{ 'hide-nav': secondStepType !== undefined }">
- <tab i18n-heading heading="Upload your video">
+ <tab i18n-heading heading="Upload a file">
<my-video-upload #videoUpload (firstStepDone)="onFirstStepDone('upload', $event)"></my-video-upload>
</tab>
- <tab *ngIf="isVideoImportEnabled()" i18n-heading heading="Import your video">
+ <tab *ngIf="isVideoImportEnabled()" i18n-heading heading="Import with URL">
<my-video-import #videoImport (firstStepDone)="onFirstStepDone('import', $event)"></my-video-import>
</tab>
</tabset>
margin-bottom: -$border-width;
}
- .nav-link {
+ a.nav-link {
+ @include disable-default-a-behaviour;
+
+ color: #000;
height: 40px !important;
padding: 0 30px !important;
font-size: 15px;
import { Router } from '@angular/router'
import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service'
import { NotificationsService } from 'angular2-notifications'
-import { VideoConstant, VideoPrivacy, VideoUpdate } from '../../../../../shared/models/videos'
+import { VideoPrivacy, VideoUpdate } from '../../../../../shared/models/videos'
import { AuthService, ServerService } from '../../core'
-import { FormReactive } from '../../shared'
-import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
import { VideoService } from '../../shared/video/video.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
-import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
import { VideoImportService } from '@app/shared/video-import'
import { VideoEdit } from '@app/shared/video/video-edit.model'
-import { switchMap } from 'rxjs/operators'
import { LoadingBarService } from '@ngx-loading-bar/core'
import { VideoCaptionService } from '@app/shared/video-caption'
+import { VideoSend } from '@app/videos/+video-edit/shared/video-send'
@Component({
selector: 'my-video-import',
'./video-import.component.scss'
]
})
-export class VideoImportComponent extends FormReactive implements OnInit, CanComponentDeactivate {
+export class VideoImportComponent extends VideoSend implements OnInit, CanComponentDeactivate {
@Output() firstStepDone = new EventEmitter<string>()
targetUrl = ''
hasImportedVideo = false
isUpdatingVideo = false
- userVideoChannels: { id: number, label: string, support: string }[] = []
- videoPrivacies: VideoConstant<string>[] = []
- videoCaptions: VideoCaptionEdit[] = []
-
- firstStepPrivacyId = 0
- firstStepChannelId = 0
video: VideoEdit
+ protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PRIVATE
+
constructor (
protected formValidatorService: FormValidatorService,
+ protected loadingBar: LoadingBarService,
+ protected notificationsService: NotificationsService,
+ protected authService: AuthService,
+ protected serverService: ServerService,
+ protected videoService: VideoService,
+ protected videoCaptionService: VideoCaptionService,
private router: Router,
- private loadingBar: LoadingBarService,
- private notificationsService: NotificationsService,
- private authService: AuthService,
- private serverService: ServerService,
- private videoService: VideoService,
private videoImportService: VideoImportService,
- private videoCaptionService: VideoCaptionService,
private i18n: I18n
) {
super()
}
ngOnInit () {
- this.buildForm({})
-
- populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
- .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
-
- this.serverService.videoPrivaciesLoaded
- .subscribe(
- () => {
- this.videoPrivacies = this.serverService.getVideoPrivacies()
-
- // Private by default
- this.firstStepPrivacyId = VideoPrivacy.PRIVATE
- })
+ super.ngOnInit()
}
canDeactivate () {
return { canDeactivate: true }
}
- checkForm () {
- this.forceCheck()
-
- return this.form.valid
- }
-
isTargetUrlValid () {
return this.targetUrl && this.targetUrl.match(/https?:\/\//)
}
this.video.patch(this.form.value)
- this.loadingBar.start()
this.isUpdatingVideo = true
// Update the video
- this.videoService.updateVideo(this.video)
- .pipe(
- // Then update captions
- switchMap(() => this.videoCaptionService.updateCaptions(this.video.id, this.videoCaptions))
- )
+ this.updateVideoAndCaptions(this.video)
.subscribe(
() => {
this.isUpdatingVideo = false
- this.loadingBar.complete()
this.notificationsService.success(this.i18n('Success'), this.i18n('Video to import updated.'))
this.router.navigate([ '/my-account', 'video-imports' ])
},
err => {
- this.loadingBar.complete()
this.isUpdatingVideo = false
this.notificationsService.error(this.i18n('Error'), err.message)
console.error(err)
import { NotificationsService } from 'angular2-notifications'
import { BytesPipe } from 'ngx-pipes'
import { Subscription } from 'rxjs'
-import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
+import { VideoPrivacy } from '../../../../../shared/models/videos'
import { AuthService, ServerService } from '../../core'
-import { FormReactive } from '../../shared'
-import { populateAsyncUserVideoChannels } from '../../shared/misc/utils'
import { VideoEdit } from '../../shared/video/video-edit.model'
import { VideoService } from '../../shared/video/video.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
-import { switchMap } from 'rxjs/operators'
import { VideoCaptionService } from '@app/shared/video-caption'
-import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
+import { VideoSend } from '@app/videos/+video-edit/shared/video-send'
@Component({
selector: 'my-video-upload',
'./video-upload.component.scss'
]
})
-export class VideoUploadComponent extends FormReactive implements OnInit, OnDestroy, CanComponentDeactivate {
+export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy, CanComponentDeactivate {
@Output() firstStepDone = new EventEmitter<string>()
@ViewChild('videofileInput') videofileInput
// So that it can be accessed in the template
readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
+ userVideoQuotaUsed = 0
+
isUploadingVideo = false
isUpdatingVideo = false
videoUploaded = false
uuid: ''
}
- userVideoChannels: { id: number, label: string, support: string }[] = []
- userVideoQuotaUsed = 0
- videoPrivacies: VideoConstant<string>[] = []
- firstStepPrivacyId = 0
- firstStepChannelId = 0
- videoCaptions: VideoCaptionEdit[] = []
+ protected readonly DEFAULT_VIDEO_PRIVACY = VideoPrivacy.PUBLIC
constructor (
protected formValidatorService: FormValidatorService,
- private router: Router,
- private notificationsService: NotificationsService,
- private authService: AuthService,
+ protected loadingBar: LoadingBarService,
+ protected notificationsService: NotificationsService,
+ protected authService: AuthService,
+ protected serverService: ServerService,
+ protected videoService: VideoService,
+ protected videoCaptionService: VideoCaptionService,
private userService: UserService,
- private serverService: ServerService,
- private videoService: VideoService,
- private loadingBar: LoadingBarService,
- private i18n: I18n,
- private videoCaptionService: VideoCaptionService
+ private router: Router,
+ private i18n: I18n
) {
super()
}
}
ngOnInit () {
- this.buildForm({})
-
- populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
- .then(() => this.firstStepChannelId = this.userVideoChannels[0].id)
+ super.ngOnInit()
this.userService.getMyVideoQuotaUsed()
.subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
-
- this.serverService.videoPrivaciesLoaded
- .subscribe(
- () => {
- this.videoPrivacies = this.serverService.getVideoPrivacies()
-
- // Public by default
- this.firstStepPrivacyId = VideoPrivacy.PUBLIC
- })
}
ngOnDestroy () {
- if (this.videoUploadObservable) {
- this.videoUploadObservable.unsubscribe()
- }
+ if (this.videoUploadObservable) this.videoUploadObservable.unsubscribe()
}
canDeactivate () {
this.uploadFirstStep()
}
- checkForm () {
- this.forceCheck()
-
- return this.form.valid
- }
-
cancelUpload () {
if (this.videoUploadObservable !== null) {
this.videoUploadObservable.unsubscribe()
video.uuid = this.videoUploadedIds.uuid
this.isUpdatingVideo = true
- this.loadingBar.start()
- this.videoService.updateVideo(video)
- .pipe(
- // Then update captions
- switchMap(() => this.videoCaptionService.updateCaptions(video.id, this.videoCaptions))
- )
+
+ this.updateVideoAndCaptions(video)
.subscribe(
() => {
this.isUpdatingVideo = false
this.isUploadingVideo = false
- this.loadingBar.complete()
this.notificationsService.success(this.i18n('Success'), this.i18n('Video published.'))
this.router.navigate([ '/videos/watch', video.uuid ])