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

atinc / ngx-tethys / d9ae709b-3c27-4b69-b125-b8b80b54f90b

pending completion
d9ae709b-3c27-4b69-b125-b8b80b54f90b

Pull #2757

circleci

mengshuicmq
fix: fix code review
Pull Request #2757: feat(color-picker): color-picker support disabled (#INFR-8645)

98 of 6315 branches covered (1.55%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2392 of 13661 relevant lines covered (17.51%)

83.12 hits per line

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

5.08
/src/slide/slide.service.ts
1
import { ComponentTypeOrTemplateRef, ThyAbstractOverlayRef, ThyAbstractOverlayService } from 'ngx-tethys/core';
2
import { coerceArray } from 'ngx-tethys/util';
3
import { of } from 'rxjs';
4

5
import { Directionality } from '@angular/cdk/bidi';
6
import { coerceElement } from '@angular/cdk/coercion';
7
import { Overlay, OverlayConfig, OverlayRef } from '@angular/cdk/overlay';
8
import { ComponentPortal } from '@angular/cdk/portal';
9
import { Inject, Injectable, Injector, OnDestroy, Optional, StaticProvider } from '@angular/core';
10

11
import { ThySlideContainerComponent } from './slide-container.component';
12
import { ThyInternalSlideRef, ThySlideRef } from './slide-ref.service';
13
import { slideAbstractOverlayOptions, slideDefaultConfigValue, THY_SLIDE_DEFAULT_CONFIG, ThySlideConfig } from './slide.config';
14

15
/**
16
 * @public
17
 * @order 10
1✔
18
 */
19
@Injectable()
×
20
export class ThySlideService extends ThyAbstractOverlayService<ThySlideConfig, ThySlideContainerComponent> implements OnDestroy {
×
21
    private originElementAddActiveClass(config: ThySlideConfig) {
22
        if (config.origin) {
23
            coerceElement<HTMLElement>(config.origin).classList.add(...coerceArray(config.originActiveClass));
24
        }
×
25
    }
×
26

27
    private originElementRemoveActiveClass(config: ThySlideConfig) {
28
        if (config.origin) {
29
            coerceElement<HTMLElement>(config.origin).classList.remove(...coerceArray(config.originActiveClass));
×
30
        }
×
31
    }
32

33
    protected buildOverlayConfig(config: ThySlideConfig): OverlayConfig {
34
        const defaultClasses: string[] = ['thy-slide-overlay-pane', `thy-slide-${config.from}`];
×
35
        const overlayConfig = {
36
            ...this.buildBaseOverlayConfig(config, defaultClasses),
37
            width: config.width
×
38
        };
×
39
        return overlayConfig;
×
40
    }
41

42
    protected attachOverlayContainer(overlay: OverlayRef, config: ThySlideConfig): ThySlideContainerComponent {
×
43
        const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
×
44
        const injector = Injector.create({
×
45
            parent: userInjector || this.injector,
46
            providers: [{ provide: ThySlideConfig, useValue: config }]
47
        });
×
48
        const containerPortal = new ComponentPortal(ThySlideContainerComponent, config.viewContainerRef, injector);
49
        const containerRef = overlay.attach<ThySlideContainerComponent>(containerPortal);
50
        return containerRef.instance;
×
51
    }
×
52

53
    protected createAbstractOverlayRef<T>(
54
        overlayRef: OverlayRef,
55
        containerInstance: ThySlideContainerComponent,
×
56
        config: ThySlideConfig
×
57
    ): ThyAbstractOverlayRef<T, ThySlideContainerComponent, any> {
58
        return new ThyInternalSlideRef(overlayRef, containerInstance, config);
59
    }
60

61
    protected createInjector<T>(
62
        config: ThySlideConfig,
63
        overlayRef: ThyAbstractOverlayRef<T, ThySlideContainerComponent, any>,
64
        containerInstance: ThySlideContainerComponent
×
65
    ): Injector {
66
        const userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
67

×
68
        const injectionTokens: StaticProvider[] = [
×
69
            { provide: ThySlideContainerComponent, useValue: containerInstance },
×
70
            { provide: ThySlideRef, useValue: overlayRef }
×
71
        ];
72

×
73
        if (config.direction && (!userInjector || !userInjector.get<Directionality | null>(Directionality, null))) {
74
            injectionTokens.push({
75
                provide: Directionality,
×
76
                useValue: {
×
77
                    value: config.direction,
78
                    change: of()
79
                }
80
            });
81
        }
82

×
83
        return Injector.create({ parent: userInjector || this.injector, providers: injectionTokens });
×
84
    }
85

×
86
    private overlayIsOpened(config: ThySlideConfig) {
×
87
        const openedOverlay = this.getAbstractOverlayById(config.id);
×
88
        const slideConfig = Object.assign({}, this.defaultConfig, config);
×
89
        if (!slideConfig.disableCloseLatest) {
90
            this.close(openedOverlay);
×
91
        }
92
        return openedOverlay;
93
    }
×
94

95
    constructor(
1✔
96
        overlay: Overlay,
97
        injector: Injector,
98
        @Optional()
99
        @Inject(THY_SLIDE_DEFAULT_CONFIG)
100
        defaultConfig: ThySlideConfig
101
    ) {
1✔
102
        const slideDefaultConfig = Object.assign({}, slideDefaultConfigValue, defaultConfig);
103
        super(slideAbstractOverlayOptions, overlay, injector, slideDefaultConfig);
104
    }
105

106
    /**
107
     * 打开滑动弹出框
108
     */
109
    open<T, TData = unknown, TResult = unknown>(
110
        componentOrTemplateRef: ComponentTypeOrTemplateRef<T>,
111
        config: ThySlideConfig<TData>
112
    ): ThySlideRef<T, TResult> {
113
        if (this.overlayIsOpened(config)) {
114
            return;
115
        }
116
        const slideRef = this.openOverlay<T, TResult>(componentOrTemplateRef, config);
117
        this.originElementAddActiveClass(slideRef.containerInstance.config);
118
        slideRef.afterClosed().subscribe(() => {
119
            this.originElementRemoveActiveClass(slideRef.containerInstance.config);
120
        });
121
        return slideRef;
122
    }
123

124
    ngOnDestroy() {
125
        this.dispose();
126
    }
127
}
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