Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / maintenanceApp / src / actions / maintenenceActions.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions */
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 import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
20 import { Action } from '../../../../framework/src/flux/action';
21 import { Dispatch } from '../../../../framework/src/flux/store';
22
23 import { maintenanceEntriesReloadAction } from '../handlers/maintenanceEntriesHandler';
24 import { MaintenanceEntry, spoofSymbol } from '../models/maintenanceEntryType';
25 import { maintenenceService } from '../services/maintenenceService';
26
27 export class BaseAction extends Action { }
28
29 export class LoadAllMainteneceEntriesAction extends BaseAction { }
30
31 export class AllMainteneceEntriesLoadedAction extends BaseAction {
32
33   constructor(public maintenenceEntries: MaintenanceEntry[] | null) {
34     super();
35
36   }
37 }
38
39
40 export class UpdateMaintenanceEntry extends BaseAction {
41   constructor(public maintenenceEntry: MaintenanceEntry) {
42     super();
43   }
44 }
45
46 /** Represents an async thunk action creator to add an element to the maintenence entries. */
47 export const addOrUpdateMaintenenceEntryAsyncActionCreator = (entry: MaintenanceEntry) => (dispatch: Dispatch) => {
48   maintenenceService.writeMaintenenceEntry(entry).then(result => {
49     result && window.setTimeout(() => {
50       // dispatch(loadAllMountedNetworkElementsAsync);
51       dispatch(new UpdateMaintenanceEntry(entry));
52       dispatch(new AddSnackbarNotification({ message: `Successfully ${result && result.created ? 'created' : 'updated'} maintenance settings for [${entry.nodeId}]`, options: { variant: 'success' } }));
53     }, 900);
54     dispatch(maintenanceEntriesReloadAction);
55   });
56 };
57
58 /** Represents an async thunk action creator to delete an element from the maintenence entries. */
59 export const removeFromMaintenenceEntrysAsyncActionCreator = (entry: MaintenanceEntry) => (dispatch: Dispatch) => {
60   maintenenceService.deleteMaintenenceEntry(entry).then(result => {
61     result && window.setTimeout(() => {
62       dispatch(new UpdateMaintenanceEntry({
63         [spoofSymbol]: true,
64         mId: entry.mId,
65         nodeId: entry.nodeId,
66         description: '',
67         start: '',
68         end: '',
69         active: false,
70       }));
71       dispatch(new AddSnackbarNotification({ message: `Successfully removed [${entry.nodeId}]`, options: { variant: 'success' } }));
72     }, 900);
73     dispatch(maintenanceEntriesReloadAction);
74   });
75 };
76
77 // Hint: since there is no notification of changed required network elements, this code is not aware of changes caused outiside of this browser.