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

CenterForOpenScience / ember-osf-web / 16684725173

01 Aug 2025 08:39PM UTC coverage: 67.218% (+0.009%) from 67.209%
16684725173

Pull #2607

github

web-flow
Merge 113b60ca0 into 233ec4fa0
Pull Request #2607: Feature/pbs 25 12

3279 of 5350 branches covered (61.29%)

Branch coverage included in aggregate %.

19 of 26 new or added lines in 7 files covered. (73.08%)

3 existing lines in 2 files now uncovered.

8552 of 12251 relevant lines covered (69.81%)

184.26 hits per line

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

0.0
/app/preprints/-components/submit/file/upload-file/component.ts
1
import { action } from '@ember/object';
2
import Component from '@glimmer/component';
3
import { inject as service } from '@ember/service';
4
import Intl from 'ember-intl/services/intl';
5
import Toast from 'ember-toastr/services/toast';
6
import PreprintModel from 'ember-osf-web/models/preprint';
7
import PreprintStateMachine from 'ember-osf-web/preprints/-components/submit/preprint-state-machine/component';
8
import FileModel from 'ember-osf-web/models/file';
9
import { task } from 'ember-concurrency';
10
import { waitFor } from '@ember/test-waiters';
11
import { taskFor } from 'ember-concurrency-ts';
12
import { tracked } from '@glimmer/tracking';
13

14
interface PreprintUploadArgs {
15
    manager: PreprintStateMachine;
16
    preprint: PreprintModel;
17
    allowVersioning: boolean;
18
    isEdit: boolean;
19
    validate: (_: FileModel) => {};
20
    clickableElementId: string;
21
    dragEnter: () => {};
22
    dragLeave: () => {};
23
    dragOver: () => {};
24
}
25

26
export default class PreprintUpload extends Component<PreprintUploadArgs> {
27
    @service intl!: Intl;
28
    @service toast!: Toast;
29
    url?: URL;
30
    rootFolder?: FileModel;
31
    primaryFile: FileModel | undefined;
32
    @tracked isUploadFileDisplayed = false;
×
NEW
33
    @tracked isEnabled = false;
×
34

35
    constructor(owner: unknown, args: any) {
36
        super(owner, args);
×
37

38
        taskFor(this.prepUrl).perform();
×
39
    }
40

41
    get clickableElementSelectors() {
42
        if (this.args.clickableElementId) {
×
43
            return [`#${this.args.clickableElementId}`];
×
44
        }
45
        return [];
×
46
    }
47

48
    get dropzoneOptions() {
49
        const uploadLimit = 1;
×
50
        return {
×
51
            createImageThumbnails: false,
52
            method: 'PUT',
53
            withCredentials: true,
54
            preventMultipleFiles: true,
55
            acceptDirectories: false,
56
            autoProcessQueue: true,
57
            autoQueue: true,
58
            parallelUploads: uploadLimit,
59
            maxFilesize: 10000000,
60
            timeout: null,
61
        };
62
    }
63

64
    @task
65
    @waitFor
66
    async prepUrl() {
67
        let urlString: string;
68
        const theFiles = await this.args.preprint.files;
×
69
        const rootFolder = await theFiles.firstObject!.rootFolder;
×
70
        if(this.args.isEdit) {
×
71
            this.primaryFile = await this.args.preprint.primaryFile;
×
72
            urlString = this.primaryFile?.links?.upload as string;
×
73
        } else {
74
            urlString = await theFiles.firstObject!.links.upload as string;
×
75
        }
76

77
        this.url = new URL( urlString );
×
78
        this.rootFolder = rootFolder;
×
NEW
79
        this.isEnabled = true;
×
80
    }
81

82
    @action
83
    buildUrl(files: any[]): string {
84
        const { name } = files[0];
×
85
        this.url!.searchParams.append('kind', 'file');
×
86
        if(!this.args.isEdit) {
×
87
            this.url!.searchParams.append('name', name);
×
88
        }
89
        return this.url!.toString();
×
90
    }
91

92
    @task
93
    @waitFor
94
    async success(_: any, __:any, file: FileModel): Promise<void> {
95
        if (this.args.isEdit) {
×
96
            if (file.name !== this.primaryFile?.name) {
×
97
                await this.primaryFile?.rename(file.name);
×
98
            }
99
        } else {
100
            const primaryFile = await this.rootFolder!.files;
×
101
            this.args.manager.preprint.set('primaryFile', primaryFile.firstObject);
×
102
            await this.args.manager.preprint.save();
×
103
        }
104
        this.args.validate(file);
×
105
    }
106

107
    @task
108
    @waitFor
109
    async preUpload(): Promise<void> {
110
        this.isUploadFileDisplayed = true;
×
111
    }
112

113
}
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