Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / connectApp / src / actions / mountedNetworkElementsActions.ts
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import { Action } from '../../../../framework/src/flux/action';
20 import { Dispatch } from '../../../../framework/src/flux/store';
21
22 import { connectService } from '../services/connectService';
23 import { NetworkElementConnection } from '../models/networkElementConnection';
24 import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
25 import { updateCurrentViewAsyncAction } from './commonNetworkElementsActions';
26
27 /** Represents the base action. */
28 export class BaseAction extends Action { }
29
30 /** Represents an action creator for a async thunk action to mount a network element/node. */
31 export const mountNetworkElementAsyncActionCreator = (networkElement: NetworkElementConnection) => (dispatch: Dispatch) => {
32   return connectService.mountNetworkElement(networkElement).then((success) => {
33     if (success) {
34       dispatch(updateCurrentViewAsyncAction());
35       dispatch(new AddSnackbarNotification({ message: `Requesting mount [${networkElement.nodeId}]`, options: { variant: 'info' } }));
36     } else {
37       dispatch(new AddSnackbarNotification({ message: `Failed to mount [${networkElement.nodeId}]`, options: { variant: 'warning' } }));
38     }
39   }).catch(error => {
40     dispatch(new AddSnackbarNotification({ message: `Failed to mount [${networkElement.nodeId}]`, options: { variant: 'error' } }));
41     console.error(error);
42   });
43 };
44
45 /** Represents an action creator for a async thunk action to unmount a network element/node. */
46 export const unmountNetworkElementAsyncActionCreator = (nodeId: string) => (dispatch: Dispatch) => {
47   return connectService.unmountNetworkElement(nodeId).then((success) => {
48     if (success) {
49       dispatch(updateCurrentViewAsyncAction());
50       dispatch(new AddSnackbarNotification({ message: `Requesting unmount [${nodeId}]`, options: { variant: 'info' } }));
51     } else {
52       dispatch(new AddSnackbarNotification({ message: `Failed to unmount [${nodeId}]`, options: { variant: 'warning' } }));
53     }
54   }).catch(error => {
55     dispatch(new AddSnackbarNotification({ message: `Failed to unmount [${nodeId}]`, options: { variant: 'error' } }));
56     console.error(error);
57   });
58 };
59
60