# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
before_filter :find_optional_project, :only => [:index]
accept_rss_auth :index
accept_api_auth :index, :show, :create, :update, :destroy
-
+
helper :sort
include SortHelper
helper :issues
include TimelogHelper
helper :custom_fields
include CustomFieldsHelper
-
+
def index
sort_init 'spent_on', 'desc'
sort_update 'spent_on' => 'spent_on',
'project' => "#{Project.table_name}.name",
'issue' => 'issue_id',
'hours' => 'hours'
-
+
cond = ARCondition.new
if @issue
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
elsif @project
cond << @project.project_condition(Setting.display_subprojects_issues?)
end
-
+
retrieve_date_range
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
# Paginate results
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
- @entries = TimeEntry.visible.find(:all,
+ @entries = TimeEntry.visible.find(:all,
:include => [:project, :activity, :user, {:issue => :tracker}],
:conditions => cond.conditions,
:order => sort_clause,
format.api {
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
@offset, @limit = api_offset_and_limit
- @entries = TimeEntry.visible.find(:all,
+ @entries = TimeEntry.visible.find(:all,
:include => [:project, :activity, :user, {:issue => :tracker}],
:conditions => cond.conditions,
:order => sort_clause,
}
format.csv {
# Export all entries
- @entries = TimeEntry.visible.find(:all,
+ @entries = TimeEntry.visible.find(:all,
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
:conditions => cond.conditions,
:order => sort_clause)
}
end
end
-
+
def show
respond_to do |format|
# TODO: Implement html response
def new
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
@time_entry.attributes = params[:time_entry]
-
+
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
render :action => 'edit'
end
def create
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
@time_entry.attributes = params[:time_entry]
-
+
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
-
+
if @time_entry.save
respond_to do |format|
format.html {
format.html { render :action => 'edit' }
format.api { render_validation_errors(@time_entry) }
end
- end
+ end
end
-
+
def edit
@time_entry.attributes = params[:time_entry]
-
+
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
end
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
def update
@time_entry.attributes = params[:time_entry]
-
+
call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
-
+
if @time_entry.save
respond_to do |format|
format.html {
format.html { render :action => 'edit' }
format.api { render_validation_errors(@time_entry) }
end
- end
+ end
end
def bulk_edit
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
def destroy
- @time_entries.each do |t|
+ @time_entries.each do |t|
begin
unless t.destroy && t.destroyed?
respond_to do |format|
rescue ActiveRecord::RecordNotFound
render_404
end
-
+
def find_optional_project
if !params[:issue_id].blank?
@issue = Issue.find(params[:issue_id])
end
deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true)
end
-
+
# Retrieves the date range based on predefined ranges or specific from/to param dates
def retrieve_date_range
@free_period = false
else
# default
end
-
+
@from, @to = @to, @from if @from && @to && @from > @to
@from ||= (TimeEntry.earilest_date_for_project(@project) || Date.today)
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)