aboutsummaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/configurationApp/src/actions
diff options
context:
space:
mode:
authorHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-04-03 17:12:30 +0200
committerHerbert Eiselt <herbert.eiselt@highstreet-technologies.com>2019-04-03 17:13:01 +0200
commit97fa6d943c57a784a52462aaacb329ce93cf42d6 (patch)
treeb5f0f2484c0a886fcade7b9bcf1d230e6f9e9501 /sdnr/wt/odlux/apps/configurationApp/src/actions
parent3d6dd098db8ec243ca716a09fc55decbdd23b726 (diff)
SDN-R odlux configuration
Add odlux configuration app Change-Id: Ifecd3f6e1e3060a1fd1008f1f625a70cb2475a8a Issue-ID: SDNC-584 Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/odlux/apps/configurationApp/src/actions')
-rw-r--r--sdnr/wt/odlux/apps/configurationApp/src/actions/configurationActions.ts137
1 files changed, 137 insertions, 0 deletions
diff --git a/sdnr/wt/odlux/apps/configurationApp/src/actions/configurationActions.ts b/sdnr/wt/odlux/apps/configurationApp/src/actions/configurationActions.ts
new file mode 100644
index 000000000..82055a761
--- /dev/null
+++ b/sdnr/wt/odlux/apps/configurationApp/src/actions/configurationActions.ts
@@ -0,0 +1,137 @@
+import { Action } from '../../../../framework/src/flux/action';
+import { Dispatch } from '../../../../framework/src/flux/store';
+
+import { CoreModelNetworkElement, LpResponse } from '../models/coreModel';
+import configurationService, { getValueByName } from '../services/configurationService';
+import { ViewSpecification } from 'models/uiModels';
+import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
+import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
+
+export class ConfigurationApplicationBaseAction extends Action { }
+
+export class UpdateLoading extends ConfigurationApplicationBaseAction {
+ constructor (public loading: boolean) {
+ super();
+
+ }
+}
+
+export class UpdateCoreModel extends ConfigurationApplicationBaseAction {
+ constructor (public nodeId?: string, public coreModel?: CoreModelNetworkElement) {
+ super();
+
+ }
+}
+
+export class UpdateLp extends ConfigurationApplicationBaseAction {
+ constructor (public lpId?: string, public capability?: string, public conditionalPackage?: string, public viewSpecifications: ViewSpecification[] = []) {
+ super();
+
+ }
+}
+
+export class UpdateViewData extends ConfigurationApplicationBaseAction {
+ constructor (public viewId?: string, public indexValues: string = "", public viewData: {} = {}) {
+ super();
+
+ }
+}
+
+
+export const updateMountIdAsyncActionCreator = (nodeId: string | undefined) => async (dispatch: Dispatch) => {
+ if (!nodeId) {
+ dispatch(new UpdateCoreModel());
+ return;
+ }
+ dispatch(new UpdateLoading(true));
+ const coreModel = await configurationService.getCoreModelByNodeId(nodeId);
+ dispatch(new UpdateLoading(false));
+
+ return coreModel
+ ? dispatch(new UpdateCoreModel(nodeId, coreModel))
+ : dispatch(new UpdateCoreModel());
+}
+
+export const updateLpIdAsyncActionCreator = (lpId: string | undefined) => async (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
+ const { configuration: { coreModel: coreModel, nodeId: nodeId } } = getState();
+ if (! nodeId || !lpId || !coreModel) {
+ dispatch(new UpdateLp());
+ return;
+ }
+
+ // find the lp with its unique uuid
+ let lpData: LpResponse | null = null;
+ for (let ltp of coreModel.ltp) {
+ const lp = ltp.lp.find(pl => pl.uuid === lpId);
+ if (lp) {
+ lpData = lp;
+ break;
+ }
+ }
+
+ // urn:onf:params:xml:ns:yang:microwave-model?module=microwave-model => microwave-model
+ let capability: string | null = lpData && getValueByName("capability", lpData.extension, null);
+ if (capability) {
+ const paramIndex = capability.indexOf('?');
+ if (paramIndex > -1) {
+ capability = capability.slice(paramIndex+1);
+ }
+ const params = capability.split("&").map(p => (p || "=").split("="));
+ const capParam = params.find(p => p[0] === "module") || null;
+ capability = capParam && capParam[1] || null;
+ }
+
+ const revision: string | null = lpData && getValueByName("revision", lpData.extension, null);
+ const conditionalPackage: string | null = lpData && getValueByName("conditional-package", lpData.extension, null);
+
+ dispatch(new UpdateLoading(true));
+ const viewSpecifications = capability && await configurationService.getUIDescriptionByCapability(capability, revision) || [];
+ dispatch(new UpdateLoading(false));
+
+ return coreModel ?
+ dispatch(new UpdateLp(lpId, capability || undefined, conditionalPackage || undefined, viewSpecifications)) :
+ dispatch(new UpdateLp());
+}
+
+export const updateViewDataAsyncActionCreator = (viewId: string | undefined, indexValues: string[] = []) => async (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
+ const { configuration: { nodeId, lpId, capability, conditionalPackage, viewSpecifications } } = getState();
+ if (!viewId || !capability || !nodeId || !lpId || !conditionalPackage) {
+ dispatch(new AddSnackbarNotification({ message: `Error invalid parameter !${JSON.stringify({viewId ,capability ,nodeId ,lpId ,conditionalPackage}, null,2)}`, options: { variant: 'error' } }));
+ dispatch(new UpdateViewData());
+ return;
+ }
+
+ const viewSpecification = viewSpecifications.find(desc => desc.id === viewId);
+ if (!viewSpecification) {
+ dispatch(new AddSnackbarNotification({ message: `Error viewId ${viewId} not found !`, options: { variant: 'error' } }));
+ dispatch(new UpdateViewData());
+ return;
+ }
+
+ const url = viewSpecification.url.replace(/\$\$NODEID\$\$/g, nodeId).replace(/\$\$LPUUID\$\$/g, lpId);
+
+ dispatch(new UpdateLoading(true));
+ const data = capability && await configurationService.getViewData(url) || { };
+ dispatch(new UpdateLoading(false));
+
+ let viewData: { [path: string]: {} } = data;
+
+ const pathElements = viewSpecification.dataPath &&
+ viewSpecification.dataPath.replace(
+ /\/\$\$INDEX:(\d+):?([a-z\-]+)?\$\$/ig,
+ (_, indexStr, keyStr) => {
+ const index = +indexStr;
+ return indexValues[index] && '/' + indexValues[index] || '';
+ }).split("/") || [];
+
+ for (let path of pathElements) {
+ if (path === "") {
+ break;
+ }
+ viewData = viewData[path];
+ }
+
+ return viewData ?
+ dispatch(new UpdateViewData(viewId, indexValues.length > 0 ? indexValues.join("/") : "", viewData)) :
+ dispatch(new UpdateViewData());
+} \ No newline at end of file