Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/config/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface KeenConfig {

declare const config: {
WATER_BUTLER_ENABLED: boolean;
PREPRINT_ADAPTER_OPTIONS_ENABLED: boolean;
plauditWidgetUrl: string,
environment: any;
cedarConfig: any;
Expand Down
48 changes: 48 additions & 0 deletions app/preprints/-components/preprint-metrics/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';
import { taskFor } from 'ember-concurrency-ts';
import Store from '@ember-data/store';
import config from 'ember-osf-web/config/environment';
import { BaseMeta } from 'osf-api';


interface InputArgs {
guid: string;
}

export default class PreprintMetrics extends Component<InputArgs> {
@service store!: Store;
@tracked apiMetrics!: BaseMeta;

metricsStartDate = config.OSF.metricsStartDate;

constructor(owner: unknown, args: InputArgs) {
super(owner, args);

taskFor(this.loadPreprintMetrics).perform();
}

@task
@waitFor
private async loadPreprintMetrics() {
try {
const adapterOptions = Object({
query: {
'metrics[views]': 'total',
'metrics[downloads]': 'total',
},
});

const preprintMetrics = await this.store.findRecord('preprint', this.args.guid, {
reload: true,
adapterOptions,
});

this.apiMetrics = preprintMetrics.apiMetrics;
// eslint-disable-next-line
} catch (_){ }
}
}
17 changes: 17 additions & 0 deletions app/preprints/-components/preprint-metrics/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div>
{{#if this.loadPreprintMetrics.isRunning}}
<LoadingIndicator data-test-loading-indicator @dark={{true}} />
{{else}}
<span data-test-view-count-label>
{{t 'preprints.detail.share.views'}}:
</span>
<span data-test-view-count> {{this.apiMeta?.metrics?.views}} </span> |
<span data-test-download-count-label>
{{t 'preprints.detail.share.downloads'}}:
</span>
<span data-test-download-count>{{this.apiMeta?.metrics?.downloads}}</span>
<EmberTooltip>
{{t 'preprints.detail.share.metrics_disclaimer'}} {{moment-format this.metricsStartDate 'YYYY-MM-DD'}}
</EmberTooltip>
{{/if}}
</div>
1 change: 0 additions & 1 deletion app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class PrePrintsDetailController extends Controller {
@tracked fullScreenMFR = false;
@tracked plauditIsReady = false;

metricsStartDate = config.OSF.metricsStartDate;
reviewStateLabelKeyMap = VersionStatusSimpleLabelKey;

get hyperlink(): string {
Expand Down
8 changes: 1 addition & 7 deletions app/preprints/detail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,11 @@ export default class PreprintsDetail extends Route {
'contributors',
'identifiers',
];
const adapterOptions = config.PREPRINT_ADAPTER_OPTIONS_ENABLED ? Object({
query: {
'metrics[views]': 'total',
'metrics[downloads]': 'total',
},
}) : undefined;


const preprint = await this.store.findRecord('preprint', guid, {
reload: true,
include: embeddableFields,
adapterOptions,
});

const provider = await preprint?.get('provider');
Expand Down Expand Up @@ -122,6 +115,7 @@ export default class PreprintsDetail extends Route {
&& !isWithdrawalRejected && !hasPendingWithdrawal;

return {
guid,
preprint,
brand: provider.brand.content,
contributors,
Expand Down
14 changes: 3 additions & 11 deletions app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,9 @@
</OsfLink>
</div>
<div>
<span data-test-view-count-label>
{{t 'preprints.detail.share.views'}}:
</span>
<span data-test-view-count> {{this.model.preprint.apiMeta.metrics.views}} </span> |
<span data-test-download-count-label>
{{t 'preprints.detail.share.downloads'}}:
</span>
<span data-test-download-count>{{this.model.preprint.apiMeta.metrics.downloads}}</span>
<EmberTooltip>
{{t 'preprints.detail.share.metrics_disclaimer'}} {{moment-format this.metricsStartDate 'YYYY-MM-DD'}}
</EmberTooltip>
<Preprints::-Components::PreprintMetrics
@guid={{this.model.guid}}
></Preprints::-Components::PreprintMetrics>
</div>
</div>
<div local-class='plaudit-container'>
Expand Down
2 changes: 0 additions & 2 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const {
KEEN_CONFIG: keenConfig,
LINT_ON_BUILD: lintOnBuild = false,
WATER_BUTLER_ENABLED = true,
PREPRINT_ADAPTER_OPTIONS_ENABLED = true,
MIRAGE_ENABLED = false,
MIRAGE_SCENARIOS = [
'cedar',
Expand Down Expand Up @@ -119,7 +118,6 @@ module.exports = function(environment) {
modulePrefix: 'ember-osf-web',
cedarConfig,
WATER_BUTLER_ENABLED,
PREPRINT_ADAPTER_OPTIONS_ENABLED,
plauditWidgetUrl,
environment,
lintOnBuild,
Expand Down