From ac77c26c50037c113a0d4b99ef2a10f813169be4 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 23 Feb 2017 09:47:15 +0800 Subject: [PATCH] =?UTF-8?q?task=E5=86=99=E5=85=A5=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 +- app/models/training_task.rb | 8 ++ .../projects/_act_training_tasks.html.erb | 76 +++++++++++++++++++ .../projects/_project_activities.html.erb | 2 + app/views/projects/show.html.erb | 1 + .../training_tasks/_content_list.html.erb | 4 +- 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 app/views/projects/_act_training_tasks.html.erb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index fe00088b5..dab3b8168 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -332,9 +332,11 @@ class ProjectsController < ApplicationController if User.current.member_of?(@project) || User.current.admin? case params[:type] when nil - @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'TrainingTask','Message','News', 'Project', 'Attachment','Commit')", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'issue' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) + when 'training_task' + @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'TrainingTask'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'news' @events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'", @project).includes(:forge_act).order("updated_at desc").limit(10).offset(@page * 10) when 'message' diff --git a/app/models/training_task.rb b/app/models/training_task.rb index e518b1b4c..3ddf99286 100644 --- a/app/models/training_task.rb +++ b/app/models/training_task.rb @@ -13,8 +13,16 @@ class TrainingTask < ActiveRecord::Base :readonly => true has_many :praise_tread, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy + has_many :forge_acts, :class_name => 'ForgeActivity', :as => :forge_act, :dependent => :destroy + acts_as_attachable validates_presence_of :subject, :author validates_length_of :subject, :maximum => 255 + after_create :act_as_forge_activity + + def act_as_forge_activity + self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.project_id) + end + end diff --git a/app/views/projects/_act_training_tasks.html.erb b/app/views/projects/_act_training_tasks.html.erb new file mode 100644 index 000000000..f60ac213b --- /dev/null +++ b/app/views/projects/_act_training_tasks.html.erb @@ -0,0 +1,76 @@ +<% unless activity.author.nil? %> +
+
+
+ <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> + <%#= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
+
+
+ <%= link_to activity.try(:author).show_name, user_path(activity.author_id), :class => "newsBlue mr15" %> + TO + <%= link_to activity.project.name.to_s+" | 实训任务", project_training_tasks_path(activity.project), :class => "newsBlue ml15"%> +
+ <% if User.current.logged? && is_project_manager?(User.current.id, project_id) || activity.author_id == User.current.id %> +
+
    +
  • +
      +
    • + <%#= link_to l(:button_edit), edit_issue_path(activity.id), :class => 'postOptionLink', :accesskey => accesskey(:edit) if activity.editable? && User.current.allowed_to?(:edit_issues, activity.project) %> +
    • +
    • + <%#= link_to l(:button_delete), issue_path(activity.id), :data => {:confirm => issues_destroy_confirmation_message(activity)}, :method => :delete, :class => 'postOptionLink' if User.current.allowed_to?(:delete_issues, activity.project) %> +
    • +
    +
  • +
+
+ <% 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 %> +
+
+
+
+ 发布时间: + <%=format_time(activity.created_at) %> +
+
+ 更新时间:<%= format_time(ForgeActivity.where("forge_act_type='#{activity.class}' and forge_act_id =#{activity.id}").first.updated_at) %> +
+
+
+ <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id => user_activity_id, :content => activity.description} %> + + +
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
+
+
+
+
+ <%= render :partial => 'projects/project_issue_reply', :locals => {:activity => activity, :user_activity_id => user_activity_id} %> +
+
+ +<% end %> + diff --git a/app/views/projects/_project_activities.html.erb b/app/views/projects/_project_activities.html.erb index 07363a0a5..3f758c599 100644 --- a/app/views/projects/_project_activities.html.erb +++ b/app/views/projects/_project_activities.html.erb @@ -40,6 +40,8 @@ <% when "Issue" %> <%= render :partial => 'projects/act_issues', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> + <% when "TrainingTask" %> + <%= render :partial => 'projects/act_training_tasks', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :project_id => activity.project_id} %> <% when "Message" %> <%= render :partial => 'projects/act_messages', :locals => {:activity => activity.forge_act, :user_activity_id => activity.id, :is_course => 1, :is_board => 0} %> diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 24b982b77..5ad7c3f5f 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -24,6 +24,7 @@
  • <%= link_to "资源库动态", {:controller => "projects", :action => "show", :type => "attachment"}, :class => "homepagePostTypeResource resourcesGrey" %>
  • <%= link_to "讨论区动态", {:controller => "projects", :action => "show", :type => "message"}, :class => "homepagePostTypeForum postTypeGrey" %>
  • +
  • <%= link_to "讨论区动态", {:controller => "projects", :action => "show", :type => "training_task"}, :class => "homepagePostTypeForum postTypeGrey" %>
  • diff --git a/app/views/training_tasks/_content_list.html.erb b/app/views/training_tasks/_content_list.html.erb index b304a35e8..37940eacc 100644 --- a/app/views/training_tasks/_content_list.html.erb +++ b/app/views/training_tasks/_content_list.html.erb @@ -12,7 +12,9 @@ step<%= activity.position %> <%= activity.subject.to_s %> - <% if activity.status == 0 %> + <% if activity.status == 1 %> + 已解决 + <% else %> 正在解决中 <% end %>