Commit 83d3a0d2 authored by Richard Blechinger's avatar Richard Blechinger
Browse files

Expand playlist duration automatically

parent c6658d17
...@@ -295,23 +295,25 @@ ...@@ -295,23 +295,25 @@
return !entry.duration return !entry.duration
}); });
console.log(unknowns);
return unknowns.length > 1; return unknowns.length > 1;
}, },
playlistDuration() { playlistDuration() {
if (!this.playlistEditor.entries) {
return 0
}
const totalDuration = this.playlistEditor.entries.reduce((acc, entry) => { const totalDuration = this.playlistEditor.entries.reduce((acc, entry) => {
const file = entry.file || {} const newDuration = entry.file
const {id} = file ? acc + this.getFileById(entry.file.id).duration
const savedFile = this.getFileById(id) || {}; : acc + entry.duration
if (Number.isNaN(acc + savedFile.duration)) { if (Number.isNaN(newDuration)) {
return acc; return acc
} }
return acc + savedFile.duration; return newDuration
}, 0); }, 0)
return this.prettyNanoseconds(totalDuration) return this.prettyNanoseconds(totalDuration)
}, },
...@@ -344,7 +346,7 @@ ...@@ -344,7 +346,7 @@
this.playlistEditor.durationField = false; this.playlistEditor.durationField = false;
this.playlistEditor.newDuration = ''; this.playlistEditor.newDuration = '';
Vue.delete(this.playlistEditor[entryIndex], 'duration'); Vue.delete(this.playlistEditor.entries[entryIndex], 'duration');
return; return;
} }
...@@ -359,7 +361,7 @@ ...@@ -359,7 +361,7 @@
} }
Vue.set(entry, 'duration', this.hmsToNanoseconds(duration)); Vue.set(entry, 'duration', this.hmsToNanoseconds(duration));
Vue.set(this.playlistEditor, entryIndex, entry); Vue.set(this.playlistEditor.entries, entryIndex, entry);
this.playlistEditor.durationField = false; this.playlistEditor.durationField = false;
this.playlistEditor.newDuration = ''; this.playlistEditor.newDuration = '';
...@@ -477,6 +479,7 @@ ...@@ -477,6 +479,7 @@
entry.file.id = playlist.entries[i].file.id entry.file.id = playlist.entries[i].file.id
} else { } else {
entry.uri = playlist.entries[i].uri entry.uri = playlist.entries[i].uri
entry.duration = playlist.entries[i].duration
} }
this.playlistEditor.entries.push(entry) this.playlistEditor.entries.push(entry)
} }
......
...@@ -465,8 +465,6 @@ export default { ...@@ -465,8 +465,6 @@ export default {
// submit a conflict-resolved schedule to steering // submit a conflict-resolved schedule to steering
resolveSubmit () { resolveSubmit () {
console.log("before", this.resolveData);
// TODO: check why steering retourns undefined and null values here // TODO: check why steering retourns undefined and null values here
if (this.resolveData.schedule.add_business_days_only === undefined) { this.resolveData.schedule.add_business_days_only = false } if (this.resolveData.schedule.add_business_days_only === undefined) { this.resolveData.schedule.add_business_days_only = false }
if (this.resolveData.schedule.add_days_no === null) { this.resolveData.schedule.add_days_no = 0 } if (this.resolveData.schedule.add_days_no === null) { this.resolveData.schedule.add_days_no = 0 }
...@@ -475,8 +473,6 @@ export default { ...@@ -475,8 +473,6 @@ export default {
if (this.resolveData.schedule.automation_id === null) { this.resolveData.schedule.automation_id = 0 } if (this.resolveData.schedule.automation_id === null) { this.resolveData.schedule.automation_id = 0 }
if (this.resolveData.schedule.byweekday === undefined) { this.resolveData.schedule.byweekday = 0 } if (this.resolveData.schedule.byweekday === undefined) { this.resolveData.schedule.byweekday = 0 }
console.log("after", this.resolveData);
// create the resolved schedule object including solutions // create the resolved schedule object including solutions
let resolvedSchedule = { let resolvedSchedule = {
schedule: this.resolveData.schedule, schedule: this.resolveData.schedule,
......
...@@ -293,8 +293,6 @@ export default { ...@@ -293,8 +293,6 @@ export default {
} }
}; };
console.log(newSchedule);
this.$store.dispatch('shows/submitSchedule', { this.$store.dispatch('shows/submitSchedule', {
showId: this.selectedShow.id, showId: this.selectedShow.id,
schedule: newSchedule, schedule: newSchedule,
...@@ -392,8 +390,6 @@ export default { ...@@ -392,8 +390,6 @@ export default {
}, },
getRepetitionParameters() { getRepetitionParameters() {
console.log(typeof this.repetitionRule);
if (this.repetitionRule == 1) { if (this.repetitionRule == 1) {
return { return {
onlyBusinessDays: false, onlyBusinessDays: false,
......
...@@ -30,14 +30,12 @@ ...@@ -30,14 +30,12 @@
This column displays the number of entries of the playlist. This column displays the number of entries of the playlist.
--> -->
<template v-slot:cell(entries)="data"> <template v-slot:cell(entries)="data">
{{ data.value.length }} items <span
<b-button
v-b-tooltip.html="playlistToolTip(data.value)" v-b-tooltip.html="playlistToolTip(data.value)"
variant="outline-success" class="tw-underline hover:tw-no-underline tw-cursor-help"
size="sm"
> >
show entries {{ data.value.length }} items
</b-button> </span>
</template> </template>
...@@ -48,7 +46,7 @@ ...@@ -48,7 +46,7 @@
<span <span
:class="{'is-mismatched': isMismatchedLength(data) }" :class="{'is-mismatched': isMismatchedLength(data) }"
> >
{{ playlistDuration(data) }} {{ prettyNanoseconds(playlistDuration(data)) }}
<abbr <abbr
v-if="isMismatchedLength(data)" v-if="isMismatchedLength(data)"
...@@ -124,6 +122,15 @@ export default { ...@@ -124,6 +122,15 @@ export default {
computed: { computed: {
loaded () { return this.$store.state.playlists.loaded.playlists }, loaded () { return this.$store.state.playlists.loaded.playlists },
timeslotDurationInNs() {
const mm = this.timeslotDuration % 60;
const hh = (this.timeslotDuration - mm) / 60;
return this.hmsToNanoseconds(
`${this.leadingZero(hh)}:${this.leadingZero(mm)}:00`
);
},
timeslotDuration() { timeslotDuration() {
const { start, end } = this.timeslot const { start, end } = this.timeslot
...@@ -199,20 +206,40 @@ export default { ...@@ -199,20 +206,40 @@ export default {
}, },
playlistDuration({ item }) { playlistDuration({ item }) {
const totalDuration = item.entries.reduce((acc, entry) => acc + entry.duration, 0); if (!item.entries) {
return this.prettyNanoseconds(totalDuration) return 0;
}, }
isMismatchedLength({ item }) { let delta = 0;
const totalDuration = this.calculatePlaylistDuration(item) const totalDuration = item.entries.reduce((acc, entry) => {
const durationInMinutes = this.nanosecondsToMinutes(totalDuration) const newDuration = acc + entry.duration;
if (Number.isNaN(newDuration)) {
return acc;
}
return this.timeslotDuration !== durationInMinutes return newDuration
}, 0);
const unknowns = item.entries.filter(entry => !entry.duration);
if (unknowns.length === 1) {
delta = this.timeslotDurationInNs - totalDuration;
}
return totalDuration + delta
}, },
calculatePlaylistDuration(item) { isMismatchedLength(playlist) {
return item.entries.reduce((acc, entry) => acc + entry.duration, 0) const totalDuration = this.playlistDuration(playlist);
} let delta = 0;
const unknowns = playlist.item.entries.filter(entry => !entry.duration);
if (unknowns.length === 1) {
delta = this.timeslotDurationInNs - totalDuration;
}
return this.timeslotDurationInNs !== totalDuration + delta;
},
} }
} }
</script> </script>
......
function leadingZero (num) {
if (num < 10) { return '0' + num }
else { return num.toString() }
}
var day = [ var day = [
'Sunday', 'Sunday',
'Monday', 'Monday',
...@@ -30,9 +25,14 @@ var month = [ ...@@ -30,9 +25,14 @@ var month = [
export default { export default {
methods: { methods: {
leadingZero (num) {
if (num < 10) { return '0' + num }
else { return num.toString() }
},
apiDate: function (date) { apiDate: function (date) {
var d = new Date(date) var d = new Date(date)
return d.getFullYear() + '-' + leadingZero(d.getMonth() + 1) + '-' + leadingZero(d.getDate()) return d.getFullYear() + '-' + this.leadingZero(d.getMonth() + 1) + '-' + this.leadingZero(d.getDate())
}, },
getWeekdayFromApiDate: function (date) { getWeekdayFromApiDate: function (date) {
let d = new Date(date) let d = new Date(date)
...@@ -45,7 +45,7 @@ export default { ...@@ -45,7 +45,7 @@ export default {
var d = new Date(date) var d = new Date(date)
var dstring = '' var dstring = ''
dstring += day[d.getDay()] + ', ' dstring += day[d.getDay()] + ', '
dstring += leadingZero(d.getDate()) + '. ' dstring += this.leadingZero(d.getDate()) + '. '
dstring += month[d.getMonth()] + ' ' dstring += month[d.getMonth()] + ' '
dstring += d.getFullYear() dstring += d.getFullYear()
return dstring return dstring
...@@ -55,14 +55,14 @@ export default { ...@@ -55,14 +55,14 @@ export default {
/* /*
// This is a simple numbered representation - have to decide which one to use in final design // This is a simple numbered representation - have to decide which one to use in final design
// note: Date.getMonth() returns the month as an index from 0 to 11 // note: Date.getMonth() returns the month as an index from 0 to 11
return leadingZero(d.getDate()) + '.' + leadingZero(d.getMonth() + 1) + '.' + d.getFullYear() + ' ' + leadingZero(d.getHours()) + ':' + leadingZero(d.getMinutes()) return this.leadingZero(d.getDate()) + '.' + this.leadingZero(d.getMonth() + 1) + '.' + d.getFullYear() + ' ' + this.leadingZero(d.getHours()) + ':' + this.leadingZero(d.getMinutes())
*/ */
var dstring = '' var dstring = ''
dstring += day[d.getDay()] + ', ' dstring += day[d.getDay()] + ', '
dstring += leadingZero(d.getDate()) + '. ' dstring += this.leadingZero(d.getDate()) + '. '
dstring += month[d.getMonth()] + ' ' dstring += month[d.getMonth()] + ' '
dstring += d.getFullYear() + ', ' dstring += d.getFullYear() + ', '
dstring += leadingZero(d.getHours()) + ':' + leadingZero(d.getMinutes()) + ':' + leadingZero(d.getSeconds()) dstring += this.leadingZero(d.getHours()) + ':' + this.leadingZero(d.getMinutes()) + ':' + this.leadingZero(d.getSeconds())
return dstring return dstring
}, },
prettyHours(hours) { prettyHours(hours) {
...@@ -84,7 +84,7 @@ export default { ...@@ -84,7 +84,7 @@ export default {
var hours = Math.floor(sec_total / 3600) var hours = Math.floor(sec_total / 3600)
var minutes = Math.floor((sec_total - (hours * 3600)) / 60) var minutes = Math.floor((sec_total - (hours * 3600)) / 60)
var seconds = Math.floor((sec_total - (hours * 3600) - (minutes * 60)) * 10) / 10 var seconds = Math.floor((sec_total - (hours * 3600) - (minutes * 60)) * 10) / 10
return leadingZero(hours) + ':' + leadingZero(minutes) + ':' + leadingZero(seconds.toFixed(0)) return this.leadingZero(hours) + ':' + this.leadingZero(minutes) + ':' + this.leadingZero(seconds.toFixed(0))
}, },
nanosecondsToMinutes: function(ns) { nanosecondsToMinutes: function(ns) {
return ns / 1000 / 1000 / 1000 / 60; return ns / 1000 / 1000 / 1000 / 60;
......
...@@ -200,7 +200,6 @@ const actions = { ...@@ -200,7 +200,6 @@ const actions = {
*/ */
let uri = process.env.VUE_APP_API_TANK + 'shows/' + data.show + '/files/' + data.file + '/upload' let uri = process.env.VUE_APP_API_TANK + 'shows/' + data.show + '/files/' + data.file + '/upload'
console.log(data);
axios.put(uri, data.uploadSourceFile, { axios.put(uri, data.uploadSourceFile, {
withCredentials: true, withCredentials: true,
headers: { headers: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment