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

IgniteUI / igniteui-angular / 10094028922

25 Jul 2024 12:23PM CUT coverage: 91.534% (-0.01%) from 91.548%
10094028922

Pull #14587

github

web-flow
Merge 721edf892 into 1f753a2f9
Pull Request #14587: chore(demos): fix type errors, add missing functionality in dock manager

12765 of 14977 branches covered (85.23%)

26024 of 28431 relevant lines covered (91.53%)

32318.97 hits per line

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

89.06
/projects/igniteui-angular/src/lib/grids/moving/moving.drag.directive.ts
1
import { Directive, OnDestroy, Input, ElementRef, ViewContainerRef, NgZone, ChangeDetectorRef, Renderer2 } from '@angular/core';
2
import { IgxDragDirective } from '../../directives/drag-drop/drag-drop.directive';
3
import { Subscription, fromEvent } from 'rxjs';
4
import { PlatformUtil } from '../../core/utils';
5
import { IgxColumnMovingService } from './moving.service';
6
import { ColumnType } from '../common/grid.interface';
7

8
/**
9
 * @hidden
10
 * @internal
11
 */
12
@Directive({
13
    selector: '[igxColumnMovingDrag]',
14
    standalone: true
15
})
16
export class IgxColumnMovingDragDirective extends IgxDragDirective implements OnDestroy {
2✔
17

18
    @Input('igxColumnMovingDrag')
19
    public column: ColumnType;
20

21
    public get draggable(): boolean {
22
        return this.column && (this.column.grid.moving || (this.column.groupable && !this.column.columnGroup));
110✔
23
    }
24

25
    public get icon(): HTMLElement {
26
        return this.cms.icon;
10✔
27
    }
28

29
    private subscription$: Subscription;
30
    private _ghostClass = 'igx-grid__drag-ghost-image';
27,340✔
31
    private ghostImgIconClass = 'igx-grid__drag-ghost-image-icon';
27,340✔
32
    private ghostImgIconGroupClass = 'igx-grid__drag-ghost-image-icon-group';
27,340✔
33
    private columnSelectedClass = 'igx-grid-th--selected';
27,340✔
34

35
    constructor(
36
        element: ElementRef<HTMLElement>,
37
        viewContainer: ViewContainerRef,
38
        zone: NgZone,
39
        renderer: Renderer2,
40
        cdr: ChangeDetectorRef,
41
        private cms: IgxColumnMovingService,
27,340✔
42
        _platformUtil: PlatformUtil,
43
    ) {
44
        super(cdr, element, viewContainer, zone, renderer, _platformUtil);
27,340✔
45
        this.ghostClass = this._ghostClass;
27,340✔
46
    }
47

48
    public override ngOnDestroy() {
49
        this._unsubscribe();
27,227✔
50
        super.ngOnDestroy();
27,227✔
51
    }
52

53
    public onEscape(event: Event) {
54
        this.cms.cancelDrop = true;
×
55
        this.onPointerUp(event);
×
56
    }
57

58
    public override onPointerDown(event: Event) {
59
        if (!this.draggable || (event.target as HTMLElement).getAttribute('draggable') === 'false') {
110✔
60
            return;
50✔
61
        }
62

63
        super.onPointerDown(event);
60✔
64
    }
65

66
    public override onPointerMove(event: Event) {
67
        if (this._clicked && !this._dragStarted) {
118✔
68
            this._removeOnDestroy = false;
57✔
69
            this.cms.column = this.column;
57✔
70
            this.column.grid.cdr.detectChanges();
57✔
71

72
            const movingStartArgs = {
57✔
73
                source: this.column
74
            };
75
            this.column.grid.columnMovingStart.emit(movingStartArgs);
57✔
76

77
            this.subscription$ = fromEvent(this.column.grid.document.defaultView, 'keydown').subscribe((ev: KeyboardEvent) => {
57✔
78
                if (ev.key === this.platformUtil.KEYMAP.ESCAPE) {
×
79
                    this.onEscape(ev);
×
80
                }
81
            });
82
        }
83

84
        super.onPointerMove(event);
118✔
85
        if (this._dragStarted && this.ghostElement && !this.cms.column) {
118!
86
            this.cms.column = this.column;
×
87
            this.column.grid.cdr.detectChanges();
×
88
        }
89

90
        if (this.cms.column) {
118✔
91
            const args = {
118✔
92
                source: this.column,
93
                cancel: false
94
            };
95
            this.column.grid.columnMoving.emit(args);
118✔
96

97
            if (args.cancel) {
118!
98
                this.onEscape(event);
×
99
            }
100
        }
101
    }
102

103
    public override onPointerUp(event: Event) {
104
        // Run it explicitly inside the zone because sometimes onPointerUp executes after the code below.
105
        this.zone.run(() => {
210✔
106
            super.onPointerUp(event);
210✔
107
            this.cms.column = null;
210✔
108
            this.column.grid.cdr.detectChanges();
210✔
109
        });
110

111
        this._unsubscribe();
210✔
112
    }
113

114
    protected override createGhost(pageX: number, pageY: number) {
115
        super.createGhost(pageX, pageY);
57✔
116

117
        this.ghostElement.style.height = null;
57✔
118
        this.ghostElement.style.minWidth = null;
57✔
119
        this.ghostElement.style.flexBasis = null;
57✔
120
        this.ghostElement.style.position = null;
57✔
121

122
        this.ghostElement.classList.remove(this.columnSelectedClass);
57✔
123

124
        const icon = document.createElement('i');
57✔
125
        const text = document.createTextNode('block');
57✔
126
        icon.appendChild(text);
57✔
127

128
        icon.classList.add('material-icons');
57✔
129
        this.cms.icon = icon;
57✔
130

131
        if (!this.column.columnGroup) {
57✔
132
            icon.classList.add(this.ghostImgIconClass);
47✔
133

134
            this.ghostElement.insertBefore(icon, this.ghostElement.firstElementChild);
47✔
135

136
            this.ghostLeft = this._ghostStartX = pageX - ((this.ghostElement.getBoundingClientRect().width / 3) * 2);
47✔
137
            this.ghostTop = this._ghostStartY = pageY - ((this.ghostElement.getBoundingClientRect().height / 3) * 2);
47✔
138
        } else {
139
            this.ghostElement.insertBefore(icon, this.ghostElement.childNodes[0]);
10✔
140

141
            icon.classList.add(this.ghostImgIconGroupClass);
10✔
142
            this.ghostElement.children[0].style.paddingLeft = '0px';
10✔
143

144
            this.ghostLeft = this._ghostStartX = pageX - ((this.ghostElement.getBoundingClientRect().width / 3) * 2);
10✔
145
            this.ghostTop = this._ghostStartY = pageY - ((this.ghostElement.getBoundingClientRect().height / 3) * 2);
10✔
146
        }
147
    }
148

149
    private _unsubscribe() {
150
        if (this.subscription$) {
27,437✔
151
            this.subscription$.unsubscribe();
57✔
152
            this.subscription$ = null;
57✔
153
        }
154
    }
155
}
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