2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 import {getTSUIElasticSearchQueryString} from 'app/networking/NetworkUtil.js';
27 import networkCall from 'app/networking/NetworkCalls.js';
32 } from 'app/networking/NetworkConstants.js';
35 globalAutoCompleteSearchBarActionTypes,
36 ERROR_INVALID_SEARCH_TERMS,
38 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
40 getSetGlobalMessageEvent,
41 getClearGlobalMessageEvent
42 } from 'app/GlobalInlineMessageBar/GlobalInlineMessageBarActions.js';
45 function createSuggestionFoundEvent({suggestions}) {
47 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
52 function createSuggestionNotFoundEvent() {
54 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND
58 function createSuggestionChangedEvent(value) {
60 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
65 function getInvalidQueryEvent(value) {
67 type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
68 data: {value: value, errorMsg: ERROR_RETRIEVING_DATA}
72 function getSearchBarWarningMessageEvent(message) {
74 type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
75 data: {errorMsg: message}
78 export function getInvalidSearchInputEvent(value) {
79 return getSearchBarWarningMessageEvent(
80 ERROR_INVALID_SEARCH_TERMS + ': ' + value);
84 function fetchView(selectedSuggestion) {
86 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
87 data: {selectedSuggestion: selectedSuggestion}
92 export function populateView(
93 searchRequestObject, keyWord, selectedNodeFetchRequest) {
94 if (selectedNodeFetchRequest === undefined) {
95 let postBody = JSON.stringify(searchRequestObject);
96 selectedNodeFetchRequest =
97 () => networkCall.fetchRequest('', POST,
98 POST_HEADER, postBody);
102 dispatch(fetchView(searchRequestObject));
107 export function fetchRequestedValues(fetchRequestCallback, keyWord) {
109 return fetchRequestCallback().then(
110 (responseJson) => responseJson.suggestions
112 (filteredResults)=> {
113 if (filteredResults.length > 0) {
114 dispatch(createSuggestionFoundEvent({suggestions: filteredResults}));
116 dispatch(createSuggestionNotFoundEvent());
121 dispatch(getInvalidQueryEvent(keyWord));
127 export function queryRequestedValues(keyWord, requestedFetchRequest) {
128 if (requestedFetchRequest === undefined) {
129 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(keyWord));
130 requestedFetchRequest =
131 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
135 dispatch(fetchRequestedValues(requestedFetchRequest, keyWord), keyWord);
139 export function clearSuggestionsTextField() {
142 {type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD});
146 export function onSuggestionsChange(event, value) {
148 dispatch(createSuggestionChangedEvent(value));
149 //Only fetch values if the enter key is used.
150 if (event.keyCode === 13) {
151 let postBody = JSON.stringify(getTSUIElasticSearchQueryString(value));
152 dispatch(fetchRequestedValues(
153 () => networkCall.fetchRequest(GLOBAL_SEARCH_URL, POST, POST_HEADER,
159 export function onSuggestionsClearRequested() {
161 dispatch({type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS});
165 export function setNotificationText(msgText, msgSeverity) {
166 if (msgText.length > 0) {
169 getSetGlobalMessageEvent(msgText, msgSeverity));
173 dispatch(getClearGlobalMessageEvent());