diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a2902e3fc..b15be4896 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -374,6 +374,9 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.run.attachments_added(attachments[:files]) end + # 更新课程英雄榜得分 + update_contributor_score(@course, attachments[:files].first) + # end if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array) params[:course_attachment_type].each do |type| tag_name = get_tag_name_by_type_number type @@ -423,6 +426,20 @@ class FilesController < ApplicationController end end + def update_contributor_score(course, file ) + unless file.author.allowed_to?(:as_teacher, course) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5) + else + score = course_contributor_score.resource_num + 5 + total_score = course_contributor_score.total_score + 5 + course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score) + end + end + end + def get_tag_name_by_type_number type case type when "1" diff --git a/app/controllers/org_courses_controller.rb b/app/controllers/org_courses_controller.rb index 3d1d313c5..d054e41de 100644 --- a/app/controllers/org_courses_controller.rb +++ b/app/controllers/org_courses_controller.rb @@ -3,7 +3,9 @@ class OrgCoursesController < ApplicationController org_ids = params[:orgNames] @course = Course.find(params[:course_id]) org_ids.each do |org_id| - OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now) + if OrgCourse.where("organization_id =? and course_id =?", org_id.to_i, params[:course_id].to_i).count == 0 + OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now) + end end respond_to do |format| format.js diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index 61a27c433..776bd132d 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -38,12 +38,19 @@ class OrgDocumentCommentsController < ApplicationController act.update_attributes(:updated_at => @org_document.updated_at) end respond_to do |format| - format.html {redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)} + format.html { + if params[:flag] == 0 + redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id) + else + redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id) + end + } end end def edit @org_document = OrgDocumentComment.find(params[:id]) + @flag = params[:flag] @organization = Organization.find(params[:organization_id]) end diff --git a/app/controllers/org_projects_controller.rb b/app/controllers/org_projects_controller.rb index 29e60a62a..a455ce408 100644 --- a/app/controllers/org_projects_controller.rb +++ b/app/controllers/org_projects_controller.rb @@ -3,7 +3,9 @@ class OrgProjectsController < ApplicationController org_ids = params[:orgNames] @project = Project.find(params[:project_id]) org_ids.each do |org_id| - OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now) + if OrgProject.where("organization_id =? and project_id =?", org_id.to_i, @project.id).count == 0 + OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now) + end end respond_to do |format| format.js diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 0d22ab461..ba4dda939 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -175,4 +175,75 @@ class OrganizationsController < ApplicationController format.js end end + + def join_course_menu + @organization = Organization.find(params[:id]) + respond_to do |format| + format.js + end + end + + def search_courses + @organization = Organization.find(params[:id]) + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + #sql = "select courses.* from courses inner join members on courses.id = members.course_id inner join org_courses on courses.id = org_courses.course_id where org_courses.organization_id != #{@organization.id} and members.user_id = #{User.current.id} and courses.name like '#{condition}'" + sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'" + user_courses = Course.find_by_sql(sql) + @added_course_ids = @organization.courses.map(&:id) + @courses = [] + user_courses.each do |course| + if !@added_course_ids.include?(course.id) + @courses << course + end + end + end + + def join_courses + @organization = Organization.find(params[:id]) + course_ids = params[:courseNames] + course_ids.each do |id| + OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now) + end + respond_to do |format| + format.js + end + end + + def join_project_menu + @organization = Organization.find(params[:id]) + respond_to do |format| + format.js + end + end + + def search_projects + @organization = Organization.find(params[:id]) + condition = '%%' + if !params[:name].nil? + condition = "%#{params[:name].strip}%".gsub(" ","") + end + sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" + user_projects = Course.find_by_sql(sql) + @added_course_ids = @organization.projects.map(&:id) + @projects = [] + user_projects.each do |project| + if !@added_course_ids.include?(project.id) + @projects << project + end + end + end + + def join_projects + @organization = Organization.find(params[:id]) + project_ids = params[:projectNames] + project_ids.each do |id| + OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now) + end + respond_to do |format| + format.js + end + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f4e0f88ff..046e0c5a0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -75,6 +75,50 @@ module ApplicationHelper end end + # 更新课程英雄榜得分 + # user传过来必须是学生 + def course_member_score(course_id,user_id,type) + course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first + case type + when "JournalForMessage" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1) + else + score = course_contributor_score.journal_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score) + end + when "Message" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0, + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2) + else + score = course_contributor_score.message_num + 2 + total_score = course_contributor_score.total_score + 2 + course_contributor_score.update_attributes(:message_num => score, :total_score => total_score) + end + when "MessageReply" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1, + :news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + else + score = course_contributor_score.message_reply_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score) + end + when "NewReply" + if course_contributor_score.nil? + CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0, + :news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1) + else + score = course_contributor_score.news_reply_num + 1 + total_score = course_contributor_score.total_score + 1 + course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score) + end + end + end + # Added by young # Define the course menu's link class # 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表 diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index caca6fb1e..a1b119cb5 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -25,6 +25,10 @@ module CoursesHelper # searchTeacherAndAssistant(project).count end + def show_nav?(count) + count == 0 ? true : false + end + #课程模块需要展示的模块 def course_model @nav_dispaly_course_all_label = 1 @@ -733,4 +737,26 @@ module CoursesHelper end desc.html_safe end + + # 学生按作业总分排序,取前8个 + def hero_homework_score(course, score_sort_by) + sql_select = "SELECT members.*,( + SELECT SUM(student_works.final_score) + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = #{course.id} + AND student_works.user_id = members.user_id + ) AS score + FROM members + JOIN students_for_courses + ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id + WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9" + homework_scores = Member.find_by_sql(sql_select) + end + + def contributor_course_scor(course_id) + ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9) + end + end + diff --git a/app/models/attachment.rb b/app/models/attachment.rb index f7fb9b1aa..9c6bb9cb1 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -560,4 +560,5 @@ class Attachment < ActiveRecord::Base self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id) end end + end diff --git a/app/models/comment.rb b/app/models/comment.rb index bb31eb894..9de25c50d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -35,7 +35,7 @@ class Comment < ActiveRecord::Base belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' validates_presence_of :commented, :author, :comments safe_attributes 'comments' - after_create :send_mail, :act_as_system_message + after_create :send_mail, :act_as_system_message, :act_as_student_score def act_as_system_message if self.commented.course @@ -66,13 +66,24 @@ class Comment < ActiveRecord::Base def set_notify_id(notify_id) @notify_id= notify_id end + def get_notify_id() return @notify_id end + def set_notify_is_read(notify_is_read) @notify_is_read = notify_is_read end + def get_notify_is_read() return @notify_is_read end + + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.author.allowed_to?(:as_teacher, self.commented.course) + course_member_score(self.commented.course.id, self.author_id, "NewReply") + end + end + end diff --git a/app/models/course.rb b/app/models/course.rb index 1350b8cf7..ec1afd611 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -40,8 +40,10 @@ class Course < ActiveRecord::Base has_many :course_activities # 课程消息 - has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy has_many :exercises, :dependent => :destroy + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy diff --git a/app/models/course_contributor_score.rb b/app/models/course_contributor_score.rb new file mode 100644 index 000000000..f2b05458f --- /dev/null +++ b/app/models/course_contributor_score.rb @@ -0,0 +1,5 @@ +class CourseContributorScore < ActiveRecord::Base + attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score + belongs_to :course + belongs_to :user +end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 5e40267cb..eaece95ce 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -64,7 +64,7 @@ class JournalsForMessage < ActiveRecord::Base has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy validates :notes, presence: true, if: :is_homework_jour? - after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -263,4 +263,12 @@ class JournalsForMessage < ActiveRecord::Base end end + + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.user.allowed_to?(:as_teacher, self.jour) + course_member_score(self.jour_id, self.user_id, "JournalForMessage") + end + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 7af59815b..21e5e1c71 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -74,7 +74,7 @@ class Message < ActiveRecord::Base after_update :update_messages_board after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets - after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail + after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score #before_save :be_user_score scope :visible, lambda {|*args| @@ -285,4 +285,16 @@ class Message < ActiveRecord::Base delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE end + # 课程成员得分(英雄榜) + def act_as_student_score + unless self.author.allowed_to?(:as_teacher, self.course) + if self.parent_id.nil? + # 发帖 + course_member_score(self.course.id, self.author_id, "Message") + else + # 回帖 + course_member_score(self.course.id, self.author_id, "MessageReply") + end + end + end end diff --git a/app/models/user.rb b/app/models/user.rb index 3e7bc2ddb..cd8b96d47 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -153,6 +153,8 @@ class User < Principal # 邮件邀请状态 has_many :invite_lists, :dependent => :destroy # end + # 课程贡献榜 + has_many :course_contributor_scores, :dependent => :destroy ######added by nie has_many :project_infos, :dependent => :destroy diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb new file mode 100644 index 000000000..9a36b8efb --- /dev/null +++ b/app/views/courses/_tool_expand.html.erb @@ -0,0 +1,47 @@ +<% course_file_num = visable_attachemnts_incourse(@course).count%> +<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> +<% if show_nav?(@course.homework_commons.count) %> + +<% end %> +<% if show_nav?(@course.news.count) %> + +<% end %> +<% if show_nav?(course_file_num) %> + +<% end %> +<% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> + +<% end %> +<% if show_nav?(course_feedback_count) %> + +<% end %> +<% if show_nav?(course_poll_count) %> + +<% end %> +<% if show_nav?(User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status=2").count) %> + +<% end %> \ No newline at end of file diff --git a/app/views/courses/settings/_join_org.html.erb b/app/views/courses/settings/_join_org.html.erb index cd2d515cc..fff0f807c 100644 --- a/app/views/courses/settings/_join_org.html.erb +++ b/app/views/courses/settings/_join_org.html.erb @@ -68,8 +68,7 @@ }); }); function cancel_join_orgs() { - $("#search_orgs_result_list").html(""); - $("#paginator").css("display", "none") + $("#join_orgs_for_course input:checked").attr("checked", false); } function course_join_org(courseId) { $.ajax({ diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 106aa35a7..603f7febb 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -136,50 +136,125 @@ + <%# 课程贡献榜 %>
+ <% unless contributor_course_scor(@course.id).count == 0 %> + + <% end %> + + <% hero_homework_scores = hero_homework_score(@course, "desc") %> + <% unless hero_homework_scores.map(&:score).detect{|s| s != nil}.nil? %> + + <% end %> +

<%= l(:label_course_brief_introduction)%>:

@@ -278,6 +353,16 @@ $('#ajax-modal').parent().css("top","").css("left",""); $('#ajax-modal').parent().addClass("popbox_polls"); } +// 鼠标经过的时候显示内容 + function message_titile_show(obj,e) + { + obj.parent().parent().next("div").show(); + obj.parent().next("div").css("top",e.pageY).css("left",e.pageX).css("position","absolute"); + } + function message_titile_hide(obj) + { + obj.parent().parent().next("div").hide(); + } diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index 84edf02e1..b89977b09 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -85,10 +85,24 @@
<%= link_to "动态",organization_path(@organization), :class => "homepageMenuText" %>
-
项目 +
+ 项目 + <%=link_to "", join_project_menu_organization_path(@organization),:remote => true, :method => "post", :class => "homepageMenuSetting fr", :title => "关联项目"%> + + + + + + + + + + + +
-
+
    <%= render :partial => 'layouts/org_projects',:locals=>{:projects=>@organization.projects.reorder('created_at').limit(5),:org_id=>@organization.id,:page=>1}%> @@ -97,10 +111,25 @@
-
课程 +
+ 课程 + <%=link_to "", join_course_menu_organization_path(@organization),:remote => true, :method => "post", :class => "homepageMenuSetting fr", :title => "关联课程"%> + <%#= link_to "关联课程",join_course_menu_organization_path(@organization),:remote => true,:class => "menuGrey",:method => "post"%> + + + + + + + + + + + +
-
+
    <%= render :partial => 'layouts/org_courses',:locals=>{:courses=>@organization.courses.reorder('created_at').limit(5),:org_id=>@organization.id,:page=>1}%>
@@ -125,6 +154,21 @@ + + diff --git a/app/views/org_document_comments/_new.html.erb b/app/views/org_document_comments/_new.html.erb index 3a3356c66..a7ce22548 100644 --- a/app/views/org_document_comments/_new.html.erb +++ b/app/views/org_document_comments/_new.html.erb @@ -25,13 +25,14 @@ $("#document_title").val(""); org_document_description_editor.html(""); org_document_description_editor.sync(); - $('#org_document_editor').hide(); $('#doc_title_hint').hide(); + $('#org_document_editor').hide(); + $('#doc_title_hint').hide(); } <%= form_tag organization_org_document_comments_path(:organization_id => @organization.id), :id => 'new_org_document_form' do |f| %>
- +
diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb index 4b50c1064..c4a74c791 100644 --- a/app/views/org_document_comments/edit.html.erb +++ b/app/views/org_document_comments/edit.html.erb @@ -17,7 +17,7 @@
-<%= form_tag url_for(:controller => 'org_document_comments',:action => 'update', :id => @org_document.id),:method => 'put', :id => 'new_org_document_form' do |f| %> +<%= form_tag url_for(:controller => 'org_document_comments',:action => 'update', :id => @org_document.id, :flag => @flag),:method => 'put', :id => 'new_org_document_form' do |f| %>
diff --git a/app/views/org_document_comments/show.html.erb b/app/views/org_document_comments/show.html.erb index 9df568e02..31e4f7e05 100644 --- a/app/views/org_document_comments/show.html.erb +++ b/app/views/org_document_comments/show.html.erb @@ -43,7 +43,7 @@ <% end %>
  • - <%= link_to "编辑文章", edit_org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id), :class => "postOptionLink" %> + <%= link_to "编辑文章", edit_org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id, :flag => 1), :class => "postOptionLink" %>
  • <%= link_to "删除文章", org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id), :method => 'delete', diff --git a/app/views/org_document_comments/update.js.erb b/app/views/org_document_comments/update.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/org_member/create.js.erb b/app/views/org_member/create.js.erb index f1e48281f..25bbded34 100644 --- a/app/views/org_member/create.js.erb +++ b/app/views/org_member/create.js.erb @@ -4,4 +4,5 @@ $("#org_member_list").html('<%= escape_javascript( render :partial=>"organizations/org_member_list",:locals=> {:members=>@org.org_members}) %>'); $("#principals_for_new_member").html(''); $("#org_members_count_id").html("<%= @org.org_members.count %>"); + $("#not_org_member_search").val(""); <% end %> \ No newline at end of file diff --git a/app/views/organizations/_join_course_menu.html.erb b/app/views/organizations/_join_course_menu.html.erb new file mode 100644 index 000000000..e66d0bcce --- /dev/null +++ b/app/views/organizations/_join_course_menu.html.erb @@ -0,0 +1,99 @@ + + + + + + + + + + + + + +
    +
    +
    请选择关联到组织的课程
    +
    +
    +
    + <%=form_tag url_for(:controller => 'organizations', :action => 'join_courses', :organization_id => organization_id),:method => 'post', :id => 'join_courses_form', :remote => true,:class=>"resourcesSearchBox" do %> + +
    +
    + 关联 +
    + + <% end %> +
    + +
    +
    +
    +
    +
    + + + + diff --git a/app/views/organizations/_join_project_menu.html.erb b/app/views/organizations/_join_project_menu.html.erb new file mode 100644 index 000000000..765b4b23a --- /dev/null +++ b/app/views/organizations/_join_project_menu.html.erb @@ -0,0 +1,95 @@ + + + + + + + + + + + + + +
    +
    +
    请选择关联到组织的项目
    +
    +
    +
    + <%=form_tag url_for(:controller => 'organizations', :action => 'join_projects', :organization_id => organization_id),:method => 'post', :id => 'join_projects_form', :remote => true,:class=>"resourcesSearchBox" do %> + +
    +
    + 关联 +
    + + <% end %> +
    +
    +
    + + + + diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb index aa48fedf1..33ac13e76 100644 --- a/app/views/organizations/_org_activities.html.erb +++ b/app/views/organizations/_org_activities.html.erb @@ -56,7 +56,7 @@ <% end %> <% if org_act_count == 10 %> -
    展开更多<%=link_to "", organization_path(org,:page => page.to_i + 1),:id => "more_org_activities_link",:remote => "true",:class => "none" %>
    +
    展开更多<%=link_to "", organization_path(org,:page => page.to_i + 1, :type => params[:type]),:id => "more_org_activities_link",:remote => "true",:class => "none" %>
    <%#= link_to "点击展开更多",user_activities_path(@user.id,:type => type,:page => page),:id => "show_more_activities",:remote => "true",:class => "loadMore mt10 f_grey"%> <% end%> diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index e74da846e..888cbbf68 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -36,7 +36,7 @@ <% end %>
  • - <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :class => "postOptionLink" %> + <%= link_to "编辑文章", edit_org_document_comment_path(:id => document.id, :organization_id => document.organization_id, :flag => 0), :class => "postOptionLink" %>
  • <%= link_to "删除文章", org_document_comment_path(:id => document.id, :organization_id => document.organization_id), :method => 'delete', @@ -87,7 +87,7 @@
  • -
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33", :alt => "用户头像"), user_path(User.current) %>
    diff --git a/app/views/organizations/join_course_menu.js.erb b/app/views/organizations/join_course_menu.js.erb new file mode 100644 index 000000000..27c96c8c7 --- /dev/null +++ b/app/views/organizations/join_course_menu.js.erb @@ -0,0 +1,3 @@ +$('#topnav_course_menu').hide(); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_course_menu', :locals => {:organization_id => @organization.id}) %>'); +$('#ajax-modal').show(); diff --git a/app/views/organizations/join_courses.js.erb b/app/views/organizations/join_courses.js.erb new file mode 100644 index 000000000..1c234704e --- /dev/null +++ b/app/views/organizations/join_courses.js.erb @@ -0,0 +1,5 @@ +$("#homepageLeftMenuCourses").html(""); +$("#homepageLeftMenuCourses").append("
      "); +$("#homepageLeftMenuCourses").append("<%= escape_javascript(render :partial => 'layouts/org_courses', + :locals=>{:courses=>@organization.courses.reorder('created_at').limit(5),:org_id=>@organization.id,:page=> 1}) %>"); +$("#homepageLeftMenuCourses").append("
    "); \ No newline at end of file diff --git a/app/views/organizations/join_project_menu.js.erb b/app/views/organizations/join_project_menu.js.erb new file mode 100644 index 000000000..413aa7081 --- /dev/null +++ b/app/views/organizations/join_project_menu.js.erb @@ -0,0 +1,3 @@ +$('#topnav_project_menu').hide(); +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_project_menu', :locals => {:organization_id => @organization.id}) %>'); +$('#ajax-modal').show(); \ No newline at end of file diff --git a/app/views/organizations/join_projects.js.erb b/app/views/organizations/join_projects.js.erb new file mode 100644 index 000000000..1db8021bf --- /dev/null +++ b/app/views/organizations/join_projects.js.erb @@ -0,0 +1,5 @@ +$("#homepageLeftMenuProjects").html(""); +$("#homepageLeftMenuProjects").append("
      "); +$("#homepageLeftMenuProjects").append("<%= escape_javascript(render :partial => 'layouts/org_projects', + :locals=>{:projects=>@organization.projects.reorder('created_at').limit(5),:org_id=>@organization.id,:page=> 1}) %>"); +$("#homepageLeftMenuProjects").append("
    "); \ No newline at end of file diff --git a/app/views/organizations/search_courses.js.erb b/app/views/organizations/search_courses.js.erb new file mode 100644 index 000000000..9e92b4b07 --- /dev/null +++ b/app/views/organizations/search_courses.js.erb @@ -0,0 +1,9 @@ +$("#search_courses_result_list").html(""); +$("#search_courses_result_list").append('
      '); + +<% @courses.each do |course|%> +link = "
    • "; +$("#search_courses_result_list").append(link ); +<%end %> +$("#search_courses_result_list").append('
    ') + diff --git a/app/views/organizations/search_projects.js.erb b/app/views/organizations/search_projects.js.erb new file mode 100644 index 000000000..184683e9b --- /dev/null +++ b/app/views/organizations/search_projects.js.erb @@ -0,0 +1,9 @@ +$("#search_projects_result_list").html(""); +$("#search_projects_result_list").append('
      '); + +<% @projects.each do |project|%> + link = "
    • "; + $("#search_projects_result_list").append(link ); +<%end %> +$("#search_projects_result_list").append('
    ') + diff --git a/app/views/projects/settings/_join_org.html.erb b/app/views/projects/settings/_join_org.html.erb index 44c1e4849..6270e5477 100644 --- a/app/views/projects/settings/_join_org.html.erb +++ b/app/views/projects/settings/_join_org.html.erb @@ -67,9 +67,7 @@ }); }); function cancel_join_orgs() { - $("#search_orgs_result_list").html(""); - $("#paginator").html(""); - $("#paginator").css("display", "none"); + $("#join_orgs_for_project input:checked").attr("checked", false); } function join_org(projectId) { $.ajax({ diff --git a/app/views/student_work/edit.html.erb b/app/views/student_work/edit.html.erb index 517a238b0..d506b5542 100644 --- a/app/views/student_work/edit.html.erb +++ b/app/views/student_work/edit.html.erb @@ -62,10 +62,13 @@
    \ No newline at end of file diff --git a/app/views/student_work/new.html.erb b/app/views/student_work/new.html.erb index fdf1e31a3..4f9999277 100644 --- a/app/views/student_work/new.html.erb +++ b/app/views/student_work/new.html.erb @@ -121,10 +121,13 @@
    \ No newline at end of file diff --git a/app/views/users/user_organizations.html.erb b/app/views/users/user_organizations.html.erb index e9d78e695..ed8238169 100644 --- a/app/views/users/user_organizations.html.erb +++ b/app/views/users/user_organizations.html.erb @@ -6,8 +6,8 @@
    组织列表 - - + <%#= form_tag url_for(:controller => 'users', :action => 'search_user_orgs', :id => User.current.id), :method => 'get', :id => "search_org_form", :class=>"resourcesSearchloadBox", :style=>"float:right; margin-top:-5px;" do %> + diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 4563944c8..ea172b554 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2081,7 +2081,7 @@ zh: label_co_organizer_BHU: 北京航空航天大学 label_co_organizer_CAS: 中国科学院软件研究所 label_co_organizer_InforS: 中创软件 - label_rights_reserved: Copyright 2007~2015, All Rights Riserved + label_rights_reserved: Copyright 2007~2015, All Rights Reserved label_about_us: 关于我们 label_contact_us: 联系我们 label_recruitment_information: 招聘信息 diff --git a/config/routes.rb b/config/routes.rb index c783b1082..8998d50f2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,6 +39,12 @@ RedmineApp::Application.routes.draw do get 'members' get 'more_org_projects' get 'more_org_courses' + get 'search_courses' + post 'join_course_menu' + post 'join_courses' + get 'search_projects' + post 'join_project_menu' + post 'join_projects' end collection do get 'check_uniq' diff --git a/db/migrate/20151124032319_delete_useless_org_activities.rb b/db/migrate/20151124032319_delete_useless_org_activities.rb new file mode 100644 index 000000000..57d858e7e --- /dev/null +++ b/db/migrate/20151124032319_delete_useless_org_activities.rb @@ -0,0 +1,18 @@ +class DeleteUselessOrgActivities < ActiveRecord::Migration + def up + OrgActivity.all.each do |act| + if act.container_type == 'Course' + if CourseActivity.where("course_act_type=? and course_act_id =? and course_id =?", act.org_act_type, act.org_act_id, act.container_id).count == 0 + act.destroy + end + else + if act.container_type == 'Project' and ForgeActivity.where("forge_act_type=? and forge_act_id =? and project_id =?", act.org_act_type, act.org_act_id, act.container_id).count == 0 + act.destroy + end + end + end + end + + def down + end +end diff --git a/db/migrate/20151125064914_create_course_contributor_scores.rb b/db/migrate/20151125064914_create_course_contributor_scores.rb new file mode 100644 index 000000000..0d16ac68b --- /dev/null +++ b/db/migrate/20151125064914_create_course_contributor_scores.rb @@ -0,0 +1,16 @@ +class CreateCourseContributorScores < ActiveRecord::Migration + def change + create_table :course_contributor_scores do |t| + t.integer :course_id + t.integer :user_id + t.integer :message_num + t.integer :message_reply_num + t.integer :news_reply_num + t.integer :resource_num + t.integer :journal_num + t.integer :journal_reply_num + + t.timestamps + end + end +end diff --git a/db/migrate/20151126160252_add_total_score_to_course_contributor_score.rb b/db/migrate/20151126160252_add_total_score_to_course_contributor_score.rb new file mode 100644 index 000000000..80cf0bb72 --- /dev/null +++ b/db/migrate/20151126160252_add_total_score_to_course_contributor_score.rb @@ -0,0 +1,5 @@ +class AddTotalScoreToCourseContributorScore < ActiveRecord::Migration + def change + add_column :course_contributor_scores, :total_score, :integer + end +end diff --git a/db/migrate/20151127011351_add_course_contributor_total_score.rb b/db/migrate/20151127011351_add_course_contributor_total_score.rb new file mode 100644 index 000000000..2606864d8 --- /dev/null +++ b/db/migrate/20151127011351_add_course_contributor_total_score.rb @@ -0,0 +1,36 @@ +class AddCourseContributorTotalScore < ActiveRecord::Migration + def up + # course_count = Course.all.count / 30 + 1 + # transaction do + # for i in 1 ... course_count do i + Course.all.each do |course| + if course.course_activities.count > 1 + course.student.each do |s| + puts course.id + puts course.name + puts s.student_id + # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 + board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is null;").count * 2 + message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.student_id} and me.parent_id is not null").count * 1 + common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.student_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 + # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.student_id};").count * 5 + journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.student_id, course.id, "Course").count * 1 + # journal_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "JournalsForMessage").count * 1 + # journal_reply_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? and status =?", s.student_id, course.id, "Course",1).count * 1 + total = board_count + message_reply_count + common_reply_count + attachment_count + journal_count + if total !=0 + CourseContributorScore.create(:course_id => course.id, :user_id => s.student_id, :message_num => board_count, :message_reply_num => message_reply_count, + :news_reply_num => common_reply_count, :resource_num => attachment_count, :journal_num => journal_count, :journal_reply_num => 0, :total_score => total) + end + + end + end + end + # end + # end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index e77265f2f..87342bf9c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151120134208) do +ActiveRecord::Schema.define(:version => 20151127011351) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -382,6 +382,20 @@ ActiveRecord::Schema.define(:version => 20151120134208) do t.integer "container_id", :default => 0 end + create_table "course_contributor_scores", :force => true do |t| + t.integer "course_id" + t.integer "user_id" + t.integer "message_num" + t.integer "message_reply_num" + t.integer "news_reply_num" + t.integer "resource_num" + t.integer "journal_num" + t.integer "journal_reply_num" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "total_score" + end + create_table "course_groups", :force => true do |t| t.string "name" t.integer "course_id" diff --git a/lib/trustie/gitlab/manage_member.rb b/lib/trustie/gitlab/manage_member.rb index b8c2149f4..433b101f5 100644 --- a/lib/trustie/gitlab/manage_member.rb +++ b/lib/trustie/gitlab/manage_member.rb @@ -1,60 +1,63 @@ -#coding=utf-8 -# -# -module Trustie - module Gitlab - - module ManageMember - def self.included(base) - base.class_eval { - before_create :add_gitlab_member - before_destroy :delete_gitlab_member - after_save :change_gitlab_member - } - end - - def change_gitlab_member - if isGitlabProject? - @g ||= ::Gitlab.client - @g.edit_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role ) - end - end - - def add_gitlab_member - if isGitlabProject? - @g ||= ::Gitlab.client - @g.add_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role ) - end - end - - def delete_gitlab_member - if isGitlabProject? - if member.roles.count <=1 - @g ||= ::Gitlab.client - @g.remove_team_member(project.gpid, self.member.user.gid) - end - end - end - - private - def project - self.member.project - end - - def repository - unless project.nil? - project.repository - end - end - - def isGitlabProject? - unless repository.nil? - repository && repository.gitlab? - end - end - - end - - end -end - +#coding=utf-8 +# +# +module Trustie + module Gitlab + + module ManageMember + def self.included(base) + base.class_eval { + before_create :add_gitlab_member + before_destroy :delete_gitlab_member + after_save :change_gitlab_member + } + end + + def change_gitlab_member + if isGitlabProject? + @g ||= ::Gitlab.client + @g.edit_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role ) + end + end + + def add_gitlab_member + if isGitlabProject? + @g ||= ::Gitlab.client + if self.member.user.gid.nil? + add_user(self.member.user) + end + @g.add_team_member(project.gpid, self.member.user.gid, self.role.to_gitlab_role ) + end + end + + def delete_gitlab_member + if isGitlabProject? + if member.roles.count <=1 + @g ||= ::Gitlab.client + @g.remove_team_member(project.gpid, self.member.user.gid) + end + end + end + + private + def project + self.member.project + end + + def repository + unless project.nil? + project.repository + end + end + + def isGitlabProject? + unless repository.nil? + repository && repository.gitlab? + end + end + + end + + end +end + diff --git a/lib/trustie/gitlab/manage_user.rb b/lib/trustie/gitlab/manage_user.rb index a87984490..489dd7b9b 100644 --- a/lib/trustie/gitlab/manage_user.rb +++ b/lib/trustie/gitlab/manage_user.rb @@ -11,7 +11,7 @@ module Trustie base.class_eval { #before_create :add_gitlab_user #before_destroy :delete_gitlab_user - before_save :change_gitlab_user + #before_save :change_gitlab_user } end @@ -22,10 +22,10 @@ module Trustie def delete_gitlab_user del_user(self) end - - def change_gitlab_user - change_password(self.gid, self.hashed_password, self.salt) - end + # + #def change_gitlab_user + # change_password(self.gid, self.hashed_password, self.salt) + #end def g @g ||= ::Gitlab.client diff --git a/public/javascripts/course.js b/public/javascripts/course.js index 9f1815695..15968772f 100644 --- a/public/javascripts/course.js +++ b/public/javascripts/course.js @@ -1306,3 +1306,60 @@ function cancel_org_course_relation(id, courseId){ // alert('<%= @course.id%>') // }) //}) + +//项目点击展开 +function expand_tools_expand(content) { + if (content == "invit") { + $("#expand_tools_expand_invit").toggleClass("currentDd").siblings(".subNav").removeClass("currentDd"); + $("#expand_tools_expand_invit").toggleClass("currentDt").siblings(".subNav").removeClass("currentDt"); + $("#expand_tools_expand_invit").next(".navContent").slideToggle(500).siblings(".navContent").slideUp(500); + } + else { +// $("#expand_tools_expand").toggleClass("currentDd").siblings(".subNav").removeClass("currentDd"); +// $("#expand_tools_expand").toggleClass("currentDt").siblings(".subNav").removeClass("currentDt"); +// $("#expand_tools_expand").next(".navContent").slideToggle(500).siblings(".navContent").slideUp(500); + $("#navContent").toggle(500); + } + + // 修改数字控制速度, slideUp(500)控制卷起速度 +} + +//通过cookie存储伸开形式 +$(function(){ + var personalized_expand_key = "personalized_expand"; + function personalized_init(){ + var personalized_map = cookieget(personalized_expand_key); + if(personalized_map!=false){ + personalized_map = JSON.parse(personalized_map); + $("*[nhtype='toggle4cookie']").each(function(){ + var personalized_id=$(this).data('id'); + var val = personalized_map[personalized_id]; + if(val!=undefined && val!=$(this).data('val')){ + personalized_click($(this),0); + } + }); + } + } + function personalized_click(obj,timeout){ + var target = $(obj.data('target')); + var oldval = obj.data('val'); + var val=''; + if(oldval=='expand'){val='retract';}else{val='expand';} + obj.data('val',val); + var personalized_map = cookieget(personalized_expand_key); + if(personalized_map == false){ + personalized_map={}; + }else{ + personalized_map = JSON.parse(personalized_map); + } + var personalized_id=obj.data('id'); + personalized_map[personalized_id]=val; + cookiesave(personalized_expand_key,JSON.stringify(personalized_map)); + target.toggle(timeout); + } + $("*[nhtype='toggle4cookie']").on('click',function(){ + personalized_click($(this),500); + }); + + personalized_init(); +}); \ No newline at end of file diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 5ff34a4e1..f840f20cf 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -1166,4 +1166,13 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;} .questionEditContainer {border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px; margin-top:10px;} .fillInput {border:1px solid #cbcbcb; padding-left:5px; background-color:#ffffff; width:693px; height:30px; color:#888888;} .mr130 {margin-right:130px;} -.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; } \ No newline at end of file +.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; } + +/*20151123课程排行榜Tim*/ +.courseMenuSetting {background:url(../images/homepage_icon2.png) -190px -365px no-repeat; width:15px; height:15px; margin-top:3px; float:right; margin-right:5px;} +.courseMenuSetting:hover {background:url(../images/homepage_icon2.png) -190px -407px no-repeat;} +.rankList {width:220px; padding:10px; background-color:#ffffff; margin-top:10px;} +.rankList li {width:73px; padding:8px 0px 0px 0px; text-align:center; float:left; position:relative;} +.rankList li p {width:100%; overflow:hidden; white-space:normal; text-overflow:ellipsis; color:#585858;word-wrap: normal; word-break: normal;} +.rankPortrait {border-radius:50%; width:35px; height:35px;} +.numIntro {position:absolute; text-align:left; z-index:999; box-shadow:0px 2px 8px rgba(146, 153, 169, 0.5); border:1px solid #eaeaea; background-color:#ffffff; padding:3px 5px; left:15px; color:#585858; white-space: nowrap;} \ No newline at end of file diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index d18dd27d8..01e149bfb 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -384,6 +384,8 @@ a.resourcesGrey:hover {font-size:12px; color:#269ac9;} a.uploadText {color:#ffffff; font-size:14px;} .resourcesSearchloadBox {border:1px solid #e6e6e6; width:225px; float:left; background-color:#ffffff;} .searchResource {border:none; outline:none; background-color:#ffffff; width:184px; height:32px; padding-left:10px; display:block; float:left;} +.searchCourse {border:none; outline:none; background-color:#ffffff; width:184px; padding-left:10px; display:block; margin-bottom:15px;} +.searchResource:focus {border:none;} .searchIcon{width:31px; height:32px; background-color:#ffffff; background:url(images/resource_icon_list.png) -40px -15px no-repeat; display:block; float:left;} /*.resourcesSearchBanner {height:34px; margin-bottom:10px;}*/ .resourcesSearchBanner {width:710px; height:34px; margin-bottom:10px; margin-top:15px; margin-left:auto; margin-right:auto;} diff --git a/public/stylesheets/org.css b/public/stylesheets/org.css index 914df16b5..a0118b263 100644 --- a/public/stylesheets/org.css +++ b/public/stylesheets/org.css @@ -37,16 +37,21 @@ a.org_member_btn{ padding:1px 5px; background:#15bccf; color:#fff;} /*项目关联css*/ .relateOrg {width:335px;} .relatedList {width:335px;} -.searchOrg {height:24px; width:200px; color:#9b9b9b9; border:1px solid #15bccf;} +.searchOrg {height:24px; width:200px; color:#9b9b9b; border:1px solid #15bccf;} a.cancelBtn {padding:3px 5px; background-color:#D9D9D9; color:#656565;} a.cancelBtn:hover {background-color:#717171; color:#ffffff;} .relatedList ul li {border-bottom:1px solid #e4e4e4; width:320px; height:22px; vertical-align:middle; line-height:22px;} .relatedListName {width:240px; text-align:left; max-width:240px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;} .relatedListOption {width:80px; text-align:center;} .relateOrgName {width:240px; max-width:240px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;color:#656565;} +.search_org {width:150px; max-width:200px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;color:#656565;} /*组织列表*/ .mt28 {margin-top:28px;} .orgWrap {width:880px; float:left;} .orgTitle {width:880px; max-width:880px; margin-bottom:5px;word-break: break-all; word-wrap:break-word; } -.orgIntro {width:880px; max-width:880px; margin-bottom:6px; color:#484848;} \ No newline at end of file +.orgIntro {width:880px; max-width:880px; margin-bottom:6px; color:#484848;} + +/*关联项目弹窗*/ +.projectRelate {float:left; max-height:118px;margin-right:16px;margin-bottom:10px; overflow:auto; overflow-x:hidden; width:288px;} +.relateText {font-size:16px; color:#269ac9; line-height:16px; padding-top:20px; display:inline-block; font-weight: bold;} \ No newline at end of file diff --git a/spec/factories/course_contributor_scores.rb b/spec/factories/course_contributor_scores.rb new file mode 100644 index 000000000..2226a60d2 --- /dev/null +++ b/spec/factories/course_contributor_scores.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :course_contributor_score do + course_id 1 +user_id 1 +message_num 1 +message_reply_num 1 +news_reply_num 1 +resource_num 1 +journal_num 1 +journal_reply_num 1 + end + +end diff --git a/spec/models/course_contributor_score_spec.rb b/spec/models/course_contributor_score_spec.rb new file mode 100644 index 000000000..bc3b3cb52 --- /dev/null +++ b/spec/models/course_contributor_score_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseContributorScore, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end