From 5306d7e2a4628ee9fb2a767e721df922ac6bda09 Mon Sep 17 00:00:00 2001 From: huang Date: Mon, 24 Aug 2015 23:53:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F=EF=BC=88?= =?UTF-8?q?=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 77 ++++++- app/models/message_all.rb | 5 + app/views/users/user_messages_new.html.erb | 233 +++++++++++++++++++++ config/routes.rb | 3 + spec/factories/message_alls.rb | 8 + spec/models/message_all_spec.rb | 5 + 6 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 app/models/message_all.rb create mode 100644 app/views/users/user_messages_new.html.erb create mode 100644 spec/factories/message_alls.rb create mode 100644 spec/models/message_all_spec.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 989727825..f677bc4d4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -45,14 +45,14 @@ class UsersController < ApplicationController :activity_new_score_index, :influence_new_score_index, :score_new_index,:update_score,:user_activities,:user_projects_index, :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist, :user_resource,:user_resource_create,:user_resource_delete,:rename_resource,:search_user_course,:add_exist_file_to_course, - :search_user_project,:resource_preview,:resource_search,:add_exist_file_to_project,:user_messages] + :search_user_project,:resource_preview,:resource_search,:add_exist_file_to_project,:user_messages, :user_messages_new] #edit has been deleted by huang, 2013-9-23 before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses, :user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, - :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction] + :user_courses4show,:user_projects4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_messages_new] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -122,6 +122,7 @@ class UsersController < ApplicationController @new_message_count = @user.forge_messages.count + @user.memo_messages.count + @user.course_messages.count + @user.user_feedback_messages.count case params[:type] when nil + @all_message = MessageAll.where("user_id =?",@user).order("created_at desc") @user_course_messages = CourseMessage.where("user_id =?",@user).order("created_at desc") @user_forge_messages = ForgeMessage.where("user_id =?",@user).order("created_at desc") @user_memo_messages = MemoMessage.where("user_id =?",@user).order("created_at desc") @@ -181,6 +182,78 @@ class UsersController < ApplicationController end end + def user_messages_new + unless User.current.logged? + render_403 + return + end + # 当前用户查看消息,则设置消息为已读 + course_querys = @user.course_messages + forge_querys = @user.forge_messages + user_querys = @user.user_feedback_messages + forum_querys = @user.memo_messages + # if User.current.id == @user.id + # course_querys.update_all(:viewed => true) + # forge_querys.update_all(:viewed => true) + # user_querys.update_all(:viewed => true) + # forum_querys.update_all(:viewed => true) + # end + @new_message_count = @user.forge_messages.count + @user.memo_messages.count + @user.course_messages.count + @user.user_feedback_messages.count + case params[:type] + when nil + @user_message_all = MessageAll.where("user_id =?", @user).order("created_at desc") + @user_message_all_count = @user_message_all.count + when 'homework' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'course_message' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_message' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Message", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'course_news' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "News", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_news' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "News", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'course_news_reply' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'forge_news_reply' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Comment", @user).order("created_at desc") + @user_forge_messagess_count = @user_forge_messages.count + when 'poll' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "Poll", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'works_reviewers' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "StudentWorksScore", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'works_reply' + @user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") + @user_course_messages_count = @user_course_messages.count + when 'issue' + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Issue", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'issue_update' # 缺陷状态更新、留言 + @user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Journal", @user).order("created_at desc") + @user_forge_messages_count = @user_forge_messages.count + when 'forum' + @user_memo_messages = MemoMessage.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc") + @user_memo_messages_count = @user_memo_messages.count + when 'user_feedback' + @user_feedback_messages = UserFeedbackMessage.where("journals_for_message_type =? and user_id =?", "JournalsForMessage", @user).order("created_at desc") + @user_feedback_messages_count = @user_feedback_messages.count + else + render_404 + return + end + respond_to do |format| + format.html{render :layout=>'new_base_user'} + end + end + def user_projects_index if User.current.admin? memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}").first diff --git a/app/models/message_all.rb b/app/models/message_all.rb new file mode 100644 index 000000000..6e0276875 --- /dev/null +++ b/app/models/message_all.rb @@ -0,0 +1,5 @@ +class MessageAll < ActiveRecord::Base + attr_accessible :message_id, :message_type, :user_id + # 虚拟关联---项目消息表/课程消息表/用户留言消息表/贴吧消息表 + belongs_to :message ,:polymorphic => true +end diff --git a/app/views/users/user_messages_new.html.erb b/app/views/users/user_messages_new.html.erb new file mode 100644 index 000000000..d861f867d --- /dev/null +++ b/app/views/users/user_messages_new.html.erb @@ -0,0 +1,233 @@ +
+
+
+
消息
+ +
+<% if params[:type].nil? %> +
+ 有 8 封未读全部设为已读 +
+<% end %> +
+<% if @new_message_count >0 %> + <%# 课程消息 %> + <% unless @user_message_all.nil? %> + <% @user_message_all.each do |uma| %> + <% if uma.message.course_message_type == "News" %> +
    +
  • <%= image_tag(url_to_avatar(uma.message.course_message.author), :width => "30", :height => "30") %>
  • +
  • <%=link_to uma.message.course_message.author, user_path(uma.message.course_message.author), :class => "newsBlue" %>
  • +
  • ">发布通知
  • +
  • + <%= link_to uma.message.course_message.title, {:controller => 'news', :action => 'show', :id => uma.message.course_message.id }, + :class =>"#{uma.message.viewed == 0 ? "newsBlack" : "newsGrey"}", + :title => "#{uma.message.course_message.title}" %>
  • +
  • <%= time_tag(uma.message.course_message.created_on).html_safe %>
  • +
+ <% end %> + <% if uma.message.course_message_type == "Comment" %> +
    +
  • <%= image_tag(url_to_avatar(uma.message.course_message.author), :width => "30", :height => "30") %>
  • +
  • <%=link_to uma.message.course_message.author, user_path(uma.message.course_message.author), :class => "newsBlue" %>
  • +
  • ">回复了通知
  • +
  • + <%= link_to uma.message.course_message.comments.html_safe, {:controller => 'news', :action => 'show', :id => uma.message.course_message.commented.id }, + :class =>"#{uma.message.viewed == 0 ? "newsBlack" : "newsGrey"}", + :title => "#{uma.message.course_message.comments.html_safe}" %>
  • +
  • <%= time_tag(uma.message.course_message.created_on).html_safe %>
  • +
+ <% end %> + <% if uma.message.course_message_type == "HomeworkCommon" %> + + <% end %> + <% if uma.message.course_message_type == "Poll" %> + + <% end %> + <% if uma.message.course_message_type == "Message" %> + + <% end %> + <% if uma.message.course_message_type == "StudentWorksScore" %> + + <% end %> + <% if uma.message.course_message_type == "JournalsForMessage" %> + + <% end %> + + + <% if uma.message.forge_message_type == "Issue" %> + + <% end %> + <% if uma.message.forge_message_type == "Journal" %> + + <% end %> + <% if uma.message.forge_message_type == "Message" %> + + <% end %> + <% if uma.message.forge_message_type == "News" %> + + <% end %> + <% if uma.message.forge_message_type == "Comment" %> +
    +
  • <%= image_tag(url_to_avatar(uma.message.forge_message.author), :width => "30", :height => "30") %>
  • +
  • <%=link_to uma.message.forge_message.author, user_path(uma.message.forge_message.author), :class => "newsBlue" %>
  • +
  • 回复了新闻
  • +
  • + <%= link_to "#{uma.message.forge_message.comments.html_safe}", + {:controller => 'news', :action => 'show', :id => uma.message.forge_message.commented.id },:class =>"#{uma.message.viewed == 0 ? "newsBlack" : "newsGrey"}", :title => "#{uma.message.forge_message.comments.html_safe}"%>
  • +
  • <%= time_tag(uma.message.forge_message.created_on).html_safe %>
  • +
+ <% end %> + + + <% end %> + <% end %> + + + <%# 公共贴吧 %> + + <%# 用户留言消息 %> + +<% else %> +
暂无消息!
+<% end %> +
+
+
+
+ + + + + + + + + + + + diff --git a/config/routes.rb b/config/routes.rb index 61bac37cb..7ba09a83a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -364,7 +364,10 @@ RedmineApp::Application.routes.draw do end match 'users/:id/user_newfeedback', :to => 'users#user_newfeedback', :via => :get, :as => "feedback" match 'users/:id/user_projects', :to => 'users#user_projects', :via => :get + #消息 match 'users/:id/user_messages', :to => 'users#user_messages', :via => :get, :as => "user_message" + match 'users/:id/user_messages_new', :to => 'users#user_messages_new', :via => :get, :as => "user_messages_new" + #match 'users/:id/user_messages/:homework', :to => 'users#user_messages_homework', :via => :get, :as => "user_message_homewrok" diff --git a/spec/factories/message_alls.rb b/spec/factories/message_alls.rb new file mode 100644 index 000000000..c14c153cf --- /dev/null +++ b/spec/factories/message_alls.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :message_all do + user_id 1 +message_id 1 +message_type "MyString" + end + +end diff --git a/spec/models/message_all_spec.rb b/spec/models/message_all_spec.rb new file mode 100644 index 000000000..33ac896e2 --- /dev/null +++ b/spec/models/message_all_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe MessageAll, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end