resources/assets/js/core/tree.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 1.5

Size

Lines of Code 56
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 33
c 0
b 0
f 0
dl 0
loc 56
rs 10
mnd 4
bc 4
fnc 8
bpm 0.5
cpm 1.5
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
C Tree.initJsTree 0 50 11
A Tree.constructor 0 3 1
1
export class Tree {
2
    constructor() {
3
        this.initJsTree();
4
    }
5
6
    initJsTree() {
7
        let moduleTree = $('#treeview')
8
        moduleTree.jstree({
9
            "core" : {
10
                "themes" : {
11
                    "icons": false
12
                },
13
                "data" : {
14
                    "url" : function (node) {
15
                        return node.id === '#' ?
16
                        $("meta[name='module-tree-default-url']").attr('content') :
17
                        $("meta[name='module-tree-children-url']").attr('content');
18
                    },
19
                    "data" : function (node) {
20
                        return { 'id' : node.id };
21
                    }
22
                }
23
            },
24
            "plugins" : ['search', 'sort'],
25
            "search" : {
26
                "show_only_matches" : true
27
            }
28
        })
29
30
        // Open tree automatically
31
        .on('ready.jstree', () => {
32
            if ($("meta[name='module-tree-open-all']").attr('content')) {
33
                moduleTree.jstree('open_all')
34
            }
35
        })
36
37
        // Switch on detail view on click
38
        .on('changed.jstree', (e, data) => {
39
            if (data.node.a_attr.href !== '#') {
40
                document.location.href = data.node.a_attr.href
41
            }
42
        })
43
44
        let to = false
45
        $('.treeview-search-bar #record-name').keyup(() => {
46
            if(to) {
47
                clearTimeout(to)
48
            }
49
50
            to = setTimeout(() => {
51
                let v = $('#record-name').val()
52
                moduleTree.jstree(true).search(v)
53
            }, 250)
54
        })
55
    }
56
}