@@ -2,63 +2,38 @@ import Store from '@ember-data/store';
22import Controller from '@ember/controller' ;
33import { action , computed } from '@ember/object' ;
44import { reads } from '@ember/object/computed' ;
5+ import RouterService from '@ember/routing/router-service' ;
56import { inject as service } from '@ember/service' ;
6- import Cookies from 'ember-cookies/services/cookies' ;
7- import config from 'ember-get-config' ;
8- import moment , { Moment } from 'moment' ;
97
108import Node from 'ember-osf-web/models/node' ;
119import AnalyticsService from 'ember-osf-web/services/analytics' ;
12-
13- const {
14- OSF : {
15- cookies : {
16- analyticsDismissAdblock : dismissAdblockCookie ,
17- } ,
18- } ,
19- } = config ;
20-
21- interface DateRange {
22- key : string ;
23- start : Moment ;
24- end : Moment ;
25- }
10+ import { Timespan , TIMESPANS } from './route' ;
2611
2712export default class ApplicationController extends Controller {
28- @service cookies ! : Cookies ;
2913 @service analytics ! : AnalyticsService ;
14+ @service router ! : RouterService ;
3015 @service store ! : Store ;
3116
32- dateRanges : DateRange [ ] = [
33- {
34- key : 'pastWeek' ,
35- start : moment ( ) . subtract ( 1 , 'weeks' ) ,
36- end : moment ( ) ,
37- } ,
38- {
39- key : 'pastTwoWeeks' ,
40- start : moment ( ) . subtract ( 2 , 'weeks' ) ,
41- end : moment ( ) ,
42- } ,
43- {
44- key : 'pastMonth' ,
45- start : moment ( ) . subtract ( 1 , 'months' ) ,
46- end : moment ( ) ,
47- } ,
48- ] ;
49-
50- activeDateRange = this . dateRanges [ 0 ] ;
17+ queryParams = [ 'timespan' ] ;
18+ timespan : Timespan = 'week' ;
19+ allTimespans = TIMESPANS ;
20+
21+ timespanIntlKeys : Record < Timespan , string > = {
22+ week : 'analytics.dateRanges.pastWeek' ,
23+ fortnight : 'analytics.dateRanges.pastTwoWeeks' ,
24+ month : 'analytics.dateRanges.pastMonth' ,
25+ } ;
26+
5127 linksModalShown = false ;
5228
53- hideAdblockWarning = Boolean ( this . cookies . read ( dismissAdblockCookie ) ) ;
5429 userIsBot = navigator . userAgent . includes ( 'Prerender' ) ;
5530
5631 linkedByQueryParams = { embed : 'bibliographic_contributors' } ;
5732
58- @reads ( 'model.taskInstance.value' )
33+ @reads ( 'model.nodeWithCountsTaskInstance.value. taskInstance.value' )
5934 node ?: Node ;
6035
61- @reads ( 'model.taskInstance .isRunning' )
36+ @reads ( 'model.nodeWithCountsTaskInstance .isRunning' )
6237 loading ?: boolean ;
6338
6439 @reads ( 'node.relationshipLinks.forks.links.related.meta.count' )
@@ -70,34 +45,24 @@ export default class ApplicationController extends Controller {
7045 @reads ( 'node.apiMeta.templated_by_count' )
7146 templatedByCount ?: number ;
7247
73- @computed ( 'node.public' , 'model.{id,modelName}' )
74- get nodePublic ( ) {
75- const node : Node | null = this . node || this . store . peekRecord ( this . model . modelName , this . model . id ) ;
76- return node && node . public ;
77- }
78-
79- @computed ( 'nodePublic' , 'userIsBot' )
80- get chartsEnabled ( ) {
81- return this . nodePublic && ! this . userIsBot ;
48+ @computed ( 'node.public' )
49+ get nodePrivate ( ) : boolean {
50+ const { node } = this ;
51+ return Boolean ( node && ! node . public ) ;
8252 }
8353
84- @action
85- dismissAdblockWarning ( ) {
86- this . cookies . write ( dismissAdblockCookie , 1 , { path : '/' } ) ;
87- this . set ( 'hideAdblockWarning' , true ) ;
88- this . analytics . click (
89- 'button' ,
90- 'Analytics - Dismiss adblock warning' ,
91- ) ;
54+ @computed ( 'node' , 'nodePrivate' , 'userIsBot' )
55+ get chartsEnabled ( ) : boolean {
56+ return Boolean ( this . node && ! this . nodePrivate && ! this . userIsBot ) ;
9257 }
9358
9459 @action
95- setDateRange ( dateRange : DateRange ) {
96- this . set ( 'activeDateRange' , dateRange ) ;
60+ setTimespan ( timespan : Timespan ) {
9761 this . analytics . click (
9862 'button' ,
99- `Analytics - Choose date range "${ dateRange . key } "` ,
63+ `Analytics - Choose date range "${ timespan } "` ,
10064 ) ;
65+ this . router . transitionTo ( { queryParams : { timespan } } ) ;
10166 }
10267
10368 @action
0 commit comments