组织资源栏目显示转发的帖子

This commit is contained in:
ouyangxuhua 2015-12-23 16:49:05 +08:00
parent b9ae579622
commit 73d377d06d
9 changed files with 53 additions and 4 deletions

View File

@ -313,9 +313,16 @@ class MessagesController < ApplicationController
def join_org_subfields def join_org_subfields
org_subfield_ids = params[:org_subfields] org_subfield_ids = params[:org_subfields]
@message = Message.find(params[:id]) @message = Message.find(params[:id])
# @message.update_attribute(:updated_on, Time.now)
type = @message.board.course_id.nil? ? "Project":"Course" type = @message.board.course_id.nil? ? "Project":"Course"
org_subfield_ids.each do |field_id| org_subfield_ids.each do |field_id|
OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => @message.id, :message_type => type) OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => @message.id, :message_type => type)
org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id)
if org_acts.all.size() > 0
org_acts.first.update_attribute(:updated_at, Time.now)
else
OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => @message.id, :user_id => User.current.id)
end
end end
end end

View File

@ -6,6 +6,17 @@ class OrgSubfieldsController < ApplicationController
@subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type]) @subfield.update_attributes(:priority => @subfield.id, :field_type => params[:field_type])
end end
def show
@org_subfield = OrgSubfield.find(params[:id])
@organization = @org_subfield.organization.id
@messages = []
@messages << @org_subfield.org_document_comments
@messages << @org_subfield.messages
@messages.sort{|a, b| b.updated_at <=> a.updated_at}
respond_to do |format|
format.html{render :layout => 'base_org'}
end
end
def destroy def destroy
@subfield = OrgSubfield.find(params[:id]) @subfield = OrgSubfield.find(params[:id])
@organization = Organization.find(@subfield.organization_id) @organization = Organization.find(@subfield.organization_id)
@ -18,7 +29,4 @@ class OrgSubfieldsController < ApplicationController
@subfield.update_attributes(:name => params[:name]) @subfield.update_attributes(:name => params[:name])
end end
def show
end
end end

View File

@ -71,7 +71,7 @@ class OrganizationsController < ApplicationController
if params[:org_subfield_id] if params[:org_subfield_id]
@org_subfield = OrgSubfield.find(params[:org_subfield_id]) @org_subfield = OrgSubfield.find(params[:org_subfield_id])
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0 @org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
@org_activities = OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})").order('updated_at desc').page(params[:page] || 1).per(10) @org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
else else
project_ids = @organization.projects.map(&:id) << 0 project_ids = @organization.projects.map(&:id) << 0
course_ids = @organization.courses.map(&:id) << 0 course_ids = @organization.courses.map(&:id) << 0

View File

@ -0,0 +1,3 @@
class OrgSubfieldMessage < ActiveRecord::Base
# attr_accessible :title, :body
end

View File

View File

@ -49,6 +49,16 @@
<%= render :partial => 'org_course_create', :locals => {:activity => Course.find(act.org_act_id), :user_activity_id => act.id} %> <%= render :partial => 'org_course_create', :locals => {:activity => Course.find(act.org_act_id), :user_activity_id => act.id} %>
<% end %> <% end %>
<% end %> <% end %>
<% if act.container_type == 'OrgSubfield' %>
<% if act.org_act_type == 'Message' %>
<% message = Message.find(act.org_act_id) %>
<% if !message.board.course_id.nil? %>
<%= render :partial => 'org_course_message', :locals => {:activity => message,:user_activity_id =>act.id} %>
<% else %>
<%= render :partial => 'organizations/project_message', :locals => {:activity => message,:user_activity_id =>act.id} %>
<% end %>
<% end %>
<% end %>
<% end %> <% end %>
<!--<ul class="wlist" style=" border:none; padding-top: 15px;">--> <!--<ul class="wlist" style=" border:none; padding-top: 15px;">-->
<%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> <%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>

View File

@ -0,0 +1,10 @@
class CreateOrgSubfieldMessages < ActiveRecord::Migration
def change
create_table :org_subfield_messages do |t|
t.integer :org_subfield_id
t.integer :message_id
t.string :message_type
t.timestamps
end
end
end

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :org_subfield_message, :class => 'OrgSubfieldMessage' do
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe OrgSubfieldMessage, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end