Skip to content

Commit

Permalink
Stats for files and collections, fixes #454
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Jun 17, 2014
1 parent 0aafeb9 commit e938b65
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group :development, :test do
gem 'sqlite3'
gem 'rspec-rails', '~> 3.0.1'
gem 'rspec-its'
gem 'rspec-activemodel-mocks'
gem 'launchy' unless ENV['TRAVIS']
gem 'byebug' unless ENV['TRAVIS']
gem 'capybara', '~> 2.3.0'
Expand Down
14 changes: 12 additions & 2 deletions app/helpers/sufia/dashboard_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module DashboardHelperBehavior

def render_recent_activity
if @activity.empty?
"User has no recent activity"
t('sufia.dashboard.no_activity')
else
render partial: 'users/activity_log', locals: {events: @activity}
end
end

def render_recent_notifications
if @notifications.empty?
"User has no notifications"
t('sufia.dashboard.no_notifications')
else
render partial: "mailbox/notifications", locals: { messages: @notifications }
end
Expand All @@ -21,5 +21,15 @@ def on_the_dashboard?
params[:controller].match(/^dashboard|my/)
end

def number_of_files user=nil

This comment has been minimized.

Copy link
@jcoyne

jcoyne Jun 17, 2014

Contributor

why don't you just default to current_user rather than nil?

This comment has been minimized.

Copy link
@mjgiarlo

mjgiarlo Jun 17, 2014

Member

👍 to @jcoyne's suggestion

This comment has been minimized.

Copy link
@awead

awead Jun 17, 2014

Author Contributor

Just pushed up an edited PR

user ||= current_user
::GenericFile.where(Solrizer.solr_name('depositor', :stored_searchable) => user.user_key).count
end

def number_of_collections user=nil
user ||= current_user
Collection.where(Solrizer.solr_name('depositor', :stored_searchable) => user.user_key).count
end

end
end
8 changes: 6 additions & 2 deletions app/views/dashboard/_index_partials/_stats.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

<table class="table table-condensed">
<tr>
<td><span class="label label-default"><%= number_of_deposits(@user) %></span></td>
<td><%= t("sufia.dashboard.stats.deposits") %></td>
<td><span class="label label-default"><%= number_of_files %></span></td>
<td><%= t("sufia.dashboard.stats.files") %></td>
</tr>
<tr>
<td><span class="label label-default"><%= number_of_collections %></span></td>
<td><%= t("sufia.dashboard.stats.collections") %></td>
</tr>
<tr>
<td><span class="label label-default"><%= @user.all_following.count %></span></td>
Expand Down
11 changes: 7 additions & 4 deletions config/locales/sufia.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ en:
create_collection: "Create Collection"
view_files: "View Files"
user_activity: "User Activity"
no_activity: "User has no recent activity"
user_notiticiations: "User Notifications"
no_notifications: "User has no notifications"
stats:
heading: "Your Statistics"
deposits: "Files you've deposited into Sufia"
following: "People you follow"
followers: "People who are following you"
heading: "Your Statistics"
files: "Files you've deposited"
collections: "Collections you've created"
following: "People you follow"
followers: "People who are following you"

metadata_help:
resource_type: "Pre-defined categories to describe the type of file content being uploaded, such as \"article\" or \"dataset.\" More than one type may be selected."
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

require 'rspec/rails'
require 'rspec/its'
require 'rspec/active_model/mocks'
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
Capybara.default_wait_time = ENV['TRAVIS'] ? 30 : 15
Expand Down
5 changes: 4 additions & 1 deletion spec/views/dashboard/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
allow(@user).to receive(:all_following).and_return(["magneto"])
allow(@user).to receive(:followers).and_return(["wolverine","storm"])
allow(controller).to receive(:current_user).and_return(@user)
allow(view).to receive(:number_of_files).and_return("15")
allow(view).to receive(:number_of_collections).and_return("3")
assign(:activity, [])
assign(:notifications, [])
end
Expand Down Expand Up @@ -56,7 +58,8 @@
expect(@sidebar).to include "Your Statistics"
expect(@sidebar).to include '<span class="label label-default">1</span>'
expect(@sidebar).to include '<span class="label label-default">2</span>'
expect(@sidebar).to include '<span class="label label-default">0</span>'
expect(@sidebar).to include '<span class="label label-default">15</span>'
expect(@sidebar).to include '<span class="label label-default">3</span>'
end

end
Expand Down

0 comments on commit e938b65

Please sign in to comment.