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

atinc / ngx-tethys / c572ad56-6796-461c-8809-6e2d7ed05a21

16 Apr 2025 06:23AM UTC coverage: 90.271% (+0.001%) from 90.27%
c572ad56-6796-461c-8809-6e2d7ed05a21

Pull #3341

circleci

minlovehua
refactor(all): resolve 30 circular denpendencies TINFR-1830
Pull Request #3341: refactor(all): resolve 30 circular denpendencies TINFR-1830

5614 of 6878 branches covered (81.62%)

Branch coverage included in aggregate %.

89 of 94 new or added lines in 38 files covered. (94.68%)

64 existing lines in 12 files now uncovered.

13370 of 14152 relevant lines covered (94.47%)

922.06 hits per line

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

86.6
/src/tree/tree.class.ts
1
import { helpers, isArray } from 'ngx-tethys/util';
2
import { Subject } from 'rxjs';
3

1✔
4
export enum ThyTreeNodeCheckState {
1✔
5
    unchecked = 0,
1✔
6
    checked = 1,
1✔
7
    indeterminate = 2
2✔
8
}
9

1✔
10
export enum ThyTreeDropPosition {
1✔
11
    in = 'in',
1✔
12
    before = 'before',
1✔
13
    after = 'after'
2✔
14
}
15

16
export interface ThyTreeNodeData<T = any> {
17
    key?: number | string;
18

1,173!
19
    title?: string;
1,173✔
20

UNCOV
21
    icon?: string;
×
UNCOV
22

×
23
    iconStyle?: {
24
        [key: string]: any;
25
    };
×
26

7,044✔
27
    children?: ThyTreeNodeData<T>[];
7,044✔
28

7,044✔
29
    origin?: any;
7,044✔
30

7,044✔
31
    expanded?: boolean;
7,044✔
32

7,044✔
33
    disabled?: boolean;
7,044✔
34

7,044✔
35
    checked?: boolean;
7,044✔
36

7,044✔
37
    data?: T;
7,044✔
38

6!
39
    itemClass?: string | string[];
40

7,044✔
41
    [key: string]: any;
1,576✔
42
}
6,861✔
43

44
export interface ThyTreeEmitEvent<T = any> {
45
    eventName: string;
7,044✔
46

7,044✔
47
    node?: ThyTreeNode<T>;
907✔
48

49
    event?: Event | any;
50

51
    dragNode?: ThyTreeNode<T>;
1✔
52

1✔
53
    targetNode?: ThyTreeNode<T>;
54
}
55

1✔
56
export interface ThyTreeBeforeDragStartContext {
1✔
57
    item: ThyTreeNode;
58
}
UNCOV
59

×
60
export interface ThyTreeBeforeDragDropContext {
61
    item?: ThyTreeNode;
×
62
    containerItems?: ThyTreeNode[];
1,188✔
63
    previousItem?: ThyTreeNode;
1,188✔
64
    previousContainerItems?: ThyTreeNode[];
1,188✔
65
    position?: ThyTreeDropPosition;
31✔
66
}
67

68
export interface ThyTreeDragDropEvent<T = any> {
1,157✔
69
    dragNode?: ThyTreeNode<T>;
1,159✔
70

1,159✔
71
    targetNode?: ThyTreeNode<T>;
72

73
    afterNode?: ThyTreeNode<T>;
2✔
74
}
2✔
75

76
export class ThyTreeIcons {
19✔
77
    expand?: string;
10✔
78
    collapse?: string;
79
}
80

1✔
81
export type ThyClickBehavior = 'default' | 'selectCheckbox';
82

NEW
83
export interface ThyTreeFormatEmitEvent {
×
84
    eventName: string;
85
    node: ThyTreeNode;
86
    event?: MouseEvent | DragEvent;
2✔
87
}
88

1✔
89
export interface IThyTreeService {
1✔
90
    statusChange$: Subject<ThyTreeFormatEmitEvent>;
1!
91
    syncFlattenTreeNodes: () => ThyTreeNode[];
10!
92
    setNodeChecked: (node: ThyTreeNode, checked: boolean, propagateUp?: boolean, propagateDown?: boolean) => void;
10✔
93
    syncNodeCheckState: (node: ThyTreeNode) => void;
94
    checkStateResolve: (node: ThyTreeNode) => ThyTreeNodeCheckState;
NEW
95
}
×
96

97
export class ThyTreeNode<T = any> {
98
    key?: number | string;
10✔
99

1✔
100
    title?: string;
1✔
101

102
    children: ThyTreeNode[];
103

104
    parentNode: ThyTreeNode;
105

106
    level = 0;
107

108
    origin: ThyTreeNodeData<T>;
109

110
    isExpanded: boolean;
111

112
    isChecked: ThyTreeNodeCheckState;
113

114
    isLoading: boolean;
115

116
    isDisabled: boolean;
117

118
    itemClass?: string[];
119

120
    private readonly service: IThyTreeService;
121

122
    get treeService(): IThyTreeService {
123
        if (this.service) {
124
            return this.service;
125
        } else if (this.parentNode) {
126
            return this.parentNode.treeService;
127
        }
128
    }
129

130
    constructor(node: ThyTreeNodeData, parent: ThyTreeNode = null, service?: IThyTreeService) {
131
        this.title = node.title;
132
        this.key = node.key;
133
        this.children = [];
134
        this.parentNode = parent;
135
        this.level = parent ? parent.level + 1 : this.level;
136
        this.origin = node;
137
        this.isDisabled = node.disabled || false;
138
        this.isExpanded = node.expanded || false;
139
        this.isChecked = node.checked ? ThyTreeNodeCheckState.checked : ThyTreeNodeCheckState.unchecked;
140
        this.isLoading = false;
141
        if (node.itemClass) {
142
            this.itemClass = isArray(node.itemClass) ? node.itemClass : [node.itemClass];
143
        }
144
        if (node.children) {
145
            node.children.forEach(childNode => {
146
                this.children.push(new ThyTreeNode(childNode, this, service));
147
            });
148
        }
149
        this.service = service;
150
        if (node.children && node.children.length && service) {
151
            this.isChecked = service.checkStateResolve(this);
152
        }
153
    }
154

155
    public setKey(key: string) {
156
        this.origin.key = key;
157
        this.key = key;
158
    }
159

160
    public setTitle(title: string) {
161
        this.origin.title = title;
162
        this.title = title;
163
    }
164

165
    public setLevel(level: number) {
166
        this.level = level;
167
    }
168

169
    private _setExpanded(expanded: boolean, propagate = false) {
170
        this.origin.expanded = expanded;
171
        this.isExpanded = expanded;
172
        if (propagate && this.children) {
173
            this.children.forEach(n => n._setExpanded(expanded, propagate));
174
        }
175
    }
176

177
    public setExpanded(expanded: boolean, propagate = false) {
178
        this._setExpanded(expanded, propagate);
179
        this.treeService.syncFlattenTreeNodes();
180
    }
181

182
    public setLoading(loading: boolean): void {
183
        this.isLoading = loading;
184
        this.treeService.syncFlattenTreeNodes();
185
    }
186

187
    public setChecked(checked: boolean, propagateUp = true, propagateDown = true) {
188
        this.treeService.setNodeChecked(this, checked, propagateUp, propagateDown);
189
    }
190

191
    public syncNodeCheckState() {
192
        this.treeService.syncNodeCheckState(this);
193
    }
194

195
    public getParentNode(): ThyTreeNode {
196
        return this.parentNode;
197
    }
198

199
    public getChildren(): ThyTreeNode[] {
200
        return this.children;
201
    }
202

203
    public addChildren(children: ThyTreeNodeData | ThyTreeNodeData[], index: number = -1): void {
204
        children = helpers.coerceArray(children);
205
        ((children as ThyTreeNodeData[]) || []).forEach((childNode: ThyTreeNodeData, i: number) => {
206
            if (index === -1) {
207
                this.children.push(new ThyTreeNode(childNode, this));
208
            } else {
209
                this.children.splice(index + i, 0, new ThyTreeNode(childNode, this, this.treeService));
210
            }
211
        });
212

213
        this.origin.children = this.getChildren().map(n => n.origin);
214
        this.setLoading(false);
215
        this.treeService.statusChange$.next({
216
            eventName: 'addChildren',
217
            node: this
218
        });
219
    }
220
}
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