Web Client context menu item display
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / connectApp / src / actions / commonNetworkElementsActions.ts
1
2 /**
3  * ============LICENSE_START========================================================================
4  * ONAP : ccsdk feature sdnr wt odlux
5  * =================================================================================================
6  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
7  * =================================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  * ============LICENSE_END==========================================================================
18  */
19
20 /**
21  * Create an update action that can distinguish whether one or the other view is currently active and update it.
22  * This action is then used for each update in the other actions and when notifications arrive.
23  * create an update action that can distinguish whether one or the other view is currently active and update it.
24  * This action is then used for each update in the other actions and when notifications arrive.
25  */
26
27 import { Action } from '../../../../framework/src/flux/action';
28 import { Dispatch } from '../../../../framework/src/flux/store';
29 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
30
31 import { connectionStatusLogReloadAction } from '../handlers/connectionStatusLogHandler';
32 import { networkElementsReloadAction } from '../handlers/networkElementsHandler';
33 import { guiCutThrough } from '../models/guiCutTrough';
34 import { PanelId } from '../models/panelId';
35 import { connectService } from '../services/connectService';
36
37
38 export class SetPanelAction extends Action {
39   constructor(public panelId: PanelId) {
40     super();
41   }
42 }
43
44 export class AddWebUriList extends Action {
45   constructor(public searchedElements: guiCutThrough[], public notSearchedElements: string[], public unsupportedElements: string[], public newlySearchedElements?: string[]) {
46     super();
47   }
48 }
49
50 export class RemoveWebUri extends Action {
51   constructor(public element: string) {
52     super();
53   }
54 }
55
56 export const removeWebUriAction = (nodeId: string) => {
57   return new RemoveWebUri(nodeId);
58 };
59
60 export class SetWeburiSearchBusy extends Action {
61   constructor(public isbusy: boolean) {
62     super();
63   }
64 }
65
66 let isBusy = false;
67 export const findWebUrisForGuiCutThroughAsyncAction = (networkElementIds: string[]) => async (dispatcher: Dispatch, getState: () => IApplicationStoreState) => {
68
69   // keep method from executing simultanously; state not used because change of iu isn't needed
70
71   if (isBusy)
72     return;
73   isBusy = true;
74
75   const { connect: { guiCutThrough: guiCutThrough2, networkElements } } = getState();
76
77   let notConnectedElements: string[] = [];
78   let elementsToSearch: string[] = [];
79   let prevFoundElements: string[] = [];
80   let unsupportedElements: string[] = [];
81
82   networkElementIds.forEach(id => {
83     const item = networkElements.rows.find((ne) => ne.id === id);
84     if (item) {
85       if (item.status) {
86
87         // if (item.coreModelCapability !== "Unsupported") {
88         // element is connected and is added to search list, if it doesn't exist already
89         const exists = guiCutThrough2.searchedElements.filter(element => element.id === id).length > 0;
90         if (!exists) {
91           elementsToSearch.push(id);
92
93           //element was found previously, but wasn't connected
94           if (guiCutThrough2.notSearchedElements.length > 0 && guiCutThrough2.notSearchedElements.includes(id)) {
95             prevFoundElements.push(id);
96           }
97         }
98         // } else {
99         //   // element does not support core model and must not be searched for a weburi  
100         //   const id = item.id as string;
101         //   const exists = guiCutThrough.unsupportedElements.filter(element => element === id).length > 0;
102         //   if (!exists) {
103         //     unsupportedElements.push(id);
104
105         //     //element was found previously, but wasn't connected
106         //     if (guiCutThrough.notSearchedElements.length > 0 && guiCutThrough.notSearchedElements.includes(id)) {
107         //       prevFoundElements.push(id);
108         //     }
109         //   }
110         // }
111       } else {
112         // element isn't connected and cannot be searched for a weburi
113         if (!guiCutThrough2.notSearchedElements.includes(id)) {
114           notConnectedElements.push(item.id as string);
115         }
116       }
117     }
118   });
119
120
121   if (elementsToSearch.length > 0 || unsupportedElements.length > 0) {
122     const result = await connectService.getAllWebUriExtensionsForNetworkElementListAsync(elementsToSearch);
123     dispatcher(new AddWebUriList(result, notConnectedElements, unsupportedElements, prevFoundElements));
124   }
125   isBusy = false;
126
127 };
128
129 export const setPanelAction = (panelId: PanelId) => {
130   return new SetPanelAction(panelId);
131 };
132
133 export const updateCurrentViewAsyncAction = () => (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
134   const { connect: { currentOpenPanel } } = getState();
135   if (currentOpenPanel === 'NetworkElements') {
136     return dispatch(networkElementsReloadAction);
137   } else {
138     return dispatch(connectionStatusLogReloadAction);
139   }
140 };
141