diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 9e51a859..f2e197cd 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -307,11 +307,14 @@ class BidsController < ApplicationController # a = [1] # @project = Project.where("id in []", a) @user = @bid.author - @bidding_project = @bid.biding_projects + @bidding_project = @bid.biding_projects.all + + @bidding_project = @bidding_project.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} if @bid.homework_type == 1 @homework = HomeworkAttach.new @homework_list = @bid.homeworks end + respond_to do |format| if @bid.reward_type == 3 format.html { diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index fadeec3e..940172e9 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -48,12 +48,14 @@ class MembersController < ApplicationController def create members = [] project_info = [] + user_grade = [] if params[:membership] if params[:membership][:user_ids] attrs = params[:membership].dup user_ids = attrs.delete(:user_ids) user_ids.each do |user_id| members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) + user_grade << UserGrade.new(:user_id => user_id, :project_id => @project.id) ## added by nie if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) @@ -65,13 +67,14 @@ class MembersController < ApplicationController members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) ## added by nie if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") - project_info << ProjectInfo.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) + project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id]) end ## end end @project.members << members # added by nie @project.project_infos << project_info + @project.user_grades << user_grade # end end @@ -124,13 +127,20 @@ class MembersController < ApplicationController def destroy if request.delete? && @member.deletable? @member.destroy - end + # end user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) if user_admin.size > 0 user_admin.each do |user| user.destroy end end + user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id) + if user_grade.size > 0 + user_grade.each do |grade| + grade.destroy + end + end + end respond_to do |format| format.html { redirect_to_settings_in_projects } format.js diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 783e8222..b7427b1e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -146,8 +146,20 @@ class ProjectsController < ApplicationController # # end # end + # @projects = Project.where("project_type <> ? or project_type is null", 1) # @projects.each do |project| - # ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) + # @id = project.id + # @users = Member.find_by_sql("SELECT + # members.user_id + # FROM members + # INNER JOIN users + # ON members.user_id = users.id + # WHERE members.project_id = #{@id} + # AND (users.type = 'User' AND users.status = 1);") + # @users.each do |user| + # UserGrade.create(:project_id => project.id, :user_id => user.user_id) + # end + # #ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) # end # @projects_status = Project.visible.like(params[:name]) if params[:name].present? @project_count = @projects_status.count @@ -175,13 +187,13 @@ class ProjectsController < ApplicationController when '1' @offset ||= @project_pages.reverse_offset unless @offset == 0 - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit if limit == 0 limit = @limit end - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse end @s_type = 1 @@ -202,13 +214,13 @@ class ProjectsController < ApplicationController else @offset ||= @project_pages.reverse_offset unless @offset == 0 - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit if limit == 0 limit = @limit end - @projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse + @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse end @s_type = 1 # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } @@ -524,8 +536,9 @@ class ProjectsController < ApplicationController r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first m = Member.new(:user => User.current, :roles => [r]) project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) - if (params[:project][:is_public] == '1' && @course_tag != "1") || (@course_tag=="1" && params[:project][:is_public] == '1') - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @course_tag) + UserGrade.create(:user_id => User.current.id, :project_id => @project.id, :grade => 0) + if params[:project][:is_public] == '1' + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :project_type => @course_tag) end @project.members << m @project.project_infos << project @@ -747,6 +760,20 @@ class ProjectsController < ApplicationController if @project.project_type == 1 render :layout => 'base_courses' end + # roles = Role.find_all_givable + # members = @project.member_principals.includes(:roles, :principal).all.sort +# + # users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]} +# + # temp = [] + # users.each do |user| + # members.each do |member| + # if member[:user_id] == user[:user_id] + # temp << member + # end + # end + # end + # temps = temp.reverse end # def news @@ -790,7 +817,7 @@ class ProjectsController < ApplicationController project_status = ProjectStatus.find_by_project_id(@project.id) project_status.destroy elsif params[:project][:is_public] == '1' - project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => 1) + project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0,:grade => 0, :project_type => 1) end respond_to do |format| diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb index e019af50..953274b3 100644 --- a/app/controllers/shares_controller.rb +++ b/app/controllers/shares_controller.rb @@ -1,6 +1,7 @@ # encoding: utf-8 class SharesController < ApplicationController before_filter :require_login, :except => [:index] + before_filter :require_admin, :only => [:index] # GET /shares # GET /shares.json def index diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f9d4a30e..2998eb2a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,7 +21,7 @@ class UsersController < ApplicationController menu_item :user_information, :only => :info menu_item :user_course, :only => :user_courses menu_item :user_homework, :only => :user_homeworks - menu_item :user_project, :only => :user_projects + menu_item :user_project, :only => [:user_projects, :watch_projects] menu_item :requirement_focus, :only => :watch_bids menu_item :user_newfeedback, :only => :user_newfeedback @@ -29,10 +29,12 @@ class UsersController < ApplicationController #Ended by young - before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks] + before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, + :user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects] #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_bids, :info] + :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :watch_bids, :info, + :watch_projects] accept_api_auth :index, :show, :create, :update, :destroy,:tag_save #william @@ -559,6 +561,22 @@ class UsersController < ApplicationController @auth_sources = AuthSource.all @membership ||= Member.new end + + def watch_projects + @watch_type = Watcher.visible.where("watchable_type = ? and user_id = ?", 'Project', @user.id) + @watch_projects = [] + unless @watch_type.nil? + @watch_type.each do |obj| + @watch_projects << Project.find(obj.watchable_id) if(Project.find(obj.watchable_id)) + end + end + respond_to do |format| + format.html { + render :layout => 'base_users' + } + format.api + end +end def update @user.admin = params[:user][:admin] if params[:user][:admin] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 571eb0b8..0db12e24 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -254,11 +254,13 @@ module ApplicationHelper s << "" end if @project.project_type == 1 - unless Course.find_by_extra(@project.identifier).tea_id == User.current.id + unless Course.find_by_extra(@project.identifier).nil? + unless Course.find_by_extra(@project.identifier).tea_id == User.current.id s << "" s << join_in_course(@project, User.current)#, ['whiteButton']) s << "" end + end end s << (render :partial => 'projects/project', :locals => {:project => project}).to_s s << "\n" diff --git a/app/models/project.rb b/app/models/project.rb index e45c8dc2..9e5c2f66 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -70,6 +70,7 @@ class Project < ActiveRecord::Base has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy + has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy #end has_one :wiki, :dependent => :destroy @@ -88,7 +89,7 @@ class Project < ActiveRecord::Base has_many :tags, :through => :project_tags, :class_name => 'Tag' - has_many :project_tags, :class_name => 'ProjectTags' + has_many :project_tags, :class_name => 'ProjectTags', :dependent => :destroy acts_as_nested_set :order => 'name', :dependent => :destroy acts_as_attachable :view_permission => :view_files, @@ -122,7 +123,10 @@ class Project < ActiveRecord::Base after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} before_destroy :delete_all_members - + def remove_references_before_destroy + return if self.id.nil? + Watcher.delete_all ['watchable_id = ?', id] + end scope :has_module, lambda {|mod| where("#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s) } diff --git a/app/models/user.rb b/app/models/user.rb index 2d6b5908..36bcd0d0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -95,10 +95,13 @@ class User < Principal has_many :project_infos, :dependent => :destroy has_one :user_status, :dependent => :destroy ##### + has_many :shares ,:dependent => :destroy scope :logged, lambda { where("#{User.table_name}.status <> #{STATUS_ANONYMOUS}") } scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } - + scope :visible, lambda {|*args| + nil + } acts_as_customizable @@ -774,4 +777,4 @@ class AnonymousUser < User def destroy false end -end +end \ No newline at end of file diff --git a/app/models/user_grade.rb b/app/models/user_grade.rb new file mode 100644 index 00000000..f79fcd2c --- /dev/null +++ b/app/models/user_grade.rb @@ -0,0 +1,4 @@ +class UserGrade < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :project +end diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 853e0cf6..f700e62a 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -26,7 +26,10 @@ class Watcher < ActiveRecord::Base validates_presence_of :user validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id] validate :validate_user - + scope :visible, lambda {|*args| + nil + } + # Unwatch things that users are no longer allowed to view def self.prune(options={}) if options.has_key?(:user) diff --git a/app/views/bids/_list_projects.html.erb b/app/views/bids/_list_projects.html.erb index 42812a5f..06a7a85f 100644 --- a/app/views/bids/_list_projects.html.erb +++ b/app/views/bids/_list_projects.html.erb @@ -8,12 +8,14 @@
<%= link_to(b_project.project.name, project_path(b_project.project)) %> + <%= l(:label_join_bidding)%> | @@ -21,7 +23,7 @@
-
+ <%= l(:label_system_grade) %>:<%= (b_project.project.project_status.grade.nil? ? 0 : b_project.project.project_status.grade) unless (b_project.project.project_status.nil? && b_project.project.nil?) %>
<% if get_prize(b_project).nil? or get_prize(b_project) == "" %>
<% if @bid.deadline < Date.today %>
<%= l(:label_noawards)%>
diff --git a/app/views/bids/_project_list.html.erb b/app/views/bids/_project_list.html.erb
index 5c99fdce..25f0ef45 100644
--- a/app/views/bids/_project_list.html.erb
+++ b/app/views/bids/_project_list.html.erb
@@ -1,11 +1,13 @@
<%= render_flash_messages %>
-<% if @bid.reward_type == 3 %>
+<% if @bid.reward_type == 3 %>
+ <% unless User.current.nil?%>
<% if User.current.user_extensions.identity == 1 %>
<%= l(:label_homework_prompt) %> <%= l(:label_homework_prompt_content) %>
|