diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/timelog_controller.rb | 82 | ||||
-rw-r--r-- | app/views/timelog/index.apit | 16 | ||||
-rw-r--r-- | app/views/timelog/show.apit | 12 |
3 files changed, 93 insertions, 17 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 1ac7c9a5c..4bec02f35 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -1,5 +1,5 @@ -# redMine - project management software -# Copyright (C) 2006-2007 Jean-Philippe Lang +# Redmine - project management software +# Copyright (C) 2006-2010 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -18,10 +18,11 @@ class TimelogController < ApplicationController menu_item :issues before_filter :find_project, :only => [:new, :create] - before_filter :find_time_entry, :only => [:edit, :update, :destroy] + before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy] before_filter :authorize, :except => [:index] before_filter :find_optional_project, :only => [:index] - + accept_key_auth :index, :show, :create, :update, :destroy + helper :sort include SortHelper helper :issues @@ -66,6 +67,18 @@ class TimelogController < ApplicationController render :layout => !request.xhr? } + format.api { + @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions) + @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page'] + @entries = TimeEntry.find(:all, + :include => [:project, :activity, :user, {:issue => :tracker}], + :conditions => cond.conditions, + :order => sort_clause, + :limit => @entry_pages.items_per_page, + :offset => @entry_pages.current.offset) + + render :template => 'timelog/index.apit' + } format.atom { entries = TimeEntry.find(:all, :include => [:project, :activity, :user, {:issue => :tracker}], @@ -85,6 +98,14 @@ class TimelogController < ApplicationController end end end + + def show + respond_to do |format| + # TODO: Implement html response + format.html { render :nothing => true, :status => 406 } + format.api { render :template => 'timelog/show.apit' } + end + end def new @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) @@ -102,10 +123,18 @@ class TimelogController < ApplicationController call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) if @time_entry.save - flash[:notice] = l(:notice_successful_update) - redirect_back_or_default :action => 'index', :project_id => @time_entry.project + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_back_or_default :action => 'index', :project_id => @time_entry.project + } + format.api { render :template => 'timelog/show.apit', :status => :created, :location => time_entry_url(@time_entry) } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.api { render_validation_errors(@time_entry) } + end end end @@ -122,21 +151,40 @@ class TimelogController < ApplicationController call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) if @time_entry.save - flash[:notice] = l(:notice_successful_update) - redirect_back_or_default :action => 'index', :project_id => @time_entry.project + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_update) + redirect_back_or_default :action => 'index', :project_id => @time_entry.project + } + format.api { head :ok } + end else - render :action => 'edit' + respond_to do |format| + format.html { render :action => 'edit' } + format.api { render_validation_errors(@time_entry) } + end end end verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } def destroy if @time_entry.destroy && @time_entry.destroyed? - flash[:notice] = l(:notice_successful_delete) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_successful_delete) + redirect_to :back + } + format.api { head :ok } + end else - flash[:error] = l(:notice_unable_delete_time_entry) + respond_to do |format| + format.html { + flash[:notice] = l(:notice_unable_delete_time_entry) + redirect_to :back + } + format.api { render_validation_errors(@time_entry) } + end end - redirect_to :back rescue ::ActionController::RedirectBackError redirect_to :action => 'index', :project_id => @time_entry.project end @@ -154,11 +202,11 @@ private end def find_project - if params[:issue_id] - @issue = Issue.find(params[:issue_id]) + if issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id]) + @issue = Issue.find(issue_id) @project = @issue.project - elsif params[:project_id] - @project = Project.find(params[:project_id]) + elsif project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id]) + @project = Project.find(project_id) else render_404 return false diff --git a/app/views/timelog/index.apit b/app/views/timelog/index.apit new file mode 100644 index 000000000..0367e0666 --- /dev/null +++ b/app/views/timelog/index.apit @@ -0,0 +1,16 @@ +api.array :time_entries do + @entries.each do |time_entry| + api.time_entry do + api.id time_entry.id + api.project(:id => time_entry.project_id, :name => time_entry.project.name) unless time_entry.project.nil? + api.issue(:id => time_entry.issue_id) unless time_entry.issue.nil? + api.user(:id => time_entry.user_id, :name => time_entry.user.name) unless time_entry.user.nil? + api.activity(:id => time_entry.activity_id, :name => time_entry.activity.name) unless time_entry.activity.nil? + api.hours time_entry.hours + api.comments time_entry.comments + api.spent_on time_entry.spent_on + api.created_on time_entry.created_on + api.updated_on time_entry.updated_on + end + end +end diff --git a/app/views/timelog/show.apit b/app/views/timelog/show.apit new file mode 100644 index 000000000..d5d3c5d26 --- /dev/null +++ b/app/views/timelog/show.apit @@ -0,0 +1,12 @@ +api.time_entry do + api.id @time_entry.id + api.project(:id => @time_entry.project_id, :name => @time_entry.project.name) unless @time_entry.project.nil? + api.issue(:id => @time_entry.issue_id) unless @time_entry.issue.nil? + api.user(:id => @time_entry.user_id, :name => @time_entry.user.name) unless @time_entry.user.nil? + api.activity(:id => @time_entry.activity_id, :name => @time_entry.activity.name) unless @time_entry.activity.nil? + api.hours @time_entry.hours + api.comments @time_entry.comments + api.spent_on @time_entry.spent_on + api.created_on @time_entry.created_on + api.updated_on @time_entry.updated_on +end |