Merge branch 'api' of http://repository.trustie.net/xianbo/trustie2 into api
This commit is contained in:
commit
f73eaf31b5
|
@ -1,3 +1,5 @@
|
||||||
|
#coding=utf-8
|
||||||
|
|
||||||
module Mobile
|
module Mobile
|
||||||
|
|
||||||
module Entities
|
module Entities
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#coding=utf-8
|
||||||
module Mobile
|
module Mobile
|
||||||
module Apis
|
module Apis
|
||||||
class Courses < Grape::API
|
class Courses < Grape::API
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#coding=utf-8
|
||||||
module Mobile
|
module Mobile
|
||||||
module Apis
|
module Apis
|
||||||
class Users < Grape::API
|
class Users < Grape::API
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#coding=utf-8
|
||||||
module Mobile
|
module Mobile
|
||||||
module Apis
|
module Apis
|
||||||
class Watches < Grape::API
|
class Watches < Grape::API
|
||||||
|
|
|
@ -126,18 +126,21 @@ class CoursesController < ApplicationController
|
||||||
# 课程搜索
|
# 课程搜索
|
||||||
# add by nwb
|
# add by nwb
|
||||||
def search
|
def search
|
||||||
courses_all = Course.all_course
|
#courses_all = Course.all_course
|
||||||
name = params[:name]
|
#name = params[:name]
|
||||||
(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank?
|
#(redirect_to courses_url, :notice => l(:label_sumbit_empty);return) if name.blank?
|
||||||
@courses = courses_all.visible
|
#@courses = courses_all.visible
|
||||||
if params[:name].present?
|
#if params[:name].present?
|
||||||
@courses_all = @courses.like(params[:name])
|
# @courses_all = @courses.like(params[:name])
|
||||||
else
|
#else
|
||||||
@courses_all = @courses;
|
# @courses_all = @courses;
|
||||||
end
|
#end
|
||||||
|
cs = CoursesService.new
|
||||||
|
@courses_all = cs.search_course params
|
||||||
@course_count = @courses_all.count
|
@course_count = @courses_all.count
|
||||||
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
@course_pages = Paginator.new @course_count, per_page_option, params['page']
|
||||||
|
|
||||||
|
|
||||||
# 课程的动态数
|
# 课程的动态数
|
||||||
@course_activity_count=Hash.new
|
@course_activity_count=Hash.new
|
||||||
@courses_all.each do |course|
|
@courses_all.each do |course|
|
||||||
|
@ -194,24 +197,31 @@ class CoursesController < ApplicationController
|
||||||
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}")
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rescue Exception => e
|
||||||
|
if e.message == 'sumbit empty'
|
||||||
|
(redirect_to courses_url, :notice => l(:label_sumbit_empty);return)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def member
|
def member
|
||||||
## 有角色参数的才是课程,没有的就是项目
|
## 有角色参数的才是课程,没有的就是项目
|
||||||
@render_file = 'member_list'
|
@render_file = 'member_list'
|
||||||
@teachers= searchTeacherAndAssistant(@course)
|
#@teachers= searchTeacherAndAssistant(@course)
|
||||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||||
case params[:role]
|
case params[:role]
|
||||||
when '1'
|
when '1'
|
||||||
@subPage_title = l :label_teacher_list
|
@subPage_title = l :label_teacher_list
|
||||||
@members = searchTeacherAndAssistant(@course)
|
#@members = searchTeacherAndAssistant(@course)
|
||||||
when '2'
|
when '2'
|
||||||
@subPage_title = l :label_student_list
|
@subPage_title = l :label_student_list
|
||||||
@members = searchStudent(@course)
|
#@members = searchStudent(@course)
|
||||||
else
|
else
|
||||||
@subPage_title = ''
|
@subPage_title = ''
|
||||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
#@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||||
end
|
end
|
||||||
|
cs = CoursesService.new
|
||||||
|
@members = cs.course_teacher_or_student_list(params,@course)
|
||||||
@members = paginateHelper @members
|
@members = paginateHelper @members
|
||||||
render :layout => 'base_courses'
|
render :layout => 'base_courses'
|
||||||
end
|
end
|
||||||
|
|
|
@ -364,33 +364,35 @@ class UsersController < ApplicationController
|
||||||
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)
|
||||||
(redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
(redirect_to user_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
|
||||||
case params[:format]
|
case params[:format]
|
||||||
when 'xml', 'json'
|
when 'xml', 'json'
|
||||||
@offset, @limit = api_offset_and_limit({:limit => 15})
|
@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
|
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
|
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|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class CoursesService
|
class CoursesService
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
include CoursesHelper
|
||||||
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
#参数school_id为0或不传时返回所有课程,否则返回对应学校的课程
|
||||||
#参数per_page_count分页功能,每页显示的课程数
|
#参数per_page_count分页功能,每页显示的课程数
|
||||||
#参数page分页功能,当前页码
|
#参数page分页功能,当前页码
|
||||||
|
@ -26,4 +27,43 @@ class CoursesService
|
||||||
course_list
|
course_list
|
||||||
end
|
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
|
end
|
|
@ -126,4 +126,16 @@ class UsersService
|
||||||
@current_user
|
@current_user
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue