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

CenterForOpenScience / ember-osf-web / 12832262567

17 Jan 2025 03:43PM UTC coverage: 68.238% (+3.3%) from 64.94%
12832262567

Pull #2447

github

web-flow
Merge 08b0aa590 into 8621f29d7
Pull Request #2447: [ENG-6813] FE Reference PR for Preprints DOI Versioning

2960 of 4717 branches covered (62.75%)

Branch coverage included in aggregate %.

202 of 268 new or added lines in 13 files covered. (75.37%)

94 existing lines in 2 files now uncovered.

7417 of 10490 relevant lines covered (70.71%)

203.5 hits per line

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

46.12
/app/preprints/-components/submit/preprint-state-machine/component.ts
1
import Component from '@glimmer/component';
2
import PreprintModel, { PreprintDataLinksEnum, PreprintPreregLinksEnum } from 'ember-osf-web/models/preprint';
3
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
4
import Store from '@ember-data/store';
5
import { inject as service } from '@ember/service';
6
import RouterService from '@ember/routing/router-service';
7
import { tracked } from '@glimmer/tracking';
8
import { action } from '@ember/object';
9
import Intl from 'ember-intl/services/intl';
10
import { task } from 'ember-concurrency';
11
import { waitFor } from '@ember/test-waiters';
12
import FileModel from 'ember-osf-web/models/file';
13
import Toast from 'ember-toastr/services/toast';
14
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';
15
import { Permission } from 'ember-osf-web/models/osf-model';
16
import { ReviewsState } from 'ember-osf-web/models/provider';
17
import InstitutionModel from 'ember-osf-web/models/institution';
18
import CurrentUserService from 'ember-osf-web/services/current-user';
19
import { ReviewActionTrigger } from 'ember-osf-web/models/review-action';
20

21
export enum PreprintStatusTypeEnum {
22
    titleAndAbstract = 'titleAndAbstract',
23
    file = 'file',
24
    metadata = 'metadata',
25
    authorAssertions = 'authorAssertions',
26
    supplements = 'supplements',
27
    review = 'review',
28
}
29

30
/**
31
 * The State Machine Args
32
 */
33
interface StateMachineArgs {
34
    provider: PreprintProviderModel;
35
    preprint: PreprintModel;
36
    setPageDirty: () => void;
37
    resetPageDirty: () => void;
38
    newVersion?: boolean;
39
}
40

41
/**
42
 * The Preprint State Machine
43
 */
44
export default class PreprintStateMachine extends Component<StateMachineArgs>{
45
    @service store!: Store;
46
    @service router!: RouterService;
47
    @service intl!: Intl;
48
    @service toast!: Toast;
49
    @service currentUser!: CurrentUserService;
50

51
    titleAndAbstractValidation = false;
10✔
52
    fileValidation = false;
10✔
53
    metadataValidation = false;
10✔
54
    authorAssertionValidation = false;
10✔
55
    supplementValidation = false;
10✔
56
    @tracked isNextButtonDisabled = true;
5✔
57
    @tracked isPreviousButtonDisabled = true;
10✔
58
    @tracked isDeleteButtonDisplayed = false;
1✔
59

60
    provider = this.args.provider;
10✔
61
    @tracked preprint: PreprintModel;
62
    displayAuthorAssertions = false;
10✔
63
    @tracked statusFlowIndex = 1;
10✔
64
    @tracked isEditFlow = false;
5✔
65
    @tracked displayFileUploadStep = true;
1✔
66
    @tracked isNewVersionFlow = this.args.newVersion;
10✔
67
    affiliatedInstitutions = [] as InstitutionModel[];
10✔
68

69
    constructor(owner: unknown, args: StateMachineArgs) {
70
        super(owner, args);
10✔
71

72
        if (this.args.newVersion) {
10✔
73
            this.preprint = this.args.preprint;
1✔
74
            return;
1✔
75
        }
76
        if (this.args.preprint) {
9✔
77
            this.preprint = this.args.preprint;
5✔
78
            this.setValidationForEditFlow();
5✔
79
            this.isEditFlow = true;
5✔
80
            if (this.args.preprint.reviewsState === ReviewsState.REJECTED) {
5✔
81
                this.displayFileUploadStep = true;
2✔
82
            } else {
83
                this.displayFileUploadStep = false;
3✔
84
            }
85
            this.isDeleteButtonDisplayed = false;
5✔
86
        } else {
87
            this.isDeleteButtonDisplayed = true;
4✔
88
            this.displayFileUploadStep = true;
4✔
89
            this.preprint = this.store.createRecord('preprint', {
4✔
90
                provider: this.provider,
91
            });
92
        }
93

94
        this.displayAuthorAssertions = this.provider.assertionsEnabled;
9✔
95
    }
96

97
    private setValidationForEditFlow(): void {
98
        this.titleAndAbstractValidation = true;
5✔
99
        this.fileValidation = true;
5✔
100
        this.metadataValidation = true;
5✔
101
        this.authorAssertionValidation = true;
5✔
102
        this.supplementValidation = true;
5✔
103
        this.isNextButtonDisabled = false;
5✔
104
    }
105

106
    /**
107
     * Callback for the action-flow component
108
     */
109
    @task
110
    @waitFor
111
    public async onDelete(): Promise<void> {
UNCOV
112
        await this.preprint.deleteRecord();
×
UNCOV
113
        await this.router.transitionTo('preprints.discover', this.provider.id);
×
114
    }
115

116
    /**
117
     * Callback for the action-flow component
118
     */
119
    @task
120
    @waitFor
121
    public async onCancel(): Promise<void> {
UNCOV
122
        await this.router.transitionTo('preprints.detail', this.provider.id, this.preprint.id);
×
123
    }
124

125
    /**
126
     * saveOnStep
127
     *
128
     * @description Abstracted method to save after each step
129
     */
130
    private async saveOnStep(): Promise<void> {
131
        try {
×
UNCOV
132
            await this.preprint.save();
×
UNCOV
133
            this.toast.success(
×
134
                this.intl.t('preprints.submit.action-flow.success',
135
                    {
136
                        singularPreprintWord: this.provider.documentType.singular,
137
                    }),
138
            );
139
        } catch (e) {
UNCOV
140
            const errorMessage = this.intl.t('preprints.submit.action-flow.error',
×
141
                {
142
                    singularPreprintWord: this.provider.documentType.singular,
143
                });
UNCOV
144
            this.toast.error(errorMessage);
×
145
            captureException(e, { errorMessage });
×
146
        }
UNCOV
147
        this.statusFlowIndex++;
×
UNCOV
148
        this.determinePreviousButtonState();
×
149
    }
150

151
    /**
152
     * determinePreviousButtonState
153
     *
154
     * @description Abstracted method to determine the state of the previous button
155
     *
156
     * @returns void
157
     */
158
    private determinePreviousButtonState(): void {
UNCOV
159
        this.isPreviousButtonDisabled = this.statusFlowIndex === 1;
×
160
    }
161

162
    /**
163
     * Callback for the action-flow component
164
     */
165
    @task
166
    @waitFor
167
    public async onSubmit(): Promise<void> {
168
        this.args.resetPageDirty();
×
169

NEW
170
        if (this.isNewVersionFlow) {
×
NEW
171
            try {
×
NEW
172
                await this.preprint.save();
×
NEW
173
                let toastMessage = this.intl.t('preprints.submit.new-version.success');
×
174

NEW
175
                if (this.provider.reviewsWorkflow) {
×
NEW
176
                    toastMessage = this.intl.t('preprints.submit.new-version.success-review');
×
NEW
177
                    const reviewAction = this.store.createRecord('review-action', {
×
178
                        actionTrigger: ReviewActionTrigger.Submit,
179
                        target: this.preprint,
180
                    });
NEW
181
                    await reviewAction.save();
×
182
                } else {
NEW
183
                    this.preprint.isPublished = true;
×
NEW
184
                    await this.preprint.save();
×
185
                }
NEW
186
                this.toast.success(toastMessage);
×
NEW
187
                this.router.transitionTo('preprints.detail', this.provider.id, this.preprint.id);
×
188
            } catch (e) {
NEW
189
                const errorTitle = this.intl.t('preprints.submit.new-version.error.title');
×
NEW
190
                const errorMessage = getApiErrorMessage(e);
×
NEW
191
                captureException(e, { errorMessage });
×
NEW
192
                this.toast.error(errorMessage, errorTitle);
×
193
            }
NEW
194
            return;
×
195
        }
196

197
        if (this.preprint.reviewsState === ReviewsState.ACCEPTED) {
×
198
            await this.preprint.save();
×
199
        } else if (this.provider.reviewsWorkflow) {
×
UNCOV
200
            const reviewAction = this.store.createRecord('review-action', {
×
201
                actionTrigger: ReviewActionTrigger.Submit,
202
                target: this.preprint,
203
            });
204
            await reviewAction.save();
×
205
        } else {
UNCOV
206
            this.preprint.isPublished = true;
×
UNCOV
207
            await this.preprint.save();
×
208
        }
209

UNCOV
210
        await this.preprint.reload();
×
UNCOV
211
        await this.router.transitionTo('preprints.detail', this.provider.id, this.preprint.id);
×
212
    }
213

214
    /**
215
     * Callback for the action-flow component
216
     */
217
    @task
218
    @waitFor
219
    public async onNext(): Promise<void> {
NEW
220
        if (this.isNewVersionFlow) {
×
221
            // no need to save original or new version on new version flow
NEW
222
            this.statusFlowIndex++;
×
NEW
223
            return;
×
224
        }
225

UNCOV
226
        if (this.isEditFlow) {
×
227
            this.args.resetPageDirty();
×
228
        } else {
229
            this.args.setPageDirty();
×
230
        }
231
        this.isNextButtonDisabled = true;
×
232

UNCOV
233
        if (
×
234
            this.statusFlowIndex === this.getTypeIndex(PreprintStatusTypeEnum.titleAndAbstract) &&
×
235
            this.titleAndAbstractValidation
236
        ) {
237
            await this.saveOnStep();
×
NEW
238
            if (this.displayFileUploadStep) {
×
NEW
239
                await this.preprint.files;
×
NEW
240
                this.isNextButtonDisabled = !this.fileValidation;
×
241
            } else {
NEW
242
                this.isNextButtonDisabled = !this.metadataValidation;
×
243
            }
UNCOV
244
            return;
×
UNCOV
245
        } else if (
×
246
            this.statusFlowIndex === this.getTypeIndex(PreprintStatusTypeEnum.file) &&
×
247
            this.fileValidation
248
        ) {
249
            await this.saveOnStep();
×
250
            this.isNextButtonDisabled = !this.metadataValidation;
×
UNCOV
251
            return;
×
UNCOV
252
        } else if (
×
253
            this.statusFlowIndex === this.getTypeIndex(PreprintStatusTypeEnum.metadata) &&
×
254
            this.metadataValidation
255
        ) {
256
            await this.saveOnStep();
×
257

258
            if (this.preprint.currentUserPermissions.includes(Permission.Write)) {
×
UNCOV
259
                try {
×
UNCOV
260
                    await this.preprint.updateM2MRelationship(
×
261
                        'affiliatedInstitutions',
262
                        this.affiliatedInstitutions,
263
                    );
UNCOV
264
                    await this.preprint.reload();
×
265
                } catch (e) {
266
                    // eslint-disable-next-line max-len
267
                    const errorMessage = this.intl.t('preprints.submit.step-metadata.institutions.save-institutions-error');
×
268
                    captureException(e, { errorMessage });
×
UNCOV
269
                    this.toast.error(getApiErrorMessage(e), errorMessage);
×
UNCOV
270
                    throw e;
×
271
                }
272
            }
273

UNCOV
274
            if (this.displayAuthorAssertions) {
×
275
                this.isNextButtonDisabled = !this.authorAssertionValidation;
×
276
            } else {
277
                this.isNextButtonDisabled = !this.supplementValidation;
×
278
            }
UNCOV
279
            return;
×
UNCOV
280
        } else if (
×
281
            this.statusFlowIndex === this.getTypeIndex(PreprintStatusTypeEnum.authorAssertions) &&
×
282
            this.authorAssertionValidation
283
        ) {
284
            await this.saveOnStep();
×
285
            this.isNextButtonDisabled = !this.supplementValidation;
×
UNCOV
286
            return;
×
UNCOV
287
        } else if (
×
288
            this.statusFlowIndex === this.getTypeIndex(PreprintStatusTypeEnum.supplements) &&
×
289
            this.supplementValidation
290
        ) {
UNCOV
291
            await this.saveOnStep();
×
UNCOV
292
            return;
×
293
        }
294
    }
295

296
    private setPageDirty(): void {
297
        if (this.isEditFlow) {
1!
UNCOV
298
            this.args.setPageDirty();
×
299
        }
300
    }
301

302
    /**
303
     * Callback for the action-flow component
304
     */
305
    @action
306
    public validateTitleAndAbstract(valid: boolean): void {
307
        this.titleAndAbstractValidation = valid;
×
UNCOV
308
        this.isNextButtonDisabled = !valid;
×
UNCOV
309
        this.setPageDirty();
×
310
    }
311

312
    /**
313
     * Callback for the action-flow component
314
     */
315
    @action
316
    public validateFile(valid: boolean): void {
317
        this.fileValidation = valid;
1✔
318
        this.isNextButtonDisabled = !valid;
1✔
319
        this.setPageDirty();
1✔
320
    }
321

322
    /**
323
     * Callback for the action-flow component
324
     */
325
    @action
326
    public validateMetadata(valid: boolean): void {
327
        this.metadataValidation = valid;
×
UNCOV
328
        this.isNextButtonDisabled = !valid;
×
UNCOV
329
        this.setPageDirty();
×
330
    }
331

332
    /**
333
     * Callback for the action-flow component
334
     */
335
    @action
336
    public validateAuthorAssertions(valid: boolean): void {
UNCOV
337
        if (this.preprint.hasCoi === false) {
×
338
            this.preprint.conflictOfInterestStatement = null;
×
339
        }
UNCOV
340
        if (this.preprint.hasDataLinks === PreprintDataLinksEnum.NOT_APPLICABLE) {
×
341
            this.preprint.whyNoData = null;
×
342
        }
UNCOV
343
        if (this.preprint.hasPreregLinks === PreprintPreregLinksEnum.NOT_APPLICABLE) {
×
344
            this.preprint.whyNoPrereg = null;
×
345
        }
346
        this.authorAssertionValidation = valid;
×
UNCOV
347
        this.isNextButtonDisabled = !valid;
×
UNCOV
348
        this.setPageDirty();
×
349
    }
350

351
    /**
352
     * Callback for the action-flow component
353
     */
354
    @action
355
    public validateSupplements(valid: boolean): void {
356
        this.supplementValidation = valid;
×
UNCOV
357
        this.isNextButtonDisabled = !valid;
×
UNCOV
358
        this.setPageDirty();
×
359
    }
360

361
    @action
362
    public onPrevious(): void {
UNCOV
363
        if (this.statusFlowIndex > 1) {
×
364
            this.statusFlowIndex--;
×
365
        }
UNCOV
366
        this.determinePreviousButtonState();
×
UNCOV
367
        this.isNextButtonDisabled = false;
×
368
    }
369

370
    @action
371
    public onClickStep(type: string): void {
UNCOV
372
        this.isNextButtonDisabled = !this.isFinished(type);
×
UNCOV
373
        if (
×
374
            type === PreprintStatusTypeEnum.titleAndAbstract &&
×
375
            this.statusFlowIndex > this.getTypeIndex(type)
376
        ) {
UNCOV
377
            this.statusFlowIndex = this.getTypeIndex(type);
×
UNCOV
378
        } else if (
×
379
            type === PreprintStatusTypeEnum.file &&
×
380
            this.statusFlowIndex > this.getTypeIndex(type)
381
        ) {
UNCOV
382
            this.statusFlowIndex = this.getTypeIndex(type);
×
UNCOV
383
        } else if (
×
384
            type === PreprintStatusTypeEnum.metadata &&
×
385
            this.statusFlowIndex > this.getTypeIndex(type)
386
        ) {
UNCOV
387
            this.statusFlowIndex = this.getTypeIndex(type);
×
UNCOV
388
        } else if (
×
389
            type === PreprintStatusTypeEnum.authorAssertions &&
×
390
            this.statusFlowIndex > this.getTypeIndex(type) &&
391
            this.displayAuthorAssertions
392
        ) {
UNCOV
393
            this.statusFlowIndex = this.getTypeIndex(type);
×
UNCOV
394
        } else if (
×
395
            type === PreprintStatusTypeEnum.supplements &&
×
396
            this.statusFlowIndex > this.getTypeIndex(type)
397
        ) {
UNCOV
398
            this.statusFlowIndex = this.getTypeIndex(type);
×
UNCOV
399
        } else if (
×
400
            type === PreprintStatusTypeEnum.review &&
×
401
            this.statusFlowIndex > this.getTypeIndex(type)
402
        ) {
UNCOV
403
            this.statusFlowIndex = this.getTypeIndex(type);
×
404
        }
405

UNCOV
406
        this.determinePreviousButtonState();
×
407
    }
408

409
    @action
410
    public isSelected(type: string): boolean {
411
        if (
232✔
412
            type === PreprintStatusTypeEnum.titleAndAbstract &&
270✔
413
            this.getTypeIndex(type) === this.statusFlowIndex
414
        ) {
415
            return true;
36✔
416
        } else if (
196✔
417
            type === PreprintStatusTypeEnum.file &&
231✔
418
            this.getTypeIndex(type) === this.statusFlowIndex
419
        ) {
420
            return true;
8✔
421
        } else if (
188!
422
            type === PreprintStatusTypeEnum.metadata &&
226✔
423
            this.getTypeIndex(type) === this.statusFlowIndex
424
        ) {
UNCOV
425
            return true;
×
426
        } else if (
188!
427
            type === PreprintStatusTypeEnum.authorAssertions &&
217!
428
            this.getTypeIndex(type) === this.statusFlowIndex &&
429
            this.displayAuthorAssertions
430
        ) {
UNCOV
431
            return true;
×
432
        } else if (
188!
433
            type === PreprintStatusTypeEnum.supplements &&
226✔
434
            this.getTypeIndex(type) === this.statusFlowIndex
435
        ) {
UNCOV
436
            return true;
×
437
        } else if (
188!
438
            type === PreprintStatusTypeEnum.review &&
242✔
439
            this.getTypeIndex(type) === this.statusFlowIndex
440
        ) {
441
            return true;
×
442
        } else {
443
            return false;
188✔
444
        }
445
    }
446

447
    @action
448
    public getAnalytics(type: string): string {
UNCOV
449
        return this.intl.t('preprints.submit.data-analytics', {statusType: this.getStatusTitle(type)  } );
×
450
    }
451

452

453
    @action
454
    public isDisabled(type: string): boolean {
UNCOV
455
        if (
×
456
            type === PreprintStatusTypeEnum.titleAndAbstract &&
×
457
            this.getTypeIndex(type) === this.statusFlowIndex
458
        ) {
UNCOV
459
            return true;
×
UNCOV
460
        } else if (
×
461
            type === PreprintStatusTypeEnum.file &&
×
462
            this.getTypeIndex(type) === this.statusFlowIndex
463
        ) {
UNCOV
464
            return true;
×
UNCOV
465
        } else if (
×
466
            type === PreprintStatusTypeEnum.metadata &&
×
467
            this.getTypeIndex(type) === this.statusFlowIndex
468
        ) {
UNCOV
469
            return true;
×
UNCOV
470
        } else if (
×
471
            type === PreprintStatusTypeEnum.authorAssertions &&
×
472
            this.getTypeIndex(type) === this.statusFlowIndex &&
473
            this.displayAuthorAssertions
474
        ) {
UNCOV
475
            return true;
×
UNCOV
476
        } else if (
×
477
            type === PreprintStatusTypeEnum.supplements &&
×
478
            this.getTypeIndex(type) === this.statusFlowIndex
479
        ) {
UNCOV
480
            return true;
×
UNCOV
481
        } else if (
×
482
            type === PreprintStatusTypeEnum.review &&
×
483
            this.getTypeIndex(type) === this.statusFlowIndex
484
        ) {
485
            return true;
×
486
        } else {
UNCOV
487
            return false;
×
488
        }
489
    }
490

491
    private getTypeIndex(type: string): number {
492
        if (this.isNewVersionFlow) {
418✔
493
            if (type === PreprintStatusTypeEnum.file) {
37✔
494
                return 1;
12✔
495
            } else if (type === PreprintStatusTypeEnum.review) {
25✔
496
                return 2;
17✔
497
            } else {
498
                return 0;
8✔
499
            }
500
        }
501

502
        if (this.displayFileUploadStep) {
381✔
503
            if (type === PreprintStatusTypeEnum.titleAndAbstract) {
268✔
504
                return 1;
36✔
505
            } else if (type === PreprintStatusTypeEnum.file) {
232✔
506
                return 2;
48✔
507
            } else if (type === PreprintStatusTypeEnum.metadata) {
184✔
508
                return 3;
48✔
509
            } else if (type === PreprintStatusTypeEnum.authorAssertions) {
136✔
510
                return 4;
34✔
511
            } else if (type === PreprintStatusTypeEnum.supplements && this.displayAuthorAssertions) {
102✔
512
                return 5;
32✔
513
            } else if (type === PreprintStatusTypeEnum.supplements && !this.displayAuthorAssertions) {
70✔
514
                return 4;
16✔
515
            } else if (type === PreprintStatusTypeEnum.review && this.displayAuthorAssertions) {
54✔
516
                return 6;
36✔
517
            } else if (type === PreprintStatusTypeEnum.review && !this.displayAuthorAssertions) {
18!
518
                return 5;
18✔
519
            } else {
NEW
520
                return 0;
×
521
            }
522
        } else {
523
            if (type === PreprintStatusTypeEnum.titleAndAbstract) {
113✔
524
                return 1;
18✔
525
            } else if (type === PreprintStatusTypeEnum.metadata) {
95✔
526
                return 2;
24✔
527
            } else if (type === PreprintStatusTypeEnum.authorAssertions) {
71✔
528
                return 3;
17✔
529
            } else if (type === PreprintStatusTypeEnum.supplements && this.displayAuthorAssertions) {
54✔
530
                return 4;
16✔
531
            } else if (type === PreprintStatusTypeEnum.supplements && !this.displayAuthorAssertions) {
38✔
532
                return 3;
8✔
533
            } else if (type === PreprintStatusTypeEnum.review && this.displayAuthorAssertions) {
30✔
534
                return 5;
18✔
535
            } else if (type === PreprintStatusTypeEnum.review && !this.displayAuthorAssertions) {
12✔
536
                return 4;
9✔
537
            } else {
538
                return 0;
3✔
539
            }
540
        }
541
    }
542

543
    @action
544
    public isFinished(type: string): boolean {
545
        if (this.displayAuthorAssertions && this.statusFlowIndex > this.getTypeIndex(type)) {
93!
546
            return true;
×
547
        } else if (!this.displayAuthorAssertions && this.statusFlowIndex > this.getTypeIndex(type)) {
93!
548
            return true;
×
549
        } else if (this.statusFlowIndex > this.getTypeIndex(type)) {
93!
550
            return true;
×
551
        } else {
552
            return false;
93✔
553
        }
554
    }
555

556
    @action
557
    public getStatusTitle(type: string): string {
558
        switch (type) {
52!
559
        case PreprintStatusTypeEnum.titleAndAbstract:
560
            return this.intl.t('preprints.submit.status-flow.step-title-and-abstract');
9✔
561
        case PreprintStatusTypeEnum.file:
562
            return this.intl.t('preprints.submit.status-flow.step-file');
8✔
563
        case PreprintStatusTypeEnum.metadata:
564
            return this.intl.t('preprints.submit.status-flow.step-metadata');
9✔
565
        case PreprintStatusTypeEnum.authorAssertions:
566
            return this.intl.t('preprints.submit.status-flow.step-author-assertions');
6✔
567
        case PreprintStatusTypeEnum.supplements:
568
            return this.intl.t('preprints.submit.status-flow.step-supplements');
9✔
569
        case PreprintStatusTypeEnum.review:
570
            return this.intl.t('preprints.submit.status-flow.step-review');
11✔
571
        default:
UNCOV
572
            return '';
×
573
        }
574
    }
575

576
    @action
577
    public getFaIcon(type: string): string {
578
        if (this.isSelected(type)) {
52✔
579
            return 'dot-circle';
11✔
580
        } else if (this.isFinished(type)) {
41!
581
            return 'check-circle';
×
582
        } else {
583
            return 'circle';
41✔
584
        }
585
    }
586

587
    /**
588
     * shoulddisplayStatusType
589
     *
590
     * @description Determines if the status type should be displayed
591
     *
592
     * @returns boolean
593
     */
594
    public shouldDisplayStatusType(type: string): boolean{
595
        if (this.isNewVersionFlow) {
66✔
596
            if (type === PreprintStatusTypeEnum.file) {
12✔
597
                return true;
2✔
598
            } else if (type === PreprintStatusTypeEnum.review) {
10✔
599
                return true;
2✔
600
            } else {
601
                return false;
8✔
602
            }
603
        }
604

605
        if (type === PreprintStatusTypeEnum.file) {
54✔
606
            return this.displayFileUploadStep;
9✔
607
        } else if (type === PreprintStatusTypeEnum.authorAssertions) {
45✔
608
            return this.displayAuthorAssertions;
9✔
609
        }
610
        return true;
36✔
611
    }
612

613
    /**
614
     * getTitleAndAbstractType
615
     *
616
     * @description Provides the enum type to limit strings in the hbs files
617
     *
618
     * @returns strings
619
     */
620
    public get getTitleAndAbstractType(): string {
621
        return PreprintStatusTypeEnum.titleAndAbstract;
10✔
622
    }
623

624
    /**
625
     * getFileType
626
     *
627
     * @description Provides the enum type to limit strings in the hbs files
628
     *
629
     * @returns strings
630
     */
631
    public get getFileType(): string {
632
        return PreprintStatusTypeEnum.file;
10✔
633
    }
634

635
    /**
636
     * getMetadataType
637
     *
638
     * @description Provides the enum type to limit strings in the hbs files
639
     *
640
     * @returns strings
641
     */
642
    public get getMetadataType(): string {
643
        return PreprintStatusTypeEnum.metadata;
10✔
644
    }
645

646
    /**
647
     * getAuthorAssertionsType
648
     *
649
     * @description Provides the enum type to limit strings in the hbs files
650
     *
651
     * @returns strings
652
     */
653
    public get getAuthorAssertionsType(): string {
654
        return PreprintStatusTypeEnum.authorAssertions;
10✔
655
    }
656

657
    /**
658
     * getSupplementsType
659
     *
660
     * @description Provides the enum type to limit strings in the hbs files
661
     *
662
     * @returns strings
663
     */
664
    public get getSupplementsType(): string {
665
        return PreprintStatusTypeEnum.supplements;
10✔
666
    }
667

668
    /**
669
     * getReviewType
670
     *
671
     * @description Provides the enum type to limit strings in the hbs files
672
     *
673
     * @returns strings
674
     */
675
    public get getReviewType(): string {
676
        return PreprintStatusTypeEnum.review;
10✔
677
    }
678

679
    @task
680
    @waitFor
681
    public async addProjectFile(file: FileModel): Promise<void>{
NEW
UNCOV
682
        const target = this.preprint;
×
NEW
UNCOV
683
        await file.copy(target, '/', 'osfstorage', {
×
684
            conflict: 'replace',
685
        });
NEW
686
        const theFiles = await target.files;
×
687
        const rootFolder = await theFiles.firstObject!.rootFolder;
×
UNCOV
688
        const primaryFile = await rootFolder!.files;
×
NEW
UNCOV
689
        target.set('primaryFile', primaryFile.lastObject);
×
690
    }
691

692
    @action
693
    public updateAffiliatedInstitution(institution: InstitutionModel): void {
UNCOV
694
        if (this.isInstitutionAffiliated(institution.id)) {
×
695
            this.affiliatedInstitutions.removeObject(institution);
×
696
        } else {
UNCOV
697
            this.affiliatedInstitutions.addObject(institution);
×
698
        }
699
    }
700

701
    private isInstitutionAffiliated(id: string): boolean {
UNCOV
702
        return this.affiliatedInstitutions.find(
×
UNCOV
703
            institution => institution.id === id,
×
704
        ) !== undefined;
705
    }
706

707
    @action
708
    public resetAffiliatedInstitutions(): void {
UNCOV
709
        this.affiliatedInstitutions.length = 0;
×
710
    }
711

712
    public isAdmin(): boolean {
NEW
UNCOV
713
        return this.preprint.currentUserPermissions?.includes(Permission.Admin);
×
714
    }
715

716
    public isElementDisabled(): boolean {
UNCOV
717
        return !this.isAdmin();
×
718
    }
719

720
    public isAffiliatedInstitutionsDisabled(): boolean {
UNCOV
721
        return !this.preprint.currentUserPermissions.includes(Permission.Write);
×
722
    }
723
}
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