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

atinc / ngx-tethys / f1a286ce-ff11-484c-ae71-950dd547bf85

20 May 2025 06:07AM UTC coverage: 90.216% (-0.007%) from 90.223%
f1a286ce-ff11-484c-ae71-950dd547bf85

Pull #3449

circleci

why520crazy
refactor: update @Output to output
Pull Request #3449: refactor(upload): migrate inputs to signal #TINFR-1787

5568 of 6832 branches covered (81.5%)

Branch coverage included in aggregate %.

35 of 36 new or added lines in 3 files covered. (97.22%)

4 existing lines in 3 files now uncovered.

13592 of 14406 relevant lines covered (94.35%)

907.0 hits per line

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

87.18
/src/upload/file-select-base.ts
1
import { isNumber } from 'ngx-tethys/util';
2
import { Directive, ElementRef, Input, NgZone, numberAttribute, inject, Inject, input, OutputEmitterRef } from '@angular/core';
3
import { ThyFileSelectEvent, ThySizeExceedsHandler } from './types';
4
import { THY_UPLOAD_DEFAULT_OPTIONS, ThyUploadConfig } from './upload.config';
5
import { mimeTypeConvert } from './util';
6

7
/**
8
 * @private
9
 */
10
@Directive()
1✔
11
export class FileSelectBaseDirective {
12
    readonly thySizeThreshold = input(this.defaultConfig.sizeThreshold, {
15✔
13
        transform: (inputValue: string | number) => {
15✔
14
            const sizeThreshold = numberAttribute(inputValue);
15✔
15
            if (isNumber(sizeThreshold)) {
16
                return sizeThreshold;
15✔
17
            }
15!
18
            return this.defaultConfig.sizeThreshold;
15✔
19
        }
NEW
20
    });
×
21

22
    readonly thySizeExceedsHandler = input(this.defaultConfig.sizeExceedsHandler, {
23
        transform: (inputValue: ThySizeExceedsHandler) => {
15✔
24
            if (inputValue) {
25
                return inputValue;
14!
26
            }
14✔
27
            return this.defaultConfig.sizeExceedsHandler;
UNCOV
28
        }
×
29
    });
30

31
    /**
15✔
32
     * 指定文件后缀类型(MIME_Map),例如".xls,xlsx","[".doc",".docx"]"
33
     */
19✔
34
    thyAcceptType = input(mimeTypeConvert(this.defaultConfig.acceptType), {
35
        transform: (inputValue: Array<string> | string) => {
36
            return mimeTypeConvert(inputValue);
37
        }
38
    });
4✔
39

3✔
40
    constructor(
1✔
41
        public elementRef: ElementRef,
42
        @Inject(THY_UPLOAD_DEFAULT_OPTIONS) public defaultConfig: ThyUploadConfig
43
    ) {}
44

45
    handleSizeExceeds(event: Event, files: File[]) {
46
        let sizeExceedsFiles = files.filter(item => item.size / 1024 > this.thySizeThreshold());
1✔
47
        if (sizeExceedsFiles.length > 0) {
48
            const sizeExceedContext = {
2✔
49
                files: files,
50
                exceedsFiles: sizeExceedsFiles,
51
                nativeEvent: event,
3✔
52
                sizeThreshold: this.thySizeThreshold()
3!
53
            };
3✔
54
            return this.thySizeExceedsHandler()(sizeExceedContext);
55
        }
3✔
56
        return files;
2✔
57
    }
58

59
    selectFiles(event: Event, files: File[], eventEmitter: OutputEmitterRef<ThyFileSelectEvent>) {
60
        let successFiles: File[] | void = files;
61
        if (this.thySizeThreshold() && this.thySizeThreshold() > 0) {
62
            successFiles = this.handleSizeExceeds(event, files);
1✔
63
        }
64
        if (successFiles) {
65
            eventEmitter.emit({
66
                files: successFiles,
1✔
67
                nativeEvent: event
68
            });
69
        }
70
    }
71
}
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