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

Fix metadata inheritance in scheduler and rundown #107

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
13 changes: 3 additions & 10 deletions frontend/src/containers/Calendar/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Calendar = ({
draggedAsset,
events,
saveEvent,
copyEvent,
contextMenu,
}) => {
const navigate = useNavigate()
Expand Down Expand Up @@ -290,16 +291,8 @@ const Calendar = ({
// handle control key for copying events
if (e.ctrlKey) {
console.log('Copying event', draggedEvent.current)
saveEvent({
id: null,
is_empty_event: true,
start: Math.floor(cursorTime.current.getTime() / 1000),
// TODO: copy metadata based on channel config
title: draggedEvent.current.title,
subtitle: draggedEvent.current.subtitle,
duration: draggedEvent.current.duration,
color: draggedEvent.current.color,
})
const newTs = Math.floor(cursorTime.current.getTime() / 1000)
copyEvent(draggedEvent.current.id, newTs)
} else {
saveEvent({
id: draggedEvent.current.id,
Expand Down
31 changes: 16 additions & 15 deletions frontend/src/containers/VideoPlayer/Trackbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ const Trackbar = ({
ctx.lineTo(markOutX, height - 1)
ctx.stroke()

// Draw the poster frame

if (auxMarks.poster_frame) {
const posterFrameX = (auxMarks.poster_frame / duration) * width
ctx.fillStyle = '#ff00ff'
ctx.beginPath()
ctx.moveTo(posterFrameX - 4, 0)
ctx.lineTo(posterFrameX + 4, 0)
ctx.lineTo(posterFrameX, 4)
ctx.closePath()
ctx.fill()
}

//
// Draw the handle
//
Expand All @@ -124,13 +111,27 @@ const Trackbar = ({
ctx.beginPath()
ctx.fillRect(progressX - 1, 0, handleWidth, height)
ctx.fill()
}, [currentTime, duration, markIn, markOut])

// Draw the poster frame

if (auxMarks.poster_frame) {
const posterFrameX =
(auxMarks.poster_frame / duration) * width + frameWidth / 2
ctx.fillStyle = '#ff00ff'
ctx.beginPath()
ctx.moveTo(posterFrameX - 4, 0)
ctx.lineTo(posterFrameX + 4, 0)
ctx.lineTo(posterFrameX, 4)
ctx.closePath()
ctx.fill()
}
}, [currentTime, duration, markIn, markOut, marks])

// Events

useEffect(() => {
drawSlider()
}, [currentTime, duration, markIn, markOut])
}, [currentTime, duration, markIn, markOut, marks])

// Dragging

Expand Down
9 changes: 7 additions & 2 deletions frontend/src/pages/AssetEditor/AssetEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nebula from '/src/nebula'

import { useNavigate } from 'react-router-dom'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { useEffect, useState, useMemo } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { toast } from 'react-toastify'
Expand Down Expand Up @@ -72,6 +72,7 @@ const AssetEditor = () => {
const [originalData, setOriginalData] = useState({})
const [loading, setLoading] = useState(false)
const [editorMode, setEditorMode] = useLocalStorage('editorMode', 'metadata')
const [searchParams, setSearchParams] = useSearchParams()

const showDialog = useDialog()

Expand All @@ -84,7 +85,11 @@ const AssetEditor = () => {
.then((response) => {
setAssetData(response.data.data[0] || {})
setOriginalData(response.data.data[0] || {})
navigate({ pathname: `/mam/editor`, search: `?asset=${id_asset}` })
//navigate({ pathname: `/mam/editor`, search: `?asset=${id_asset}` })
setSearchParams((o) => {
o.set('asset', id_asset)
return o
})
})
.catch((error) => {
toast.error(
Expand Down
109 changes: 90 additions & 19 deletions frontend/src/pages/Rundown/RundownTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,39 @@ const RundownTable = ({
.catch(() => {})
}

const onSetPrimary = async () => {
const id_asset = focusedObject.id_asset
const id_event = focusedObject.id_event
try {
const res = await nebula.request('get', {
object_type: 'asset',
ids: [id_asset],
})
console.log('Asset:', res.data.data)
if (!res.data?.data?.length) {
console.error('Asset not found:', id_asset)
return
}
const meta = res.data.data[0]
const emeta = {}
for (const field of channelConfig.fields) {
const key = field.name
emeta[key] = meta[key] || null
}
emeta.id_asset = id_asset
await nebula.request('set', {
object_type: 'event',
id: id_event,
data: emeta,
})

loadRundown()
} catch (err) {
onError(err)
return
}
}

const onSolve = (solver) => {
const items = data
.filter(
Expand All @@ -126,17 +159,28 @@ const RundownTable = ({
updateObject(object_type, id, { run_mode })
}

const editObject = (object_type, id) => {
const objectData = data.find(
(row) => row.id === id && row.type === object_type
)
if (!objectData) return // this should never happen
const editObject = async (object_type, id) => {
let objectData = {}
try {
const res = await nebula.request('get', {
object_type,
ids: [id],
})
objectData = res.data.data[0]
} catch (err) {
onError(err)
return
}

// Create a field list based on the object type

let fields
if (objectData.type === 'event') {
if (object_type === 'event') {
fields = [...channelConfig.fields]
} else if (objectData.item_role === 'placeholder') {
fields = [{ name: 'title' }, { name: 'duration' }]
} else if (['lead_in', 'lead_out'].includes(objectData.item_role)) {
return
} else if (objectData.id_asset) {
fields = [
{ name: 'title' },
Expand All @@ -145,24 +189,44 @@ const RundownTable = ({
{ name: 'mark_in' },
{ name: 'mark_out' },
]
} else if (['lead_in', 'lead_out'].includes(objectData.item_role)) {
return
} else {
return
}

const title = `Edit ${objectData.type}: ${objectData.title}`
// if the object is item with asset, we need to get the asset data

if (object_type === 'item' && objectData.id_asset) {
try {
const res = await nebula.request('get', {
object_type: 'asset',
ids: [objectData.id_asset],
})
const assetData = res.data.data[0]
for (const field of fields) {
const key = field.name
if (!objectData.key) objectData[key] = assetData[key]
}
} catch (err) {
onError(err)
return
}
}

// construct the form title and initial data

const title = `Edit ${object_type}: ${objectData.title}`
const initialData = {}
for (const field of fields) {
initialData[field.name] = objectData[field.name]
}

showDialog('metadata', title, { fields, initialData })
.then((newData) => {
updateObject(objectData.type, objectData.id, newData)
try {
const newData = await showDialog('metadata', title, {
fields,
initialData,
})
.catch(() => {})
updateObject(object_type, id, newData)
} catch {}
}

//
Expand Down Expand Up @@ -263,21 +327,26 @@ const RundownTable = ({
const res = []
if (selectedItems.length) {
if (selectedItems.length === 1) {
res.push(...getRunModeOptions('item', selectedItems[0], setRunMode))
res.push({
label: 'Edit item',
icon: 'edit',
separator: true,
onClick: () => editObject('item', selectedItems[0]),
})
}
if (focusedObject.id_asset) {
if (focusedObject.id_asset) {
res.push({
label: 'Set as primary',
icon: 'star',
onClick: onSetPrimary,
})
}

res.push({
label: 'Send to...',
icon: 'send',
onClick: onSendTo,
})
}

if (focusedObject.item_role === 'placeholder') {
for (const solver of channelConfig.solvers) {
res.push({
Expand All @@ -287,6 +356,9 @@ const RundownTable = ({
})
}
}

res.push(...getRunModeOptions('item', selectedItems[0], setRunMode))

res.push({
label: 'Delete',
icon: 'delete',
Expand All @@ -296,13 +368,12 @@ const RundownTable = ({
})
return res
} else if (selectedEvents.length === 1) {
res.push(...getRunModeOptions('event', selectedEvents[0], setRunMode))
res.push({
label: 'Edit event',
icon: 'edit',
separator: true,
onClick: () => editObject('event', selectedEvents[0]),
})
res.push(...getRunModeOptions('event', selectedEvents[0], setRunMode))
}
return res
}
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/pages/Rundown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const getRunModeOptions = (object_type, selection, func) => {
{
label: 'Run: Auto',
icon: 'play_arrow',
separator: true,
onClick: () => func('event', selection, 0),
},
{
Expand All @@ -29,17 +30,18 @@ const getRunModeOptions = (object_type, selection, func) => {
if (object_type === 'item') {
return [
{
label: 'Run: Auto',
label: 'Run auto',
icon: 'play_arrow',
separator: true,
onClick: () => func('item', selection, 0),
},
{
label: 'Run: Manual',
label: 'Manual',
icon: 'hand_gesture',
onClick: () => func('item', selection, 1),
},
{
label: 'Run: Skip',
label: 'Skip',
icon: 'skip_next',
onClick: () => func('item', selection, 4),
},
Expand Down
1 change: 0 additions & 1 deletion frontend/src/pages/Scheduler/ApplySchedulingTemplate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const ApplySchedulingTemplate = ({ loadEvents, date, loading, setLoading }) => {
if (b.name === channelConfig.default_template) return 1
return a.title.localeCompare(b.title)
})
console.log(templates)
setTemplates(templates)
})
}
Expand Down
Loading