RIFT-14916: Code added but commented out for removing cat severity filter
[osm/UI.git] / skyquake / plugins / logging / src / loggingSource.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 let rw = require('utils/rw.js');
19 var API_SERVER = rw.getSearchParams(window.location).api_server;
20 var loggingActions = require('./loggingActions.js');
21 var Utils = require('utils/utils.js');
22 import $ from 'jquery';
23
24 function apiUrl(endpoint) {
25 return endpoint.replace(/\/$/,'') + '?api_server=' + API_SERVER;
26 }
27
28 export default {
29 /**
30 * Retrieve the logging configuration data from the Node API server
31 */
32 getLoggingConfig: function() {
33 //console.log("LoggingSource.getLoggingConfig called");
34 return {
35 remote: function(state) {
36 return new Promise(function(resolve, reject) {
37 //console.log("loggingSource.getLoggingConfig called");
38 $.ajax({
39 url: apiUrl('api/aggregate'),
40 type: 'GET',
41 beforeSend: Utils.addAuthorizationStub,
42 success: function(data) {
43 //console.log("LoggingSource.getLoggingConfig success call. data=", data);
44 resolve(data);
45 },
46 error: function(e) {
47 console.log("Error getting logging config details");
48 }
49 });
50 });
51 },
52 success: loggingActions.getLoggingConfigSuccess,
53 error: loggingActions.getLoggingConfigError
54 }
55 },
56 /**
57 * Update the logging configuration data on the server
58 * @param {object} state - Reference to parent store state
59 * @param {object} loggingConfig - logging configuration data
60 * @return {[type]} [description]
61 }
62 */
63 updateLoggingConfig: function () {
64 return {
65 remote: function(state, nulledCategories, loggingConfig) {
66 return new Promise(function(resolve, reject) {
67 let promises = [];
68 let remove = null;
69 // if(nulledCategories.length > 0) {
70 // remove = $.ajax({
71 // // url: apiUrl('api/config/default-severity'),
72 // url: apiUrl('api/config/default-syslog-severity/' + nulledCategories.join(',')),
73 // type: 'DELETE',
74 // beforeSend: Utils.addAuthorizationStub,
75 // success: function(data) {
76 // resolve(data);
77 // },
78 // error: function(error) {
79 // console.log("There was an error updating the logging config data",
80 // error);
81 // reject(error);
82 // }
83 // });
84 // promises.push(remove);
85 // }
86 Promise.all(promises).then(function(data) {
87 return $.ajax({
88 url: apiUrl('api/aggregate'),
89 type: 'PUT',
90 beforeSend: Utils.addAuthorizationStub,
91 data: loggingConfig,
92 success: function(data) {
93 resolve(data);
94 },
95 error: function(error) {
96 console.log("There was an error updating the logging config data",
97 error);
98 reject(error);
99 }
100 });
101 }).then(function(data){
102 resolve(data)
103 }, function(){
104 reject(arguments)
105 })
106
107 });
108
109 },
110 success: loggingActions.putLoggingConfigSuccess,
111 error: loggingActions.putLoggingConfigError
112 }
113 }
114 }