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