diff --git a/.gitignore b/.gitignore index cf54e93..bc236cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ app/views/issues/show.html.erb +.idea + #ignore vim files *.swp -*.swo \ No newline at end of file +*.swo diff --git a/app/views/issues/3.0.0.show.html.erb b/app/views/issues/3.0.0.show.html.erb index bf23a7c..2c3012b 100644 --- a/app/views/issues/3.0.0.show.html.erb +++ b/app/views/issues/3.0.0.show.html.erb @@ -63,7 +63,7 @@ end end if User.current.allowed_to?(:view_time_entries, @project) - rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), issue_time_entries_path(@issue)) : "-"), :class => 'spent-time' + rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@total_hours), issue_time_entries_path(@issue)) : '-'), :class => 'spent-time' end end %> <%= render_custom_fields_rows(@issue) %> diff --git a/app/views/issues/3.0.1.show.html.erb b/app/views/issues/3.0.1.show.html.erb index d74ba56..677efdc 100644 --- a/app/views/issues/3.0.1.show.html.erb +++ b/app/views/issues/3.0.1.show.html.erb @@ -63,7 +63,7 @@ end end if User.current.allowed_to?(:view_time_entries, @project) - rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), issue_time_entries_path(@issue)) : "-"), :class => 'spent-time' + rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@total_hours), issue_time_entries_path(@issue)) : '-'), :class => 'spent-time' end end %> <%= render_custom_fields_rows(@issue) %> diff --git a/app/views/issues/3.2.0.show.html.erb b/app/views/issues/3.2.0.show.html.erb index c0269fe..17d8e20 100644 --- a/app/views/issues/3.2.0.show.html.erb +++ b/app/views/issues/3.2.0.show.html.erb @@ -62,9 +62,9 @@ rows.right l(:field_estimated_hours), issue_estimated_hours_details(@issue), :class => 'estimated-hours' end end - if User.current.allowed_to_view_all_time_entries?(@project) + if User.current.allowed_to?(:view_time_entries, @project) if @issue.total_spent_hours > 0 - rows.right l(:label_spent_time), issue_spent_hours_details(@issue), :class => 'spent-time' + rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@total_hours), issue_time_entries_path(@issue)) : '-'), :class => 'spent-time' end end end %> diff --git a/app/views/issues/_floating_report.html.erb b/app/views/issues/_floating_report.html.erb index ac7e08e..502a17f 100644 --- a/app/views/issues/_floating_report.html.erb +++ b/app/views/issues/_floating_report.html.erb @@ -1,7 +1,7 @@

Spent Time Report

- <% @issue.time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each_with_index do |entry, index| %> + <% @time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each_with_index do |entry, index| %>
">

<%= content_tag(:span, format_date( entry.spent_on ) ) if spent_on_shown? %> diff --git a/app/views/issues/_time_spent_report.html.erb b/app/views/issues/_time_spent_report.html.erb index 7745a6d..f80b93d 100644 --- a/app/views/issues/_time_spent_report.html.erb +++ b/app/views/issues/_time_spent_report.html.erb @@ -1,8 +1,8 @@


<%= t('plugin_spent_time_in_issue.timeEntries') %> - <% if @issue.time_entries.count > Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i %> - <%= link_to "#{t "plugin_spent_time_in_issue.seeAllCount", count: @issue.time_entries.count}", issue_time_entries_path( @issue ) %> + <% if @time_entries.count > Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i %> + <%= link_to "#{t "plugin_spent_time_in_issue.seeAllCount", count: @time_entries.count}", issue_time_entries_path( @issue ) %> <% end %>

@@ -14,7 +14,7 @@ <%= content_tag(:th ) %> - <% @issue.time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each do |entry| %> + <% @time_entries.last( Setting.plugin_redmine_spent_time_in_issue_description['spent_time_max_display'].to_i ).each do |entry| %> <%= content_tag(:td, format_date( entry.spent_on ) ) if spent_on_shown? %> <%= content_tag(:td, link_to_user( entry.user )) if user_shown? %> diff --git a/config/locales/zh.yml b/config/locales/zh.yml new file mode 100644 index 0000000..0227141 --- /dev/null +++ b/config/locales/zh.yml @@ -0,0 +1,25 @@ +zh: + plugin_spent_time_in_issue: + timeEntries: 工时记录 + spentOn: 工时发生日期 + max_display: 显示最大记录数 + time_format: 工时显示格式 + time_format_decimal: 小时-含小数 (如:1.5 ) + time_format_human: 自适应格式 ( 如:1小时 ) + datetime: + hours: + one: 1 小时 + other: "%{hours} 小时" + minutes: + one: 1 分钟 + other: "%{minutes} 分钟" + user: 用户 + hours: 工时 + comments: 备注 + display_cols: 显示列 + activity: 活动 + seeAllCount: "( 查看所有 %{count} 个工时记录 )" + error: "系统错误" + error_description: "该插件不能向问题写入信息。" + error_from_file: "请复制并重命名文件:" + error_to_file: "至文件:" diff --git a/init.rb b/init.rb index 8dba717..0b15f04 100644 --- a/init.rb +++ b/init.rb @@ -15,7 +15,9 @@ partial: 'settings/spent_time_in_issue_description_settings') ActionDispatch::Callbacks.to_prepare do + require 'issues_controller_patch' SetupIssueShow.new.replace + IssuesController.send(:include, TimeEntriesPatch::IssuesControllerPatch) end Rails.application.config.after_initialize do require 'issue_helper_patch' diff --git a/lib/issues_controller_patch.rb b/lib/issues_controller_patch.rb new file mode 100644 index 0000000..0f8b8a1 --- /dev/null +++ b/lib/issues_controller_patch.rb @@ -0,0 +1,61 @@ +module TimeEntriesPatch + module IssuesControllerPatch + + def self.included(base) + base.class_eval do + + def show_with_plugin + @journals = @issue.journals.includes(:user, :details). + references(:user, :details). + reorder(:created_on, :id).to_a + @journals.each_with_index { |j, i| j.indice = i+1 } + @journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project) + Journal.preload_journals_details_custom_fields(@journals) + @journals.select! { |journal| journal.notes? || journal.visible_details.any? } + @journals.reverse! if User.current.wants_comments_in_reverse_order? + + @changesets = @issue.changesets.visible.preload(:repository, :user).to_a + @changesets.reverse! if User.current.wants_comments_in_reverse_order? + + @relations = @issue.relations.select { |r| r.other_issue(@issue) && r.other_issue(@issue).visible? } + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) + @priorities = IssuePriority.active + @time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project) + @relation = IssueRelation.new + + @time_query = TimeEntryQuery.build_from_params(params) + scope = time_entry_scope(). + includes(:project, :user, :issue). + preload(:issue => [:project, :tracker, :status, :assigned_to, :priority]) + @total_hours = scope.sum(:hours).to_f + @time_entries = scope + + respond_to do |format| + format.html { + retrieve_previous_and_next_issue_ids + render :template => 'issues/show' + } + format.api + format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' } + format.pdf { + send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf" + } + end + end + + alias_method_chain :show, :plugin + + private + + def time_entry_scope(options={}) + scope = @time_query.results_scope(options) + if @issue + scope = scope.on_issue(@issue) + end + scope + end + + end + end + end +end