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

atinc / ngx-tethys / 68ef226c-f83e-44c1-b8ed-e420a83c5d84

28 May 2025 10:31AM UTC coverage: 10.352% (-80.0%) from 90.316%
68ef226c-f83e-44c1-b8ed-e420a83c5d84

Pull #3460

circleci

pubuzhixing8
chore: xxx
Pull Request #3460: refactor(icon): migrate signal input #TINFR-1476

132 of 6823 branches covered (1.93%)

Branch coverage included in aggregate %.

10 of 14 new or added lines in 1 file covered. (71.43%)

11648 existing lines in 344 files now uncovered.

2078 of 14525 relevant lines covered (14.31%)

6.69 hits per line

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

12.37
/src/tree/tree.class.ts
1
import { helpers, isArray } from 'ngx-tethys/util';
2
import { BehaviorSubject, 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;
UNCOV
18

×
UNCOV
19
    title?: string;
×
20

21
    icon?: string;
×
22

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

×
UNCOV
27
    children?: ThyTreeNodeData<T>[];
×
UNCOV
28

×
UNCOV
29
    origin?: any;
×
UNCOV
30

×
UNCOV
31
    expanded?: boolean;
×
UNCOV
32

×
UNCOV
33
    disabled?: boolean;
×
UNCOV
34

×
UNCOV
35
    checked?: boolean;
×
UNCOV
36

×
UNCOV
37
    data?: T;
×
UNCOV
38

×
39
    itemClass?: string | string[];
UNCOV
40

×
UNCOV
41
    [key: string]: any;
×
UNCOV
42
}
×
43

44
export interface ThyTreeEmitEvent<T = any> {
UNCOV
45
    eventName: string;
×
UNCOV
46

×
UNCOV
47
    node?: ThyTreeNode<T>;
×
48

49
    event?: Event | any;
50

UNCOV
51
    dragNode?: ThyTreeNode<T>;
×
UNCOV
52

×
53
    targetNode?: ThyTreeNode<T>;
54
}
UNCOV
55

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

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

68
export interface ThyTreeDragDropEvent<T = any> {
×
UNCOV
69
    dragNode?: ThyTreeNode<T>;
×
UNCOV
70

×
71
    targetNode?: ThyTreeNode<T>;
72

UNCOV
73
    afterNode?: ThyTreeNode<T>;
×
UNCOV
74
}
×
75

76
export class ThyTreeIcons {
×
UNCOV
77
    expand?: string;
×
78
    collapse?: string;
79
}
UNCOV
80

×
81
export type ThyClickBehavior = 'default' | 'selectCheckbox';
82

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

×
UNCOV
89
export interface IThyTreeService {
×
UNCOV
90
    selectedNode: ThyTreeNode;
×
UNCOV
91
    flattenNodes$: BehaviorSubject<ThyTreeNode[]>;
×
UNCOV
92
    flattenTreeNodes: ThyTreeNode[];
×
93
    treeNodes: ThyTreeNode[];
94
    statusChange$: Subject<ThyTreeFormatEmitEvent>;
95
    initializeTreeNodes: (rootNodes: ThyTreeNodeData[]) => void;
×
96
    syncFlattenTreeNodes: () => ThyTreeNode[];
97
    setCheckStateResolve: (resolve: (node: ThyTreeNode) => ThyTreeNodeCheckState) => void;
UNCOV
98
    resetSortedTreeNodes: (treeNodes: ThyTreeNode[], parent?: ThyTreeNode) => void;
×
UNCOV
99
    getTreeNode: (key: string | number) => ThyTreeNode;
×
UNCOV
100
    getExpandedNodes: () => ThyTreeNode[];
×
101
    getCheckedNodes: () => ThyTreeNode[];
102
    deleteTreeNode: (node: ThyTreeNode) => void;
103
    addTreeNode: (node: ThyTreeNode, parent?: ThyTreeNode, index?: number) => void;
104
    expandTreeNodes: (keyOrKeys: string | number | (string | number)[] | true) => void;
105
    setNodeChecked: (node: ThyTreeNode, checked: boolean, propagateUp?: boolean, propagateDown?: boolean) => void;
106
    syncNodeCheckState: (node: ThyTreeNode) => void;
107
    checkStateResolve: (node: ThyTreeNode) => ThyTreeNodeCheckState;
108
}
109

110
export class ThyTreeNode<T = any> {
111
    key?: number | string;
112

113
    title?: string;
114

115
    children: ThyTreeNode[];
116

117
    parentNode: ThyTreeNode;
118

119
    level = 0;
120

121
    origin: ThyTreeNodeData<T>;
122

123
    isExpanded: boolean;
124

125
    isChecked: ThyTreeNodeCheckState;
126

127
    isLoading: boolean;
128

129
    isDisabled: boolean;
130

131
    itemClass?: string[];
132

133
    private readonly service: IThyTreeService;
134

135
    get treeService(): IThyTreeService {
136
        if (this.service) {
137
            return this.service;
138
        } else if (this.parentNode) {
139
            return this.parentNode.treeService;
140
        }
141
    }
142

143
    constructor(node: ThyTreeNodeData, parent: ThyTreeNode = null, service?: IThyTreeService) {
144
        this.title = node.title;
145
        this.key = node.key;
146
        this.children = [];
147
        this.parentNode = parent;
148
        this.level = parent ? parent.level + 1 : this.level;
149
        this.origin = node;
150
        this.isDisabled = node.disabled || false;
151
        this.isExpanded = node.expanded || false;
152
        this.isChecked = node.checked ? ThyTreeNodeCheckState.checked : ThyTreeNodeCheckState.unchecked;
153
        this.isLoading = false;
154
        if (node.itemClass) {
155
            this.itemClass = isArray(node.itemClass) ? node.itemClass : [node.itemClass];
156
        }
157
        if (node.children) {
158
            node.children.forEach(childNode => {
159
                this.children.push(new ThyTreeNode(childNode, this, service));
160
            });
161
        }
162
        this.service = service;
163
        if (node.children && node.children.length && service) {
164
            this.isChecked = service.checkStateResolve(this);
165
        }
166
    }
167

168
    public setKey(key: string) {
169
        this.origin.key = key;
170
        this.key = key;
171
    }
172

173
    public setTitle(title: string) {
174
        this.origin.title = title;
175
        this.title = title;
176
    }
177

178
    public setLevel(level: number) {
179
        this.level = level;
180
    }
181

182
    private _setExpanded(expanded: boolean, propagate = false) {
183
        this.origin.expanded = expanded;
184
        this.isExpanded = expanded;
185
        if (propagate && this.children) {
186
            this.children.forEach(n => n._setExpanded(expanded, propagate));
187
        }
188
    }
189

190
    public setExpanded(expanded: boolean, propagate = false) {
191
        this._setExpanded(expanded, propagate);
192
        this.treeService.syncFlattenTreeNodes();
193
    }
194

195
    public setLoading(loading: boolean): void {
196
        this.isLoading = loading;
197
        this.treeService.syncFlattenTreeNodes();
198
    }
199

200
    public setChecked(checked: boolean, propagateUp = true, propagateDown = true) {
201
        this.treeService.setNodeChecked(this, checked, propagateUp, propagateDown);
202
    }
203

204
    public syncNodeCheckState() {
205
        this.treeService.syncNodeCheckState(this);
206
    }
207

208
    public getParentNode(): ThyTreeNode {
209
        return this.parentNode;
210
    }
211

212
    public getChildren(): ThyTreeNode[] {
213
        return this.children;
214
    }
215

216
    public addChildren(children: ThyTreeNodeData | ThyTreeNodeData[], index: number = -1): void {
217
        children = helpers.coerceArray(children);
218
        ((children as ThyTreeNodeData[]) || []).forEach((childNode: ThyTreeNodeData, i: number) => {
219
            if (index === -1) {
220
                this.children.push(new ThyTreeNode(childNode, this));
221
            } else {
222
                this.children.splice(index + i, 0, new ThyTreeNode(childNode, this, this.treeService));
223
            }
224
        });
225

226
        this.origin.children = this.getChildren().map(n => n.origin);
227
        this.setLoading(false);
228
        this.treeService.statusChange$.next({
229
            eventName: 'addChildren',
230
            node: this
231
        });
232
    }
233
}
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