From 7deeab62bc7a205118cb680166c900de1fcc82ec Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 24 Feb 2014 10:40:45 +0800 Subject: [PATCH] course.trustie.net --- app/controllers/users_controller.rb | 9 ++ app/controllers/welcome_controller.rb | 5 +- app/helpers/application_helper.rb | 7 +- app/helpers/welcome_helper.rb | 22 +++++ app/models/user.rb | 7 ++ app/models/user_status.rb | 11 +++ app/views/layouts/_base_footer.html.erb | 2 + app/views/layouts/base.html.erb | 6 +- app/views/welcome/course.html.erb | 117 ++++++------------------ app/views/welcome/index.html.erb | 2 +- config/locales/zh.yml | 2 + public/stylesheets/welcome.css | 8 ++ 12 files changed, 105 insertions(+), 93 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f1b8ba528..741ccce10 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -220,6 +220,7 @@ class UsersController < ApplicationController def index @project_type = params[:project_type] + role = params[:role] sort_init 'login', 'asc' sort_update %w(login firstname lastname mail admin created_on last_login_on) @@ -238,6 +239,14 @@ class UsersController < ApplicationController # @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.each do |user| diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 5b4e8caff..64f3002fb 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -19,6 +19,7 @@ class WelcomeController < ApplicationController caches_action :robots def index + (course() and render :course and return 0) if request.headers['REQUEST_URI'].match(/course\.trustie\.net/) # @news = News.latest User.current # @projects = Project.latest User.current #by young @@ -74,7 +75,9 @@ class WelcomeController < ApplicationController end def course - + @course = Project.course_entities + @teacher = User.teacher + @student = User.student end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 26180d815..43883fd6f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1501,6 +1501,8 @@ module ApplicationHelper def render_dynamic_nav home_link = link_to l(:field_homepage), home_path + course_all_course_link = link_to l(:label_course_all), {:controller => 'projects', :action => 'course', :project_type => 1} + course_teacher_all_link = link_to l(:label_teacher_all), {:controller => 'users', :action => 'index', :role => 'teacher'} courses_link = link_to l(:label_course_practice), {:controller => 'projects', :action => 'course', :project_type => 1} projects_link = link_to l(:label_project_deposit), {:controller => 'projects', :action => 'index', :project_type => 0} users_link = link_to l(:label_software_user), {:controller => 'users', :action => 'index'} @@ -1512,13 +1514,16 @@ module ApplicationHelper #@nav_dispaly_project_label nav_list = Array.new nav_list.push(home_link) + nav_list.push(course_all_course_link) if @nav_dispaly_course_all_label + nav_list.push(course_teacher_all_link) if @nav_dispaly_teacher_all_label + nav_list.push(courses_link) if @nav_dispaly_course_label nav_list.push(projects_link) if @nav_dispaly_project_label nav_list.push(users_link) if @nav_dispaly_user_label nav_list.push(contest_link) if @nav_dispaly_contest_label nav_list.push(bids_link) if @nav_dispaly_bid_label nav_list.push(forum_link) if @nav_dispaly_forum_label - nav_list.push(stores_link) + nav_list.push(stores_link) if !@nav_dispaly_course_all_label content_li = '' nav_list.collect do |nav_item| diff --git a/app/helpers/welcome_helper.rb b/app/helpers/welcome_helper.rb index b85b3276b..7d93d0cdf 100644 --- a/app/helpers/welcome_helper.rb +++ b/app/helpers/welcome_helper.rb @@ -229,4 +229,26 @@ module WelcomeHelper end end + def newbie_send_path + create_new_forum_path '新手讨论' + end + def suggestion_send_path + create_new_forum_path '网站建议' + end + + private + + def create_new_forum_path name + # 没有论坛则返回'#' 不能发帖 + # 否则到指定论坛里发帖 + # 没有找到置顶论坛就跑默认第一个论坛发帖 + forum_relation = create_find_undefine_forum name + backUrl = '#' + backUrl = new_forum_memo_path(Forum.first) if Forum.count > 0 + backUrl = new_forum_memo_path(forum_relation.first) if !forum_relation.empty? + return backUrl + end + def create_find_undefine_forum name + Forum.where("name LIKE \'%#{name}%\'") + end end diff --git a/app/models/user.rb b/app/models/user.rb index 53aacd239..4042fd84f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -122,6 +122,13 @@ class User < Principal has_one :user_extensions,:dependent => :destroy ## end + scope :teacher, -> { + joins(:user_extensions).where('user_extensions.identity = ?', 0) + } + scope :student, -> { + joins(:user_extensions).where('user_extensions.identity = ?', 1) + } + attr_accessor :password, :password_confirmation attr_accessor :last_before_login_on # Prevents unauthorized assignments diff --git a/app/models/user_status.rb b/app/models/user_status.rb index f7815b62e..f6dd0c8b6 100644 --- a/app/models/user_status.rb +++ b/app/models/user_status.rb @@ -7,6 +7,17 @@ class UserStatus < ActiveRecord::Base validates_uniqueness_of :user_id scope :visible, lambda {|*args| nil } + scope :teacher, -> { + joins('LEFT JOIN users ON user_statuses.user_id=users.id'). + joins('LEFT JOIN user_extensions ON users.id=user_extensions.user_id'). + where('user_extensions.identity = ?', 0) + } + scope :student, -> { + joins('LEFT JOIN users ON user_statuses.user_id=users.id'). + joins('LEFT JOIN user_extensions ON users.id=user_extensions.user_id'). + where('user_extensions.identity = ?', 1) + } + # 更新字段 watchers_count 加1 这里没有做用户是否存在的匹配 # 负责这个表的聂同学 是在新建用户时就新建了该表的记录 # 但是 如果超级用户删除其他用户的话会造成读取错误 这里是遗漏点 diff --git a/app/views/layouts/_base_footer.html.erb b/app/views/layouts/_base_footer.html.erb index 822795ef9..24a72eac4 100644 --- a/app/views/layouts/_base_footer.html.erb +++ b/app/views/layouts/_base_footer.html.erb @@ -6,6 +6,8 @@ <%= debug(params) if Rails.env.development? %> +<%= 'request.headers[REQUEST_URI] ===> '+request.headers['REQUEST_URI'] if Rails.env.development? %> +