Hacked some column sorting onto RatesController
* Added SortHelper to RatesController * Init and updating the sorting (pre 0.8 sort_update) * RatesController#index will only render the layout on non-xhr requests * Changed Rate.history_for_user to take an order clause * Added rate_sort_header_tag and rate_sort_link to the SortHelper in order to get the correct parameters for sorting Rates * Added rate_sort_header_tags to the Rate lists #1915
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
class RatesController < ApplicationController
|
||||
helper :users
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
||||
before_filter :require_admin
|
||||
before_filter :require_user_id, :only => [:index, :new]
|
||||
before_filter :set_back_url, :only => [:new, :edit]
|
||||
@@ -7,10 +10,13 @@ class RatesController < ApplicationController
|
||||
# GET /rates?user_id=1
|
||||
# GET /rates.xml?user_id=1
|
||||
def index
|
||||
@rates = Rate.history_for_user(@user)
|
||||
sort_init "#{Rate.table_name}.date_in_effect", "desc"
|
||||
sort_update # 'date_in_effect' => "#{Rate.table_name}.date_in_effect"
|
||||
|
||||
@rates = Rate.history_for_user(@user, sort_clause)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.html { render :action => 'index', :layout => !request.xhr?}
|
||||
format.xml { render :xml => @rates }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,13 +11,13 @@ class Rate < ActiveRecord::Base
|
||||
before_save :unlocked?
|
||||
before_destroy :unlocked?
|
||||
|
||||
named_scope :history_for_user, lambda { |user|
|
||||
named_scope :history_for_user, lambda { |user, order|
|
||||
{
|
||||
:conditions => { :user_id => user.id },
|
||||
:order => 'date_in_effect DESC'
|
||||
:order => order
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def locked?
|
||||
return self.time_entries.length > 0
|
||||
end
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
<table class="list">
|
||||
<thead>
|
||||
<th style="width:15%"><%= l(:label_date) %></th>
|
||||
<th><%= l(:label_project) %></th>
|
||||
<%= rate_sort_header_tag("date_in_effect",
|
||||
:caption => l(:label_date),
|
||||
:default_order => 'desc',
|
||||
:style => "width: 15%",
|
||||
:method => :get,
|
||||
:update => "rate-history",
|
||||
:user_id => @user.id) %>
|
||||
<%= rate_sort_header_tag("project_id",
|
||||
:caption => l(:label_project),
|
||||
:default_order => 'asc',
|
||||
:method => :get,
|
||||
:update => "rate-history",
|
||||
:user_id => @user.id) %>
|
||||
<th style="width:15%"><%= l(:rate_label_rate) %></th>
|
||||
<th style="width:5%"></th>
|
||||
</thead>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<div id="rate_history">
|
||||
<h1><%= l(:rate_label_rate_history) %></h1>
|
||||
|
||||
<%= render :partial => 'list' %>
|
||||
<%= render :partial => 'list' %>
|
||||
</div>
|
||||
|
||||
@@ -4,9 +4,15 @@
|
||||
<% @back_url = url_for(:controller => 'users', :action => 'edit', :id => @user, :tab => 'rates') %>
|
||||
<%= render :partial => 'rates/form' %>
|
||||
|
||||
<div id="rate_history">
|
||||
<h1><%= l(:rate_label_rate_history) %></h1>
|
||||
<%# TODO: Refactor out of the view once there is a hook in the controller (Post 0.8.0). %>
|
||||
<%# Can't expect everyone to upgrade at the moment %>
|
||||
<% @rates = Rate.history_for_user(@user) %>
|
||||
<% sort_init "#{Rate.table_name}.date_in_effect", "desc" %>
|
||||
<% sort_update # 'date_in_effect' => "#{Rate.table_name}.date_in_effect" %>
|
||||
|
||||
|
||||
<% @rates = Rate.history_for_user(@user, "#{Rate.table_name}.date_in_effect desc") %>
|
||||
|
||||
<%= render :partial => 'rates/list' %>
|
||||
</div>
|
||||
Reference in New Issue
Block a user