wazuh-kibana-app/public/services/app-state.js

94 lines
3.2 KiB
JavaScript
Raw Normal View History

/*
* Wazuh app - App state service
* Copyright (C) 2018 Wazuh, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Find more information about this on the LICENSE file.
*/
2018-06-15 10:42:57 +00:00
import { uiModules } from 'ui/modules'
2018-06-15 10:42:57 +00:00
uiModules.get('app/wazuh', [])
.service('appState', function ($cookies, $window) {
2017-10-30 09:14:36 +00:00
return {
2018-06-07 16:13:10 +00:00
getExtensions: id => {
const current = $cookies.getObject('extensions');
return current ? current[id] : false;
2017-10-30 09:14:36 +00:00
},
2018-06-07 16:13:10 +00:00
setExtensions: (id,extensions) => {
const current = $cookies.getObject('extensions') || {};
current[id] = extensions;
2018-03-11 11:17:53 +00:00
const exp = new Date();
exp.setDate(exp.getDate() + 365);
2017-10-30 09:14:36 +00:00
if (extensions) {
2018-06-07 16:13:10 +00:00
$cookies.putObject('extensions', current, { 'expires': exp });
2017-10-30 09:14:36 +00:00
}
},
getClusterInfo: () => {
return $cookies.getObject('_clusterInfo');
},
2018-03-11 11:17:53 +00:00
removeClusterInfo: () => {
return $cookies.remove('_clusterInfo');
},
2017-11-13 11:49:22 +00:00
setClusterInfo: cluster_info => {
2018-03-11 11:17:53 +00:00
const exp = new Date();
exp.setDate(exp.getDate() + 365);
2017-10-30 09:14:36 +00:00
if (cluster_info) {
$cookies.putObject('_clusterInfo', cluster_info, { 'expires': exp });
2017-10-30 09:14:36 +00:00
}
},
getCurrentPattern: () => {
return $cookies.getObject('_currentPattern');
},
2018-03-11 11:17:53 +00:00
setCreatedAt: date => {
const exp = new Date();
exp.setDate(exp.getDate() + 365);
$cookies.putObject('_createdAt',date,{ 'expires': exp });
},
setCurrentPattern: newPattern => {
2018-03-11 11:17:53 +00:00
const exp = new Date();
exp.setDate(exp.getDate() + 365);
if (newPattern) {
$cookies.putObject('_currentPattern', newPattern, { 'expires': exp });
}
},
2018-03-11 11:17:53 +00:00
removeCurrentPattern: () => {
return $cookies.remove('_currentPattern');
},
getCreatedAt: () => {
return $cookies.getObject('_createdAt');
},
removeCreatedAt: () => {
return $cookies.remove('_createdAt');
},
getCurrentAPI: () => {
return $cookies.getObject('API');
},
removeCurrentAPI: () => {
return $cookies.remove('API');
},
setCurrentAPI: API => {
2018-03-11 11:17:53 +00:00
const exp = new Date();
exp.setDate(exp.getDate() + 365);
if (API) {
$cookies.putObject('API', API, { 'expires': exp});
}
2018-01-25 12:44:01 +00:00
},
getPatternSelector: () => {
return $cookies.getObject('patternSelector');
},
setPatternSelector: value => {
$cookies.putObject('patternSelector', value);
},
setCurrentDevTools: current => {
$window.localStorage.setItem('currentDevTools',current);
},
getCurrentDevTools: () => {
return $window.localStorage.getItem('currentDevTools')
2017-10-30 09:14:36 +00:00
}
};
});