Skip to content

Commit

Permalink
Start refactor and add variable support for item names (#50)
Browse files Browse the repository at this point in the history
* Update dependencies

Signed-off-by: Axel Boberg <[email protected]>

* Replace electron-packager with @electron/packager

Signed-off-by: Axel Boberg <[email protected]>

* Add a script for installing plugin dependencies regardless of OS

Signed-off-by: Axel Boberg <[email protected]>

* Use npm install rather than npm ci

Signed-off-by: Axel Boberg <[email protected]>

* Fix an issue causing the identity to not be set

Signed-off-by: Axel Boberg <[email protected]>

* Start tweaking UI to look more modern

Signed-off-by: Axel Boberg <[email protected]>

* Style tabs

Signed-off-by: Axel Boberg <[email protected]>

* Style the live switch of the caspar plugin

Signed-off-by: Axel Boberg <[email protected]>

* Update copy

Signed-off-by: Axel Boberg <[email protected]>

* Add a grid behind widgets in the edit mode

Signed-off-by: Axel Boberg <[email protected]>

* Tweak the border radius of popovers

Signed-off-by: Axel Boberg <[email protected]>

* Tweak the design of the inspector

Signed-off-by: Axel Boberg <[email protected]>

* Increase the opacity of the editing grid background

Signed-off-by: Axel Boberg <[email protected]>

* Add a border to the inspector form header

Signed-off-by: Axel Boberg <[email protected]>

* Set the correct flex-shrink modes for the main header and frame headers

Signed-off-by: Axel Boberg <[email protected]>

* Update screenshot

Signed-off-by: Axel Boberg <[email protected]>

* Update readme header

Signed-off-by: Axel Boberg <[email protected]>

* Add a link to releases

Signed-off-by: Axel Boberg <[email protected]>

* Delete screenshot

Signed-off-by: Axel Boberg <[email protected]>

* Add screenshot back

Signed-off-by: Axel Boberg <[email protected]>

* Fix typo

Signed-off-by: Axel Boberg <[email protected]>

* Template data
- Fix an issue causing the input to reset when selecting non-template-data items in the rundown
- Allow items' names to contain variables and give access to the template data

Signed-off-by: Axel Boberg <[email protected]>

* Add renderValue to the documentation

Signed-off-by: Axel Boberg <[email protected]>

* Start refactor by breaking apart the main index file

Signed-off-by: Axel Boberg <[email protected]>

* Move everything related to electron into its own directory

Signed-off-by: Axel Boberg <[email protected]>

* Move server initialization to its own file

Signed-off-by: Axel Boberg <[email protected]>

* Move the clean up logic to platform specific initializers

Signed-off-by: Axel Boberg <[email protected]>

* Update dependencies

Signed-off-by: Axel Boberg <[email protected]>

* Update the security section of the readme

Signed-off-by: Axel Boberg <[email protected]>

---------

Signed-off-by: Axel Boberg <[email protected]>
Signed-off-by: Axel Boberg <[email protected]>
Co-authored-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg and Axel Boberg authored Sep 30, 2024
1 parent a2e498a commit ebf5799
Show file tree
Hide file tree
Showing 20 changed files with 11,825 additions and 624 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ As developers of production software we found ourselves in a position of rebuild
- [ ] A fully customizable grid layout

## Download and install
Built packages are available on the releases page.
Built binaries are available on the releases page.

[Releases and downloads](https://github.com/svt/bridge/releases)

Expand All @@ -46,7 +46,9 @@ The full documentation is hosted in this repository under the [`docs`](/docs/REA
[Full documentation](/docs/README.md)

## Security
Always keep an eye open when interacting with third party code. As a general rule, **never run code you don't trust.** This includes third party plugins as they have a great amount of access when running on your computer or server.
We do our best to keep this software secure and its dependencies up-to-date.
Be careful when installing and running third party plugins.
Please see our security policy for instructions on how to report security issues.

## License

Expand Down
29 changes: 28 additions & 1 deletion api/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function deepClone (obj) {

/**
* Populate any variable placeholders
* in an item's properities - in place
* in an item's properties - in place
*
* @param { any } item
* @param { any } type
Expand Down Expand Up @@ -359,3 +359,30 @@ async function removeIssue (itemId, issueId) {
})
}
exports.removeIssue = removeIssue

/**
* Render a value for an item by its id,
* this will replace any variable placeholders
*
* @example
*
* Item {
* id: '1234',
* data: {
* name: '$(this.data.myValue)',
* myValue: 'Hello World'
* }
* }
*
* renderValue('1234', 'data.name') -> 'Hello World'
*
* @param { String } itemId The id of the item
* @param { String } path The path to the value to render
* @returns { Promise.<String | any | undefined> }
*/
async function renderValue (itemId, path) {
const item = await getItem(itemId)
const currentValue = objectPath.get(item || {}, path)
return variables.substituteInString(currentValue, undefined, { this: item })
}
exports.renderValue = renderValue
18 changes: 13 additions & 5 deletions api/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MIT

const objectPath = require('object-path')

const commands = require('./commands')
const state = require('./state')

Expand Down Expand Up @@ -44,12 +46,18 @@ exports.getAllVariables = getAllVariables
* "Hello $(my variable)" -> "Hello world"
*
* @param { String } str
* @param { any } data Data to substitute variables for,
* defaults to the local state
* @param { any } data Data to substitute variables for,
* defaults to the local state
* @param { any } overrideData Data that will override the
* default data rather than replace
* @returns { String }
*/
function substituteInString (str, data = (state.getLocalState()?.variables || {})) {
function substituteInString (str, data = (state.getLocalState()?.variables || {}), overrideData = {}) {
const text = str.split(VARIABLE_REGEX)
const values = {
...data,
...overrideData
}

let out = ''
let i = 0
Expand All @@ -58,8 +66,8 @@ function substituteInString (str, data = (state.getLocalState()?.variables || {}
if (i % 2 === 0) {
out += text.shift()
} else {
const variableName = text.shift()
const value = data[variableName]
const path = text.shift()
const value = objectPath.get(values, path)
out += value || ''
}
i++
Expand Down
5 changes: 4 additions & 1 deletion docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ Play an item and set its state to 'playing'.
Stop an item and set its state to 'stopped'.

### `bridge.items.applyIssue(itemId, issueId, issueSpec): Promise<Void>`
Add an issue to an item
Add an issue to an item.

**Example**
```javascript
Expand All @@ -358,6 +358,9 @@ Remove an issue from an item
bridge.items.removeIssue('6jI2', 'myIssue')
```

### `bridge.items.renderValue(itemId, path): Promise<String | any | undefined>`
Render a specific value for an item.

## Client
**The client api between the renerer and main processes**
Control aspects of clients
Expand Down
Loading

0 comments on commit ebf5799

Please sign in to comment.