(graphString)
| 16 | * @return {{}} 画布操纵器对象. |
| 17 | */ |
| 18 | const graphOperator = (graphString) => { |
| 19 | const self = {}; |
| 20 | const graph = JSON.parse(graphString); |
| 21 | const shapes = graph.pages[0].shapes; |
| 22 | |
| 23 | /** |
| 24 | * 获取配置信息. |
| 25 | * |
| 26 | * @param keys 键值数组. |
| 27 | * @return {{}|*|null} 配置信息. |
| 28 | */ |
| 29 | self.getConfig = (keys) => { |
| 30 | const config = getConfigByKeys(keys); |
| 31 | return config ? configToStruct(config) : null; |
| 32 | }; |
| 33 | |
| 34 | const getInputParams = (shape) => { |
| 35 | if (shape.type === 'startNodeStart') { |
| 36 | return shape.flowMeta.inputParams; |
| 37 | } else if (shape.type === 'endNodeEnd') { |
| 38 | return shape.flowMeta.callback.converter.entity.inputParams; |
| 39 | } else { |
| 40 | return shape.flowMeta.jober.converter.entity.inputParams; |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | const getConfigByKeys = (keys) => { |
| 45 | if (!Array.isArray(keys)) { |
| 46 | throw new Error('Expected keys to be an array'); |
| 47 | } |
| 48 | |
| 49 | if (keys.length === 0) { |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | const tmpKeys = [...keys]; |
| 54 | const shapeId = tmpKeys.shift(); |
| 55 | const shape = getShapeById(shapeId); |
| 56 | const inputParams = getInputParams(shape); |
| 57 | if (!inputParams) { |
| 58 | throw new Error('Expected inputParams exists'); |
| 59 | } |
| 60 | let config = {type: DATA_TYPES.OBJECT, value: inputParams}; |
| 61 | while (tmpKeys.length > 0 && config && config.value) { |
| 62 | const key = tmpKeys.shift(); |
| 63 | config = config.value.find(v => v.name === key); |
| 64 | } |
| 65 | return config; |
| 66 | }; |
| 67 | |
| 68 | const getShapeById = (shapeId) => { |
| 69 | return shapes.find((shape) => shape.id === shapeId); |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * 修改配置. |
| 74 | * |
| 75 | * @param keys 键值数组. |
no test coverage detected