@ -24,6 +24,7 @@ class AdminController < ApplicationController
before_filter :require_admin
before_filter :require_admin
helper :sort
helper :sort
helper :Users
helper :Users
helper :Settings
include SortHelper
include SortHelper
def index
def index
@ -35,15 +36,12 @@ class AdminController < ApplicationController
scope = Project . status ( @status ) . order ( 'lft' )
scope = Project . status ( @status ) . order ( 'lft' )
scope = scope . like ( params [ :name ] ) if params [ :name ] . present?
scope = scope . like ( params [ :name ] ) if params [ :name ] . present?
@projects = scope . all
@projects = scope . where( project_type : Project :: ProjectType_project ) . all
render :action = > " projects " , :layout = > false if request . xhr?
render :action = > " projects " , :layout = > false if request . xhr?
end
end
def users
def users
@project_type = params [ :project_type ]
role = params [ :role ]
sort_init 'login' , 'asc'
sort_init 'login' , 'asc'
sort_update %w( login firstname lastname mail admin created_on last_login_on )
sort_update %w( login firstname lastname mail admin created_on last_login_on )
@ -55,95 +53,14 @@ class AdminController < ApplicationController
end
end
@status = params [ :status ] || 1
@status = params [ :status ] || 1
has = {
scope = User . logged . status ( @status )
" show_changesets " = > true
scope = User . like ( params [ :name ] ) if params [ :name ] . present?
}
# @count = Redmine::Activity::Fetcher.new(User.current, :author => @user).scope_select {|t| !has["show_#{t}"].nil?}.events(nil, nil).count
scope = UserStatus . visible
case role
when 'teacher'
scope = UserStatus . teacher
when 'student'
scope = UserStatus . student
else
end
scope = scope . in_group ( params [ :group_id ] ) if params [ :group_id ] . present?
scope = scope . in_group ( params [ :group_id ] ) if params [ :group_id ] . present?
# scope.each do |user|
# UserStatus.create(:changesets_count => user.changesets.count, :watchers_count => user.watcher_users.count, :user_id => user.id)
# end
@user_count = scope . count
@user_count = scope . count
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
#@offset ||= @user_pages.offset
@offset || = @user_pages . offset
#@users = scope.order(sort_clause).limit(@limit).offset(@offset).all
@users = scope . order ( sort_clause ) . limit ( @limit ) . offset ( @offset ) . all
@user_base_tag = params [ :id ] ? 'base_users' :'base'
if params [ :user_sort_type ] . present?
case params [ :user_sort_type ]
when '0'
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users_statuses = scope . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users_statuses = scope . offset ( @offset ) . limit ( limit ) . all . reverse
end
@s_type = 0
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
# @projects = @projects[@offset, @limit]
when '1'
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users_statuses = scope . reorder ( 'grade' ) . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users_statuses = scope . reorder ( 'grade' ) . offset ( @offset ) . limit ( limit ) . all . reverse
end
@s_type = 1
#sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}
#@users = @users[@offset, @limit]
when '2'
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users_statuses = scope . reorder ( 'watchers_count' ) . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users_statuses = scope . reorder ( 'watchers_count' ) . offset ( @offset ) . limit ( limit ) . all . reverse
end
@s_type = 2
#@users = @users[@offset, @limit]
end
else
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users_statuses = scope . reorder ( 'grade' ) . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users_statuses = scope . reorder ( 'grade' ) . offset ( @offset ) . limit ( limit ) . all . reverse
end
@s_type = 1
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
# @projects = @projects[@offset, @limit]
end
@users = [ ]
@users_statuses . each do | obj |
@users << User . find_by_id ( " #{ obj . user_id } " )
end
respond_to do | format |
respond_to do | format |
@ -208,24 +125,13 @@ class AdminController < ApplicationController
end
end
@status = params [ :status ] || 1
@status = params [ :status ] || 1
has = {
" show_changesets " = > true
}
scope = User . logged . status ( @status )
scope = User . logged . status ( @status )
scope = scope . like ( params [ :name ] ) if params [ :name ] . present?
scope = scope . like ( params [ :name ] ) if params [ :name ] . present?
@user_count = scope . count
@user_count = scope . count
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
@user_pages = Paginator . new @user_count , @limit , params [ 'page' ]
@user_base_tag = params [ :id ] ? 'base_users' :'base'
@user_base_tag = params [ :id ] ? 'base_users' :'base'
@offset || = @user_pages . reverse_offset
unless @offset == 0
@users = scope . offset ( @user_pages . offset ) . limit ( @user_pages . per_page )
@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 |
respond_to do | format |
format . html {
format . html {
@ -242,8 +148,8 @@ class AdminController < ApplicationController
elsif request . post?
elsif request . post?
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@first_page . web_title = params [ :web_title ]
@first_page . web_title = params [ :web_title ]
@first_page . description = params [ : description]
@first_page . description = params [ : first_page] [ : description]
@first_page . title = params [ :title ]
#@first_page.title = params[:title ]
@first_page . sort_type = params [ :sort_type ]
@first_page . sort_type = params [ :sort_type ]
if @first_page . save
if @first_page . save
respond_to do | format |
respond_to do | format |
@ -305,14 +211,19 @@ class AdminController < ApplicationController
if request . get?
if request . get?
@contest_page = FirstPage . where ( " page_type = 'contest' " ) . first
@contest_page = FirstPage . where ( " page_type = 'contest' " ) . first
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@notification = ContestNotification . all . first ;
elsif request . post?
elsif request . post?
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@first_page = FirstPage . where ( " page_type = 'project' " ) . first
@contest_page = FirstPage . where ( " page_type = 'contest' " ) . first
@contest_page = FirstPage . where ( " page_type = 'contest' " ) . first
@notification = ContestNotification . all . first ;
@first_page . web_title = params [ :web_title ]
@first_page . web_title = params [ :web_title ]
@contest_page . web_title = params [ :web_title ]
@contest_page . web_title = params [ :web_title ]
@contest_page . title = params [ :contest_title ]
@contest_page . title = params [ :contest_title ]
@contest_page . description = params [ :contest_description ]
@contest_page . description = params [ :contest_description ]
if @first_page . save && @contest_page . save
@notification . title = params [ :contest_notification_title ]
@notification . content = params [ :contest_notification ] [ :content ]
if @first_page . save && @contest_page . save && @notification . save
respond_to do | format |
respond_to do | format |
format . html {
format . html {
flash [ :notice ] = l ( :notice_successful_update )
flash [ :notice ] = l ( :notice_successful_update )