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