Skip to content

Commit

Permalink
Working in the new code of treeview
Browse files Browse the repository at this point in the history
  • Loading branch information
mdtrooper committed Dec 17, 2014
1 parent 99756ea commit 42c08f1
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 67 deletions.
24 changes: 13 additions & 11 deletions pandora_console/include/ajax/tree.ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
?>
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,71 @@ 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,
array('id_grupo', 'nombre'));
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(
Expand Down Expand Up @@ -126,33 +127,97 @@ public function get_data_group() {

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;
}
}
?>
41 changes: 20 additions & 21 deletions pandora_console/include/javascript/tree/TreeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TreeController = {
if (typeof this.recipient == 'undefined' || this.recipient.length == 0) {
return;
}

function _processGroup (container, elements, baseURL, rootGroup) {
var $group = $("<ul></ul>");

Expand All @@ -44,27 +44,27 @@ TreeController = {
.addClass("tree-group")
.hide();
}

container.append($group);

var lastNode;
var firstNode;
elements.forEach(function(element, index) {
lastNode = index == elements.length - 1 ? true : false;
firstNode = rootGroup && index == 0 ? true : false;
element.jqObject = _processNode($group, element, lastNode, firstNode);
}, $group);

return $group;
}
function _processNode (container, element, lastNode, firstNode) {
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) {
Expand All @@ -75,28 +75,28 @@ TreeController = {
$content.append(element.name);
break;
}

$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, element.children, this.baseURL);
$node.data('children', $children);

$leafIcon.click(function () {
if ($node.hasClass("leaf-open")) {
$node
Expand All @@ -116,14 +116,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',
Expand All @@ -140,10 +140,10 @@ TreeController = {
success: function(data, textStatus, xhr) {
if (data.success) {
$node.addClass("leaf-open");

var $children = _processGroup($node, data.elements, this.baseURL);
$children.slideDown();

$node.data('children', $children);
}
else {
Expand Down Expand Up @@ -176,23 +176,22 @@ TreeController = {
else {
$node.addClass("leaf-empty");
}

return $node;
}

if (this.recipient.length == 0) {
return;
}
else if (this.tree.length == 0) {
this.recipient.html("<div>" + this.emptyMessage + "</div>");
return;
}

this.recipient.empty();

var $children = _processGroup(this.recipient, this.tree, this.baseURL, true);
$children.show();

this.recipient.data('children', $children);
},
load: function () {
Expand Down
2 changes: 1 addition & 1 deletion pandora_console/operation/tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


require_once("tree2.php");
//~ return;
return;
////////////////////////////////////////////////////////////////////////


Expand Down
Loading

0 comments on commit 42c08f1

Please sign in to comment.