Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Commit

Permalink
Replaced old dashboard with new one based on petition_reports table.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelpetry committed Jan 3, 2013
1 parent 2c10299 commit 306d486
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 168 deletions.
7 changes: 0 additions & 7 deletions app/controllers/admin/petitions_controller.rb
Expand Up @@ -3,13 +3,6 @@ class Admin::PetitionsController < ApplicationController
before_filter :require_admin

def index
respond_to do |format|
format.html { }
format.json { render json: PetitionsDatatable.new(view_context, PetitionStatisticsBuilder.new) }
end
end

def new_dashboard
respond_to do |format|
format.html {}
format.json { render json: PetitionsDatatable.new(view_context, PetitionReportRepository.new) }
Expand Down
4 changes: 2 additions & 2 deletions app/datatables/petitions_datatable.rb
Expand Up @@ -12,7 +12,7 @@
=end

class PetitionsDatatable
delegate :params, :h, :float_to_percentage, :format_date_time, :link_to, to: :@view
delegate :params, :h, :float_to_percentage, :format_date_time, :link_to, :petition_path, to: :@view

def initialize(view, statistics_builder)
@view = view
Expand Down Expand Up @@ -43,7 +43,7 @@ def dpct(numerator, denominator, percentify=true)
def data
petitions.map do |petition|
[
link_to(petition.petition_title, petition.p),
link_to(petition.petition_title, petition_path(petition.petition_id)),
h(petition.email_count),
dpct(petition.opened_emails_count, petition.email_count),
dpct(petition.clicked_emails_count, petition.email_count),
Expand Down
33 changes: 0 additions & 33 deletions app/models/petition_statistics.rb

This file was deleted.

38 changes: 0 additions & 38 deletions app/models/petition_statistics_builder.rb

This file was deleted.

9 changes: 4 additions & 5 deletions app/views/admin/petitions/index.html.haml
Expand Up @@ -2,11 +2,10 @@
%h1 Petitions dashboard

%p
- labels = 'today', 'yesterday', 'a week ago', 'a month ago', 'a year ago'
- today = Date.today
- values = today, today - 1.day, today - 1.week, today - today.month, today - 1.year
- options = Hash[labels.zip(values.map(&:to_s))]
Activity since #{link_to_self_with_param :since, options, " | "}
- labels = 'day', 'week', 'month', 'year'
- options = Hash[labels.zip(labels)]
- params[:since] ||= 'year'
Activity since last #{link_to_self_with_param :since, options, " | "}

<button style="float: right" class="btn btn-success" onClick="$('table').dataTable().fnDraw()">Reload</button>

Expand Down
25 changes: 0 additions & 25 deletions app/views/admin/petitions/new_dashboard.html.haml

This file was deleted.

4 changes: 1 addition & 3 deletions config/routes.rb
Expand Up @@ -32,9 +32,7 @@
get 'contact', to: 'user_feedbacks#new', as: 'contact'

namespace(:admin) do
resources :petitions do
collection { get 'new_dashboard' }
end
resources :petitions
resources :users

resource :stats do
Expand Down
7 changes: 1 addition & 6 deletions spec/controllers/admin/petitions_controller_spec.rb
@@ -1,16 +1,11 @@
module Admin
describe PetitionsController do
before :each do
AnalyticsGateway.stub(:get_report_results).and_return({})
before do
stub_bandit controller
end
describe "GET index" do
let(:action) { get :index }
it_behaves_like "an admin only resource page"
end
describe "GET new_dashboard" do
let(:action) { get :new_dashboard }
it_behaves_like "an admin only resource page"
end
end
end
15 changes: 0 additions & 15 deletions spec/models/petition_statistics_builder_spec.rb

This file was deleted.

34 changes: 0 additions & 34 deletions spec/models/petition_statistics_spec.rb

This file was deleted.

0 comments on commit 306d486

Please sign in to comment.