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,
|
'statusAgent' => AGENT_STATUS_ALL,
|
||||||
'searchModule' => '',
|
'searchModule' => '',
|
||||||
'statusModule' => -1,
|
'statusModule' => -1,
|
||||||
|
'groupID' => 0,
|
||||||
|
'tagID' => 0,
|
||||||
);
|
);
|
||||||
$filter = get_parameter('filter', $default_filters);
|
$filter = get_parameter('filter', $default_filters);
|
||||||
|
|
||||||
|
|
|
@ -480,6 +480,12 @@ class Tree {
|
||||||
if ($this->strictACL)
|
if ($this->strictACL)
|
||||||
return false;
|
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';
|
$columns = 'tt.id_tag AS id, tt.name AS name';
|
||||||
$order_fields = 'tt.name ASC, tt.id_tag ASC';
|
$order_fields = 'tt.name ASC, tt.id_tag ASC';
|
||||||
|
|
||||||
|
@ -500,6 +506,7 @@ class Tree {
|
||||||
$group_acl
|
$group_acl
|
||||||
$agent_search_filter
|
$agent_search_filter
|
||||||
$agent_status_filter
|
$agent_status_filter
|
||||||
|
$tag_filter
|
||||||
GROUP BY tt.id_tag
|
GROUP BY tt.id_tag
|
||||||
ORDER BY $order_fields";
|
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() {
|
public function getData() {
|
||||||
|
|
||||||
if (! $this->strictACL) {
|
if (! $this->strictACL) {
|
||||||
|
@ -1565,6 +1594,16 @@ class Tree {
|
||||||
// array_filter clean the empty elements
|
// array_filter clean the empty elements
|
||||||
$processed_items = array_filter($processed_items_tmp);
|
$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 {
|
else {
|
||||||
$unmerged_items = array();
|
$unmerged_items = array();
|
||||||
|
@ -1597,6 +1636,20 @@ class Tree {
|
||||||
|
|
||||||
$processed_items = $this->getMergedItems($unmerged_items);
|
$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
|
// Agents
|
||||||
else {
|
else {
|
||||||
|
@ -1686,6 +1739,15 @@ class Tree {
|
||||||
|
|
||||||
$processed_items = $this->getMergedItems($item_list);
|
$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
|
// Agents
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -306,7 +306,7 @@ TreeController = {
|
||||||
+'images/groups_small/'+element.icon+'" /> ');
|
+'images/groups_small/'+element.icon+'" /> ');
|
||||||
}
|
}
|
||||||
else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) {
|
else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) {
|
||||||
$content.append(element.iconHTML);
|
$content.append(element.iconHTML + " ");
|
||||||
}
|
}
|
||||||
$content.append(element.name);
|
$content.append(element.name);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -22,6 +22,8 @@ $search_agent = get_parameter('searchAgent', '');
|
||||||
$status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL);
|
$status_agent = get_parameter('statusAgent', AGENT_STATUS_ALL);
|
||||||
$search_module = get_parameter('searchModule', '');
|
$search_module = get_parameter('searchModule', '');
|
||||||
$status_module = get_parameter('statusModule', -1);
|
$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']);
|
$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'));
|
ui_toggle($form_html, __('Tree search'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html_print_input_hidden("group-id", $group_id);
|
||||||
|
html_print_input_hidden("tag-id", $tag_id);
|
||||||
|
|
||||||
// --------------------- form filter -----------------------------------
|
// --------------------- form filter -----------------------------------
|
||||||
|
|
||||||
ui_include_time_picker();
|
ui_include_time_picker();
|
||||||
|
@ -263,6 +269,8 @@ enterprise_hook('close_meta_frame');
|
||||||
parameters['filter']['statusAgent'] = $("select#status_agent").val();
|
parameters['filter']['statusAgent'] = $("select#status_agent").val();
|
||||||
parameters['filter']['searchModule'] = $("input#text-search_module").val();
|
parameters['filter']['searchModule'] = $("input#text-search_module").val();
|
||||||
parameters['filter']['statusModule'] = $("select#status_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({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
|
Loading…
Reference in New Issue