wazuh-kibana-app/public/controllers/groups.js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-10-30 09:08:42 +00:00
let app = require('ui/modules').get('app/wazuh', []);
const beautifier = require('plugins/wazuh/utils/json-beautifier');
2017-10-20 19:04:22 +00:00
// Groups preview controller
app.controller('groupsPreviewController', function ($scope, apiReq, Groups, GroupFiles, GroupAgents) {
2017-10-30 09:08:42 +00:00
$scope.searchTerm = '';
$scope.load = true;
$scope.groups = Groups;
$scope.groupAgents = GroupAgents;
2017-10-30 09:08:42 +00:00
$scope.groupFiles = GroupFiles;
2017-10-20 19:04:22 +00:00
// Actual execution in the controller's initialization
2017-10-30 09:08:42 +00:00
$scope.groups.nextPage('')
.then(() => $scope.loadGroup(0));
2017-10-20 19:04:22 +00:00
$scope.load = false;
2017-10-20 19:04:22 +00:00
2017-10-30 09:08:42 +00:00
$scope.showFiles = (index) => {
$scope.groupFiles.reset();
2017-10-30 09:08:42 +00:00
$scope.groupFiles.path = `/agents/groups/${$scope.groups.items[index].name}/files`;
$scope.groupFiles.nextPage('');
2017-10-30 09:08:42 +00:00
};
2017-10-20 19:04:22 +00:00
$scope.showAgents = (index) => {
$scope.groupAgents.reset();
2017-10-30 09:08:42 +00:00
$scope.groupAgents.path = `/agents/groups/${$scope.groups.items[index].name}`;
$scope.groupAgents.nextPage('')
.then(() => {
let promises = [];
for(let agent of $scope.groupAgents.items){
promises.push(apiReq.request('GET', `/agents/${agent.id}`, {}));
}
return Promise.all(promises);
})
.then((resolvedArray) => {
for(let data of resolvedArray){
console.log(data);
}
2017-10-20 19:04:22 +00:00
});
};
2017-10-20 19:04:22 +00:00
$scope.loadGroup = (index) => {
$scope.groupAgents.reset();
$scope.groupFiles.reset();
$scope.selectedGroup = index;
$scope.showFiles(index);
$scope.showAgents(index);
};
2017-10-20 19:04:22 +00:00
// Select specific group
$scope.checkSelected = (index) => {
for(let group of $scope.groups.items){
if (group.selected) {
group = false;
}
}
$scope.groups.items[index] = true;
};
2017-10-20 19:04:22 +00:00
$scope.showFile = (index) => {
$scope.test = !$scope.test;
$scope.file = 'Loading...';
let tmpName = `/agents/groups/${$scope.groups.items[$scope.selectedGroup].name}`+
`/files/${$scope.groupFiles.items[index].filename}`;
apiReq.request('GET', tmpName, {})
.then((data) => $scope.file = data.data);
};
2017-10-20 19:04:22 +00:00
// Changing the view to overview a specific group
$scope.groupOverview = (group) => {
$scope.$parent.$parent.groupName = group;
2017-10-30 09:08:42 +00:00
$scope.$parent.$parent.groupsMenu = 'overview';
};
// Resetting the factory configuration
$scope.$on("$destroy", () => {
$scope.groups.reset();
$scope.groupsFiles.reset();
$scope.groupsAgents.reset();
});
2017-10-20 19:04:22 +00:00
});
app.controller('groupsController', function ($scope) {
2017-10-30 09:08:42 +00:00
$scope.groupsMenu = 'preview';
$scope.groupName = '';
});