wazuh-kibana-app/public/services/vis-factory-handler.js
2018-09-12 11:00:55 +02:00

79 lines
2.4 KiB
JavaScript

/*
* Wazuh app - Vis factory 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.
*/
export class VisFactoryService {
constructor(
$rootScope,
appState,
genericReq,
discoverPendingUpdates,
rawVisualizations,
tabVisualizations,
loadedVisualizations,
commonData,
visHandlers
) {
this.$rootScope = $rootScope;
this.appState = appState;
this.genericReq = genericReq;
this.discoverPendingUpdates = discoverPendingUpdates;
this.rawVisualizations = rawVisualizations;
this.tabVisualizations = tabVisualizations;
this.loadedVisualizations = loadedVisualizations;
this.commonData = commonData;
this.visHandlers = visHandlers;
}
clear(onlyAgent = false) {
if (!onlyAgent) this.visHandlers.removeAll();
this.discoverPendingUpdates.removeAll();
this.rawVisualizations.removeAll();
this.loadedVisualizations.removeAll();
}
clearAll() {
this.clear();
this.tabVisualizations.removeAll();
}
async buildOverviewVisualizations(filterHandler, tab, subtab, localChange) {
try {
const data = await this.genericReq.request(
'GET',
`/api/wazuh-elastic/create-vis/overview-${tab}/${this.appState.getCurrentPattern()}`
);
this.rawVisualizations.assignItems(data.data.raw);
this.commonData.assignFilters(filterHandler, tab, localChange);
this.$rootScope.$emit('changeTabView', { tabView: subtab });
this.$rootScope.$broadcast('updateVis');
return;
} catch (error) {
return Promise.reject(error);
}
}
async buildAgentsVisualizations(filterHandler, tab, subtab, localChange, id) {
try {
const data = await this.genericReq.request(
'GET',
`/api/wazuh-elastic/create-vis/agents-${tab}/${this.appState.getCurrentPattern()}`
);
this.rawVisualizations.assignItems(data.data.raw);
this.commonData.assignFilters(filterHandler, tab, localChange, id);
this.$rootScope.$emit('changeTabView', { tabView: subtab });
this.$rootScope.$broadcast('updateVis');
return;
} catch (error) {
return Promise.reject(error);
}
}
}