Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support Uploading Additional Video Files #1984

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ <h5 class="text-muted"><strong>Tips</strong></h5>
<h3>Click here to select videos to upload</h3>
</div>
<p class="cds-deposit-box-upload-description">You can also <strong>Drag & Drop</strong> video files here</p>
<p class="text-muted mt-20">supported files <mark>{{ $ctrl.videoExtensions }}</mark></p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ <h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
</ul>
</div>
<!-- Error alert -->

<div class="cds-deposit-box" ng-if="!$ctrl.cdsDepositCtrl.isPublished()">
<div
ngf-drag-over-class="'cds-deposit-dragover'"
Expand All @@ -309,8 +310,31 @@ <h4>Upload complimentary files for this video</h4>
<div class="text-muted">
<h5 class="text-muted"><strong>Tips and suggestions</strong></h5>
<ul>
<li>To replace the video file, just upload another video.</li>
<li>To replace the video file, just upload another video to here.</li>
</ul>
<div
ngf-drag-over-class="{accept: 'cds-deposit-dragover', delay:100}"
ngf-drop=""
ngf-change="$ctrl.replaceMasterFile($newFiles, $invalidFiles)"
ngf-select=""
ngf-model-options="{allowInvalid: false}"
ngf-max-size="500GB"
ngf-multiple="true"
ngf-accept="'{{$ctrl.cdsDepositsCtrl.videoExtensions}}'"
ngf-pattern="'{{$ctrl.cdsDepositsCtrl.videoExtensions}}'"
>
<div class="pa-10 cds-deposit-box-upload-wrapper text-center">
<p class="cds-deposit-box-upload-icon mb-20">
<i class="fa fa-2x fa-video-camera" aria-hidden="true"></i>
</p>
<div class="cds-deposit-box-upload-content">
<div class="cds-deposit-box-upload-title">
<h4>To replace the video file, just upload a video to here.</h4>
</div>
<p class="cds-deposit-box-upload-description"> Or Drag & Drop files</p>
</div>
</div>
</div>
</div>
</div>
<div ng-if="$ctrl.cdsDepositCtrl.isPublished()" class="cds-deposit-box text-muted">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function cdsUploaderCtrl(
if (!upload.key) {
upload.key = upload.name;
}
if (that.cdsDepositsCtrl.isVideoFile(upload.key)) {
if (!upload.isAdditional && that.cdsDepositsCtrl.isVideoFile(upload.key)) {
_subpromise = Upload.http(_startWorkflow(upload, response));
} else {
var d = $q.defer();
Expand Down Expand Up @@ -282,21 +282,13 @@ function cdsUploaderCtrl(
angular.forEach(_files, function (file) {
file.key = file.name;
file.local = !file.receiver;
file.isAdditional = true;
// Add any extra paramemters to the files
if (extraHeaders) {
file.headers = extraHeaders;
}
});

// Add the files to the list
var masterFile = that.cdsDepositCtrl.findMasterFile() || {};
var videoFiles = _.values(
that.cdsDepositsCtrl.filterOutFiles(_files).videos
);

// Exclude video files
_files = _.difference(_files, videoFiles);

// Find if any of the existing files has been replaced
// (file with same filename), and if yes remove it from the existing
// file list (aka from the interface).
Expand All @@ -323,6 +315,45 @@ function cdsUploaderCtrl(
Array.prototype.push.apply(that.files, _files);
// Add the files to the queue
Array.prototype.push.apply(that.queue, _files);

// Start upload automatically if the option is selected
if (that.autoStartUpload) {
that.upload();
}
};

this.replaceMasterFile = function(_files, invalidFiles){
// Do nothing if files array is empty
if (!_files) {
return;
}
// Remove any invalid files
_files = _.difference(_files, invalidFiles || []);
// Make sure they have proper metadata
angular.forEach(_files, function (file) {
file.key = file.name;
file.local = !file.receiver;
});

// Add the files to the list
var masterFile = that.cdsDepositCtrl.findMasterFile() || {};
var videoFiles = _.values(
that.cdsDepositsCtrl.filterOutFiles(_files).videos
);


if ((invalidFiles || []).length > 0) {
// Push a notification
toaster.pop({
type: "error",
title:
"Invalid file(s) for " +
(that.cdsDepositCtrl.record.title.title || "video."),
body: _.map(invalidFiles, "name").join(", "),
bodyOutputType: "trustedHtml",
});
}

if (!that.cdsDepositCtrl.master) {
// Check for new master file
var newMasterFile = videoFiles[0];
Expand Down Expand Up @@ -359,10 +390,6 @@ function cdsUploaderCtrl(
}
}

// Start upload automatically if the option is selected
if (that.autoStartUpload) {
that.upload();
}
};

// Prepare file request
Expand Down