From 727a6fd536e58e0dd75fd50148189b24f076fe88 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 23 Feb 2017 14:13:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A1=B9=E7=9B=AE=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/training_tasks_controller.rb | 335 +----------------- .../projects/_act_training_tasks.html.erb | 18 +- app/views/training_tasks/_detail.html.erb | 13 +- .../_training_task_details.html.erb | 15 + 4 files changed, 32 insertions(+), 349 deletions(-) create mode 100644 app/views/training_tasks/_training_task_details.html.erb diff --git a/app/controllers/training_tasks_controller.rb b/app/controllers/training_tasks_controller.rb index 56ce9da79..ad10d34c2 100644 --- a/app/controllers/training_tasks_controller.rb +++ b/app/controllers/training_tasks_controller.rb @@ -2,7 +2,7 @@ class TrainingTasksController < ApplicationController layout 'base_projects' - before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete] + before_filter :find_project, :only => [:index, :new, :create, :update_form, :issue_commits, :commit_for_issue, :issue_commit_delete, :destroy] before_filter :allow_manager, :only => [] before_filter :allow_members, :only => [:new, :create] before_filter :build_new_task_from_params, :only => [:new, :create, :update_form] @@ -168,125 +168,15 @@ class TrainingTasksController < ApplicationController def update_form end - # Bulk edit/copy a set of issues - def bulk_edit - @issues.sort! - @copy = params[:copy].present? - @notes = params[:notes] - - if User.current.allowed_to?(:move_issues, @projects) - @allowed_projects = Issue.allowed_target_projects_on_move - if params[:issue] - @target_project = @allowed_projects.detect {|p| p.id.to_s == params[:issue][:project_id].to_s} - if @target_project - target_projects = [@target_project] - end - end - end - target_projects ||= @projects - - if @copy - @available_statuses = [IssueStatus.default] - else - @available_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) - end - @custom_fields = target_projects.map{|p|p.all_issue_custom_fields}.reduce(:&) - @assignables = target_projects.map(&:assignable_users).reduce(:&) - @trackers = target_projects.map(&:trackers).reduce(:&) - @versions = target_projects.map {|p| p.shared_versions.open}.reduce(:&) - @categories = target_projects.map {|p| p.issue_categories}.reduce(:&) - if @copy - @attachments_present = @issues.detect {|i| i.attachments.any?}.present? - @subtasks_present = @issues.detect {|i| !i.leaf?}.present? - end - - @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) - render :layout => false if request.xhr? - end - - def bulk_update - @issues.sort! - @copy = params[:copy].present? - attributes = parse_params_for_bulk_issue_attributes(params) - - unsaved_issue_ids = [] - moved_issues = [] - - if @copy && params[:copy_subtasks].present? - # Descendant issues will be copied with the parent task - # Don't copy them twice - @issues.reject! {|issue| @issues.detect {|other| issue.is_descendant_of?(other)}} - end - - @issues.each do |issue| - issue.reload - if @copy - issue = issue.copy({}, - :attachments => params[:copy_attachments].present?, - :subtasks => params[:copy_subtasks].present? - ) - end - journal = issue.init_journal(User.current, params[:notes]) - issue.safe_attributes = attributes - call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue }) - if issue.save - moved_issues << issue - else - # Keep unsaved issue ids to display them in flash error - unsaved_issue_ids << issue.id - end - end - set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids) - - if params[:follow] - if @issues.size == 1 && moved_issues.size == 1 - redirect_to issue_url(moved_issues.first) - elsif moved_issues.map(&:project).uniq.size == 1 - redirect_to project_issues_url(moved_issues.map(&:project).first) - end - else - redirect_back_or_default _project_issues_path(@project) - end - end - def destroy - # 增加删除页面类型,如果是个人主页,则返回该主页,项目动态则返回项目动态页眉 - page_classify = params[:page_classify] unless params[:page_classify].nil? - page_id = params[:page_id] unless params[:page_id].nil? - @hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f - if @hours > 0 - case params[:todo] - when 'destroy' - # nothing to do - when 'nullify' - TimeEntry.update_all('issue_id = NULL', ['issue_id IN (?)', @issues]) - when 'reassign' - reassign_to = @project.issues.find_by_id(params[:reassign_to_id]) - if reassign_to.nil? - flash.now[:error] = l(:error_issue_not_found_in_project) - return - else - TimeEntry.update_all("issue_id = #{reassign_to.id}", ['issue_id IN (?)', @issues]) - end - else - # display the destroy form if it's a user request - return unless api_request? - end - end - @issues.each do |issue| - begin - issue.reload.destroy - rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists - # nothing to do, issue was already deleted (eg. by a parent) - end - end + return unless build_new_task_from_params + @training_task.destroy respond_to do |format| - if page_classify - format.html { redirect_back_or_default _project_issues_path(@project, page_classify, page_id) } + if params[:type] == "project_show" + format.html {redirect_to project_path(@project)} else - format.html { redirect_back_or_default _project_issues_path(@project) } + format.html {redirect_to project_training_tasks_path(@project)} end - format.api { render_api_ok } end end @@ -413,219 +303,6 @@ class TrainingTasksController < ApplicationController end end - def statistics - @project = Project.find(params[:id]) - params[:author_id].to_i != 0 ? (@author = User.find(params[:author_id].to_i).show_name) : @author = 0 - case params[:tracker_id].to_i - when 1 - @tracker = "缺陷" - when 2 - @tracker = "功能" - when 3 - @tracker = "支持" - when 4 - @tracker = "任务" - when 5 - @tracker = "周报" - when 0 - @tracker = 0 - end - params[:subject].blank? ? @search = 0 : @search = params[:subject] - params[:assigned_to_id].to_i != 0 ? (@assigned = User.find(params[:assigned_to_id].to_i).show_name) : @assigned = 0 - params[:fixed_version_id].to_i != 0 ? (@version = Version.find(params[:fixed_version_id].to_i).name) : @version = 0 - params[:done_ratio].to_i != -1 ? (@done = params[:done_ratio].to_i) : @done = -1 - case params[:priority_id].to_i - when 1 - @prior = "低" - when 2 - @prior = "正常" - when 3 - @prior = "高" - when 4 - @prior = "紧急" - when 5 - @prior = "立刻" - when 0 - @prior = 0 - end - case params[:status_id].to_i - when 1 - @status = "新增" - when 2 - @status = "正在解决" - when 3 - @status = "已解决" - when 4 - @status = "反馈" - when 5 - @status = "关闭" - when 6 - @status = "拒绝" - when 0 - @status = 0 - end - params[:issue_create_date_start].blank? ? @start_time = 0 : @start_time = params[:issue_create_date_start] - params[:issue_create_date_end].blank? ? @end_time = 0 : @end_time = params[:issue_create_date_end] - @filter_condition = true - @filter_condition = false if (@author == 0 && @tracker == 0 && @search == 0 && @assigned == 0 && @version == 0 && @done == -1 && @prior ==0 && @status == 0 && @start_time ==0 && @end_time) - if @project.nil? - render_404 - end - retrieve_query - sort_init(@query.sort_criteria.empty? ? [['id', 'desc']] : @query.sort_criteria) - sort_update(@query.sortable_columns) - @query.sort_criteria = sort_criteria.to_a - @project_base_tag = 'base_projects' - if @query.valid? - @tracker_id = params[:tracker_id] - @assign_to_id = params[:assigned_to_id] - @author_id = params[:author_id] - @priority_id = params[:priority_id] - @status_id = params[:status_id] - @subject = params[:subject] - @done_ratio = params[:done_ratio] - @fixed_version_id = params[:fixed_version_id] - @issue_count = @query.issue_count - @test = params[:test] - @project_sort = 'issues.updated_on desc' - if params[:test] != "0" - case @test - when "1" - @project_sort = 'issues.created_on desc' - when "2" - @project_sort = 'issues.created_on asc' - when "3" - @project_sort = 'issues.updated_on desc' - when "4" - @project_sort = 'issues.updated_on asc' - end - end - # 搜索结果 - # SELECT assigned_to_id, count(*) as ac FROM `issues` where project_id = @project.id group by assigned_to_id order by ac desc; - @issues_filter = @query.issues.sort_by{ |i| Issue.where(:project_id => @project.id , :assigned_to_id => i.assigned_to_id).count }.reverse - # @issues_filter = @query.issues(:order => @project_sort) - - # if params[:type] == 1 || params[:type].nil? - # @results = @issues_filter - # elsif params[:type] == "2" - # @results = @issues_filter.collect{|result| result.status_id !=5 } - # elsif params[:type] == "3" - # @results = @issues_filter.collect{|result| result.status_id !=5 } - # end - - #统计 - @results = {} - - #统计total - @alltotal = {} - for i in 0..5 do - @alltotal[i] = 0 - end - - @opentotal = {} - for i in 0..5 do - @opentotal[i] = 0 - end - - @closetotal = {} - for i in 0..5 do - @closetotal[i] = 0 - end - - #开启关闭 - @issue_open_count = 0 - @issue_close_count = 0 - - @issues_filter.each do |issue| - @alltotal[0] = @alltotal[0] + 1 - @alltotal[issue.tracker_id.to_i] = @alltotal[issue.tracker_id.to_i] + 1 - user_id = issue.assigned_to_id - if issue.assigned_to_id.nil? - user_id = 0 - end - - if !@results[user_id].nil? - @results[user_id][0] = @results[user_id][0] + 1 - @results[user_id][issue.tracker_id.to_i] = @results[user_id][issue.tracker_id.to_i] + 1 - - if issue.status_id.to_i == 5 - @issue_close_count = @issue_close_count + 1 - @results[user_id][12] = @results[user_id][12]+1 - @results[user_id][12+issue.tracker_id.to_i] = @results[user_id][12+issue.tracker_id.to_i]+1 - - @closetotal[0] = @closetotal[0] + 1 - @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 - else - @issue_open_count = @issue_open_count + 1 - @results[user_id][6] = @results[user_id][6]+1 - @results[user_id][6+issue.tracker_id.to_i] = @results[user_id][6+issue.tracker_id.to_i]+1 - - @opentotal[0] = @opentotal[0] + 1 - @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 - end - else - - @results[user_id] = {} - - tmpuser = User.find(user_id) - - @results[user_id][:name] = tmpuser.nil? ? "" : tmpuser.show_name - #所有的 - @results[user_id][0] = 1 - for i in 1..17 do - @results[user_id][i] = 0 - end - # @results[user_id][1] = 0 - # @results[user_id][2] = 0 - # @results[user_id][3] = 0 - # @results[user_id][4] = 0 - # @results[user_id][5] = 0 - @results[user_id][issue.tracker_id.to_i] = 1 - - #开启的 status_id = 12346 - # @results[user_id][6] = 0 - # @results[user_id][7] = 0 - # @results[user_id][8] = 0 - # @results[user_id][9] = 0 - # @results[user_id][10] = 0 - # @results[user_id][11] = 0 - - #关闭的 status_id = 5 - # @results[user_id][12] = 0 - # @results[user_id][13] = 0 - # @results[user_id][14] = 0 - # @results[user_id][15] = 0 - # @results[user_id][16] = 0 - # @results[user_id][17] = 0 - - if issue.status_id.to_i == 5 - @results[user_id][12] = 1 - @results[user_id][12+issue.tracker_id.to_i] = 1 - @issue_close_count = @issue_close_count+1 - - @closetotal[0] = @closetotal[0] + 1 - @closetotal[issue.tracker_id.to_i] = @closetotal[issue.tracker_id.to_i] + 1 - else - @issue_open_count = @issue_open_count+1 - @results[user_id][6] = 1 - @results[user_id][6+issue.tracker_id.to_i] = 1 - - @opentotal[0] = @opentotal[0] + 1 - @opentotal[issue.tracker_id.to_i] = @opentotal[issue.tracker_id.to_i] + 1 - end - - end - end - - respond_to do |format| - format.js - end - - else - render_404 - end - end - private def find_project diff --git a/app/views/projects/_act_training_tasks.html.erb b/app/views/projects/_act_training_tasks.html.erb index 1bc9ec80e..12825c4c7 100644 --- a/app/views/projects/_act_training_tasks.html.erb +++ b/app/views/projects/_act_training_tasks.html.erb @@ -20,27 +20,15 @@ <%= link_to l(:button_edit), edit_training_task_path(activity.id), :class => 'postOptionLink', :accesskey => accesskey(:edit) %>
  • - <%= link_to l(:button_delete), training_task_path(activity.id), :data => {:confirm => l(:text_trainig_task_destroy_confirmation)}, :method => :delete, :class => 'postOptionLink' %> + <%= link_to l(:button_delete), training_task_path(activity.id, :project_id => @project.id, :type => "project_show"), :data => {:confirm => l(:text_trainig_task_destroy_confirmation)}, :method => :delete, :class => 'postOptionLink' %>
  • <% end %> -
    - <% if activity.status == 1 %> -
    - <% else %> -
    - <% end %> - step<%= activity.position %> - - <%= link_to activity.subject.to_s, training_task_url(activity), :class => "postGrey ml5 fl", :target => "_blank" %> - <% if activity.status == 1 %> - 已解决 - <% else %> - 正在解决中 - <% end %> +
    + <%= render :partial => "training_tasks/training_task_details", :locals => {:activity => activity} %>
    diff --git a/app/views/training_tasks/_detail.html.erb b/app/views/training_tasks/_detail.html.erb index e28fef9f2..9065952af 100644 --- a/app/views/training_tasks/_detail.html.erb +++ b/app/views/training_tasks/_detail.html.erb @@ -3,9 +3,9 @@ <%= link_to image_tag(url_to_avatar(@training_task.author), :width => 46, :height => 46), user_path(@training_task.author), :class => "ping_dispic" %>
    -

    - <%= @training_task.subject %>

    - +
    + <%= render :partial => "training_tasks/training_task_details", :locals => {:activity => @training_task, :project_id => @project.id} %> +

    由<%=link_to @training_task.author.show_name, user_path(@training_task.author), :class => "link-blue" %>添加于 <%= format_time(@training_task.created_at).html_safe %> @@ -14,12 +14,15 @@ - <%#= render :partial => 'action_menu' %> + <% if User.current.logged? && is_project_manager?(User.current.id, @project.id) || @training_task.author_id == User.current.id %> + <%= link_to l(:button_delete), training_task_path(@training_task.id, :project_id => @project.id), :data => {:confirm => l(:text_trainig_task_destroy_confirmation)}, :method => :delete, :class => 'talk_edit fr' %> + <%= link_to l(:button_edit), edit_training_task_path(@training_task), :class => 'talk_edit fr', :accesskey => accesskey(:edit) %> + <% end %> +
    <% if @training_task.description? || @training_task.attachments.any? -%>
    <% if @training_task.description? %> - <%#= link_to l(:button_quote), quoted_issue_path(@issue.id), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %> <%= textAreailizable @training_task, :description, :attachments => @training_task.attachments %> <% end %>
    diff --git a/app/views/training_tasks/_training_task_details.html.erb b/app/views/training_tasks/_training_task_details.html.erb new file mode 100644 index 000000000..9ef46f019 --- /dev/null +++ b/app/views/training_tasks/_training_task_details.html.erb @@ -0,0 +1,15 @@ +
    + <% if activity.status == 1 %> +
    + <% else %> +
    + <% end %> + step<%= activity.position %> + + <%= link_to activity.subject.to_s, training_task_url(activity), :class => "postGrey ml5 fl", :target => "_blank" %> + <% if activity.status == 1 %> + 已解决 + <% else %> + 正在解决中 + <% end %> +
    \ No newline at end of file