diff --git a/Gemfile b/Gemfile index 7ff3df60..1d827679 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,7 @@ unless RUBY_PLATFORM =~ /w32/ gem 'rubyzip' gem 'zip-zip' end + gem 'seems_rateable', path: 'lib/seems_rateable' gem "rails", "3.2.13" gem "jquery-rails", "~> 2.0.2" @@ -15,6 +16,11 @@ gem "fastercsv", "~> 1.5.0", :platforms => [:mri_18, :mingw_18, :jruby] gem "builder", "3.0.0" gem 'acts-as-taggable-on' +group :development do + gem 'better_errors', path: 'lib/better_errors' + gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' +end + # Gems used only for assets and not required # in production environments by default. group :assets do @@ -82,16 +88,6 @@ else warn("Please configure your config/database.yml first") end -group :development do - gem "rdoc", ">= 2.4.2" - if nil - gem 'thin' - gem 'rack-mini-profiler' - end -end - - - local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local") if File.exists?(local_gemfile) puts "Loading Gemfile.local ..." if $DEBUG # `ruby -d` or `bundle -v` diff --git a/Gemfile.lock b/Gemfile.lock index 3486c743..6680070a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,16 @@ +PATH + remote: lib/better_errors + specs: + better_errors (1.1.0) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + +PATH + remote: lib/rack-mini-profiler + specs: + rack-mini-profiler (0.9.1) + rack (>= 1.1.3) + PATH remote: lib/seems_rateable specs: @@ -122,6 +135,7 @@ DEPENDENCIES activerecord-jdbc-adapter (= 1.2.5) activerecord-jdbcmysql-adapter acts-as-taggable-on + better_errors! builder (= 3.0.0) coderay (~> 1.0.6) coffee-rails (~> 3.2.1) @@ -130,9 +144,9 @@ DEPENDENCIES jquery-rails (~> 2.0.2) mysql2 (~> 0.3.11) net-ldap (~> 0.3.1) + rack-mini-profiler! rack-openid rails (= 3.2.13) - rdoc (>= 2.4.2) ruby-openid (~> 2.1.4) sass-rails (~> 3.2.3) seems_rateable! diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index ab3d7b12..2a3ce15d 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -149,7 +149,6 @@ class AdminController < ApplicationController respond_to do |format| format.html { @groups = Group.all.sort - render :layout => @user_base_tag } format.api end @@ -196,4 +195,43 @@ class AdminController < ApplicationController [:text_rmagick_available, Object.const_defined?(:Magick)] ] end + #管理功能用户列表的搜索 + def search + sort_init 'login', 'asc' + sort_update %w(login firstname lastname mail admin created_on last_login_on) + + case params[:format] + when 'xml', 'json' + @offset, @limit = api_offset_and_limit({:limit => 15}) + else + @limit = 15#per_page_option + end + + @status = params[:status] || 1 + has = { + "show_changesets" => true + } + scope = User.logged.status(@status) + scope = scope.like(params[:name]) if params[:name].present? + @user_count = scope.count + @user_pages = Paginator.new @user_count, @limit, params['page'] + @user_base_tag = params[:id] ? 'base_users':'base' + @offset ||= @user_pages.reverse_offset + unless @offset == 0 + @users = scope.offset(@offset).limit(@limit).all.reverse + else + limit = @user_count % @limit + if limit == 0 + limit = @limit + end + @users = scope.offset(@offset).limit(limit).all.reverse + end + + respond_to do |format| + format.html { + @groups = Group.all.sort + } + format.api + end + end end diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index f9236d0b..ed6f9937 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -52,9 +52,14 @@ class FilesController < ApplicationController end def create - if params[:tag_name] + if params[:add_tag] + @addTag=true + #render :back tag_saveEx - render :text =>"success" + #render :text =>"success" + respond_to do |format| + format.js + end else @addTag=false container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id])) @@ -64,7 +69,27 @@ class FilesController < ApplicationController if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added') Mailer.attachments_added(attachments[:files]).deliver end - redirect_to project_files_path(@project) + + # TODO: 临时用 nyan + sort_init 'created_on', 'desc' + sort_update 'created_on' => "#{Attachment.table_name}.created_on", + 'filename' => "#{Attachment.table_name}.filename", + 'size' => "#{Attachment.table_name}.filesize", + 'downloads' => "#{Attachment.table_name}.downloads" + + @containers = [ Project.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").find(@project.id)] #modify by Long Jun + @containers += @project.versions.includes(:attachments).reorder("#{Attachment.table_name}.created_on DESC").all.sort + + @attachtype = 0 + @contenttype = 0 + + respond_to do |format| + format.js + format.html { + redirect_to project_files_path(@project) + } + end + end end diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 8eae8b85..64bfe5c4 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -102,11 +102,12 @@ class HomeworkAttachController < ApplicationController percent_m.to_s + "%" end @limit = 10 - @jours = @homework.journals_for_messages.order("created_on DESC") + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset @jour = @jours[@offset, @limit] + @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") end #删除留言 @@ -127,13 +128,14 @@ class HomeworkAttachController < ApplicationController #添加留言 def addjours @homework = HomeworkAttach.find(params[:jour_id]) - @homework.addjours User.current.id, params[:new_form][:user_message],0 - @jours = @homework.journals_for_messages.order("created_on DESC") + @add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation] + @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC") @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @offset ||= @feedback_pages.offset @jour = @jours[@offset, @limit] + @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC") respond_to do |format| format.js end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index d8e583bf..30c6c7e8 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -76,8 +76,7 @@ class MembersController < ApplicationController # ProjectInfo.create(:name => "test", :user_id => 123) end ## end - AppliedProject.deleteappiled(user_id, @project.id) - end + end else members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) user_grades << UserGrade.new(:user_id => params[:membership][:user_id], :project_id => @project.id) @@ -95,6 +94,13 @@ class MembersController < ApplicationController end end + if members.present? && members.all? {|m| m.valid? } + members.each do |member| + AppliedProject.deleteappiled(member.user_id, @project.id) + end + + end + respond_to do |format| format.html { redirect_to_settings_in_projects } format.js { @members = members;@applied_members = applied_members; } diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 0723cf16..a87df4fe 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -54,6 +54,7 @@ class MyController < ApplicationController @user.safe_attributes = params[:user] @user.pref.attributes = params[:pref] @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') + @user.login = params[:login] unless @user.user_extensions.nil? if @user.user_extensions.identity == 2 @user.firstname = params[:enterprise_name] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a6dd7cf3..16d9d71d 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -37,7 +37,7 @@ class ProjectsController < ApplicationController # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] - before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches] + before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :file, :statistics, :watcherlist @@ -716,6 +716,11 @@ class ProjectsController < ApplicationController @document = @project.documents.build # @base_courses_tag = @project.project_type + #判断能否显示真名(当前用户为课程的教师时显示真名) + if @project.project_type == Project::ProjectType_course + @teachers= searchTeacherAndAssistant(@project) + @canShowRealName = isCourseTeacher(User.current.id) + end respond_to do |format| format.html{render :layout => 'base_courses' if @base_courses_tag==1} format.api diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 19c84cc3..6452bcc8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -65,13 +65,13 @@ class UsersController < ApplicationController def user_projects if User.current.admin? - @memberships = @user.memberships.all + @memberships = @user.memberships.all(conditions: "projects.project_type = #{Project::ProjectType_project}") else cond = Project.visible_condition(User.current) + " AND projects.project_type <> 1" @memberships = @user.memberships.all(:conditions => cond) end - events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) - @events_by_day = events.group_by(&:event_date) + #events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 20) + #@events_by_day = events.group_by(&:event_date) @state = 0 @@ -289,7 +289,7 @@ class UsersController < ApplicationController when '0' @offset ||= @user_pages.reverse_offset unless @offset == 0 - @users_statuses = scope.offset(@offset).limit(@limit).all.reverse + @users_statuses = scope.offset(@offset).limit(@limit).all.reverse else limit = @user_count % @limit if limit == 0 @@ -313,7 +313,7 @@ class UsersController < ApplicationController end @s_type = 1 #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} - #@users = @users[@offset, @limit] + #@users = @users[@offset, @limit] when '2' @offset ||= @user_pages.reverse_offset unless @offset == 0 @@ -326,9 +326,9 @@ class UsersController < ApplicationController @users_statuses = scope.reorder('watchers_count').offset(@offset).limit(limit).all.reverse end @s_type = 2 - #@users = @users[@offset, @limit] + #@users = @users[@offset, @limit] end - + else @offset ||= @user_pages.reverse_offset unless @offset == 0 @@ -565,7 +565,7 @@ class UsersController < ApplicationController end def watch_projects - @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and watchers.user_id = ?", '1','Project', @user.id) + @watch_projects = Project.joins(:watchers).where("project_type <>? and watchable_type = ? and `watchers`.user_id = ?", '1','Project', @user.id) @state = 1 respond_to do |format| format.html { @@ -689,7 +689,7 @@ class UsersController < ApplicationController end def tag_saveEx - @tags = params[:tag_name][:name] + @tags = params[:tag_name] @obj_id = params[:obj_id] @obj_flag = params[:obj_flag] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd1f6f16..7bfe9512 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -58,9 +58,14 @@ module ApplicationHelper end # Displays a link to user's account page if active - def link_to_user(user, options={}) + def link_to_user(user, canShowRealName = false, options={}) if user.is_a?(User) - name = h(user.name(options[:format])) + if canShowRealName + name = h(user.realname(options[:format])) + else + name = h(user.name(options[:format])) + end + if user.active? || (User.current.admin? && user.logged?) link_to name, {:controller=> 'users', :action => 'show', id: user.id, host: Setting.user_domain}, :class => user.css_classes else diff --git a/app/helpers/bids_helper.rb b/app/helpers/bids_helper.rb index a5c25ecb..8b03d74c 100644 --- a/app/helpers/bids_helper.rb +++ b/app/helpers/bids_helper.rb @@ -155,6 +155,16 @@ module BidsHelper end people.include?(User.current) end + #当前用户是不是指定课程的学生 + def is_cur_course_student? course + people = [] + course.members.each do |member| + if [5,10].include? member.roles.first.id + people << member.user + end + end + people.include?(User.current) + end # def select_option_helper option # tmp = Hash.new diff --git a/app/helpers/bids_helper.rb.orig b/app/helpers/bids_helper.rb.orig new file mode 100644 index 00000000..80c59530 --- /dev/null +++ b/app/helpers/bids_helper.rb.orig @@ -0,0 +1,184 @@ +#enconding:utf-8 +# fq +module BidsHelper + + def render_notes(bid, journal, options={}) + content = '' + removable = User.current == journal.user || User.current == bid.author + links = [] + if !journal.notes.blank? + links << link_to(image_tag('comment.png'), + {:controller => 'bids', :action => 'new', :id => bid, :journal_id => journal}, + :remote => true, + :method => 'post', + :title => l(:button_quote)) if options[:reply_links] + if removable + url = {:controller => 'bids', + :action => 'destroy', + :object_id => journal, + :id => bid} + links << ' ' + links << link_to(image_tag('delete.png'), url, + :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) + end + end + content << content_tag('div', links.join(' ').html_safe, :class => 'contextual') unless links.empty? + content << textilizable(journal.notes) + css_classes = "wiki" + content_tag('div', content.html_safe, :id => "journal-#{journal.id}-notes", :class => css_classes) + end + + def link_to_in_place_notes_editor(text, field_id, url, options={}) + onclick = "$.ajax({url: '#{url_for(url)}', type: 'get'}); return false;" + link_to text, '#', options.merge(:onclick => onclick) + end + + # this method is used to get all projects that tagged one tag + # added by william + def get_bids_by_tag(tag_name) + Bid.tagged_with(tag_name).order('updated_on desc') + end + + #added by huang + def sort_bid_enterprise(state, project_type) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") + + when 1 + content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs_enterprise") + end + #end + + def sort_bid(state, project_type) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type))) + content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type), :class=>"selected"), :class=>"selected") + + when 1 + content << content_tag('li', link_to(l(:label_sort_by_active), calls_path(:bid_sort_type => '1', :project_type => project_type), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), calls_path(:bid_sort_type => '0', :project_type => project_type))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end + + #huang + def sort_contest(state) + content = ''.html_safe + case state + when 0 + content << content_tag('li', link_to(l(:label_sort_by_active), contest_path(:contest_sort_type => '1'))) + content << content_tag('li', link_to(l(:label_sort_by_time), contest_path(:contest_sort_type => '0'), :class=>"selected"), :class=>"selected") + + when 1 + content << content_tag('li', link_to(l(:label_sort_by_active), contest_path(:contest_sort_type => '1'), :class=>"selected"), :class=>"selected") + content << content_tag('li', link_to(l(:label_sort_by_time), contest_path(:contest_sort_type => '0'))) + end + content = content_tag('ul', content) + content_tag('div', content, :class => "tabs") + end + #end + + def course_options_for_select(courses) + # + html = '' + courses.each do |course| + html << "" + end + html.html_safe + end + + + # used to get the reward and handle the value which can be used to display in views + # added by william + def get_prize(b_project) + b_project.get_reward + end + + def count_bid_project + bids = Bid.where('parent_id = ?', @bid.id) + @projects = [] + for bid in bids + @projects += bid.biding_projects + end + @projects.count + end + + def count_bid_user + bids = Bid.where('parent_id = ?', @bid.id) + @users = [] + for bid in bids + for project in bid.projects + @users += project.users + end + end + @users.count + end + + # 查看学号 + def im_watching_student_id? bid + people = [] + people << bid.author + case bid.reward_type # 天煞的bid分了三用途,里面各种hasmany还不定能用! + when Bid::Enterprise + when Bid::Contest + bid.join_in_contests.each do |jic| + people << jic.user + end + when Bid::Homework + # people += bid.courses.first.users.to_a + people += searchTeacherAndAssistant(bid.courses.first).to_a + else + raise 'bids_helper: unknow bid type' # 出了错看这里!不知道的抛异常,省的找不到出错的地方! + end + people.include?(User.current) + end + + # 当前用户是否加入了此课程(包括教师) + def is_cur_course_user? bid + people = [] + #people << bid.author + course = bid.courses.first + course.members.each do |member| + people << member.user + end + people.include?(User.current) + end +<<<<<<< HEAD +======= + #当前用户是不是指定课程的学生 + def is_cur_course_student? course + people = [] + course.members.each do |member| + if [5,10].include? member.roles.first.id + people << member.user + end + end + people.include?(User.current) + end +>>>>>>> 8c33cf0afb89556112710759615cbd88bb0326f2 + + # def select_option_helper option + # tmp = Hash.new + # option.each do |project| + # tmp[project.name] = project.identifier + # end + # tmp + # end + + def can_delete_project_homework bind_project,current_user + current_user.id == bind_project.user.id || current_user.admin + end + +end \ No newline at end of file diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 45ebaf24..959d36cb 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -137,14 +137,24 @@ module CoursesHelper Course.find_by_extra(try(extra)) end #判断制定用户是不是当前课程的老师 - def is_course_teacher user,project - is_teacher = false - searchTeacherAndAssistant(project).each do |teacher| - if user == teacher - is_teacher = true - break + def is_course_teacher user,course + people = [] + course.members.each do |member| + role_id = member.roles.first.id + if TeacherRoles.include? role_id + people << member.user end end - is_teacher + people.include?(user) + end + #当前用户是不是指定课程的学生 + def is_cur_course_student? course + people = [] + course.members.each do |member| + if StudentRoles.include? member.roles.first.id + people << member.user + end + end + people.include?(User.current) end end diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index ba2470fe..201a582f 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -49,5 +49,9 @@ module TagsHelper end return @result end - + +end + +def tagname_val + ("#tag_name_name").value end \ No newline at end of file diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index f412e0c8..87b495f0 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -69,28 +69,30 @@ module UsersHelper #
- | <%= text_field_tag 'username', params[:username], :tabindex => '1' %> | ++ | + <%= text_field_tag 'username', params[:username], :tabindex => '1' , :value => "#{l(:label_login_prompt)}", + :onfocus => "clearInfo('username','#{l(:label_login_prompt)}')", + :onblur => "showInfo('username','#{l(:label_login_prompt)}')", + :style => "resize: none;font-size: 12px;color: #818283;"%> + | |||||||||
diff --git a/app/views/account/register.html.erb b/app/views/account/register.html.erb index f24f7d05..cc7a26ad 100644 --- a/app/views/account/register.html.erb +++ b/app/views/account/register.html.erb @@ -279,7 +279,7 @@ <% if @user.auth_source_id.nil? %> |
<%= l(:label_gender) %> | ++ <%= select_tag 'gender', " + ".html_safe %> + | +
<%= l(:label_location) %> * | diff --git a/app/views/admin/search.html.erb b/app/views/admin/search.html.erb new file mode 100644 index 00000000..17d91e78 --- /dev/null +++ b/app/views/admin/search.html.erb @@ -0,0 +1,68 @@ +<% if User.current.admin? %> +
+ | |||||||
---|---|---|---|---|---|---|---|
<%= avatar(user, :size => "14") %><%= link_to h(user.login), edit_user_path(user) %> | +<%= h(user.firstname) %> | +<%= h(user.lastname) %> | +<%= mail_to(h(user.mail)) %> | +<%= checked_image user.admin? %> | +<%= format_time(user.created_on) %> | +<%= format_time(user.last_login_on) unless user.last_login_on.nil? %> | +<%= change_status_link(user) %> + <%= delete_link user_path(user, :back_url => users_path(params)) unless User.current == user %> | +