Revision 704b1fa1
vigigraph: utilisation du GroupTree avec chargement progressif
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@6808 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigigraph/controllers/rpc.py | ||
---|---|---|
423 | 423 |
return dict() |
424 | 424 |
|
425 | 425 |
@expose('json') |
426 |
def hosttree(self, parent_id=None): |
|
426 |
def hosttree(self, parent_id=None, onlytype="", offset=0, noCache=None):
|
|
427 | 427 |
""" |
428 | 428 |
Affiche un étage de l'arbre de |
429 | 429 |
sélection des hôtes et groupes d'hôtes. |
... | ... | |
440 | 440 |
|
441 | 441 |
# TODO: Utiliser un schéma de validation |
442 | 442 |
parent_id = int(parent_id) |
443 |
offset = int(offset) |
|
443 | 444 |
|
444 | 445 |
# On vérifie si le groupe parent fait partie des |
445 | 446 |
# groupes auxquel l'utilisateur a accès, et on |
... | ... | |
474 | 475 |
else: |
475 | 476 |
return dict(groups = [], leaves = []) |
476 | 477 |
|
477 |
# On récupère la liste des groupes dont |
|
478 |
# l'identifiant du parent est passé en paramètre |
|
479 |
db_groups = DBSession.query( |
|
480 |
SupItemGroup |
|
481 |
).join( |
|
482 |
(GroupHierarchy, GroupHierarchy.idchild == \ |
|
483 |
SupItemGroup.idgroup), |
|
484 |
).filter(GroupHierarchy.hops == 1 |
|
485 |
).filter(GroupHierarchy.idparent == parent_id |
|
486 |
).order_by(SupItemGroup.name.asc()) |
|
487 |
if not is_manager and not direct_access: |
|
488 |
id_list = [ug for ug in user_groups.keys()] |
|
489 |
|
|
490 |
db_groups = db_groups.filter( |
|
491 |
SupItemGroup.idgroup.in_(id_list)) |
|
492 |
groups = [] |
|
493 |
for group in db_groups.all(): |
|
494 |
groups.append({ |
|
495 |
'id' : group.idgroup, |
|
496 |
'name' : group.name, |
|
497 |
}) |
|
478 |
limit = int(config.get("max_menu_entries", 20)) |
|
479 |
result = {"groups": [], "items": []} |
|
480 |
|
|
481 |
if not onlytype or onlytype == "group": |
|
482 |
# On récupère la liste des groupes dont |
|
483 |
# l'identifiant du parent est passé en paramètre |
|
484 |
db_groups = DBSession.query( |
|
485 |
SupItemGroup |
|
486 |
).join( |
|
487 |
(GroupHierarchy, GroupHierarchy.idchild == \ |
|
488 |
SupItemGroup.idgroup), |
|
489 |
).filter(GroupHierarchy.hops == 1 |
|
490 |
).filter(GroupHierarchy.idparent == parent_id |
|
491 |
).order_by(SupItemGroup.name.asc()) |
|
492 |
if not is_manager and not direct_access: |
|
493 |
id_list = [ug for ug in user_groups.keys()] |
|
494 |
|
|
495 |
db_groups = db_groups.filter( |
|
496 |
SupItemGroup.idgroup.in_(id_list)) |
|
497 |
num_children_left = db_groups.count() - offset |
|
498 |
if offset: |
|
499 |
result["continued_from"] = offset |
|
500 |
result["continued_type"] = "group" |
|
501 |
all_groups = db_groups.limit(limit).offset(offset).all() |
|
502 |
for group in all_groups: |
|
503 |
result["groups"].append({ |
|
504 |
'id' : group.idgroup, |
|
505 |
'name' : group.name, |
|
506 |
'type' : "group", |
|
507 |
}) |
|
508 |
if num_children_left > limit: |
|
509 |
result["groups"].append({ |
|
510 |
'name': _("Next %(limit)s") % {"limit": limit}, |
|
511 |
'offset': offset + limit, |
|
512 |
'parent_id': parent_id, |
|
513 |
'type': 'continued', |
|
514 |
'for_type': 'group', |
|
515 |
}) |
|
498 | 516 |
|
499 | 517 |
# On récupère la liste des hôtes appartenant au |
500 | 518 |
# groupe dont l'identifiant est passé en paramètre |
501 |
hosts = []
|
|
502 |
if is_manager or direct_access:
|
|
519 |
if ((not onlytype or onlytype == "item")
|
|
520 |
and (is_manager or direct_access)):
|
|
503 | 521 |
db_hosts = DBSession.query( |
504 | 522 |
Host.idhost, |
505 | 523 |
Host.name, |
... | ... | |
509 | 527 |
), |
510 | 528 |
).filter(SUPITEM_GROUP_TABLE.c.idgroup == parent_id |
511 | 529 |
).order_by(Host.name.asc()) |
512 |
hosts = [] |
|
513 |
for host in db_hosts.all(): |
|
514 |
hosts.append({ |
|
530 |
num_children_left = db_hosts.count() - offset |
|
531 |
if offset: |
|
532 |
result["continued_from"] = offset |
|
533 |
result["continued_type"] = "item" |
|
534 |
all_hosts = db_hosts.limit(limit).offset(offset).all() |
|
535 |
for host in all_hosts: |
|
536 |
result["items"].append({ |
|
515 | 537 |
'id' : host.idhost, |
516 | 538 |
'name' : host.name, |
539 |
'type' : "item", |
|
540 |
}) |
|
541 |
if num_children_left > limit: |
|
542 |
result["items"].append({ |
|
543 |
'name': _("Next %(limit)s") % {"limit": limit}, |
|
544 |
'offset': offset + limit, |
|
545 |
'parent_id': parent_id, |
|
546 |
'type': 'continued', |
|
547 |
'for_type': 'item', |
|
517 | 548 |
}) |
518 | 549 |
|
519 |
return dict(groups = groups, leaves = hosts)
|
|
550 |
return result
|
|
520 | 551 |
|
521 | 552 |
@expose('json') |
522 |
def graphtree(self, host_id=None, parent_id=None): |
|
553 |
def graphtree(self, host_id=None, parent_id=None, offset=0, noCache=None):
|
|
523 | 554 |
""" |
524 | 555 |
Affiche un étage de l'arbre de sélection |
525 | 556 |
des graphes et groupes de graphes. |
... | ... | |
533 | 564 |
if host_id is None: |
534 | 565 |
return dict(groups = [], graphs=[]) |
535 | 566 |
|
567 |
limit = int(config.get("max_menu_entries", 20)) |
|
536 | 568 |
# On vérifie les permissions sur l'hôte |
537 | 569 |
# TODO: Utiliser un schéma de validation |
538 | 570 |
host_id = int(host_id) |
... | ... | |
590 | 622 |
groups.append({ |
591 | 623 |
'id' : gg.idgroup, |
592 | 624 |
'name' : gg.name, |
625 |
'type' : "group", |
|
593 | 626 |
}) |
594 | 627 |
|
595 | 628 |
# On récupère la liste des graphes appartenant au |
... | ... | |
615 | 648 |
graphs.append({ |
616 | 649 |
'id' : graph.idgraph, |
617 | 650 |
'name' : graph.name, |
651 |
'type' : "item", |
|
618 | 652 |
}) |
619 | 653 |
|
620 |
return dict(groups = groups, leaves = graphs)
|
|
654 |
return dict(groups=groups, items=graphs)
|
|
621 | 655 |
|
622 | 656 |
def get_root_host_groups(self): |
623 | 657 |
""" |
... | ... | |
658 | 692 |
groups.append({ |
659 | 693 |
'id' : group.idgroup, |
660 | 694 |
'name' : group.name, |
695 |
'type' : "group", |
|
661 | 696 |
}) |
662 | 697 |
|
663 |
return dict(groups = groups, leaves=[])
|
|
698 |
return dict(groups=groups, leaves=[])
|
|
664 | 699 |
|
665 | 700 |
def getListIndicators(self, host, graph): |
666 | 701 |
""" |
vigigraph/public/js/toolbar.js | ||
---|---|---|
1 | 1 |
Jx.Button.SelectorFlyout = new Class({ |
2 | 2 |
Extends: Jx.Button.Flyout, |
3 | 3 |
|
4 |
initialize: function (options, url, hostid) {
|
|
4 |
initialize: function (options, url, itemImage) {
|
|
5 | 5 |
this.idselection = null; |
6 |
this.tree = new TreeGroup({ |
|
6 |
this.hostid = null; |
|
7 |
var tree_container = new Element("div"); |
|
8 |
tree_container.setStyle("padding", "0 10px 10px 10px"); |
|
9 |
this.tree = new GroupTree({ |
|
10 |
parent: tree_container, |
|
11 |
url: url, |
|
12 |
itemName: "item", |
|
13 |
itemImage: "images/" + itemImage, |
|
14 |
onItemClick: this.selectItem.bind(this) |
|
15 |
}); |
|
16 |
/* |
|
17 |
this.tree = new GroupTree({ |
|
7 | 18 |
title: this.options.label, |
8 | 19 |
url: url, |
9 | 20 |
hostid: hostid |
10 | 21 |
}); |
11 |
options.content = this.tree.container; |
|
22 |
*/ |
|
23 |
options.content = tree_container; |
|
24 |
options.onOpen = function() { |
|
25 |
if (! this.tree.isLoaded) { |
|
26 |
this.tree.load(); |
|
27 |
} |
|
28 |
}.bind(this); |
|
12 | 29 |
this.parent(options); |
13 | 30 |
this.tree.addEvent('select', this.selectItem.bind(this)); |
14 | 31 |
|
... | ... | |
26 | 43 |
this.contentContainer.setContentBoxSize( |
27 | 44 |
$(this.content).getMarginBoxSize()); |
28 | 45 |
}; |
46 |
this.tree.addEvent("load", adaptPopup.bind(this)); |
|
29 | 47 |
this.tree.addEvent("branchloaded", adaptPopup.bind(this)); |
30 | 48 |
this.tree.addEvent("nodedisclosed", adaptPopup.bind(this)); |
49 |
this.tree.addEvent("groupClick", adaptPopup.bind(this)); |
|
31 | 50 |
}, |
32 | 51 |
|
33 | 52 |
setItem: function (idselection, label) { |
... | ... | |
37 | 56 |
}, |
38 | 57 |
|
39 | 58 |
selectItem: function (item) { |
40 |
this.setItem(item.options.data, item.options.label);
|
|
59 |
this.setItem(item.id, item.name);
|
|
41 | 60 |
this.hide(); |
42 | 61 |
}, |
43 | 62 |
|
63 |
setHostId: function(hostid) { |
|
64 |
this.tree.options.requestOptions = {"host_id": hostid}; |
|
65 |
this.hostid = hostid; |
|
66 |
}, |
|
67 |
|
|
44 | 68 |
//clicked: function (e) { |
45 | 69 |
// if (!this.options.enabled) |
46 | 70 |
// return; |
... | ... | |
48 | 72 |
//}, |
49 | 73 |
|
50 | 74 |
redraw: function() { |
51 |
this.tree.redraw(); |
|
75 |
this.tree.clear(); |
|
76 |
this.tree.load(); |
|
52 | 77 |
} |
53 | 78 |
}); |
54 | 79 |
|
... | ... | |
83 | 108 |
tooltip: _('Click me to select another host') |
84 | 109 |
}, |
85 | 110 |
app_path + 'rpc/hosttree', |
86 |
null
|
|
111 |
"drive-harddisk.png"
|
|
87 | 112 |
); |
88 | 113 |
|
89 | 114 |
this.host_picker.addEvent("select", function() { |
90 | 115 |
var idselection = this.host_picker.idselection; |
91 |
if (this.graph_picker.tree.options.hostid != idselection) {
|
|
92 |
this.graph_picker.tree.options.hostid = idselection;
|
|
93 |
this.graph_picker.tree.redraw();
|
|
116 |
if (this.graph_picker.hostid !== idselection) {
|
|
117 |
this.graph_picker.setHostId(idselection);
|
|
118 |
this.graph_picker.redraw(); |
|
94 | 119 |
this.graph_picker.setItem(null, this.graph_picker.options.label); |
95 | 120 |
} |
96 | 121 |
this.show_nagios.setEnabled(1); |
... | ... | |
142 | 167 |
enabled: false |
143 | 168 |
}, |
144 | 169 |
app_path + 'rpc/graphtree', |
145 |
null
|
|
170 |
"utilities-system-monitor.png"
|
|
146 | 171 |
); |
147 | 172 |
|
148 | 173 |
this.graph_picker.addEvent("select", function (idselection, label) { |
... | ... | |
185 | 210 |
// Vérification de la date de dernière modification en base, et |
186 | 211 |
// rechargement des arbres le cas échéant |
187 | 212 |
this.loadtime = new Date(); |
188 |
this.req_expiration = new Request.JSON({ |
|
189 |
method: "get", |
|
190 |
url: app_path + "rpc/dbmtime", |
|
191 |
onSuccess: function(result){ |
|
192 |
if (!result) return; |
|
193 |
var mtime = Date.parse(result.mtime); |
|
194 |
if ((toolbar.loadtime - mtime) >= 0) return; |
|
195 |
// la base a changé, on recharge les arbres |
|
196 |
toolbar.host_picker.tree.redraw(); |
|
197 |
toolbar.graph_picker.tree.redraw(); |
|
198 |
// @todo: En théorie on devrait aussi vérifier que l'élément |
|
199 |
// sélectionné existe dans l'arbre, mais c'est un peu compliqué |
|
200 |
// avec le chargement dynamique. Il faudrait faire une requête |
|
201 |
// spécifique |
|
202 |
toolbar.loadtime = new Date(); |
|
203 |
} |
|
204 |
}); |
|
205 |
this.req_expiration.send.periodical(30 * 1000, this.req_expiration); |
|
213 |
this.checkExpiration.periodical(30 * 1000, this); |
|
206 | 214 |
}, |
207 | 215 |
|
208 | 216 |
// Retourne un objet opaque qui possède un label, |
... | ... | |
236 | 244 |
if ((toolbar.loadtime - mtime) >= 0) return; |
237 | 245 |
// la base a changé, on recharge les arbres |
238 | 246 |
if (toolbar.host_picker.idselection) { |
239 |
toolbar.host_picker.tree.redraw();
|
|
247 |
toolbar.host_picker.redraw(); |
|
240 | 248 |
} |
241 | 249 |
if (toolbar.graph_picker.idselection) { |
242 |
toolbar.graph_picker.tree.redraw();
|
|
250 |
toolbar.graph_picker.redraw(); |
|
243 | 251 |
} |
244 | 252 |
// @todo: En théorie on devrait aussi vérifier que |
245 | 253 |
// l'élément sélectionné existe dans l'arbre, mais c'est un |
Also available in: Unified diff