Skip to content

Commit

Permalink
fix: ability to create element for templates with no fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkpunkd committed Nov 6, 2019
1 parent 0e3aff2 commit b10f7b0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rundown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class Rundown implements VRundown {
await this.mse.checkConnection()
let template = await this.pep.getJS(`/storage/shows/{${this.show}}/mastertemplates/${templateName}`)
let flatTemplate = await flattenEntry(template.js as AtomEntry)
if (Object.keys(flatTemplate).length === 1) {
flatTemplate = flatTemplate[Object.keys(flatTemplate)[0]] as FlatEntry
}
return flatTemplate as VTemplate
}

Expand All @@ -75,7 +78,8 @@ export class Rundown implements VRundown {
}
let template = await this.getTemplate(nameOrID)
// console.dir((template[nameOrID] as any).model_xml.model.schema[0].fielddef, { depth: 10 })
let fieldNames: string[] = (template[nameOrID] as any).model_xml.model.schema[0].fielddef.map((x: any): string => x.$.name)
let fielddef = (template as any).model_xml.model.schema[0].fielddef
let fieldNames: string[] = fielddef ? fielddef.map((x: any): string => x.$.name) : []
let entries = ''
let data: { [ name: string ]: string} = {}
if (Array.isArray(aliasOrTextFields)) {
Expand Down
50 changes: 50 additions & 0 deletions src/scratch/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { createMSE } from '../mse'
import * as yargs from 'yargs'

let args = yargs
.string('host')
.number('port')
.string('profile')
.string('showID')
.string('template')
.boolean('delete')
.number('timing')
.string('httphost')
.number('httpport')
.default('host', 'localhost')
.default('port', 8595)
.default('profile', 'SOFIE')
.default('showID', '66E45216-9476-4BDC-9556-C3DB487ED9DF')
.default('template', 'bund')
.default('delete', true)
.default('timing', 10000)
.default('httphost', '')
.default('httpport', 8580)
.argv

async function wait (t: number) {
return new Promise((resolve, _reject) => {
setTimeout(resolve, t)
})
}

async function run () {
let mse = createMSE(args.host, args.httpport, args.port, args.httphost.length > 0 ? args.httphost : undefined)
let rundown = await mse.createRundown(args.showID, args.profile)
let d = new Date()
let elementName = `CLI_TEST_${d.toISOString()}`
let element = await rundown.createElement(args.template, elementName, args._ ? args._ : [])
console.dir(element, { depth: 20 })
await rundown.cue(elementName)
await rundown.take(elementName)
await wait(args.timing)
console.log(`Taking element ${elementName} out.`)
await rundown.out(elementName)
if (args['delete']) {
rundown.deleteElement(elementName)
await mse.deleteRundown(rundown)
}
await mse.close()
}

run().catch(console.error)

0 comments on commit b10f7b0

Please sign in to comment.