diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 64f139c31..e5af4ac85 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -15,15 +15,49 @@ class BidsController < ApplicationController @bids = @bids.like(params[:name]) if params[:name].present? @bid_count = @bids.count @bid_pages = Paginator.new @bid_count, @limit, params['page'] - + @offset ||= @bid_pages.reverse_offset #@bids = @bids.offset(@offset).limit(@limit).all.reverse - unless @offset == 0 - @bids = @bids.offset(@offset).limit(@limit).all.reverse + # unless @offset == 0 + # @bids = @bids.offset(@offset).limit(@limit).all.reverse + # else + # limit = @bid_count % @limit + # @bids = @bids.offset(@offset).limit(limit).all.reverse + # end + #added by nie + if params[:bid_sort_type].present? + case params[:bid_sort_type] + when '0' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @bids = @bids.offset(@offset).limit(limit).all.reverse + end + when '1' + unless @offset == 0 + @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse + end + when '2' + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @bids = @bids.offset(@offset).limit(@limit).all.reverse + end + end else - limit = @bid_count % @limit - @bids = @bids.offset(@offset).limit(limit).all.reverse + unless @offset == 0 + @bids = @bids.offset(@offset).limit(@limit).all.reverse + else + limit = @bid_count % @limit + @bids = @bids.offset(@offset).limit(limit).all.reverse + end end + #end # @limit = api_offset_and_limit({:limit => 5}) # @bids = Bid.visible # @bids = @bids.like(params[:name]) if params[:name].present? @@ -187,39 +221,39 @@ class BidsController < ApplicationController def new_bid @bid = Bid.new @bid.safe_attributes = params[:bid] - # if params[:bid_title] - # # if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/ - # unless params[:bid_reward_type] == "0" - # if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ - # bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description], params[:bid_reward_type].to_i) - # unless bid.watched_by?(User.current) - # if bid.add_watcher(User.current) - # flash[:notice] = l(:label_bid_succeed) - # end - # end - # else - # flash[:error] = l(:label_wrong_date) - # end - # else - # flash[:error] = "wrong" - # end - # # else - # # flash[:error] = l(:label_wrong_budget) - # # end - # end - # @limit = 5 - # @bid_count = Bid.count - # @bid_pages = Paginator.new @bid_count, @limit, params['page'] - # @offset ||= @bid_pages.offset - # @bids = Bid.offset(@offset).limit(@limit).all - # respond_to do |format| - # # format.html - # format.html { redirect_to :back } - # format.js - # # format.api { render_api_ok } - # end + # if params[:bid_title] + # # if params[:bid_budget].to_s =~ /^(\d+)$|^(\d+).([0-9]{2})$/ + # unless params[:bid_reward_type] == "0" + # if params[:bid_deadline].to_s =~ /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/ + # bid = Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description], params[:bid_reward_type].to_i) + # unless bid.watched_by?(User.current) + # if bid.add_watcher(User.current) + # flash[:notice] = l(:label_bid_succeed) + # end + # end + # else + # flash[:error] = l(:label_wrong_date) + # end + # else + # flash[:error] = "wrong" + # end + # # else + # # flash[:error] = l(:label_wrong_budget) + # # end + # end + # @limit = 5 + # @bid_count = Bid.count + # @bid_pages = Paginator.new @bid_count, @limit, params['page'] + # @offset ||= @bid_pages.offset + # @bids = Bid.offset(@offset).limit(@limit).all + # respond_to do |format| + # # format.html + # format.html { redirect_to :back } + # format.js + # # format.api { render_api_ok } + # end end - + def create_bid @bid = Bid.new @bid.name = params[:bid][:name] diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index cc4fda9fe..e8b25b338 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -113,6 +113,9 @@ class ProjectsController < ApplicationController @projects = @projects.offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit + if limit == 0 + limit = @limit + end @projects = @projects.offset(@offset).limit(limit).all.reverse end # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } @@ -123,6 +126,9 @@ class ProjectsController < ApplicationController @projects = @projects.includes(:project_status).reorder('project_statuses.changesets_count').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit + if limit == 0 + limit = @limit + end @projects = @projects.includes(:project_status).reorder('project_statuses.changesets_count').offset(@offset).limit(limit).all.reverse end @@ -133,6 +139,9 @@ class ProjectsController < ApplicationController @projects = @projects.includes(:project_status).reorder('project_statuses.watchers_count').offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit + if limit == 0 + limit = @limit + end @projects = @projects.includes(:project_status).reorder('project_statuses.watchers_count').offset(@offset).limit(limit).all.reverse end end @@ -142,6 +151,9 @@ class ProjectsController < ApplicationController @projects = @projects.offset(@offset).limit(@limit).all.reverse else limit = @project_count % @limit + if limit == 0 + limit = @limit + end @projects = @projects.offset(@offset).limit(limit).all.reverse end # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cf31d33a9..04e0b5f2b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -174,6 +174,9 @@ class UsersController < ApplicationController @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 # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } @@ -184,6 +187,9 @@ class UsersController < ApplicationController @users = scope.includes(:user_status).reorder('user_statuses.changesets_count').offset(@offset).limit(@limit).all.reverse else limit = @user_count % @limit + if limit == 0 + limit = @limit + end @users = scope.includes(:user_status).reorder('user_statuses.changesets_count').offset(@offset).limit(limit).all.reverse end #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} @@ -194,6 +200,9 @@ class UsersController < ApplicationController @users = scope.includes(:user_status).reorder('user_statuses.watchers_count').offset(@offset).limit(@limit).all.reverse else limit = @user_count % @limit + if limit == 0 + limit = @limit + end @users = scope.includes(:user_status).reorder('user_statuses.watchers_count').offset(@offset).limit(limit).all.reverse end #@users = @users[@offset, @limit] @@ -204,6 +213,9 @@ class UsersController < ApplicationController @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 # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e99ff4eee..5204788cf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -219,7 +219,8 @@ module ApplicationHelper if projects.any? ancestors = [] original_project = @project - projects.sort_by(&:lft).each do |project| + #modified by nie + projects.each do |project| # set the project environment to please macros. @project = project if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) diff --git a/app/views/bids/index.html.erb b/app/views/bids/index.html.erb index 32ab5e1b1..091ef31c2 100644 --- a/app/views/bids/index.html.erb +++ b/app/views/bids/index.html.erb @@ -28,6 +28,21 @@ <% end %> + +