diff options
author | 2024-03-20 15:55:54 +0100 | |
---|---|---|
committer | 2024-03-20 15:56:38 +0100 | |
commit | 5418ff6a08cd2482cf76aed8def6592623253229 (patch) | |
tree | 4887e64dd559f9c99f2627126b31d7f6459c34e1 /sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities | |
parent | c1a053e3bcaeb3006b822e98b80c564c330e2bf3 (diff) |
ODLUX Update
ODLUX Update
Issue-ID: CCSDK-3999
Change-Id: I6f95cd65cabe08b27a1ff71eacb7c57aa318c376
Signed-off-by: sai-neetha <sai-neetha.phulmali@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities')
-rw-r--r-- | sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities/viewEngineHelper.ts | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities/viewEngineHelper.ts b/sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities/viewEngineHelper.ts index ad34c83b9..9a1793671 100644 --- a/sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities/viewEngineHelper.ts +++ b/sdnr/wt-odlux/odlux/apps/configurationApp/src/utilities/viewEngineHelper.ts @@ -10,6 +10,7 @@ import { isViewElementRpc, isViewElementChoice, ViewElementChoiceCase, + isViewElementObject, } from '../models/uiModels'; import { Module } from '../models/yang'; @@ -47,13 +48,13 @@ export const resolveVPath = (current: string, vPath: string): string => { return parts.join('/'); }; -export const splitVPath = (vPath: string, vPathParser : RegExp): [string, string?][] => { - const pathParts: [string, string?][] = []; +export const splitVPath = (vPath: string, vPathParser : RegExp): [string, (string | undefined | null)][] => { + const pathParts: [string, (string | undefined | null)][] = []; let partMatch: RegExpExecArray | null; if (vPath) do { partMatch = vPathParser.exec(vPath); if (partMatch) { - pathParts.push([partMatch[1], partMatch[2] || undefined]); + pathParts.push([partMatch[1], partMatch[2] || (partMatch[0].includes('[]') ? null : undefined)]); } } while (partMatch); return pathParts; @@ -321,4 +322,30 @@ export const filterViewElements = async (vPath: string, viewData: any, viewSpeci } return acc; }, Promise.resolve({ ...viewSpecification, elements: {} as { [key: string]: ViewElement } })); -};
\ No newline at end of file +}; + +export const createViewData = (namespace: string | null, viewSpecification: ViewSpecification, views: ViewSpecification[]) => Object.keys(viewSpecification.elements).reduce<{ [name: string]: any }>((acc, cur) => { + const elm = viewSpecification.elements[cur]; + let currentNamespace = namespace; + const key = elm.id; + if (elm.default) { + acc[key] = elm.default || ''; + } else if (elm.uiType === 'boolean') { + acc[key] = false; + } else if (elm.uiType === 'number') { + acc[key] = 0; + } else if (elm.uiType === 'string') { + acc[key] = ''; + } else if (isViewElementObject(elm)) { + const view = views[+elm.viewId]; + if (view) { + if (view.ns) { + currentNamespace = view.ns; + } + acc[key] = createViewData(currentNamespace, view, views); + } + } else if (isViewElementList(elm)) { + acc[key] = []; + } + return acc; +}, {}); |