diff --git a/Gemfile b/Gemfile index c739e1085..2b12860f0 100644 --- a/Gemfile +++ b/Gemfile @@ -17,7 +17,7 @@ gem 'daemons' gem 'grape', '~> 0.9.0' gem 'grape-entity' gem 'seems_rateable', '~> 1.0.13' -gem "rails", "3.2.13" +gem "rails", "~> 3.2.13" gem "jquery-rails", "~> 2.0.2" gem "i18n", "~> 0.6.0" gem 'coderay', '~> 1.1.0' diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index f8ca1d0e2..c7aa42b9e 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -24,7 +24,7 @@ class AdminController < ApplicationController before_filter :require_admin helper :sort helper :Users - helper :Settings + helper :Settings,SchoolHelper include SortHelper def index @@ -65,7 +65,17 @@ class AdminController < ApplicationController #管理员界面课程资源列表 def course_resource_list - @resource = Attachment.where(:container_type => 'Course') + + if params[:sort] == 'file_size' + @resource = Attachment.where(:container_type => 'Course').order("filesize desc") + elsif params[:sort] == 'file_upload' + @resource = Attachment.where(:container_type => 'Course').order("created_on desc") + elsif params[:sort] == 'file_download_times' + @resource = Attachment.where(:container_type => 'Course').order("downloads desc") + else + @resource = Attachment.where(:container_type => 'Course').order("created_on desc") + end + @resource = paginateHelper @resource,30 @page = (params['page'] || 1).to_i - 1 @@ -76,7 +86,17 @@ class AdminController < ApplicationController #管理员界面項目资源列表 def project_resource_list - @pro_resource = Attachment.where(:container_type => 'Project') + + if params[:sort] == 'file_size' + @pro_resource = Attachment.where(:container_type => 'Project').order("filesize desc") + elsif params[:sort] == 'file_upload' + @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc") + elsif params[:sort] == 'file_download_times' + @pro_resource = Attachment.where(:container_type => 'Project').order("downloads desc") + else + @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc") + end + @pro_resource = paginateHelper @pro_resource,30 @page = (params['page'] || 1).to_i - 1 @@ -92,9 +112,9 @@ class AdminController < ApplicationController case params[:format] when 'xml', 'json' - @offset, @limit = api_offset_and_limit({:limit => 15}) + @offset, @limit = api_offset_and_limit({:limit => 50}) else - @limit = 15#per_page_option + @limit = 50 #per_page_option end @status = params[:status] || 1 @@ -374,7 +394,13 @@ class AdminController < ApplicationController #组织 def organization - @organizations = Organization.all + @organizations = Organization.find_by_sql("SELECT * FROM organizations ORDER BY created_at DESC") + #@organizations = Organization.all.order("created_at desc") + @organization_count = @organizations.count + @organization_pages = Paginator.new @organization_count, 30, params['page'] || 1 + @organizations = paginateHelper @organizations,30 + + @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html end @@ -382,17 +408,14 @@ class AdminController < ApplicationController #学校列表 def schools - @school_name = params[:school_name] - if @school_name && @school_name != '' - @schools = School.where("name like '%#{@school_name}%'") - elsif @school_name.nil? - @schools = [] - else @school_name && @school_name == ' ' - @schools = School.where('1=1') - end + + @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC") @school_count = @schools.count - @school_pages = Paginator.new @school_count, 100, params['page'] || 1 - @schools = paginateHelper @schools,100 + + @school_pages = Paginator.new @school_count, 30, params['page'] || 1 + @schools = paginateHelper @schools,30 + + @page = (params['page'] || 1).to_i - 1 respond_to do |format| format.html end diff --git a/app/controllers/at_controller.rb b/app/controllers/at_controller.rb index 456306c64..fe16385f4 100644 --- a/app/controllers/at_controller.rb +++ b/app/controllers/at_controller.rb @@ -8,6 +8,15 @@ class AtController < ApplicationController users = find_at_users(params[:type], params[:id]) @users = users @users = users.uniq { |u| u.id }.delete_if { |u| u.id == User.current.id }.sort{|x,y| to_pinyin(x.show_name) <=> to_pinyin(y.show_name)} if users + + #加上all + if @users.size > 0 + allUser = Struct.new(:id, :name).new + allUser.id = @users.map{|u| u.id}.join(",") + allUser.name = "all" + @users.insert(0, allUser) + end + @users end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 38f1ad152..d05867427 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -573,7 +573,7 @@ class UsersController < ApplicationController @r_sort = @b_sort == "desc" ? "asc" : "desc" @user = User.current search = params[:name].to_s.strip.downcase - type_ids = params[:property]=="" ? "(1, 2, 3)" : "(" + params[:property] + ")" + type_ids = params[:property]=="" || params[:property].nil? ? "(1, 2, 3)" : "(" + params[:property] + ")" if(params[:type].blank? || params[:type] == "1") #全部 visible_course = Course.where("is_public = 1 && is_delete = 0") visible_course_ids = visible_course.empty? ? "(-1)" : "(" + visible_course.map{|course| course.id}.join(",") + ")" diff --git a/app/helpers/school_helper.rb b/app/helpers/school_helper.rb index 0528cb7ac..075d2b039 100644 --- a/app/helpers/school_helper.rb +++ b/app/helpers/school_helper.rb @@ -1,2 +1,15 @@ module SchoolHelper + def schoolMember_num school + count = student_num(school) + teacher_num(school) + count.to_s + end + + def student_num school + UserExtensions.find_by_sql("SELECT * FROM user_extensions WHERE occupation = '#{school.name}' AND identity = '1'").count + end + + def teacher_num school + UserExtensions.find_by_sql("SELECT * FROM user_extensions AS ue, schools AS s WHERE ue.school_id = s.id AND s.name = '#{school.name}' AND ue.identity = '0'").count + end + end diff --git a/app/models/issue.rb b/app/models/issue.rb index c82f6f0be..0d72407ba 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -84,7 +84,9 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message, :add_issues_count + after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, + act_as_at_message(:description, :author_id), :add_issues_count + after_update :be_user_score,:update_activity after_destroy :down_user_score, :decrease_issues_count # after_create :be_user_score @@ -165,12 +167,12 @@ class Issue < ActiveRecord::Base end # at 功能添加消息提醒 - def act_as_at_message - users = self.description.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) - end - end + # def act_as_at_message + # users = self.description.scan //m + # users && users.flatten.uniq.each do |uid| + # self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) + # end + # end # 创建issue的时候,issues_count加1 def add_issues_count diff --git a/app/models/journal.rb b/app/models/journal.rb index c37b8d2c5..fd67e8a62 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -51,7 +51,7 @@ class Journal < ActiveRecord::Base before_create :split_private_notes, :add_journals_count # fq - after_save :act_as_activity,:be_user_score, :act_as_forge_message, :act_as_at_message + after_save :act_as_activity,:be_user_score, :act_as_forge_message, act_as_at_message(:notes, :user_id) after_create :update_issue_time # end #after_destroy :down_user_score @@ -186,13 +186,6 @@ class Journal < ActiveRecord::Base end end - def act_as_at_message - users = self.notes.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) - end - end - # 更新用户分数 -by zjc def be_user_score #新建了缺陷留言且留言不为空,不为空白 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index dae779b65..fa5beb813 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -68,7 +68,9 @@ class JournalsForMessage < ActiveRecord::Base has_many :at_messages, as: :at_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_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score + after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, + act_as_at_message(:notes, :user_id), :act_as_user_feedback_message, + :act_as_principal_activity, :act_as_student_score after_create :reset_counters! #after_update :update_activity after_destroy :reset_counters! @@ -253,12 +255,7 @@ class JournalsForMessage < ActiveRecord::Base end end - def act_as_at_message - users = self.notes.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id) - end - end + # 用户留言消息通知 def act_as_user_feedback_message # 主留言 diff --git a/app/models/message.rb b/app/models/message.rb index 0ddc6f8e0..d697db236 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -81,7 +81,8 @@ class Message < ActiveRecord::Base after_update :update_messages_board, :update_activity after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets, :decrease_boards_count, :down_course_score - 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, :act_as_at_message + 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, act_as_at_message(:content, :author_id) #before_save :be_user_score scope :visible, lambda {|*args| @@ -287,13 +288,6 @@ class Message < ActiveRecord::Base end end - def act_as_at_message - users = self.content.scan //m - users && users.flatten.uniq.each do |uid| - self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id) - end - end - #更新用户分数 -by zjc def be_user_score #新建message且无parent的为发帖 diff --git a/app/views/admin/course_resource_list.html.erb b/app/views/admin/course_resource_list.html.erb index 4316555f7..2e83a96aa 100644 --- a/app/views/admin/course_resource_list.html.erb +++ b/app/views/admin/course_resource_list.html.erb @@ -10,16 +10,16 @@ 资源名称
+ | 序号 | -+ | LOGO | -+ | 学校名称 | -+ | + 用户数 + | ++ 创建时间 + | ++ 编辑高校信息 + | |
---|---|---|---|---|---|---|---|---|---|---|
- <%= school.id %> + + + <% @count +=1 %> + | + <%=@count %> | +<%= image_tag(school.logo_link,width:40,height:40) %> + | + -+ | + <%= schoolMember_num(school) %> + | ++ <%= format_time(school.created_at) %> + | +<%= link_to("修改", upload_logo_school_path(school.id,:school_name => @school_name), :class => 'icon icon-copy') %> <%#= link_to(l(:button_delete), organization_path(school.id), :method => :delete,:confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> | @@ -50,4 +71,4 @@ <%= pagination_links_full @school_pages, @school_count ,:per_page_links => true, :remote => false, :flag => true %> -<% html_title(l(:label_project_plural)) -%> +<% html_title(l(:label_school_plural)) -%> diff --git a/app/views/admin/users.html.erb b/app/views/admin/users.html.erb index 12aa95a16..2a757fdee 100644 --- a/app/views/admin/users.html.erb +++ b/app/views/admin/users.html.erb @@ -40,7 +40,10 @@ <%= sort_header_tag('admin', :caption => l(:field_admin), :default_order => 'desc') %> <%= sort_header_tag('created_on', :caption => l(:field_created_on), :default_order => 'desc') %> <%= sort_header_tag('last_login_on', :caption => l(:field_last_login_on), :default_order => 'desc') %> -+ <%#= sort_header_tag('user_occupation', :caption => l(:field_occupation), :default_order => 'desc') %> + | 用户单位 | ++ | <%= change_status_link(user) %> - <%= delete_link user_path(user, :back_url => admin_users_path(params)) unless User.current == user %> | + <% occupation = user.user_extensions.identity == 0 ? School.where("id=?",user.user_extensions.school_id).first.try(:name) : user.user_extensions.occupation %> + + + + <% end -%> diff --git a/app/views/at/show.json.erb b/app/views/at/show.json.erb index 5341f251e..6e2a244e4 100644 --- a/app/views/at/show.json.erb +++ b/app/views/at/show.json.erb @@ -1,6 +1,11 @@ [ <% @users && @users.each_with_index do |person,index| %> + <% if index == 0 %> + {"id":<%=index%>, "userid": "<%=person.id%>", "name": "所有人", "login": "<%=person.name%>", "searchKey": "<%=person.name%>"} + <%= index != @users.size-1 ? ',' : '' %> + <% else %> {"id":<%=index%>, "userid": <%=person.id%>, "name": "<%=person.show_name%>", "login": "<%=person.login%>", "searchKey": "<%=person.get_at_show_name%>"} <%= index != @users.size-1 ? ',' : '' %> <% end %> + <% end %> ] diff --git a/app/views/courses/_recommendation.html.erb b/app/views/courses/_recommendation.html.erb index d92eb3cf4..a0c659493 100644 --- a/app/views/courses/_recommendation.html.erb +++ b/app/views/courses/_recommendation.html.erb @@ -8,8 +8,8 @@