This repository was archived by the owner on Apr 14, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
-components/preprint-metrics Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ export interface KeenConfig {
1919
2020declare const config : {
2121 WATER_BUTLER_ENABLED : boolean ;
22- PREPRINT_ADAPTER_OPTIONS_ENABLED : boolean ;
2322 plauditWidgetUrl : string ,
2423 environment : any ;
2524 cedarConfig : any ;
Original file line number Diff line number Diff line change 1+ import Component from '@glimmer/component' ;
2+ import { inject as service } from '@ember/service' ;
3+ import { tracked } from '@glimmer/tracking' ;
4+ import { task } from 'ember-concurrency' ;
5+ import { waitFor } from '@ember/test-waiters' ;
6+ import { taskFor } from 'ember-concurrency-ts' ;
7+ import Store from '@ember-data/store' ;
8+ import config from 'ember-osf-web/config/environment' ;
9+ import { BaseMeta } from 'osf-api' ;
10+
11+
12+ interface InputArgs {
13+ guid : string ;
14+ }
15+
16+ export default class PreprintMetrics extends Component < InputArgs > {
17+ @service store ! : Store ;
18+ @tracked apiMetrics ! : BaseMeta ;
19+
20+ metricsStartDate = config . OSF . metricsStartDate ;
21+
22+ constructor ( owner : unknown , args : InputArgs ) {
23+ super ( owner , args ) ;
24+
25+ taskFor ( this . loadPreprintMetrics ) . perform ( ) ;
26+ }
27+
28+ @task
29+ @waitFor
30+ private async loadPreprintMetrics ( ) {
31+ try {
32+ const adapterOptions = Object ( {
33+ query : {
34+ 'metrics[views]' : 'total' ,
35+ 'metrics[downloads]' : 'total' ,
36+ } ,
37+ } ) ;
38+
39+ const preprintMetrics = await this . store . findRecord ( 'preprint' , this . args . guid , {
40+ reload : true ,
41+ adapterOptions,
42+ } ) ;
43+
44+ this . apiMetrics = preprintMetrics . apiMetrics ;
45+ // eslint-disable-next-line
46+ } catch ( _ ) { }
47+ }
48+ }
Original file line number Diff line number Diff line change 1+ <div >
2+ {{ #if this.loadPreprintMetrics.isRunning }}
3+ <LoadingIndicator data-test-loading-indicator @dark ={{ true }} />
4+ {{ else }}
5+ <span data-test-view-count-label>
6+ {{ t ' preprints.detail.share.views' }} :
7+ </span >
8+ <span data-test-view-count> {{ this.apiMeta ?.metrics ?.views }} </span > |
9+ <span data-test-download-count-label>
10+ {{ t ' preprints.detail.share.downloads' }} :
11+ </span >
12+ <span data-test-download-count>{{ this.apiMeta ?.metrics ?.downloads }} </span >
13+ <EmberTooltip >
14+ {{ t ' preprints.detail.share.metrics_disclaimer' }} {{ moment-format this.metricsStartDate ' YYYY-MM-DD' }}
15+ </EmberTooltip >
16+ {{ /if }}
17+ </div >
Original file line number Diff line number Diff line change @@ -61,7 +61,6 @@ export default class PrePrintsDetailController extends Controller {
6161 @tracked fullScreenMFR = false ;
6262 @tracked plauditIsReady = false ;
6363
64- metricsStartDate = config . OSF . metricsStartDate ;
6564 reviewStateLabelKeyMap = VersionStatusSimpleLabelKey ;
6665
6766 get hyperlink ( ) : string {
Original file line number Diff line number Diff line change @@ -60,18 +60,11 @@ export default class PreprintsDetail extends Route {
6060 'contributors' ,
6161 'identifiers' ,
6262 ] ;
63- const adapterOptions = config . PREPRINT_ADAPTER_OPTIONS_ENABLED ? Object ( {
64- query : {
65- 'metrics[views]' : 'total' ,
66- 'metrics[downloads]' : 'total' ,
67- } ,
68- } ) : undefined ;
6963
7064
7165 const preprint = await this . store . findRecord ( 'preprint' , guid , {
7266 reload : true ,
7367 include : embeddableFields ,
74- adapterOptions,
7568 } ) ;
7669
7770 const provider = await preprint ?. get ( 'provider' ) ;
@@ -122,6 +115,7 @@ export default class PreprintsDetail extends Route {
122115 && ! isWithdrawalRejected && ! hasPendingWithdrawal ;
123116
124117 return {
118+ guid,
125119 preprint,
126120 brand : provider . brand . content ,
127121 contributors,
Original file line number Diff line number Diff line change 194194 </OsfLink >
195195 </div >
196196 <div >
197- <span data-test-view-count-label>
198- {{ t ' preprints.detail.share.views' }} :
199- </span >
200- <span data-test-view-count> {{ this.model.preprint.apiMeta.metrics.views }} </span > |
201- <span data-test-download-count-label>
202- {{ t ' preprints.detail.share.downloads' }} :
203- </span >
204- <span data-test-download-count>{{ this.model.preprint.apiMeta.metrics.downloads }} </span >
205- <EmberTooltip >
206- {{ t ' preprints.detail.share.metrics_disclaimer' }} {{ moment-format this.metricsStartDate ' YYYY-MM-DD' }}
207- </EmberTooltip >
197+ <Preprints::-Components::PreprintMetrics
198+ @guid ={{ this.model.guid }}
199+ ></Preprints::-Components::PreprintMetrics >
208200 </div >
209201 </div >
210202 <div local-class =' plaudit-container' >
Original file line number Diff line number Diff line change @@ -62,7 +62,6 @@ const {
6262 KEEN_CONFIG : keenConfig ,
6363 LINT_ON_BUILD : lintOnBuild = false ,
6464 WATER_BUTLER_ENABLED = true ,
65- PREPRINT_ADAPTER_OPTIONS_ENABLED = true ,
6665 MIRAGE_ENABLED = false ,
6766 MIRAGE_SCENARIOS = [
6867 'cedar' ,
@@ -119,7 +118,6 @@ module.exports = function(environment) {
119118 modulePrefix : 'ember-osf-web' ,
120119 cedarConfig,
121120 WATER_BUTLER_ENABLED ,
122- PREPRINT_ADAPTER_OPTIONS_ENABLED ,
123121 plauditWidgetUrl,
124122 environment,
125123 lintOnBuild,
You can’t perform that action at this time.
0 commit comments