wazuh-kibana-app/public/factories/share-agent.js

86 lines
1.6 KiB
JavaScript
Raw Normal View History

/*
2018-12-13 10:02:53 +00:00
* Wazuh app - Factory to share an agent between controllers
*
* 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 ShareAgent {
/**
* Class constructor
*/
2018-09-10 08:32:49 +00:00
constructor() {
this.agent = null;
2018-09-24 15:47:10 +00:00
this.selectedGroup = null;
this.targetLocation = null;
2018-09-10 08:32:49 +00:00
}
/**
* Get current agent
*/
2018-09-10 08:32:49 +00:00
getAgent() {
return this.agent;
}
2018-08-20 07:00:50 +00:00
/**
* Get selected group
*/
2018-09-24 15:47:10 +00:00
getSelectedGroup() {
2018-12-13 10:02:53 +00:00
if (
this.agent &&
this.agent.group &&
(this.selectedGroup || this.selectedGroup === 0)
) {
2018-11-05 13:36:01 +00:00
return this.agent.group[this.selectedGroup];
}
return null;
2018-09-24 15:47:10 +00:00
}
/**
* Set a given agent and group as current
2018-12-13 10:02:53 +00:00
* @param {*} ag
* @param {*} group
*/
2018-09-24 15:47:10 +00:00
setAgent(ag, group) {
2018-09-10 08:32:49 +00:00
this.agent = ag;
2018-09-24 15:47:10 +00:00
this.selectedGroup = group;
2018-09-10 08:32:49 +00:00
}
2018-08-20 07:00:50 +00:00
/**
* Delete current agent
*/
2018-09-10 08:32:49 +00:00
deleteAgent() {
this.agent = null;
2018-09-24 15:47:10 +00:00
this.selectedGroup = null;
2018-09-10 08:32:49 +00:00
}
/**
* Get Target location
*/
getTargetLocation() {
return this.targetLocation;
}
/**
* Set Target location
2018-12-13 10:02:53 +00:00
* @param {Object} loc
*/
setTargetLocation(loc) {
2018-11-02 17:23:00 +00:00
if (!loc || typeof loc !== 'object') return;
this.targetLocation = {};
Object.assign(this.targetLocation, loc);
}
/**
* Delete target location
*/
deleteTargetLocation() {
this.targetLocation = null;
}
2018-08-20 07:00:50 +00:00
}