This commit is contained in:
guange 2014-12-11 11:11:47 +08:00
commit f73eaf31b5
8 changed files with 107 additions and 38 deletions

View File

@ -1,3 +1,5 @@
#coding=utf-8
module Mobile
module Entities

View File

@ -1,3 +1,4 @@
#coding=utf-8
module Mobile
module Apis
class Courses < Grape::API

View File

@ -1,3 +1,4 @@
#coding=utf-8
module Mobile
module Apis
class Users < Grape::API

View File

@ -1,3 +1,4 @@
#coding=utf-8
module Mobile
module Apis
class Watches < Grape::API

View File

@ -126,18 +126,21 @@ class CoursesController < ApplicationController
# 课程搜索
# add by nwb
def search
courses_all = Course.all_course
name = params[:name]
(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank?
@courses = courses_all.visible
if params[:name].present?
@courses_all = @courses.like(params[:name])
else
@courses_all = @courses;
end
#courses_all = Course.all_course
#name = params[:name]
#(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank?
#@courses = courses_all.visible
#if params[:name].present?
# @courses_all = @courses.like(params[:name])
#else
# @courses_all = @courses;
#end
cs = CoursesService.new
@courses_all = cs.search_course params
@course_count = @courses_all.count
@course_pages = Paginator.new @course_count, per_page_option, params['page']
# 课程的动态数
@course_activity_count=Hash.new
@courses_all.each do |course|
@ -194,24 +197,31 @@ class CoursesController < ApplicationController
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
}
end
rescue Exception => e
if e.message == 'sumbit empty'
(redirect_to courses_url, :notice => l(:label_sumbit_empty);return)
end
end
def member
## 有角色参数的才是课程,没有的就是项目
@render_file = 'member_list'
@teachers= searchTeacherAndAssistant(@course)
#@teachers= searchTeacherAndAssistant(@course)
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
case params[:role]
when '1'
@subPage_title = l :label_teacher_list
@members = searchTeacherAndAssistant(@course)
#@members = searchTeacherAndAssistant(@course)
when '2'
@subPage_title = l :label_student_list
@members = searchStudent(@course)
#@members = searchStudent(@course)
else
@subPage_title = ''
@members = @course.member_principals.includes(:roles, :principal).all.sort
#@members = @course.member_principals.includes(:roles, :principal).all.sort
end
cs = CoursesService.new
@members = cs.course_teacher_or_student_list(params,@course)
@members = paginateHelper @members
render :layout => 'base_courses'
end

View File

@ -364,33 +364,35 @@ class UsersController < ApplicationController
sort_init 'login', 'asc'
sort_update %w(login firstname lastname mail admin created_on last_login_on)
(redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
case params[:format]
when 'xml', 'json'
@offset, @limit = api_offset_and_limit({:limit => 15})
else
@limit = 15#per_page_option
end
#
#@status = params[:status] || 1
#has = {
# "show_changesets" => true
#}
# scope = User.logged.status(@status)
# @search_by = params[:search_by] ? params[:search_by][:id] : 0
# scope = scope.like(params[:name],@search_by) if params[:name].present?
us = UsersService.new
scope = us.search_user params
@user_count = scope.count
@user_pages = Paginator.new @user_count, @limit, params['page']
@user_base_tag = params[:id] ? 'base_users':'users_base'
@offset ||= @user_pages.reverse_offset
unless @offset == 0
@users = scope.offset(@offset).limit(@limit).all.reverse
else
@limit = 15#per_page_option
limit = @user_count % @limit
if limit == 0
limit = @limit
end
@users = scope.offset(@offset).limit(limit).all.reverse
end
@status = params[:status] || 1
has = {
"show_changesets" => true
}
scope = User.logged.status(@status)
@search_by = params[:search_by] ? params[:search_by][:id] : 0
scope = scope.like(params[:name],@search_by) if params[:name].present?
@user_count = scope.count
@user_pages = Paginator.new @user_count, @limit, params['page']
@user_base_tag = params[:id] ? 'base_users':'users_base'
@offset ||= @user_pages.reverse_offset
unless @offset == 0
@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|
format.html {

View File

@ -1,5 +1,6 @@
class CoursesService
include ApplicationHelper
include CoursesHelper
#参数school_id为0或不传时返回所有课程否则返回对应学校的课程
#参数per_page_count分页功能每页显示的课程数
#参数page分页功能当前页码
@ -26,4 +27,43 @@ class CoursesService
course_list
end
#搜索课程
def search_course params
courses_all = Course.all_course
name = params[:name]
if name.blank?
raise 'sumbit empty'
end
@courses = courses_all.visible
if params[:name].present?
@courses_all = @courses.like(params[:name])
else
@courses_all = @courses;
end
@courses_all
end
#获取头像
def get_img obj
url_to_avatar(obj)
end
#课程老师或课程学生列表
def course_teacher_or_student_list params,course
@teachers= searchTeacherAndAssistant(course)
#@canShowCode = isCourseTeacher(User.current.id,course) && params[:role] != '1'
case params[:role]
when '1'
#@subPage_title = l :label_teacher_list
@members = searchTeacherAndAssistant(course)
when '2'
#@subPage_title = l :label_student_list
@members = searchStudent(course)
else
#@subPage_title = ''
@members = @course.member_principals.includes(:roles, :principal).all.sort
end
@members
end
end

View File

@ -126,4 +126,16 @@ class UsersService
@current_user
end
#搜索用户
def search_user params
@status = params[:status] || 1
has = {
"show_changesets" => true
}
scope = User.logged.status(@status)
@search_by = params[:search_by] ? params[:search_by][:id] : 0
scope = scope.like(params[:name],@search_by) if params[:name].present?
scope
end
end