From 2ab2abe9e553ed598456fbdb7c6c8f1e833f4ad8 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 10 Dec 2014 18:26:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/auth.rb | 2 ++ app/api/mobile/apis/courses.rb | 1 + app/api/mobile/apis/users.rb | 1 + app/api/mobile/apis/watches.rb | 1 + app/controllers/courses_controller.rb | 26 +++++++++++++++++--------- app/services/courses_service.rb | 21 +++++++++++++++++++++ 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/api/mobile/apis/auth.rb b/app/api/mobile/apis/auth.rb index ae233a853..5a6c0f34f 100644 --- a/app/api/mobile/apis/auth.rb +++ b/app/api/mobile/apis/auth.rb @@ -1,3 +1,5 @@ +#coding=utf-8 + module Mobile module Entities diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 9aeea5176..515ebce77 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Courses < Grape::API diff --git a/app/api/mobile/apis/users.rb b/app/api/mobile/apis/users.rb index d05809726..52932b883 100644 --- a/app/api/mobile/apis/users.rb +++ b/app/api/mobile/apis/users.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Users < Grape::API diff --git a/app/api/mobile/apis/watches.rb b/app/api/mobile/apis/watches.rb index 0715ff4a2..ce846debd 100644 --- a/app/api/mobile/apis/watches.rb +++ b/app/api/mobile/apis/watches.rb @@ -1,3 +1,4 @@ +#coding=utf-8 module Mobile module Apis class Watches < Grape::API diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bd389ff68..ac25d59cf 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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,6 +197,11 @@ 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 diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 0a1fa553d..f1c2babbe 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -26,4 +26,25 @@ 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 + end \ No newline at end of file From 1494821b675989ac27b2aa09dbfb3f06e79240e1 Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 10 Dec 2014 20:27:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 52 +++++++++++++++-------------- app/services/users_service.rb | 12 +++++++ 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4049c2ae8..084e720d8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 { diff --git a/app/services/users_service.rb b/app/services/users_service.rb index 9587427b5..d281edb19 100644 --- a/app/services/users_service.rb +++ b/app/services/users_service.rb @@ -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 From 6dc057d03ca28bbb3e837a2af9d759d004d41f3c Mon Sep 17 00:00:00 2001 From: z9hang Date: Wed, 10 Dec 2014 20:53:41 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=80=81=E5=B8=88?= =?UTF-8?q?=E3=80=81=E5=AD=A6=E7=94=9F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 10 ++++++---- app/services/courses_service.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ac25d59cf..26b96eaf3 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -207,19 +207,21 @@ class CoursesController < ApplicationController 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 diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index f1c2babbe..0468de367 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -1,5 +1,6 @@ class CoursesService include ApplicationHelper + include CoursesHelper #参数school_id为0或不传时返回所有课程,否则返回对应学校的课程 #参数per_page_count分页功能,每页显示的课程数 #参数page分页功能,当前页码 @@ -47,4 +48,22 @@ class CoursesService 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 \ No newline at end of file