You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/app/controllers/ecs_controller.rb

66 lines
2.2 KiB

6 years ago
class EcsController < ApplicationController
6 years ago
before_filter :find_school, :except => [:get_navigation_url]
6 years ago
layout 'base_ec'
def department
@template_major = EcMajorSchool.where(:template_major => true).first
@school_managers = @school.users
@is_school_manager = User.current.admin? || @school.users.where(:id => User.current.id).count > 0 # 学校管理员
@major_schools = @school.ec_major_schools.where(:template_major => false)
unless @is_school_manager
ec_major_school_ids = EcMajorSchoolUser.where(:user_id => User.current.id).pluck(:ec_major_school_id)
6 years ago
ec_course_major_ids = EcYear.where(:id => EcCourseUser.where(:user_id => User.current.id).pluck(:ec_year_id)).pluck(:ec_major_school_id)
6 years ago
@major_schools = @major_schools.where(:id => (ec_major_school_ids + ec_course_major_ids).uniq)
end
@major_count = @major_schools.count
6 years ago
if params[:search].present?
major_ids = EcMajor.where("name like '%#{params[:search]}%' or code like '%#{params[:search]}%'").pluck(:id)
@major_schools = @major_schools.where(:ec_major_id => major_ids)
end
6 years ago
6 years ago
@obj_count = @major_schools.count
@limit = 10
@is_remote = true
@obj_pages = Paginator.new @obj_count, @limit, params['page'] || 1
@offset ||= @obj_pages.offset
@major_schools = paginateHelper @major_schools, @limit
respond_to do |format|
format.js
format.html
6 years ago
end
end
# 搜索专业
def search_major
@major_ids = @school.ec_majors.pluck(:id)
# 去除已经添加的专业
@majors = EcMajor.where("(concat(name, code) like '%#{params[:search]}%')").limit(10)
end
# 添加专业
def add_major
major_ids = params[:major_ids]
major_ids.each do |id|
EcMajorSchool.create(ec_major_id: id, school_id: params[:school_id])
end
render :json => {status: 1}
end
# 获取工程认证头部url
# GET: /ecs/get_navigation_url
def get_navigation_url
ec_user = EcSchoolUser.where(:user_id => User.current.id).first
ec_url = "#{department_ecs_path(:school_id => ec_user.school_id)}" if ec_user
render :json => {ec_url: ec_url}
end
private
def find_school
@school = School.find(params[:school_id])
end
end