Skip to content

Commit

Permalink
fix: re-enable upload for entry flavor and captions using the new upl…
Browse files Browse the repository at this point in the history
…oad management
  • Loading branch information
diamond-darrell authored and eransakal committed Oct 3, 2017
1 parent ad05d90 commit 8d24703
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 187 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable } from '@angular/core';
import {
KeyValueDiffers,
KeyValueDiffer,
IterableDiffers,
IterableDiffer,
KeyValueChangeRecord,
IterableChangeRecord
Injectable,
IterableChangeRecord,
IterableDiffer,
IterableDiffers,
KeyValueChangeRecord,
KeyValueDiffer,
KeyValueDiffers
} from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { TrackedFile, TrackedFileStatuses } from '@kaltura-ng/kaltura-common';
import { AppLocalization, TrackedFileStatuses, UploadManagement } from '@kaltura-ng/kaltura-common';

import { KalturaClient } from '@kaltura-ng/kaltura-client';
import { KalturaMultiRequest } from 'kaltura-typescript-client';
Expand All @@ -28,13 +28,10 @@ import { KalturaCaptionAssetStatus } from 'kaltura-typescript-client/types/Kaltu
import { KalturaLanguage } from 'kaltura-typescript-client/types/KalturaLanguage';
import { KalturaMediaEntry } from 'kaltura-typescript-client/types/KalturaMediaEntry';

import { AppLocalization } from '@kaltura-ng/kaltura-common';

import { EntryFormWidget } from '../entry-form-widget';
import { EntryWidgetKeys } from '../entry-widget-keys';
import { KalturaUploadFile } from '@kaltura-ng/kaltura-server-utils';
import { UploadManagement } from '@kaltura-ng/kaltura-common';

import { NewEntryCaptionFile } from './new-entry-caption-file';

export interface CaptionRow {
uploading: boolean,
Expand Down Expand Up @@ -70,40 +67,44 @@ export class EntryCaptionsHandler extends EntryFormWidget {
super(EntryWidgetKeys.Captions);
}

private _trackUploadFiles(): void {

private _trackUploadFiles(): void {

this._uploadManagement.onFileStatusChanged$
.cancelOnDestroy(this)
.subscribe(
(uploadedFile) => {
const captions = this._captions.getValue().items;
const relevantCaption = captions ? captions.find(captionFile => captionFile.uploadFileId === uploadedFile.id) : null;

switch (uploadedFile.status) {
case TrackedFileStatuses.waitingUpload:
if (uploadedFile.data instanceof KalturaUploadFile) {
relevantCaption.serverUploadToken = uploadedFile.data.serverUploadToken;
}
break;
case TrackedFileStatuses.uploadCompleted:
relevantCaption.uploading = false;
relevantCaption.uploadFailure = false;
break;
case TrackedFileStatuses.uploadFailed:
relevantCaption.uploading = false;
relevantCaption.uploadFailure = true;
break;
case TrackedFileStatuses.uploading:
relevantCaption.progress = (uploadedFile.progress * 100).toFixed(0);
relevantCaption.uploading = true;
relevantCaption.uploadFailure = false;
break;
default:
break;
}
});
}
this._uploadManagement.onFileStatusChanged$
.cancelOnDestroy(this)
.map(uploadedFile => {
let relevantCaption = null;
if (uploadedFile.data instanceof NewEntryCaptionFile) {
const captions = this._captions.getValue().items;
relevantCaption = captions ? captions.find(captionFile => captionFile.uploadFileId === uploadedFile.id) : null;
}
return { relevantCaption, uploadedFile };
})
.filter(({ relevantCaption }) => !!relevantCaption)
.subscribe(
({ relevantCaption, uploadedFile }) => {
switch (uploadedFile.status) {
case TrackedFileStatuses.waitingUpload:
relevantCaption.serverUploadToken = (<NewEntryCaptionFile>uploadedFile.data).serverUploadToken;
break;
case TrackedFileStatuses.uploadCompleted:
relevantCaption.uploading = false;
relevantCaption.uploadFailure = false;
break;
case TrackedFileStatuses.uploadFailed:
relevantCaption.uploading = false;
relevantCaption.uploadFailure = true;
break;
case TrackedFileStatuses.uploading:
relevantCaption.progress = (uploadedFile.progress * 100).toFixed(0);
relevantCaption.uploading = true;
relevantCaption.uploadFailure = false;
break;
default:
break;
}
});
}


/**
Expand Down Expand Up @@ -223,7 +224,7 @@ export class EntryCaptionsHandler extends EntryFormWidget {
public upload(captionFile: File): void {
this.currentCaption.uploading = true;

Observable.of(this._uploadManagement.addFile(new KalturaUploadFile(captionFile)))
Observable.of(this._uploadManagement.addFile(new NewEntryCaptionFile(captionFile)))
.subscribe((response) => {
this.currentCaption.uploadFileId = response.id;
this.currentCaption.uploading = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { KalturaUploadFile } from '@kaltura-ng/kaltura-server-utils';

export class NewEntryCaptionFile extends KalturaUploadFile {
constructor(file: File) {
super(file);
}
}
Loading

0 comments on commit 8d24703

Please sign in to comment.