Merge branch 'feature/NewTreeView' of https://github.com/pandorafms/pandorafms into feature/NewTreeView
Conflicts resolved: pandora_console/include/javascript/tree/TreeController.js
This commit is contained in:
commit
530454ea72
|
@ -13,21 +13,23 @@
|
|||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
require_once("include/class/tree.class.php");
|
||||
require_once("include/class/Tree.class.php");
|
||||
|
||||
$get_data = (bool)get_parameter('get_data', 0);
|
||||
$getChildren = (bool)get_parameter('getChildren', 0);
|
||||
|
||||
if ($get_data) {
|
||||
$tab = get_parameter('type', 'group');
|
||||
$search = get_parameter('search', '');
|
||||
$status = (int)get_parameter('status', AGENT_STATUS_ALL);
|
||||
if ($getChildren) {
|
||||
$filter = get_parameter('filter',
|
||||
array('type' => 'groupz',
|
||||
'search' => '',
|
||||
'status' => AGENT_STATUS_ALL));
|
||||
$root = (int)get_parameter('root', 0);
|
||||
$method = get_parameter('method', 'on_demand');
|
||||
|
||||
$tree = new Tree($tab);
|
||||
$tree->set_filter(array(
|
||||
'status' => $status,
|
||||
'search' => $search));
|
||||
echo $tree->get_json();
|
||||
$tree = new Tree($filter['type'], $method, $root);
|
||||
$tree->setFilter(array(
|
||||
'status' => $filter['status'],
|
||||
'search' => $filter['search']));
|
||||
echo json_encode(array('success' => 1, 'tree' => $tree->getArray()));
|
||||
return;
|
||||
}
|
||||
?>
|
|
@ -18,57 +18,55 @@ class Tree {
|
|||
private $tree = array();
|
||||
private $filter = array();
|
||||
private $root = null;
|
||||
private $children = "on_demand";
|
||||
|
||||
public function __construct($type, $root = null) {
|
||||
public function __construct($type, $childrenMethod = "on_demand", $root = null) {
|
||||
$this->type = $type;
|
||||
$this->root = $root;
|
||||
$this->childrenMethod = $childrenMethod;
|
||||
}
|
||||
|
||||
public function set_type($type) {
|
||||
public function setType($type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function set_filter($filter) {
|
||||
public function setFilter($filter) {
|
||||
$this->filter = $filter;
|
||||
}
|
||||
|
||||
public function get_data() {
|
||||
public function getData() {
|
||||
switch ($this->type) {
|
||||
case 'os':
|
||||
$this->get_data_os();
|
||||
$this->getDataOS();
|
||||
break;
|
||||
case 'group':
|
||||
$this->get_data_group();
|
||||
$this->getDataGroup();
|
||||
break;
|
||||
case 'module_group':
|
||||
$this->get_data_module_group();
|
||||
$this->getDataModuleGroup();
|
||||
break;
|
||||
case 'module':
|
||||
$this->get_data_module();
|
||||
$this->getDataModule();
|
||||
break;
|
||||
case 'tag':
|
||||
$this->get_data_tag();
|
||||
$this->getDataTag();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_data_os() {
|
||||
public function getDataOS() {
|
||||
}
|
||||
|
||||
public function get_data_group() {
|
||||
private function getRecursiveGroup($parent, $limit = null) {
|
||||
$filter = array();
|
||||
|
||||
if (!empty($this->root)) {
|
||||
$filter['parent'] = $this->root;
|
||||
}
|
||||
else {
|
||||
$filter['parent'] = 0;
|
||||
}
|
||||
|
||||
$filter['parent'] = $parent;
|
||||
|
||||
if (!empty($this->filter['search'])) {
|
||||
$filter['nombre'] = "%" . $this->filter['search'] . "%";
|
||||
}
|
||||
|
||||
|
||||
// First filter by name and father
|
||||
$groups = db_get_all_rows_filter('tgrupo',
|
||||
$filter,
|
||||
|
@ -76,12 +74,15 @@ class Tree {
|
|||
if (empty($groups))
|
||||
$groups = array();
|
||||
|
||||
|
||||
// Filter by status
|
||||
$status = AGENT_STATUS_ALL;
|
||||
if (!empty($this->filter['status'])) {
|
||||
$status = $this->filter['status'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($status != AGENT_STATUS_ALL) {
|
||||
foreach ($groups as $iterator => $group) {
|
||||
$count_ok = groups_monitor_ok(
|
||||
|
@ -126,33 +127,97 @@ class Tree {
|
|||
|
||||
if ($remove_group)
|
||||
unset($groups[$iterator]);
|
||||
else {
|
||||
if (is_null($limit)) {
|
||||
$groups[$iterator]['children'] =
|
||||
$this->getRecursiveGroup($group['id_grupo']);
|
||||
}
|
||||
else if ($limit >= 1) {
|
||||
$groups[$iterator]['children'] =
|
||||
$this->getRecursiveGroup(
|
||||
$group['id_grupo'],
|
||||
($limit - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach ($groups as $iterator => $group) {
|
||||
if (is_null($limit)) {
|
||||
$groups[$iterator]['children'] =
|
||||
$this->getRecursiveGroup($group['id_grupo']);
|
||||
}
|
||||
else if ($limit >= 1) {
|
||||
$groups[$iterator]['children'] =
|
||||
$this->getRecursiveGroup(
|
||||
$group['id_grupo'],
|
||||
($limit - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $groups;
|
||||
}
|
||||
|
||||
public function getDataGroup() {
|
||||
|
||||
if (!empty($this->root)) {
|
||||
$parent = $this->root;
|
||||
}
|
||||
else {
|
||||
$parent = 0;
|
||||
}
|
||||
|
||||
switch ($this->childrenMethod) {
|
||||
case 'on_demand':
|
||||
$groups = $this->getRecursiveGroup($parent, 1);
|
||||
foreach ($groups as $iterator => $group) {
|
||||
if (!empty($group['children'])) {
|
||||
$groups[$iterator]['searchChildren'] = 1;
|
||||
// I hate myself
|
||||
unset($groups[$iterator]['children']);
|
||||
}
|
||||
else {
|
||||
$groups[$iterator]['searchChildren'] = 0;
|
||||
// I hate myself
|
||||
unset($groups[$iterator]['children']);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Make the data
|
||||
$this->tree = array();
|
||||
foreach ($groups as $group) {
|
||||
$data = array();
|
||||
$data['id'] = $group['id_grupo'];
|
||||
$data['type'] = 'group';
|
||||
$data['name'] = $group['nombre'];
|
||||
$data['searchChildren'] = $group['searchChildren'];
|
||||
|
||||
$this->tree[] = $data;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_data_module_group() {
|
||||
public function getDataModuleGroup() {
|
||||
}
|
||||
|
||||
public function get_data_module() {
|
||||
public function getDataModule() {
|
||||
}
|
||||
|
||||
public function get_data_tag() {
|
||||
public function getDataTag() {
|
||||
}
|
||||
|
||||
public function get_json() {
|
||||
$this->get_data();
|
||||
public function getJSON() {
|
||||
$this->getData();
|
||||
|
||||
return json_encode($this->tree);
|
||||
}
|
||||
|
||||
public function getArray() {
|
||||
$this->getData();
|
||||
|
||||
return $this->tree;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -52,9 +52,9 @@ TreeController = {
|
|||
.addClass("tree-group")
|
||||
.hide();
|
||||
}
|
||||
|
||||
|
||||
container.append($group);
|
||||
|
||||
|
||||
var lastNode;
|
||||
var firstNode;
|
||||
elements.forEach(function(element, index) {
|
||||
|
@ -62,7 +62,7 @@ TreeController = {
|
|||
firstNode = rootGroup && index == 0 ? true : false;
|
||||
element.jqObject = _processNode($group, detailRecipient, element, lastNode, firstNode);
|
||||
}, $group);
|
||||
|
||||
|
||||
return $group;
|
||||
}
|
||||
// Load leaf
|
||||
|
@ -70,10 +70,10 @@ TreeController = {
|
|||
var $node = $("<li></li>");
|
||||
var $leafIcon = $("<div></div>");
|
||||
var $content = $("<div></div>");
|
||||
|
||||
|
||||
// Leaf icon
|
||||
$leafIcon.addClass("leaf-icon");
|
||||
|
||||
|
||||
// Content
|
||||
$content.addClass("node-content");
|
||||
switch (element.type) {
|
||||
|
@ -100,28 +100,28 @@ TreeController = {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$node
|
||||
.addClass("tree-node")
|
||||
.append($leafIcon)
|
||||
.append($content);
|
||||
|
||||
|
||||
if (typeof lastNode != 'undefinded' && lastNode == true) {
|
||||
$node.addClass("tree-last");
|
||||
}
|
||||
if (typeof firstNode != 'undefinded' && firstNode == true) {
|
||||
$node.addClass("tree-first");
|
||||
}
|
||||
|
||||
|
||||
container.append($node);
|
||||
|
||||
|
||||
if (typeof element.children != 'undefined' && element.children.length > 0) {
|
||||
$node.addClass("leaf-closed");
|
||||
|
||||
|
||||
// Add children
|
||||
var $children = _processGroup($node, this.detailContainer, element.children, this.baseURL);
|
||||
$node.data('children', $children);
|
||||
|
||||
|
||||
$leafIcon.click(function () {
|
||||
if ($node.hasClass("leaf-open")) {
|
||||
$node
|
||||
|
@ -141,14 +141,14 @@ TreeController = {
|
|||
}
|
||||
else if (typeof element.searchChildren != 'undefined' && element.searchChildren) {
|
||||
$node.addClass("leaf-closed");
|
||||
|
||||
|
||||
$leafIcon.click(function () {
|
||||
if (! $node.hasClass("children-loaded")) {
|
||||
$node
|
||||
.removeClass("leaf-closed")
|
||||
.removeClass("leaf-error")
|
||||
.addClass("leaf-loading");
|
||||
|
||||
|
||||
$.ajax({
|
||||
url: this.ajaxURL,
|
||||
type: 'POST',
|
||||
|
@ -168,7 +168,7 @@ TreeController = {
|
|||
|
||||
var $children = _processGroup($node, this.detailContainer, data.elements, this.baseURL);
|
||||
$children.slideDown();
|
||||
|
||||
|
||||
$node.data('children', $children);
|
||||
}
|
||||
else {
|
||||
|
@ -201,10 +201,10 @@ TreeController = {
|
|||
else {
|
||||
$node.addClass("leaf-empty");
|
||||
}
|
||||
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
|
||||
if (this.recipient.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -212,12 +212,12 @@ TreeController = {
|
|||
this.recipient.html("<div>" + this.emptyMessage + "</div>");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.recipient.empty();
|
||||
|
||||
var $children = _processGroup(this.recipient, this.detailContainer, this.tree, this.baseURL, true);
|
||||
$children.show();
|
||||
|
||||
|
||||
this.recipient.data('children', $children);
|
||||
},
|
||||
load: function () {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
|
||||
require_once("tree2.php");
|
||||
//~ return;
|
||||
return;
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
global $config;
|
||||
|
||||
require_once("include/class/tree.class.php");
|
||||
require_once("include/class/Tree.class.php");
|
||||
|
||||
$tab = get_parameter('tab', 'group');
|
||||
$search = get_parameter('search', '');
|
||||
|
@ -120,13 +120,43 @@ html_print_table($table);
|
|||
|
||||
// --------------------- form filter -----------------------------------
|
||||
|
||||
|
||||
|
||||
$tree = new Tree($tab);
|
||||
$tree->set_filter(array(
|
||||
'status' => $status,
|
||||
'search' => $search));
|
||||
$json_tree = $tree->get_json();
|
||||
|
||||
html_debug_print($json_tree);
|
||||
?>
|
||||
ui_require_javascript_file("TreeController", "include/javascript/tree/");
|
||||
html_print_image('images/spinner.gif', false, array('class' => "loading_tree"));
|
||||
echo "<div id='tree-controller-recipient'>";
|
||||
echo "</div>";
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
var treeController = TreeController.getController();
|
||||
|
||||
var parameters = {};
|
||||
parameters['page'] = "include/ajax/tree.ajax";
|
||||
parameters['getChildren'] = 1;
|
||||
parameters['filter'] = {};
|
||||
parameters['filter']['type'] = "<?php echo $tab; ?>";
|
||||
parameters['filter']['search'] = "<?php echo $search; ?>";
|
||||
parameters['filter']['status'] = "<?php echo $status; ?>";
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "<?php echo ui_get_full_url("ajax.php", false, false, false); ?>",
|
||||
data: parameters,
|
||||
success: function(data) {
|
||||
if (data.success) {
|
||||
$(".loading_tree").hide();
|
||||
|
||||
treeController.init({
|
||||
recipient: $("div#tree-controller-recipient"),
|
||||
page: page,
|
||||
tree: data.tree
|
||||
});
|
||||
}
|
||||
},
|
||||
dataType: "json"
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue