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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

10.0
/projects/igniteui-angular/src/lib/grids/row-drag.directive.ts
1
import { Directive, Input, OnDestroy, TemplateRef } from '@angular/core';
2
import { fromEvent, Subscription } from 'rxjs';
3
import { IgxDragDirective } from '../directives/drag-drop/drag-drop.directive';
4
import { IRowDragStartEventArgs, IRowDragEndEventArgs } from './common/events';
5
import { IgxGridEmptyTemplateContext, IgxGridRowDragGhostContext, RowType } from './common/grid.interface';
6

7

8
const ghostBackgroundClass = 'igx-grid__tr--ghost';
2✔
9
const gridCellClass = 'igx-grid__td';
2✔
10
const rowSelectedClass = 'igx-grid__tr--selected';
2✔
11
const cellSelectedClass = 'igx-grid__td--selected';
2✔
12
const cellActiveClass = 'igx-grid__td--active';
2✔
13

14
/**
15
 * @hidden
16
 */
17
@Directive({
18
    selector: '[igxRowDrag]',
19
    standalone: true
20
})
21
export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
2✔
22

23
    @Input('igxRowDrag')
24
    public override set data(value: any) {
UNCOV
25
        this._data = value;
×
26
    }
27

28
    public override get data(): any {
UNCOV
29
        return this._data.grid.createRow(this._data.index, this._data.data);
×
30
    }
31

32
    private subscription$: Subscription;
UNCOV
33
    private _rowDragStarted = false;
×
34

35
    private get row(): RowType {
UNCOV
36
        return this._data;
×
37
    }
38

39
    public override onPointerDown(event) {
UNCOV
40
        event.preventDefault();
×
UNCOV
41
        this._rowDragStarted = false;
×
UNCOV
42
        this._removeOnDestroy = false;
×
UNCOV
43
        super.onPointerDown(event);
×
44
    }
45

46
    public override onPointerMove(event) {
UNCOV
47
        super.onPointerMove(event);
×
UNCOV
48
        if (this._dragStarted && !this._rowDragStarted) {
×
UNCOV
49
            this._rowDragStarted = true;
×
UNCOV
50
            const args: IRowDragStartEventArgs = {
×
51
                dragDirective: this,
52
                dragData: this.data,
53
                dragElement: this.row.nativeElement,
54
                cancel: false,
55
                owner: this.row.grid
56
            };
57

UNCOV
58
            this.row.grid.rowDragStart.emit(args);
×
UNCOV
59
            if (args.cancel) {
×
UNCOV
60
                this.ghostElement.parentNode.removeChild(this.ghostElement);
×
UNCOV
61
                this.ghostElement = null;
×
UNCOV
62
                this._dragStarted = false;
×
UNCOV
63
                this._clicked = false;
×
UNCOV
64
                return;
×
65
            }
UNCOV
66
            this.row.grid.dragRowID = this.row.key;
×
UNCOV
67
            this.row.grid.rowDragging = true;
×
UNCOV
68
            this.row.grid.cdr.detectChanges();
×
69

UNCOV
70
            this.subscription$ = fromEvent(this.row.grid.document.defaultView, 'keydown').subscribe((ev: KeyboardEvent) => {
×
UNCOV
71
                if (ev.key === this.platformUtil.KEYMAP.ESCAPE) {
×
UNCOV
72
                    this._lastDropArea = false;
×
UNCOV
73
                    this.onPointerUp(event);
×
74
                }
75
            });
76
        }
77
    }
78

79
    public override onPointerUp(event) {
80

UNCOV
81
        if (!this._clicked) {
×
UNCOV
82
            return;
×
83
        }
84

UNCOV
85
        const args: IRowDragEndEventArgs = {
×
86
            dragDirective: this,
87
            dragData: this.data,
88
            dragElement: this.row.nativeElement,
89
            animation: false,
90
            owner: this.row.grid
91
        };
UNCOV
92
        this.zone.run(() => {
×
UNCOV
93
            this.row.grid.rowDragEnd.emit(args);
×
94
        });
95

UNCOV
96
        const dropArea = this._lastDropArea;
×
UNCOV
97
        super.onPointerUp(event);
×
UNCOV
98
        if (!dropArea && this.ghostElement) {
×
99
            this.ghostElement.addEventListener('transitionend', this.transitionEndEvent, false);
×
100
        } else {
UNCOV
101
            this.endDragging();
×
102
        }
103
    }
104

105
    protected override createGhost(pageX, pageY) {
UNCOV
106
        this.row.grid.gridAPI.crudService.endEdit(false);
×
UNCOV
107
        this.row.grid.cdr.detectChanges();
×
UNCOV
108
        this.ghostContext = {
×
109
            $implicit: this.row.data,
110
            data: this.row.data,
111
            grid: this.row.grid
112
        };
UNCOV
113
        super.createGhost(pageX, pageY, this.row.nativeElement);
×
114

115
        // check if there is an expander icon and create the ghost at the corresponding position
UNCOV
116
        if (this.isHierarchicalGrid) {
×
UNCOV
117
            const row = this.row as any;
×
UNCOV
118
            if (row.expander) {
×
UNCOV
119
                const expanderWidth = row.expander.nativeElement.getBoundingClientRect().width;
×
UNCOV
120
                this._ghostHostX += expanderWidth;
×
121
            }
122
        }
123

UNCOV
124
        const ghost = this.ghostElement;
×
125

UNCOV
126
        const gridRect = this.row.grid.nativeElement.getBoundingClientRect();
×
UNCOV
127
        const rowRect = this.row.nativeElement.getBoundingClientRect();
×
UNCOV
128
        ghost.style.overflow = 'hidden';
×
UNCOV
129
        ghost.style.width = gridRect.width + 'px';
×
UNCOV
130
        ghost.style.height = rowRect.height + 'px';
×
131

UNCOV
132
        ghost.classList.add(ghostBackgroundClass);
×
UNCOV
133
        ghost.classList.remove(rowSelectedClass);
×
134

UNCOV
135
        const ghostCells = ghost.getElementsByClassName(gridCellClass);
×
UNCOV
136
        for (const cell of ghostCells) {
×
UNCOV
137
            cell.classList.remove(cellSelectedClass);
×
UNCOV
138
            cell.classList.remove(cellActiveClass);
×
139
        }
140
    }
141

142
    private _unsubscribe() {
UNCOV
143
        if (this.subscription$ && !this.subscription$.closed) {
×
UNCOV
144
            this.subscription$.unsubscribe();
×
145
        }
146
    }
147

148
    private endDragging() {
UNCOV
149
        this.onTransitionEnd(null);
×
UNCOV
150
        this.row.grid.dragRowID = null;
×
UNCOV
151
        this.row.grid.rowDragging = false;
×
UNCOV
152
        this.row.grid.cdr.detectChanges();
×
UNCOV
153
        this._unsubscribe();
×
154
    }
155

UNCOV
156
    private transitionEndEvent = () => {
×
157
        if (this.ghostElement) {
×
158
            this.ghostElement.removeEventListener('transitionend', this.transitionEndEvent, false);
×
159
        }
160
        this.endDragging();
×
161
    };
162

163
    private get isHierarchicalGrid() {
UNCOV
164
        return this.row.grid.type === 'hierarchical';
×
165
    }
166
}
167

168
/**
169
 * @hidden
170
 */
171
@Directive({
172
    selector: '[igxDragIndicatorIcon]',
173
    standalone: true
174
})
175

176
export class IgxDragIndicatorIconDirective {
2✔
177
    public static ngTemplateContextGuard(_directive: IgxDragIndicatorIconDirective,
178
        context: unknown): context is IgxGridEmptyTemplateContext {
179
        return true;
×
180
    }
181
}
182

183
/**
184
 * @hidden
185
 */
186
@Directive({
187
    selector: '[igxRowDragGhost]',
188
    standalone: true
189
})
190
export class IgxRowDragGhostDirective {
2✔
UNCOV
191
    constructor(public templateRef: TemplateRef<IgxGridRowDragGhostContext>) { }
×
192
    public static ngTemplateContextGuard(_directive: IgxRowDragGhostDirective,
193
        context: unknown): context is IgxGridRowDragGhostContext {
194
        return true;
×
195
    }
196
}
197

198

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