-
Notifications
You must be signed in to change notification settings - Fork 32
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
Allow array index on graph widget #1402
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,14 @@ VERTICAL | |
ARRAY <%= target_name %> HEALTH_STATUS ARY | ||
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[0] RAW | ||
LABELVALUE <%= target_name %> HEALTH_STATUS ARY[1] WITH_UNITS | ||
# This item is actually called BRACKET[0] as the name | ||
# thus we have to escape the value here to avoid it | ||
# being treated like an array item | ||
LABELVALUE <%= target_name %> HEALTH_STATUS BRACKET[[0]] | ||
LABELSPARKLINE <%= target_name %> HEALTH_STATUS ARY[1] | ||
SETTING HISTORY 60s | ||
LABELSPARKLINE <%= target_name %> HEALTH_STATUS BRACKET[[0]] | ||
SETTING HISTORY 60s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting all these case to work correctly was interesting |
||
ARRAY <%= target_name %> HEALTH_STATUS ARY 300 65 nil 8 FORMATTED | ||
ARRAY <%= target_name %> HEALTH_STATUS ARY2 300 65 nil 5 WITH_UNITS | ||
TEXTBOX <%= target_name %> HEALTH_STATUS ARY 200 65 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,11 +115,29 @@ export default { | |
} | ||
}) | ||
if (this.screen) { | ||
this.items.map((item) => | ||
this.items = this.items.map((item) => { | ||
let itemName = item.itemName | ||
// Remove double bracket escaping. This means they actually have an item | ||
// with a bracket in the name, not an array index. | ||
if (item.itemName.includes('[[')) { | ||
// Change the actual item and the the name we're passing to the screen | ||
item.itemName = item.itemName.replace('[[', '[').replace(']]', ']') | ||
itemName = item.itemName | ||
} else if (item.itemName.includes('[')) { | ||
// Brackets mean array indexes (normally, but see above) | ||
let match = item.itemName.match(/\[(\d+)\]/) | ||
this.arrayIndex = parseInt(match[1]) | ||
// Here we keep the original item name with the brackets but change | ||
// the item we're passing to the screen to the non-bracket item | ||
itemName = item.itemName.replace(match[0], '') | ||
} | ||
this.screen.addItem( | ||
`${item.targetName}__${item.packetName}__${item.itemName}__${item.valueType}`, | ||
), | ||
) | ||
`${item.targetName}__${item.packetName}__${itemName}__${item.valueType}`, | ||
true, | ||
) | ||
// Return the mapped values since we may have removed bracket escaping | ||
return item | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Key to getting this work was reassigning this.items to the mapped version which returns the escaped bracket names There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't support an array item with a real bracket in the name. That's probably ok. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're naming an array item with brackets then you're really asking for trouble! |
||
} | ||
}, | ||
destroyed() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's unusual to add items to the demo but it was the only way to really test it