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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 import { AddErrorInfoAction } from '../../../../framework/src/actions/errorActions';
20 import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions';
21 import { Action } from '../../../../framework/src/flux/action';
22 import { Dispatch } from '../../../../framework/src/flux/store';
24 import { InventoryTreeNode, InventoryType, TreeDemoItem } from '../models/inventory';
25 import { inventoryService } from '../services/inventoryService';
28 * Represents the base action.
30 export class BaseAction extends Action { }
32 export class SetBusyAction extends BaseAction {
33 constructor(public busy: boolean = true) {
39 export class SetSearchTextAction extends BaseAction {
40 constructor(public searchTerm: string = '') {
46 export class UpdateInventoryTreeAction extends BaseAction {
47 constructor(public rootNode: InventoryTreeNode) {
53 export class UpdateSelectedNodeAction extends BaseAction {
54 constructor(public selectedNode?: InventoryType) {
60 export class UpdateExpandedNodesAction extends BaseAction {
61 constructor(public expandedNodes?: TreeDemoItem[]) {
67 export const setSearchTermAction = (searchTerm: string) => (dispatch: Dispatch) =>{
68 dispatch(new SetSearchTextAction(searchTerm));
72 export const updateInventoryTreeAsyncAction = (mountId: string, searchTerm?: string) => async (dispatch: Dispatch) => {
73 dispatch(new SetBusyAction(true));
74 dispatch(new SetSearchTextAction(searchTerm));
76 const result = await inventoryService.getInventoryTree(mountId, searchTerm);
78 dispatch(new AddErrorInfoAction({ title: 'Error', message: `Could not load inventory tree for [${mountId}]. Please check you connection to the server and try later.` }));
79 dispatch(new NavigateToApplication('inventory'));
81 dispatch(new UpdateInventoryTreeAction(result));
84 throw new Error('Could not load inventory tree from server.');
86 dispatch(new SetBusyAction(false));
90 export const selectInventoryNodeAsyncAction = (nodeId: string) => async (dispatch: Dispatch) => {
91 dispatch(new SetBusyAction(true));
93 const result = await inventoryService.getInventoryEntry(nodeId);
94 if (!result) throw new Error('Could not load inventory tree from server.');
95 dispatch(new UpdateSelectedNodeAction(result));
97 throw new Error('Could not load inventory tree from server.');
99 dispatch(new SetBusyAction(false));