2018-04-22 20:16:38 +00:00
|
|
|
/*
|
|
|
|
* 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-09-11 09:52:54 +00:00
|
|
|
export class AppState {
|
2018-12-12 11:47:05 +00:00
|
|
|
/**
|
|
|
|
* Class constructor
|
|
|
|
* @param {*} $cookies
|
|
|
|
* @param {*} $window
|
|
|
|
*/
|
2018-09-10 08:32:49 +00:00
|
|
|
constructor($cookies, $window) {
|
|
|
|
this.$cookies = $cookies;
|
|
|
|
this.$window = $window;
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
//Extensions setters and getters
|
2018-10-01 07:05:15 +00:00
|
|
|
getExtensions(id) {
|
|
|
|
const current = this.$cookies.getObject('extensions');
|
|
|
|
return current ? current[id] : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setExtensions(id, extensions) {
|
|
|
|
const current = this.$cookies.getObject('extensions') || {};
|
|
|
|
current[id] = extensions;
|
|
|
|
const exp = new Date();
|
|
|
|
exp.setDate(exp.getDate() + 365);
|
|
|
|
if (extensions) {
|
|
|
|
this.$cookies.putObject('extensions', current, { expires: exp });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
|
|
|
|
//Cluster setters and getters
|
2018-09-10 08:32:49 +00:00
|
|
|
getClusterInfo() {
|
|
|
|
return this.$cookies.getObject('_clusterInfo');
|
|
|
|
}
|
|
|
|
|
|
|
|
removeClusterInfo() {
|
|
|
|
return this.$cookies.remove('_clusterInfo');
|
|
|
|
}
|
|
|
|
|
|
|
|
setClusterInfo(cluster_info) {
|
|
|
|
const exp = new Date();
|
|
|
|
exp.setDate(exp.getDate() + 365);
|
|
|
|
if (cluster_info) {
|
|
|
|
this.$cookies.putObject('_clusterInfo', cluster_info, { expires: exp });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
//CreatedAt setters and getters
|
2018-09-10 08:32:49 +00:00
|
|
|
|
|
|
|
setCreatedAt(date) {
|
|
|
|
const exp = new Date();
|
|
|
|
exp.setDate(exp.getDate() + 365);
|
|
|
|
this.$cookies.putObject('_createdAt', date, { expires: exp });
|
|
|
|
}
|
|
|
|
|
|
|
|
getCreatedAt() {
|
|
|
|
return this.$cookies.getObject('_createdAt');
|
|
|
|
}
|
|
|
|
|
|
|
|
removeCreatedAt() {
|
|
|
|
return this.$cookies.remove('_createdAt');
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
//Current api setters and getters
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
getCurrentAPI() {
|
|
|
|
return this.$cookies.getObject('API');
|
|
|
|
}
|
|
|
|
|
|
|
|
removeCurrentAPI() {
|
|
|
|
return this.$cookies.remove('API');
|
|
|
|
}
|
|
|
|
|
|
|
|
setCurrentAPI(API) {
|
|
|
|
const exp = new Date();
|
|
|
|
exp.setDate(exp.getDate() + 365);
|
|
|
|
if (API) {
|
|
|
|
this.$cookies.putObject('API', API, { expires: exp });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
//Patterns setters and getters
|
2018-09-10 08:32:49 +00:00
|
|
|
getPatternSelector() {
|
|
|
|
return this.$cookies.getObject('patternSelector');
|
|
|
|
}
|
|
|
|
|
|
|
|
setPatternSelector(value) {
|
|
|
|
this.$cookies.putObject('patternSelector', value);
|
|
|
|
}
|
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
setCurrentPattern(newPattern) {
|
|
|
|
const exp = new Date();
|
|
|
|
exp.setDate(exp.getDate() + 365);
|
|
|
|
if (newPattern) {
|
|
|
|
this.$cookies.putObject('_currentPattern', newPattern, { expires: exp });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentPattern() {
|
|
|
|
return this.$cookies.getObject('_currentPattern');
|
|
|
|
}
|
|
|
|
|
|
|
|
removeCurrentPattern() {
|
|
|
|
return this.$cookies.remove('_currentPattern');
|
|
|
|
}
|
|
|
|
|
|
|
|
//Dev tools setters and getters
|
|
|
|
|
2018-09-10 08:32:49 +00:00
|
|
|
setCurrentDevTools(current) {
|
|
|
|
this.$window.localStorage.setItem('currentDevTools', current);
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurrentDevTools() {
|
|
|
|
return this.$window.localStorage.getItem('currentDevTools');
|
|
|
|
}
|
2018-11-27 11:13:28 +00:00
|
|
|
|
2018-12-12 11:47:05 +00:00
|
|
|
//Session storage setters and getters
|
2018-11-27 11:13:28 +00:00
|
|
|
setSessionStorageItem(key, value) {
|
2018-11-27 16:47:54 +00:00
|
|
|
this.$window.sessionStorage.setItem(key, value);
|
2018-11-27 11:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getSessionStorageItem(key) {
|
2018-11-27 16:47:54 +00:00
|
|
|
return this.$window.sessionStorage.getItem(key);
|
2018-11-27 11:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
removeSessionStorageItem(key) {
|
2018-11-27 16:47:54 +00:00
|
|
|
this.$window.sessionStorage.removeItem(key);
|
2018-11-27 11:13:28 +00:00
|
|
|
}
|
2018-08-20 07:00:50 +00:00
|
|
|
}
|