Added the posibility to filter by 1 group or tag. Useful when accessing the tree view from the group view
This commit is contained in:
parent
e38f31caaa
commit
756cf4cbf7
|
@ -42,6 +42,8 @@ if (is_ajax ()) {
|
|||
'statusAgent' => AGENT_STATUS_ALL,
|
||||
'searchModule' => '',
|
||||
'statusModule' => -1,
|
||||
'groupID' => 0,
|
||||
'tagID' => 0,
|
||||
);
|
||||
$filter = get_parameter('filter', $default_filters);
|
||||
|
||||
|
|
|
@ -479,10 +479,16 @@ class Tree {
|
|||
if (empty($rootID) || $rootID == -1) {
|
||||
if ($this->strictACL)
|
||||
return false;
|
||||
|
||||
|
||||
// tagID filter. To access the view from tactical views f.e.
|
||||
$tag_filter = '';
|
||||
if (!empty($this->filter['tagID'])) {
|
||||
$tag_filter = "WHERE tt.id_tag = " . $this->filter['tagID'];
|
||||
}
|
||||
|
||||
$columns = 'tt.id_tag AS id, tt.name AS name';
|
||||
$order_fields = 'tt.name ASC, tt.id_tag ASC';
|
||||
|
||||
|
||||
// Tags SQL
|
||||
if ($item_for_count === false) {
|
||||
$sql = "SELECT $columns
|
||||
|
@ -500,6 +506,7 @@ class Tree {
|
|||
$group_acl
|
||||
$agent_search_filter
|
||||
$agent_status_filter
|
||||
$tag_filter
|
||||
GROUP BY tt.id_tag
|
||||
ORDER BY $order_fields";
|
||||
}
|
||||
|
@ -1450,6 +1457,28 @@ class Tree {
|
|||
}
|
||||
}
|
||||
|
||||
private static function extractItemWithID ($items, $item_id, $item_type = "group") {
|
||||
foreach ($items as $item) {
|
||||
if ($item["type"] != $item_type)
|
||||
continue;
|
||||
|
||||
// Item found
|
||||
if ($item["id"] == $item_id)
|
||||
return $item;
|
||||
|
||||
if ($item["type"] == "group" && !empty($item["children"])) {
|
||||
$result = self::extractItemWithID($item["children"], $item_id, $item_type);
|
||||
|
||||
// Item found on children
|
||||
if ($result !== false)
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Item not found
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getData() {
|
||||
|
||||
if (! $this->strictACL) {
|
||||
|
@ -1565,6 +1594,16 @@ class Tree {
|
|||
// array_filter clean the empty elements
|
||||
$processed_items = array_filter($processed_items_tmp);
|
||||
}
|
||||
|
||||
// groupID filter. To access the view from tactical views f.e.
|
||||
if (!empty($processed_items) && !empty($this->filter['groupID'])) {
|
||||
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group");
|
||||
|
||||
if ($result === false)
|
||||
$processed_items = array();
|
||||
else
|
||||
$processed_items = array($result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$unmerged_items = array();
|
||||
|
@ -1597,6 +1636,20 @@ class Tree {
|
|||
|
||||
$processed_items = $this->getMergedItems($unmerged_items);
|
||||
}
|
||||
|
||||
if (!empty($processed_items)) {
|
||||
if (!empty($this->filter["groupID"])) {
|
||||
$result = self::extractItemWithID($processed_items, $this->filter["groupID"], "group");
|
||||
}
|
||||
else if (!empty($this->filter["tagID"])) {
|
||||
$result = self::extractItemWithID($processed_items, $this->filter["tagID"], "tag");
|
||||
}
|
||||
|
||||
if ($result === false)
|
||||
$processed_items = array();
|
||||
else
|
||||
$processed_items = array($result);
|
||||
}
|
||||
}
|
||||
// Agents
|
||||
else {
|
||||
|
@ -1686,6 +1739,15 @@ class Tree {
|
|||
|
||||
$processed_items = $this->getMergedItems($item_list);
|
||||
}
|
||||
// groupID filter. To access the view from tactical views f.e.
|
||||
if (!empty($processed_items) && !empty($this->filter['groupID'])) {
|
||||
$result = self::extractItemWithID($processed_items, $this->filter['groupID'], "group");
|
||||
|
||||
if ($result === false)
|
||||
$processed_items = array();
|
||||
else
|
||||
$processed_items = array($result);
|
||||
}
|
||||
}
|
||||
// Agents
|
||||
else {
|
||||
|
|
|
@ -306,7 +306,7 @@ TreeController = {
|
|||
+'images/groups_small/'+element.icon+'" /> ');
|
||||
}
|
||||
else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) {
|
||||
$content.append(element.iconHTML);
|
||||
$content.append(element.iconHTML + " ");
|
||||
}
|
||||
$content.append(element.name);
|
||||
break;
|
||||
|
|
|
@ -22,6 +22,8 @@ $search_agent = get_parameter('searchAgent', '');
|
|||
$status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL);
|
||||
$search_module = get_parameter('searchModule', '');
|
||||
$status_module = get_parameter('statusModule', -1);
|
||||
$group_id = (int) get_parameter('group_id');
|
||||
$tag_id = (int) get_parameter('tag_id');
|
||||
|
||||
$strict_acl = (bool) db_get_value("strict_acl", "tusuario", "id_user", $config['id_user']);
|
||||
|
||||
|
@ -204,6 +206,10 @@ if (!$strict_acl) {
|
|||
ui_toggle($form_html, __('Tree search'));
|
||||
}
|
||||
}
|
||||
|
||||
html_print_input_hidden("group-id", $group_id);
|
||||
html_print_input_hidden("tag-id", $tag_id);
|
||||
|
||||
// --------------------- form filter -----------------------------------
|
||||
|
||||
ui_include_time_picker();
|
||||
|
@ -263,6 +269,8 @@ enterprise_hook('close_meta_frame');
|
|||
parameters['filter']['statusAgent'] = $("select#status_agent").val();
|
||||
parameters['filter']['searchModule'] = $("input#text-search_module").val();
|
||||
parameters['filter']['statusModule'] = $("select#status_module").val();
|
||||
parameters['filter']['groupID'] = $("input#hidden-group-id").val();
|
||||
parameters['filter']['tagID'] = $("input#hidden-tag-id").val();
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
|
|
Loading…
Reference in New Issue