Skip to content

Commit

Permalink
Updating sorting of categories on the overview page.
Browse files Browse the repository at this point in the history
  • Loading branch information
driki committed Apr 8, 2012
1 parent ff9b033 commit d93fdcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
8 changes: 8 additions & 0 deletions app/controllers/projects_controller.rb
Expand Up @@ -33,6 +33,14 @@ def show
@meta_keywords = @project.meta_keywords
@project_expense_total = @project.items.where(:is_expense => true).sum(:total)
@project_revenue_total = @project.items.where(:is_expense => false).sum(:total)


@child_categories = @project.categories.roots
@categories_by_total = Hash.new
@child_categories.each do |cat|
@categories_by_total[cat.expenditure_items_total] = cat
end
@categories_by_total = Hash[@categories_by_total.sort.reverse]
end

# just redirect over to show, this is because of old Google cached links.
Expand Down
15 changes: 7 additions & 8 deletions app/views/projects/show.html.slim
Expand Up @@ -47,18 +47,17 @@ div class="row"
div class="row"
div class="span6 barchart-widget"
h1 Categories
- for category in @project.categories.roots

- @categories_by_total.each_pair do |total,child_category|
div class="bar-container"
div class="bar-category-text"
h3
= link_to category.name, organization_project_category_path(@organization, @project, category)
'
= number_to_currency(category.expenditure_items_total, :precision => 0)
= link_to child_category.name, organization_project_category_path(@organization, @project, child_category)
'
= number_to_currency(total, :precision => 0)
div class="progress progress-danger"
div class="bar" style="width: #{((category.expenditure_items_total)/@project_expense_total)*100.to_i}%;"
= number_to_currency(Item.where(:category_id => category.subtree_ids).where(:is_expense => false).sum(:total)+category.items.where(:is_expense => false).sum(:total), :precision => 0)
div class="bar" style="width: #{((total/@project_expense_total)*100).to_i}%;"
div class="progress progress-success"
div class="bar" style="width: #{((Item.where(:category_id => category.subtree_ids).where(:is_expense => false).sum(:total)/@project.items.where(:is_expense => false).sum(:total))*100).to_i}%;"
div class="bar" style="width: #{((child_category.revenue_items_total/@project_revenue_total)*100).to_i}%;"
div class="span6"
== render :partial => 'shared/comments'
hr
Expand Down
8 changes: 0 additions & 8 deletions app/views/shared/_comments.html.slim
Expand Up @@ -4,14 +4,6 @@

javascript:
function disqus_config() {
this.callbacks.onNewComment = [function() { trackComment(); }];
}
function trackComment() {
alert('New comment posted.');
}
var disqus_shortname = 'budgetvision'; // required: replace example with your forum shortname
(function() {
Expand Down

0 comments on commit d93fdcc

Please sign in to comment.