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

CenterForOpenScience / ember-osf-web / 12472120664

23 Dec 2024 07:45PM UTC coverage: 67.891%. First build
12472120664

Pull #2436

github

web-flow
Merge 1ae93c6dd into 5515ddc22
Pull Request #2436: [ENG-6470] Withdrawn version picker

2930 of 4698 branches covered (62.37%)

Branch coverage included in aggregate %.

26 of 66 new or added lines in 6 files covered. (39.39%)

7327 of 10410 relevant lines covered (70.38%)

204.29 hits per line

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

78.57
/app/preprints/detail/route.ts
1
import Store from '@ember-data/store';
2
import Route from '@ember/routing/route';
3
import RouterService from '@ember/routing/router-service';
4
import { inject as service } from '@ember/service';
5
import { waitFor } from '@ember/test-waiters';
6
import { taskFor } from 'ember-concurrency-ts';
7
import { all, restartableTask } from 'ember-concurrency';
8
import moment from 'moment-timezone';
9

10
import config from 'ember-osf-web/config/environment';
11
import CurrentUser from 'ember-osf-web/services/current-user';
12
import Identifier from 'ember-osf-web/models/identifier';
13
import LicenseModel from 'ember-osf-web/models/license';
14
import { SparseModel } from 'ember-osf-web/utils/sparse-fieldsets';
15
import MetaTags, { HeadTagDef } from 'ember-osf-web/services/meta-tags';
16
import Ready from 'ember-osf-web/services/ready';
17
import Theme from 'ember-osf-web/services/theme';
18
import captureException from 'ember-osf-web/utils/capture-exception';
19
import pathJoin from 'ember-osf-web/utils/path-join';
20
import Intl from 'ember-intl/services/intl';
21
import PrePrintsDetailController from './controller';
22

23

24
/**
25
 * @module ember-preprints
26
 * @submodule routes
27
 */
28

29
/**
30
 * @class Content Route Handler
31
 */
32

33

34
/**
35
 * Loads all disciplines and preprint providers to the index page
36
 * @class Index Route Handler
37
 */
38
export default class PreprintsDetail extends Route {
39
    @service store!: Store;
40
    @service theme!: Theme;
41
    @service router!: RouterService;
42
    @service currentUser!: CurrentUser;
43
    @service metaTags!: MetaTags;
44
    @service ready!: Ready;
45
    @service intl!: Intl;
46

47
    headTags?: HeadTagDef[];
48

49
    async model(params: { guid : string }) {
50
        try {
5✔
51
            const guid = params.guid;
5✔
52

53
            const preprint = await this.store.findRecord('preprint', guid, {
5✔
54
                adapterOptions: {
55
                    query: {
56
                        'metrics[views]': 'total',
57
                        'metrics[downloads]': 'total',
58
                    },
59
                },
60
            });
61

62
            const provider = await preprint?.get('provider');
5✔
63

64
            this.theme.set('providerType', 'preprint');
5✔
65
            this.theme.set('id', provider.id);
5✔
66

67
            let primaryFile;
68

69
            if (!preprint.isWithdrawn) {
5✔
70
                primaryFile = await preprint?.get('primaryFile');
3✔
71
                primaryFile.versions = await primaryFile?.versions;
3✔
72
            }
73

74
            const contributors = await preprint?.queryHasMany('contributors');
5✔
75

76
            const license = await preprint?.get('license');
5✔
77

78
            const subjects = await preprint?.queryHasMany('subjects');
5✔
79
            const versions = await preprint?.queryHasMany('versions');
5✔
80

81
            return {
5✔
82
                preprint,
83
                brand: provider.brand.content,
84
                contributors,
85
                provider,
86
                primaryFile,
87
                license,
88
                subjects,
89
                versions,
90
            };
91

92
        } catch (error) {
93
            captureException(error);
×
NEW
94
            this.router.transitionTo('not-found', this.router.currentURL.slice(1));
×
95
            return null;
×
96
        }
97
    }
98

99
    @restartableTask({ cancelOn: 'deactivate' })
100
    @waitFor
101
    async setHeadTags(model: any) {
102
        const blocker = this.ready.getBlocker();
5✔
103
        const {preprint} = await model;
5✔
104

105
        if (preprint) {
5!
106
            const [
107
                contributors = [],
×
108
                license = null,
×
109
                identifiers = [],
×
110
                provider = null,
×
111
            ] = await all([
5✔
112
                preprint.sparseLoadAll(
113
                    'bibliographicContributors',
114
                    { contributor: ['users', 'index'], user: ['fullName'] },
115
                ),
116
                preprint.license,
117
                preprint.identifiers,
118
                preprint.provider,
119
            ]);
120

121
            const doi = (identifiers as Identifier[]).find(identifier => identifier.category === 'doi');
5✔
122
            const image = 'engines-dist/registries/assets/img/osf-sharing.png';
5✔
123

124
            const preprintTitle = preprint.isWithdrawn ?
5✔
125
                this.intl.t('preprints.detail.withdrawn_title', { title: preprint.title }) :
126
                preprint.title;
127

128
            const metaTagsData = {
5✔
129
                title: preprintTitle,
130
                description: preprint.description,
131
                publishedDate: moment(preprint.datePublished).format('YYYY-MM-DD'),
132
                modifiedDate: moment(preprint.dateModified).format('YYYY-MM-DD'),
133
                identifier: preprint.id,
134
                url: pathJoin(config.OSF.url, preprint.id),
135
                doi: doi && doi.value,
5!
136
                image,
137
                keywords: preprint.tags,
138
                siteName: 'OSF',
139
                license: license && (license as LicenseModel).name,
10✔
140
                author: (contributors as SparseModel[]).map(
141
                    contrib => (contrib.users as { fullName: string }).fullName,
20✔
142
                ),
143
            };
144

145
            const allTags: HeadTagDef[] = this.metaTags.getHeadTags(metaTagsData);
5✔
146

147
            if (provider && provider.assets && provider.assets.favicon) {
5!
148
                allTags.push({
×
149
                    type: 'link',
150
                    attrs: {
151
                        rel: 'icon',
152
                        href: provider.assets.favicon,
153
                    },
154
                });
155
            }
156
            this.set('headTags', allTags);
5✔
157
            this.metaTags.updateHeadTags();
5✔
158
            (this.controller as PrePrintsDetailController).plauditIsReady = true;
5✔
159
        }
160
        blocker.done();
5✔
161
    }
162

163
    afterModel(model: any) {
164
        if (!this.currentUser.viewOnlyToken) {
5!
165
            taskFor(this.setHeadTags).perform(model);
5✔
166
        }
167
    }
168
}
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