Sha256: c13e6bba9dae03b6385270dda38f212269ab935732cc2c3263e35c3e09825f3a

Contents?: true

Size: 1008 Bytes

Versions: 7

Compression:

Stored size: 1008 Bytes

Contents

@Character.Dashboard.Charts ||= {}
@Character.Dashboard.Charts.visitors = (layout) ->
  title = 'Visitors'
  color = '#fac043'

  if layout.chartType() == 'day'
    reportModel = 'Reports-AnalyticsDaily'
    dateFormat = (d) -> moment(d).format("MMM D")
  else if layout.chartType() == 'week'
    reportModel = 'Reports-AnalyticsWeekly'
    dateFormat = (d) ->
      weekStart = moment(d).format("MMM D")
      weekEnd   = moment(d).add('days', 6).format("MMM D")
      "#{weekStart} - #{weekEnd}"
  else if layout.chartType() == 'month'
    reportModel = 'Reports-AnalyticsMonthly'
    dateFormat = (d) -> moment(d).format("MMM YYYY")

  fields    = [ 'visitors' ].join(',')
  startDate = layout.dateFrom()
  stopDate  = layout.dateTo()

  url = "/admin/#{reportModel}?f=#{fields}&where__report_date=$gte:#{ startDate },$lte:#{ stopDate }&o=report_date:asc&pp=40"

  $.get url, {}, (data) =>
    d = _.map data, (r) -> { y: dateFormat(r.report_date), a: r.visitors }
    layout.drawBarChart title, color, d

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
character-1.0.6 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.5 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.4 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.3 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.2 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.1 app/assets/javascripts/character/dashboard/_visitors.coffee
character-1.0.0 app/assets/javascripts/character/dashboard/_visitors.coffee