• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

atinc / ngx-tethys / 0bbb2cec-209e-4d8a-b1b3-6bc54e05daa6

04 Sep 2023 08:40AM UTC coverage: 15.616% (-74.6%) from 90.2%
0bbb2cec-209e-4d8a-b1b3-6bc54e05daa6

Pull #2829

circleci

cmm-va
fix: add test
Pull Request #2829: fix: add tabIndex

300 of 6386 branches covered (0.0%)

Branch coverage included in aggregate %.

78 of 78 new or added lines in 26 files covered. (100.0%)

2849 of 13779 relevant lines covered (20.68%)

83.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/tree/tree-node.class.ts
1
import { helpers, isArray } from 'ngx-tethys/util';
2

3
import { ThyTreeNodeCheckState, ThyTreeNodeData } from './tree.class';
4
import { ThyTreeService } from './tree.service';
5

×
6
export class ThyTreeNode<T = any> {
×
7
    key?: number | string;
8

×
9
    title?: string;
×
10

11
    children: ThyTreeNode[];
12

×
13
    parentNode: ThyTreeNode;
×
14

×
15
    level = 0;
×
16

×
17
    origin: ThyTreeNodeData<T>;
×
18

×
19
    isExpanded: boolean;
×
20

×
21
    isChecked: ThyTreeNodeCheckState;
×
22

×
23
    isLoading: boolean;
×
24

×
25
    isDisabled: boolean;
×
26

27
    itemClass?: string[];
×
28

×
29
    private readonly service: ThyTreeService;
×
30

31
    get treeService(): ThyTreeService {
32
        if (this.service) {
×
33
            return this.service;
×
34
        } else if (this.parentNode) {
×
35
            return this.parentNode.treeService;
36
        }
37
    }
38

×
39
    constructor(node: ThyTreeNodeData, parent: ThyTreeNode = null, service?: ThyTreeService) {
×
40
        this.title = node.title;
41
        this.key = node.key;
42
        this.children = [];
×
43
        this.parentNode = parent;
×
44
        this.level = parent ? parent.level + 1 : this.level;
45
        this.origin = node;
46
        this.isDisabled = node.disabled || false;
×
47
        this.isExpanded = node.expanded || false;
48
        this.isChecked = node.checked ? ThyTreeNodeCheckState.checked : ThyTreeNodeCheckState.unchecked;
×
49
        this.isLoading = false;
×
50
        if (node.itemClass) {
×
51
            this.itemClass = isArray(node.itemClass) ? node.itemClass : [node.itemClass];
×
52
        }
×
53
        if (node.children) {
54
            node.children.forEach(childNode => {
55
                this.children.push(new ThyTreeNode(childNode, this, service));
×
56
            });
×
57
        }
×
58
        this.service = service;
59
        if (node.children && node.children.length && service) {
60
            this.isChecked = service.checkStateResolve(this);
×
61
        }
×
62
    }
63

×
64
    public setKey(key: string) {
×
65
        this.origin.key = key;
66
        this.key = key;
67
    }
×
68

69
    public setTitle(title: string) {
70
        this.origin.title = title;
×
71
        this.title = title;
72
    }
73

×
74
    public setLevel(level: number) {
75
        this.level = level;
×
76
    }
×
77

×
78
    private _setExpanded(expanded: boolean, propagate = false) {
×
79
        this.origin.expanded = expanded;
×
80
        this.isExpanded = expanded;
81
        if (propagate && this.children) {
82
            this.children.forEach(n => n._setExpanded(expanded, propagate));
×
83
        }
84
    }
85

×
86
    public setExpanded(expanded: boolean, propagate = false) {
×
87
        this._setExpanded(expanded, propagate);
×
88
        this.treeService.syncFlattenTreeNodes();
89
    }
90

91
    public setLoading(loading: boolean): void {
92
        this.isLoading = loading;
93
        this.treeService.syncFlattenTreeNodes();
94
    }
95

96
    public setChecked(checked: boolean, propagateUp = true, propagateDown = true) {
97
        this.treeService.setNodeChecked(this, checked, propagateUp, propagateDown);
98
    }
99

100
    public syncNodeCheckState() {
101
        this.treeService.syncNodeCheckState(this);
102
    }
103

104
    public getParentNode(): ThyTreeNode {
105
        return this.parentNode;
106
    }
107

108
    public getChildren(): ThyTreeNode[] {
109
        return this.children;
110
    }
111

112
    public addChildren(children: ThyTreeNodeData | ThyTreeNodeData[], index: number = -1): void {
113
        children = helpers.coerceArray(children);
114
        ((children as ThyTreeNodeData[]) || []).forEach((childNode: ThyTreeNodeData, i: number) => {
115
            if (index === -1) {
116
                this.children.push(new ThyTreeNode(childNode, this));
117
            } else {
118
                this.children.splice(index + i, 0, new ThyTreeNode(childNode, this, this.treeService));
119
            }
120
        });
121

122
        this.origin.children = this.getChildren().map(n => n.origin);
123
        this.setLoading(false);
124
        this.treeService.statusChange$.next({
125
            eventName: 'addChildren',
126
            node: this
127
        });
128
    }
129
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc