Project

General

Profile

Revision 67eb4593

ID67eb4593a40bfabb880946d1540115d290c8794e
Parent 268f526d
Child 0dcb87f7

Added by Francois POIROTTE almost 14 years ago

Légère amélioration de l'arbre des groupes pour afficher les éléments par ordre alphabétique.

git-svn-id: https://vigilo-dev.si.c-s.fr/svn@3604 b22e2e97-25c9-44ff-b637-2e5ceca36478

View differences:

vigiboard/controllers/root.py
718 718
    @require(access_restriction)
719 719
    @expose('json')
720 720
    def get_groups(self):
721
        hierarchy = []
721 722
        user = get_current_user()
722 723
        groups = DBSession.query(
723 724
                    SupItemGroup.idgroup,
......
727 728
                    (GroupHierarchy, GroupHierarchy.idchild == \
728 729
                        SupItemGroup.idgroup),
729 730
                ).filter(GroupHierarchy.hops <= 1
730
                ).order_by(GroupHierarchy.hops.asc())
731
                ).order_by(GroupHierarchy.hops.asc()
732
                ).order_by(SupItemGroup.name.asc())
731 733

  
732 734
        is_manager = in_group('managers').is_met(request.environ)
733 735
        if not is_manager:
734 736
            user_groups = [ug[0] for ug in user.supitemgroups() if ug[1]]
735 737
            groups = groups.filter(SupItemGroup.idgroup.in_(user_groups))
736 738

  
737
        # Cas des groupes racines (parents les plus élevés dans l'arbre).
738
#        if idgroup:
739
#            groups = groups.filter(GroupHierarchy.idparent == idgroup)
740

  
741
        hierarchy = {}
742

  
743 739
        def find_parent(idgroup):
744 740
            def __find_parent(hier, idgroup):
745
                if idgroup in hier:
746
                    return hier[idgroup]['children']
747 741
                for g in hier:
748
                    res = __find_parent(hier[g]['children'], idgroup)
742
                    if g['idgroup'] == idgroup:
743
                        return g['children']
744
                for g in hier:
745
                    res = __find_parent(g['children'], idgroup)
749 746
                    if res:
750 747
                        return res
751 748
                return None
......
756 753

  
757 754
        for g in groups.all():
758 755
            parent = find_parent(g.idparent)
759
            if g.idgroup in hierarchy:
760
                parent[g.idgroup] = hierarchy[g.idgroup]
761
                del hierarchy[g.idgroup]
756
            for item in hierarchy:
757
                if item['idgroup'] == g.idgroup:
758
                    parent.append(item)
759
                    hierarchy.remove(item)
760
                    break
762 761
            else:
763
                parent[g.idgroup] = {
762
                parent.append({
763
                    'idgroup': g.idgroup,
764 764
                    'name': g.name,
765
                    'children': {},
766
                }
765
                    'children': [],
766
                })
767 767

  
768 768
        return dict(groups=hierarchy)
769 769

  
vigiboard/public/js/tree.js
28 28
            method: "get",
29 29
            url: this.options.url,
30 30
            onSuccess: function(groups) {
31
                groups = new Hash(groups.groups);
32
                $each(groups, function(item, key) {
33
                    this.addItem(key, item, this.tree);
31
                $each(groups.groups, function(item) {
32
                    this.addItem(item, this.tree);
34 33
                }, this);
35 34
            }.bind(this)
36 35
        });
......
38 37
    },
39 38

  
40 39
    /* Ajout d'un element à l'arbre */
41
    addItem: function(idgroup, data, parent) {
40
    addItem: function(data, parent) {
42 41
        var subfolder;
43
        var children = new Hash(data.children);
44
        if (children.getLength()) {
42
        if (data.children.length) {
45 43
            subfolder = new Jx.TreeFolder({
46 44
                label: data.name,
47
                data: idgroup,
45
                data: data.idgroup,
48 46
                image: this.options.app_path+"images/map-list.png",
49 47
            });
50 48
        }
51 49
        else {
52 50
            subfolder = new Jx.TreeItem({
53 51
                label: data.name,
54
                data: idgroup,
52
                data: data.idgroup,
55 53
                image: this.options.app_path+"images/map.png",
56 54
            });
57 55
        }
......
63 61
        }.bind(this));
64 62
        parent.append(subfolder);
65 63

  
66
        $each(children, function(item, key) {
67
            this.addItem(key, item, subfolder);
64
        $each(data.children, function(item) {
65
            this.addItem(item, subfolder);
68 66
        }, this);
69 67
    },
70 68

  

Also available in: Unified diff