diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 078e990ba..cc6ea91dd 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -18,6 +18,7 @@ class BidsController < ApplicationController helper :attachments include AttachmentsHelper helper :projects + helper :words def index @project_type = params[:project_type] # Modified by nie @@ -186,7 +187,7 @@ class BidsController < ApplicationController def show @user = @bid.author - @jours = @bid.journals_for_messages.reverse + @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @@ -195,21 +196,19 @@ class BidsController < ApplicationController @state = false respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } - elsif @bid.reward_type == 1 - format.html { - render :layout => 'base_bids' - } + layout_file = '' + case @bid.reward_type + when 3 + layout_file = 'base_homework' + when 1 + layout_file = 'base_bids' else - format.html { - render :layout => 'base_contest' - } + layout_file = 'base_contest' end + format.html { + render :layout => layout_file + } format.api - end end @@ -502,7 +501,7 @@ class BidsController < ApplicationController @bid.add_jour(User.current, message, refer_user_id) end @user = @bid.author - @jours = @bid.journals_for_messages.reverse + @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 736842107..de18c6454 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -80,7 +80,7 @@ class ProjectsController < ApplicationController helper :documents helper :watchers # helper :watcherlist - + helper :words ### added by william include ActsAsTaggableOn::TagsHelper @@ -181,9 +181,7 @@ class ProjectsController < ApplicationController @s_type = 2 end else - logger.debug("-------------------------------------------------") @projects = Project.visible.where("project_type = ?", 1).order("created_on desc").offset(@project_pages.offset).limit(@limit).all - logger.debug("-------------------------------------------------") @s_type = 0 end respond_to do |format| @@ -282,7 +280,7 @@ class ProjectsController < ApplicationController #Ended by young def feedback - @jours = @project.journals_for_messages.reverse + @jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @@ -297,39 +295,31 @@ class ProjectsController < ApplicationController end def project_respond + # will_reply = JournalsForMessage.find(params[:reference_id]) if params[:reference_id] + project_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1] + # @project = Project.find_by_id(project_id) + parent_id = params[:reference_id] + author_id = User.current.id + reply_user_id = params[:reference_user_id] + reply_id = params[:reference_message_id] + content = params[:project_respond] + options = {:user_id => author_id, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} - if params[:project_respond].size>0 - jour = JournalsForMessage.find(params[:reference_id]) if params[:reference_id] - if jour - user = jour.user - text = jour.notes - else - user = User.current - text = [] - end - # Replaces pre blocks with [...] - text = text.to_s.strip.gsub(%r{
((.|\s)*?)
}m, '[...]') - reference_content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> " - reference_content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n" - # reference_message = JournalForMessage.find(params[:reference_id]) - message = params[:project_respond] + "\n" + reference_content + @jfm = Project.add_new_jour(nil, nil, project_id, options) + @save_succ = @jfm.errors.empty? - - user.add_jour(User.current, message, user.id) - flash[:notice]=l(:label_projects_feedback_respond_success) - # if a_message.size > 5 - # @message = a_message[-5, 5] - # else - # @message = a_message - # end - # @message_count = a_message.count - end + # flash[:notice]=l(:label_projects_feedback_respond_success) respond_to do |format| - format.html { redirect_to :back } + # format.html { redirect_to :back } + format.js #format.api { render_api_ok } end - # redirect_to project_feedback_path(@project) end def new diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index ce4523b2f..1e23197e7 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -39,11 +39,10 @@ class WordsController < ApplicationController #format.api { render_api_ok } end end + def create_reply # deny api. api useless - user_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1] - @user = User.find(user_id) parent_id = params[:reference_id] author_id = User.current.id reply_user_id = params[:reference_user_id] @@ -55,7 +54,7 @@ class WordsController < ApplicationController :reply_id => reply_user_id, :notes => content, :is_readed => false} - @jfm = @user.add_jour(nil, nil, nil, options) + @jfm = add_reply_adapter options respond_to do |format| # format.html { @@ -74,21 +73,8 @@ class WordsController < ApplicationController def destroy @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) - @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse - @limit = 10 - @feedback_count = @jours.count - @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - # if a_message.size > 5 - # @message = a_message[-5, 5] - # else - # @message = a_message - # end - # @message_count = a_message.count respond_to do |format| - format.html { redirect_to :back } format.js #format.api { render_api_ok } end @@ -187,5 +173,32 @@ class WordsController < ApplicationController render_404 end + def obj_distinguish_url_origin + referer = request.headers["Referer"] + obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1] + if referer.match(/project/) + obj = Project.find_by_id(obj_id) + elsif referer.match(/user/) + obj = User.find_by_id(obj_id) + elsif ( referer.match(/bids/) || referer.match(/calls/) ) + obj = Bid.find_by_id(obj_id) + else + raise 'create reply obj unknow type.' + end + obj + end + + def add_reply_adapter options + obj = obj_distinguish_url_origin + if obj.kind_of? User + obj.add_jour(nil, nil, nil, options) + elsif obj.kind_of? Project + Project.add_new_jour(nil, nil, obj.id, options) + elsif obj.kind_of? Bid + obj.add_jour(nil, nil, nil, options) + else + raise 'create reply obj unknow type.' + end + end #######end of message end \ No newline at end of file diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index e67726d34..329f84742 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -82,7 +82,7 @@ module WelcomeHelper ': '.html_safe << link_to(truncate(strip_tags(event.event_description).gsub(/ /,''), length: 30, omission:'...'), event.event_url, :target => "_blank" ) when 'attachment' - str << content_tag('span', '上传了') << content_tag('span', find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) << link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container)) + str << content_tag('span', '上传了') << content_tag('span', find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url) << link_to((' ['.html_safe+l(:label_downloads_list).to_s << ']'), project_files_path(event.container), :class => "attachments_list_color") else str << content_tag("span", "更新了") << content_tag("span", find_all_event_type(event)) << ': '.html_safe << link_to(truncate(event.event_title, length: 30, omission:'...'), event.event_url, :target => "_blank" ) end @@ -110,16 +110,17 @@ module WelcomeHelper # activity.scope=['memos'] # activity.events_welcome(nil, nil, {:limit => limit}) - # resultSet = Memo.where('memos.parent_id IS NULL').includes(:last_reply).order('COALESCE (last_replies_memos.created_at, memos.created_at) DESC').limit(limit) + resultSet = Memo.where('memos.parent_id IS NULL').includes(:last_reply).order('COALESCE (last_replies_memos.created_at, memos.created_at) DESC').limit(limit) # resultSet += Message.where('messages.parent_id IS NULL').includes(:last_reply).order('COALESCE (last_replies_messages.created_on, messages.created_on) DESC').limit(limit) - resultSet = Memo.includes(:children).where('parent_id IS NULL').order('updated_at DESC').limit(limit) - resultSet += Message.includes(:children).where('parent_id IS NULL').order('updated_on DESC').limit(limit) - resultSet.sort! {|x,y| y.event_datetime <=> x.event_datetime} - resultSet = resultSet.to_a - for i in 0..(resultSet.size-1) - resultSet[i] = resultSet[i].children.last if resultSet[i].children.count > 0 - end - resultSet.take(limit) + + # resultSet = Memo.includes(:children).where('parent_id IS NULL').order('updated_at DESC').limit(limit) + # resultSet += Message.includes(:children).where('parent_id IS NULL').order('updated_on DESC').limit(limit) + # resultSet.sort! {|x,y| y.event_datetime <=> x.event_datetime} + # resultSet = resultSet.to_a + # for i in 0..(resultSet.size-1) + # resultSet[i] = resultSet[i].children.last if resultSet[i].children.count > 0 + # end + # resultSet.take(limit) end private @@ -149,7 +150,7 @@ module WelcomeHelper # } # user_objs = User.find_by_sql("SELECT * FROM users WHERE (users.id IN #{"(" << users.join(',') << ")"} )") activity = Redmine::Activity::Fetcher.new(nil) - activity.scope_select{|t| ['changesets', 'documents'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } + activity.scope_select{|t| ['changesets', 'documents', 'memos', 'messages'].include?(t) ? nil : 'You may think you know what the following code does, may be. but why don"t you close this file and go play with something else, Now?' } activity.events_welcome(nil, nil, {:limit => limit, :types => 'welcome'}) end diff --git a/app/models/bid.rb b/app/models/bid.rb index e1b6b799a..d5177116e 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -77,8 +77,14 @@ class Bid < ActiveRecord::Base # safe_attributes 'name', # 'description', # 'deadline' - def add_jour(user, notes, reference_user_id = 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + def add_jour(user, notes, reference_user_id = 0, options = {}) + if options.count == 0 + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) + else + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end end def self.creat_bids(budget, deadline, name, description=nil, reward_type) diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index e83018be6..550197889 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -27,6 +27,16 @@ class JournalsForMessage < ActiveRecord::Base after_destroy :reset_counters! # default_scope { where('m_parent_id IS NULL') } + + def remove_by_user? user + if( self.user == user || + ( self.jour.kind_of?(User) && self.jour== user ) + ) + true + else + false + end + end def self.delete_message(message_id) self.find(message_id).destroy diff --git a/app/models/project.rb b/app/models/project.rb index d198d38c0..e106ac0c0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -166,10 +166,13 @@ class Project < ActiveRecord::Base pjfm end - def self.add_new_jour(user, notes, id) + def self.add_new_jour(user, notes, id, options={}) project = Project.find(id) - # project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0) - pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + if options.count == 0 + pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + else + pjfm = project.journals_for_messages.build(options) + end pjfm.save pjfm end diff --git a/app/views/bids/_history.html.erb b/app/views/bids/_history.html.erb index 2f627fa1d..b5b2f9499 100644 --- a/app/views/bids/_history.html.erb +++ b/app/views/bids/_history.html.erb @@ -1,69 +1,56 @@ - - - - - - <% else %> - - <% end %> - - -
- - <% if @bid.reward_type ==3 %> - <%=l(:label_student_response)%><%=l(:label_user_response)%>
- +<% tip1 = (@bid.reward_type == 3) ? l(:label_student_response) : l(:label_user_response) %> +

<%=tip1%>

<%= render :partial => 'new', :locals => {:bid => @bid, :sta => @state} %>
+<% label = ''; + case @bid.reward_type + when 1 + label = l(:label_respond_requirement) + when 2 + label = l(:label_contest_requirement) + when 3 + label = l(:label_question_requirement) + else + end +%> <% if journals.size >0 %> - -<% for journal in journals%> - - - - - -
<%= image_tag(url_to_avatar(journal.user), :class => "avatar") %> - - <% label = ''; - case @bid.reward_type - when 1 - label = l(:label_respond_requirement) - when 2 - label = l(:label_contest_requirement) - when 3 - label = l(:label_question_requirement) - else - - end - %> - - - - - - - - - <% if @user==User.current|| User.current.admin? %> - - <% else %> - -
<%=link_to journal.user, user_path(journal.user)%> <%= label %>

<%= textilizable journal.notes%>

<%= l(:label_bids_published) %> <%= time_tag(journal.created_on).html_safe %> <%= l(:label_bids_published_ago) %><%= link_to(l(:label_bid_respond_quote), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, - :method => 'post', :title => l(:button_quote))%> - <%= link_to(l(:label_bid_respond_delete), {:controller => 'bids', :action => 'destroy', :object_id => journal, :id => bid},:confirm => l(:label_delete_confirm), - :remote => true, :method => 'delete', :class => "delete", :confirm => l(:text_are_you_sure), :title => l(:button_delete)) %><%= link_to(l(:label_bid_respond_quote), {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, :remote => true, - :method => 'post', :title => l(:button_quote))%> - <% end %> -
-
+ <% end %> diff --git a/app/views/bids/contest.html.erb b/app/views/bids/contest.html.erb index 6cd3df16e..565e558d7 100644 --- a/app/views/bids/contest.html.erb +++ b/app/views/bids/contest.html.erb @@ -4,7 +4,7 @@ <%= form_tag(:controller => 'bids', :action => 'contest', :method => :get) do %> - +
<%= l(:label_contest_innovate) %><%= l(:label_contest_innovate) %> <%= l(:label_user_location) %> : <% if User.current.logged? %> @@ -54,4 +54,4 @@ <%= render :partial => "layouts/no_content"%> <% end %> - +<% html_title l(:label_contest_list)%> diff --git a/app/views/bids/index.html.erb b/app/views/bids/index.html.erb index ac724b1a1..d8e80992c 100644 --- a/app/views/bids/index.html.erb +++ b/app/views/bids/index.html.erb @@ -36,3 +36,5 @@ <%= render :partial => "layouts/no_content"%> <% end %> + +<% html_title l(:label_requirement_enterprise_list)%> \ No newline at end of file diff --git a/app/views/bids/show.html.erb b/app/views/bids/show.html.erb index 22cc1dcd4..78ef3a566 100644 --- a/app/views/bids/show.html.erb +++ b/app/views/bids/show.html.erb @@ -1,49 +1,34 @@ - - - - - - - -
<%= image_tag(url_to_avatar(@bid.author), :class => "avatar")%> - - - - +
+ <%= image_tag(url_to_avatar(@bid.author), :class => "avatar")%> + +

<%= link_to(@bid.author.lastname+@bid.author.firstname, user_path(@bid.author))%>:<%= @bid.name %>

<% if @bid.reward_type.nil? or @bid.reward_type == 1%> - -
+

+ <%= l(:label_bids_reward_method) %><%= l(:label_call_bonus) %>  + <%= l(:label_RMB_sign) %><%= @bid.budget %> +

<% elsif @bid.reward_type == 2%> - - - <% else %> - - <% end %> - - - -

<%= link_to(@bid.author.lastname+@bid.author.firstname, user_path(@bid.author))%>:<%= @bid.name %>

<%= l(:label_bids_reward_method) %> - - <%= l(:label_call_bonus) %> <%= l(:label_RMB_sign) %><%= @bid.budget%> - <%= l(:label_bids_reward_method) %> - - <%= @bid.budget%> -
<%= @bid.description %> - <% if @bid.attachments.any?%> - <% options = {:author => true} %> - <%= render :partial => 'attachments/links', - :locals => {:attachments => @bid.attachments, :options => options} %> +

+ <%= l(:label_bids_reward_method) %><%= @bid.budget%> +

+ <% else %> <% end %> -
- - - <%= render :partial => "/praise_tread/praise_tread", - :locals => {:obj => @bid,:show_flag => true,:user_id =>User.current.id}%> - -
+

+ <%= @bid.description %> +

+ <% if @bid.attachments.any?%> + <% options = {:author => true} %> + <%= render :partial => 'attachments/links', + :locals => {:attachments => @bid.attachments, :options => options} %> + <% end %> + + <%= render :partial => "/praise_tread/praise_tread", + :locals => {:obj => @bid,:show_flag => true,:user_id =>User.current.id}%> + + +
+ -
<%= render :partial => 'history', :locals => { :bid => @bid, :journals => @jour, :state => false} %>
@@ -54,4 +39,3 @@
    - diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index dc7c97b36..e476ab5e4 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -29,3 +29,5 @@ <% else %> <%= render :partial => "layouts/no_content" %> <% end %> + +<%html_title l(:label_forum)%> \ No newline at end of file diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 47662f254..f3f0524ae 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -1,5 +1,5 @@ -