Skip to content

Commit

Permalink
Fixed sorting issue on category show page.
Browse files Browse the repository at this point in the history
  • Loading branch information
driki committed Apr 1, 2012
1 parent dbec33d commit 9778240
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/categories_controller.rb
Expand Up @@ -26,6 +26,12 @@ def show
@meta_keywords = @category.meta_keywords
@category_expenditures_total = Item.where(:category_id => @category.subtree_ids).where(:is_expense => true).sum(:total)
@category_revenues_total = Item.where(:category_id => @category.subtree_ids).where(:is_expense => false).sum(:total)
@child_categories = @category.children
@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

def update
Expand Down
11 changes: 7 additions & 4 deletions app/views/categories/show.html.slim
Expand Up @@ -100,16 +100,19 @@ hr
div class="row"
div class="span6 barchart-widget"
h2 Sub-Categories
- unless @category.children.empty?
- for child_category in @category.children
- unless @category.children.empty?

- @categories_by_total.each_pair do |total,child_category|
div class="bar-container"
div class="bar-category-text"
= link_to child_category.name, organization_project_category_path(@organization, @project, child_category)
'
= number_to_currency(child_category.expenditure_items_total, :precision => 0)
= number_to_currency(total, :precision => 0)
div class="progress progress-danger"
- if @category_expenditures_total > 0
div class="bar" style="width: #{((child_category.expenditure_items_total/@category_expenditures_total)*100).to_i}%;"
div class="bar" style="width: #{((total/@category_expenditures_total)*100).to_i}%;"


- else
| No sub-categories found

Expand Down

0 comments on commit 9778240

Please sign in to comment.