11import { REGISTERED_WIDGETS } from "../register" ;
2- import { ComplexParserDict , parseWidget , ParserDict } from "./parser" ;
2+ import { ComplexParserDict , parseWidget , ParserDict , toArray } from "./parser" ;
33import {
44 XmlDescription ,
55 OPI_COMPLEX_PARSERS ,
66 OPI_SIMPLE_PARSERS ,
77 OPI_PATCHERS ,
88 opiParseRules ,
99 opiParsePvName ,
10- opiParseActions ,
1110 opiParseColor ,
1211 opiParseAlarmSensitive ,
1312 opiParseString ,
@@ -23,7 +22,12 @@ import {
2322} from "../../../types/position" ;
2423import { PV } from "../../../types/pv" ;
2524import { OpiFile , Rule } from "../../../types/props" ;
26- import { WidgetActions } from "../widgetActions" ;
25+ import {
26+ OPEN_TAB ,
27+ OPEN_WEBPAGE ,
28+ WidgetActions ,
29+ WRITE_PV
30+ } from "../widgetActions" ;
2731import { Font , FontStyle } from "../../../types/font" ;
2832import { Border , BorderStyle } from "../../../types/border" ;
2933import { Color } from "../../../types/color" ;
@@ -217,6 +221,92 @@ function bobParseSymbols(jsonProp: ElementCompact): string[] {
217221 } ) ;
218222 return symbols ;
219223}
224+ /**
225+ * Creates a WidgetActions object from the actions tied to the json object
226+ * @param jsonProp
227+ * @param defaultProtocol
228+ */
229+ export function bobParseActions (
230+ jsonProp : ElementCompact ,
231+ defaultProtocol : string
232+ ) : WidgetActions {
233+ const actionsToProcess = toArray ( jsonProp . action ) ;
234+
235+ // Extract information about whether to execute all actions at once
236+ const executeAsOne = jsonProp . _attributes ?. execute_as_one === "true" ;
237+
238+ // Turn into an array of Actions
239+ const processedActions : WidgetActions = {
240+ executeAsOne : executeAsOne ,
241+ actions : [ ]
242+ } ;
243+
244+ const actionToLocation = ( action : ElementCompact ) : string => {
245+ // Bob options "replace" and "tab" correspond to opening
246+ // in the main view, or in a new panel/tab
247+ const target = action . target . _text ;
248+ switch ( target ) {
249+ case "replace" :
250+ return "main" ;
251+ case "tab" :
252+ return "details" ;
253+ default :
254+ return "details" ;
255+ }
256+ } ;
257+
258+ actionsToProcess . forEach ( ( action ) : void => {
259+ log . debug ( action ) ;
260+ const type = action . _attributes ?. type ;
261+ try {
262+ if ( type === "write_pv" ) {
263+ processedActions . actions . push ( {
264+ type : WRITE_PV ,
265+ writePvInfo : {
266+ pvName : opiParsePvName (
267+ action . pv_name ,
268+ defaultProtocol
269+ ) . qualifiedName ( ) ,
270+ value : action . value . _text ,
271+ description :
272+ ( action . description && action . description . _text ) || undefined
273+ }
274+ } ) ;
275+ } else if ( type === "open_webpage" ) {
276+ processedActions . actions . push ( {
277+ type : OPEN_WEBPAGE ,
278+ openWebpageInfo : {
279+ url : action . url . _text ,
280+ description :
281+ ( action . description && action . description . _text ) || undefined
282+ }
283+ } ) ;
284+ } else if ( type === "open_display" ) {
285+ processedActions . actions . push ( {
286+ type : OPEN_TAB ,
287+ dynamicInfo : {
288+ name : action . file . _text ,
289+ location : actionToLocation ( action ) ,
290+ description :
291+ ( action . description && action . description . _text ) || undefined ,
292+ file : {
293+ path : action . file . _text ,
294+ // TODO: Should probably be accessing properties of the element here
295+ macros : { } ,
296+ defaultProtocol : "ca"
297+ }
298+ }
299+ } ) ;
300+ }
301+ } catch ( e : any ) {
302+ log . error (
303+ `Could not find action of type ${ type } in available actions to convert: ${ e . message } `
304+ ) ;
305+ }
306+ } ) ;
307+
308+ return processedActions ;
309+ }
220310
221311function bobGetTargetWidget ( props : any ) : React . FC {
222312 const typeid = bobParseType ( props ) ;
@@ -260,7 +350,7 @@ export function parseBob(
260350 actions : [
261351 "actions" ,
262352 ( actions : ElementCompact ) : WidgetActions =>
263- opiParseActions ( actions , defaultProtocol )
353+ bobParseActions ( actions , defaultProtocol )
264354 ] ,
265355 items : [ "items" , bobParseItems ] ,
266356 imageFile : [ "file" , opiParseString ] ,
0 commit comments