Class: TimelogController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TimelogController
- Includes:
- CustomFieldsHelper, SortHelper, TimelogHelper
- Defined in:
- app/controllers/timelog_controller.rb
Overview
Redmine - project management software Copyright © 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 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.
Constant Summary
Constants included from ApplicationHelper
ApplicationHelper::HEADING_RE, ApplicationHelper::TOC_RE
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from CustomFieldsHelper
#custom_field_formats_for_select, #custom_field_label_tag, #custom_field_tag, #custom_field_tag_for_bulk_edit, #custom_field_tag_with_label, #custom_fields_tabs, #format_value, #render_api_custom_values, #show_value
Methods included from TimelogHelper
#activity_collection_for_select_options, #entries_to_csv, #format_criteria_value, #options_for_period_select, #render_timelog_breadcrumb, #report_criteria_to_csv, #report_to_csv, #select_hours, #sum_hours, #to_utf8
Methods included from ApplicationHelper
#accesskey, #api_meta, #authoring, #authorize_for, #avatar, #back_url_hidden_field_tag, #body_css_classes, #breadcrumb, #calendar_for, #check_all_links, #checked_image, #content_for, #context_menu, #context_menu_link, #current_theme, #due_date_distance_in_words, #favicon, #format_activity_day, #format_activity_description, #format_activity_title, #format_version_name, #has_content?, #heads_for_theme, #html_hours, #html_title, #image_to_function, #include_calendar_headers_tags, #include_in_api_response?, #javascript_heads, #label_tag_for, #labelled_tabular_form_for, #lang_options_for_select, #link_to_attachment, #link_to_if_authorized, #link_to_issue, #link_to_message, #link_to_project, #link_to_remote_if_authorized, #link_to_revision, #link_to_user, #other_formats_links, #page_header_title, #pagination_links_full, #parse_headings, #parse_inline_attachments, #parse_non_pre_blocks, #parse_redmine_links, #parse_wiki_links, #path_to_stylesheet, #per_page_links, #principals_check_box_tags, #progress_bar, #project_nested_ul, #project_tree, #project_tree_options_for_select, #prompt_to_remote, #render_flash_messages, #render_page_hierarchy, #render_project_jump_box, #render_tabs, #reorder_links, #replace_toc, #simple_format_without_paragraph, #stylesheet_path, #syntax_highlight, #textilizable, #time_tag, #to_path_param, #toggle_link, #truncate_lines, #truncate_single_line
Methods included from Redmine::I18n
#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages
Methods included from Redmine::WikiFormatting::Macros::Definitions
#exec_macro, #extract_macro_options
Methods included from SortHelper
#sort_clause, #sort_clear, #sort_header_tag, #sort_init, #sort_link, #sort_name, #sort_update
Methods inherited from ApplicationController
accept_key_auth, #accept_key_auth_actions, #api_key_from_request, #api_offset_and_limit, #api_request?, #authorize, #authorize_global, #back_url, #check_if_login_required, #check_project_privacy, #check_project_uniqueness, #default_template, #delete_broken_cookies, #deny_access, #filename_for_content_disposition, #find_current_user, #find_issues, #find_model_object, #find_project_by_project_id, #find_project_from_association, #invalid_authenticity_token, #logged_user=, model_object, #object_errors_to_json, #parse_qvalues, #per_page_option, #pick_layout, #query_statement_invalid, #redirect_back_or_default, #render_403, #render_404, #render_attachment_warning_if_needed, #render_error, #render_feed, #render_validation_errors, #require_admin, #require_login, #set_flash_from_bulk_issue_save, #set_localization, #use_layout, #user_setup
Methods included from Redmine::MenuManager::MenuController
#current_menu_item, included, #menu_items, #redirect_to_project_menu_item
Methods included from Redmine::Search::Controller
#default_search_scope, #default_search_scopes, included
Instance Method Details
#create ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/controllers/timelog_controller.rb', line 113 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 { flash[:notice] = l(:notice_successful_update) redirect_back_or_default :action => 'index', :project_id => @time_entry.project } format.api { render :action => 'show', :status => :created, :location => time_entry_url(@time_entry) } end else respond_to do |format| format.html { render :action => 'edit' } format.api { render_validation_errors(@time_entry) } end end end |
#destroy ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/timelog_controller.rb', line 164 def destroy if @time_entry.destroy && @time_entry.destroyed? respond_to do |format| format.html { flash[:notice] = l(:notice_successful_delete) redirect_to :back } format.api { head :ok } end else respond_to do |format| format.html { flash[:error] = l(:notice_unable_delete_time_entry) redirect_to :back } format.api { render_validation_errors(@time_entry) } end end rescue ::ActionController::RedirectBackError redirect_to :action => 'index', :project_id => @time_entry.project end |
#edit ⇒ Object
135 136 137 138 139 |
# File 'app/controllers/timelog_controller.rb', line 135 def edit @time_entry.attributes = params[:time_entry] call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) end |
#index ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/timelog_controller.rb', line 33 def index sort_init 'spent_on', 'desc' sort_update 'spent_on' => 'spent_on', 'user' => 'user_id', 'activity' => 'activity_id', '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] respond_to do |format| format.html { # 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, :include => [:project, :activity, :user, {:issue => :tracker}], :conditions => cond.conditions, :order => sort_clause, :limit => @entry_pages.items_per_page, :offset => @entry_pages.current.offset) @total_hours = TimeEntry.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f render :layout => !request.xhr? } format.api { @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, :include => [:project, :activity, :user, {:issue => :tracker}], :conditions => cond.conditions, :order => sort_clause, :limit => @entry_pages.items_per_page, :offset => @entry_pages.current.offset) } format.atom { entries = TimeEntry.visible.find(:all, :include => [:project, :activity, :user, {:issue => :tracker}], :conditions => cond.conditions, :order => "#{TimeEntry.table_name}.created_on DESC", :limit => Setting.feeds_limit.to_i) render_feed(entries, :title => l(:label_spent_time)) } format.csv { # Export all entries @entries = TimeEntry.visible.find(:all, :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}], :conditions => cond.conditions, :order => sort_clause) send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv') } end end |
#new ⇒ Object
104 105 106 107 108 109 110 |
# File 'app/controllers/timelog_controller.rb', line 104 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 |
#show ⇒ Object
96 97 98 99 100 101 102 |
# File 'app/controllers/timelog_controller.rb', line 96 def show respond_to do |format| # TODO: Implement html response format.html { render :nothing => true, :status => 406 } format.api end end |
#update ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/controllers/timelog_controller.rb', line 142 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 { flash[:notice] = l(:notice_successful_update) redirect_back_or_default :action => 'index', :project_id => @time_entry.project } format.api { head :ok } end else respond_to do |format| format.html { render :action => 'edit' } format.api { render_validation_errors(@time_entry) } end end end |