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

Update duration to check for second value in files array #3500

Merged
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 @@ -6,7 +6,7 @@
v-if="audioVideoUpload && selectedDuration === 'exactTime'"
class="defaultUpload md2 sm3"
>
{{ convertToHHMMSS(defaultUploadTime) }}
{{ convertToHHMMSS(duration || `00:00`) }}
</VFlex>
<VFlex
v-else-if="selectedDuration === 'shortActivity' || selectedDuration === 'longActivity'"
Expand Down Expand Up @@ -92,11 +92,6 @@
default: null,
},
},
data() {
return {
defaultUploadTime: this.duration || `17:12`,
};
},
computed: {
showRequiredLabel() {
if (this.audioVideoUpload) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
import LearningActivityOptions from './LearningActivityOptions.vue';
import CategoryOptions from './CategoryOptions.vue';
import CompletionOptions from './CompletionOptions.vue';

import FormatPresetsMap, { FormatPresetsNames } from 'shared/leUtils/FormatPresets';
import {
getTitleValidators,
getCopyrightHolderValidators,
Expand Down Expand Up @@ -642,10 +642,17 @@
return (this.firstNode && this.getContentNodeFiles(this.firstNode.id)) || [];
},
fileDuration() {
if (this.firstNode.kind === 'audio' || this.firstNode.kind === 'video') {
return this.nodeFiles.filter(
file => file.file_format === 'mp4' || file.file_format === 'mp3'
)[0].duration;
if (
this.firstNode.kind === ContentKindsNames.AUDIO ||
this.firstNode.kind === ContentKindsNames.VIDEO
) {
// filter for the correct file types,
// to exclude files such as subtitle or cc
let audioVideoFiles;
audioVideoFiles = this.nodeFiles.filter(file => this.allowedFileType(file));
// return the last item in the array
const file = audioVideoFiles[audioVideoFiles.length - 1];
return file.duration;
} else {
return null;
}
Expand Down Expand Up @@ -734,6 +741,17 @@
isUnique(value) {
return value !== nonUniqueValue;
},
allowedFileType(file) {
let allowedFileTypes = [];
// add the relevant format presets for audio and video
// high res and low res are currently the same, so only one is included
allowedFileTypes.push(
FormatPresetsMap.get(FormatPresetsNames.HIGH_RES_VIDEO).allowed_formats
);
allowedFileTypes.push(FormatPresetsMap.get(FormatPresetsNames.AUDIO).allowed_formats);
allowedFileTypes = allowedFileTypes.flat();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL .flat() exists on Array.prototype

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight optimization would be to only create this allowedFileTypes array once, outside of this function scope, but I think it's unlikely to have major performance differences

return allowedFileTypes.includes(file.file_format);
},
getValueFromNodes(key) {
const results = uniq(
this.nodes.map(node => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,6 @@ describe('ActivityDuration', () => {
const shortActivityMax = 30;
const longActivityMin = 31;
const longActivityMax = 120;
describe(`default state for audio/video resources`, () => {
it(`should display a static upload time when 'Exact time to complete' for audio/video resources as initial state`, () => {
const defaultValue = '17:12';
const wrapper = shallowMount(ActivityDuration);
expect(wrapper.vm.defaultUploadTime).toEqual(defaultValue);
});
it(`should display the file's time at upload when 'Exact time to complete' is chosen in Completion dropdown`, () => {
// TODO: defaultValue will need to be changed when file-upload-duration is implemented
const defaultValue = '17:12';
const wrapper = shallowMount(ActivityDuration, {
propsData: { duration: 123 },
});
expect(wrapper.props('duration')).toEqual(123);
expect(wrapper.vm.defaultUploadTime).not.toEqual(defaultValue);
expect(wrapper.vm.defaultUploadTime).toEqual(123);
});
it(`should display a "stand-in" at upload if file's time at upload is not available when 'Exact time to complete' is chosen in Completion dropdown`, () => {
// TODO: defaultValue will need to be changed when file-upload-duration is implemented
const defaultValue = '17:12';
const wrapper = shallowMount(ActivityDuration, {
propsData: { duration: null },
});
expect(wrapper.props('duration')).toEqual(null);
expect(wrapper.vm.defaultUploadTime).toEqual(defaultValue);
expect(wrapper.vm.defaultUploadTime).not.toEqual(null);
});
});

describe(`convert seconds to minutes for display`, () => {
it(`should display the seconds passed down from parent as minutes`, () => {
Expand Down