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

atinc / ngx-tethys / 3033f133-0f0d-43eb-a07d-e1848354018a

07 Mar 2024 01:58AM UTC coverage: 90.58% (-0.02%) from 90.604%
3033f133-0f0d-43eb-a07d-e1848354018a

Pull #3022

circleci

web-flow
feat(schematics): improve schematics for select and custom-select in template #INFR-11735 (#3047)
Pull Request #3022: feat: upgrade ng to 17 #INFR-11427 (#3021)

5422 of 6642 branches covered (81.63%)

Branch coverage included in aggregate %.

328 of 338 new or added lines in 193 files covered. (97.04%)

141 existing lines in 29 files now uncovered.

13502 of 14250 relevant lines covered (94.75%)

982.04 hits per line

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

92.11
/src/nav/nav-item.directive.ts
1
import { Constructor, InputBoolean, MixinBase, mixinUnsubscribe, ThyUnsubscribe } from 'ngx-tethys/core';
2
import { takeUntil } from 'rxjs/operators';
3
import { useHostRenderer } from '@tethys/cdk/dom';
4
import {
5
    AfterViewInit,
6
    ContentChildren,
7
    Directive,
1✔
8
    ElementRef,
9
    forwardRef,
10
    Input,
11
    NgZone,
12
    OnDestroy,
13
    Optional,
1✔
14
    QueryList
15
} from '@angular/core';
158✔
16
import { RouterLinkActive } from '@angular/router';
158✔
17

158✔
18
export type ThyNavLink = '' | 'active';
158✔
19

20
const _MixinBase: Constructor<ThyUnsubscribe> & typeof MixinBase = mixinUnsubscribe(MixinBase);
158✔
21

22
/**
23
 * 导航项
24
 * @name thyNavItem
25
 * @order 20
26
 */
158✔
27
@Directive({
28
    selector: '[thyNavLink],[thyNavItem]',
29
    host: {
158✔
30
        class: 'thy-nav-item',
158✔
31
        '[class.active]': 'thyNavItemActive || thyNavLinkActive',
158✔
32
        '[class.disabled]': 'thyNavItemDisabled'
574✔
33
    },
34
    standalone: true
35
})
36
export class ThyNavItemDirective extends _MixinBase implements AfterViewInit, OnDestroy {
179✔
37
    /**
38
     * 是否激活状态
39
     * @default false
40
     */
41
    @Input()
42
    @InputBoolean()
43
    thyNavItemActive: boolean;
44

941✔
45
    /**
46
     * 已经废弃,请使用 thyNavItemActive
UNCOV
47
     * @deprecated please use thyNavItemActive
×
48
     * @default false
×
49
     */
×
50
    @Input()
51
    @InputBoolean()
52
    thyNavLinkActive: boolean;
28✔
53

21✔
54
    /**
55
     * 是否禁用
56
     * @default false
7✔
57
     */
58
    @Input()
59
    @InputBoolean()
60
    thyNavItemDisabled: boolean;
158✔
61

158✔
62
    /**
63
     * @private
1✔
64
     */
65
    @ContentChildren(forwardRef(() => ThyNavItemDirective), { descendants: true })
66
    links: QueryList<ThyNavItemDirective>;
67

68
    /**
1✔
69
     * @private
70
     */
71
    @ContentChildren(RouterLinkActive, { descendants: true }) routers: QueryList<RouterLinkActive>;
72

2✔
73
    // @HostBinding('attr.href') navLinkHref = 'javascript:;';
74

75
    public offset: {
76
        width: number;
1✔
77
        height: number;
78
        left: number;
79
        top: number;
80
    } = {
1✔
81
        width: 0,
82
        height: 0,
83
        left: 0,
84
        top: 0
1✔
85
    };
86

87
    public content: HTMLElement;
88

1✔
89
    public isActive: boolean;
90

91
    private hostRenderer = useHostRenderer();
92

93
    constructor(public elementRef: ElementRef, @Optional() private routerLinkActive: RouterLinkActive, private ngZone: NgZone) {
94
        super();
95
    }
96

97
    ngAfterViewInit() {
98
        this.setOffset();
99

100
        this.content = this.elementRef.nativeElement.outerHTML;
101

102
        this.ngZone.onStable.pipe(takeUntil(this.ngUnsubscribe$)).subscribe(() => {
103
            this.isActive = this.linkIsActive();
104
        });
105
    }
106

107
    setOffset() {
108
        this.offset = {
109
            width: this.elementRef.nativeElement.offsetWidth,
110
            height: this.elementRef.nativeElement.offsetHeight,
111
            left: this.elementRef.nativeElement.offsetLeft,
112
            top: this.elementRef.nativeElement.offsetTop
113
        };
114
    }
115

116
    linkIsActive() {
117
        return (
118
            this.thyNavItemActive ||
119
            this.thyNavLinkActive ||
120
            (this.routerLinkActive && this.routerLinkActive.isActive) ||
121
            this.routers.some(router => router.isActive) ||
122
            this.links.some(item => item.thyNavItemActive) ||
123
            this.links.some(item => item.thyNavLinkActive)
124
        );
125
    }
126

127
    setNavLinkHidden(value: boolean) {
128
        if (value) {
129
            this.hostRenderer.addClass('thy-nav-item-hidden');
130
        } else {
131
            this.hostRenderer.removeClass('thy-nav-item-hidden');
132
        }
133
    }
134

135
    ngOnDestroy() {
136
        this.ngUnsubscribe$.next();
137
        this.ngUnsubscribe$.complete();
138
    }
139
}
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