From e490f7979d60713bdf6def7d305c9d7a32bb84e3 Mon Sep 17 00:00:00 2001 From: nwb Date: Tue, 3 Jun 2014 09:39:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8Bindex?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 71 +++++++-------- app/views/courses/index.html.erb | 89 ++++++++++--------- config/routes.rb | 1 + ...=> 20140530102014_add_status_to_course.rb} | 0 .../20140530102015_stored_course_procedure.rb | 2 +- db/schema.rb | 26 ++++-- 6 files changed, 107 insertions(+), 82 deletions(-) rename db/migrate/{20140530102016_add_status_to_course.rb => 20140530102014_add_status_to_course.rb} (100%) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e54d50102..3060d1f07 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -70,81 +70,81 @@ class CoursesController < ApplicationController end - def course12 - @project_type = params[:project_type] + def index + @course_type = params[:course_type] @school_id = params[:school_id] per_page_option = 10 if @school_id == "0" or @school_id.nil? - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). - where("#{Project.table_name}.project_type = ? ", Project::ProjectType_course) + @courses_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). + where("#{Project.table_name}.course_type = ? ", Project::ProjectType_course) else - @projects_all = Project.active.visible. - joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id"). + @courses_all = Project.active.visible. + joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.course_id"). joins(:course_extra). - where("#{Project.table_name}.project_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) + where("#{Project.table_name}.course_type = ? AND #{Course.table_name}.school_id = ?", Project::ProjectType_course, @school_id) end - @project_count = @projects_all.count - @project_pages = Paginator.new @project_count, per_page_option, params['page'] + @course_count = @courses_all.count + @course_pages = Paginator.new @course_count, per_page_option, params['page'] #gcm activity count - @project_activity_count=Hash.new + @course_activity_count=Hash.new #count initialize - @projects_all.each do |project| - @project_activity_count[project.id]=0 + @courses_all.each do |course| + @course_activity_count[course.id]=0 end - #@project_activity_count=get_project_activity @projects_all,@project_activity_count + #@course_activity_count=get_course_activity @courses_all,@course_activity_count #gcm end - case params[:project_sort_type] + case params[:course_sort_type] when '0' - @projects = @projects_all.order("created_on desc") + @courses = @courses_all.order("created_on desc") @s_type = 0 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend when '1' - @projects = @projects_all.order("course_ac_para desc") + @courses = @courses_all.order("course_ac_para desc") @s_type = 1 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend when '2' - @projects = @projects_all.order("watchers_count desc") + @courses = @courses_all.order("watchers_count desc") @s_type = 2 - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend #gcm when '3' #gcm - @project_activity_count=get_project_activity @projects_all,@project_activity_count + @course_activity_count=get_course_activity @courses_all,@course_activity_count #gcmend - @projects=handle_project @projects_all,@project_activity_count + @courses=handle_course @courses_all,@course_activity_count @s_type = 3 - @projects = @projects[@project_pages.offset, @project_pages.per_page] + @courses = @courses[@course_pages.offset, @course_pages.per_page] else @s_type = 0 - @projects = @projects_all.order("created_on desc") - @projects = @projects.offset(@project_pages.offset).limit(@project_pages.per_page) + @courses = @courses_all.order("created_on desc") + @courses = @courses.offset(@course_pages.offset).limit(@course_pages.per_page) #gcm - @project_activity_count=get_project_activity @projects,@project_activity_count + @course_activity_count=get_course_activity @courses,@course_activity_count #gcmend end @@ -155,21 +155,22 @@ class CoursesController < ApplicationController } format.api { # @offset, @limit = api_offset_and_limit - # @project_count = Project.visible.count - # @projects = Project.visible.offset(@offset).limit(@limit).order('lft').all + # @course_count = Project.visible.count + # @courses = Project.visible.offset(@offset).limit(@limit).order('lft').all } format.atom { - projects = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all - render_feed(projects, :title => "#{Setting.app_title}: #{l(:label_project_latest)}") + courses = Project.visible.order('created_on DESC').limit(Setting.feeds_limit.to_i).all + render_feed(courses, :title => "#{Setting.app_title}: #{l(:label_course_latest)}") } end end - def index + def index1 per_page_option = 10 + #当前所有的活动课程 @courses_all = Course.active.visible. joins("LEFT JOIN #{CourseStatus.table_name} ON #{Course.table_name}.id = #{CourseStatus.table_name}.couse_id") diff --git a/app/views/courses/index.html.erb b/app/views/courses/index.html.erb index 9b1cf841a..1492264c8 100644 --- a/app/views/courses/index.html.erb +++ b/app/views/courses/index.html.erb @@ -1,63 +1,70 @@ <% content_for :header_tags do %> -<%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %> + <%= auto_discovery_link_tag(:atom, {:action => 'index', :format => 'atom', :key => User.current.rss_key}) %> <% end %>
- <%= form_tag(courses_search_path, :method => :get) do %> - - - - - - - - - - - -
<%= l(:label_course_deposit) %><%= l(:label_user_location) %> : - <% if User.current.logged? %> - <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type =>( @course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> - <% end %> - - -
<%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> <%=link_to l(:field_homepage), home_path %> > <%=link_to l(:label_course_deposit), :controller => 'courses', :action => 'index', :course_type => 0 %>
- <% end %> + <%= form_tag(courses_search_path, :method => :get) do %> + + + + + + + + + + + +
<%= l(:label_course_all) %><%= l(:label_user_location) %> : + <% if User.current.logged? %> + <%= link_to(l(:label_course_new), {:controller => 'courses', :action => 'new', :course => 0, :course_type => (@course_type||=0)}, :class => 'icon icon-add') if User.current.allowed_to?(:add_course, nil, :global => true) %> + <% end %> + + +
+ <%= link_to request.host()+"/courses", :controller => 'courses', :action => 'index', :course_type => 0 %> + <%= link_to l(:field_homepage), home_path %> + > <%= link_to l(:label_course_all), :controller => 'courses', :action => 'index', :course_type => 0 %>
+ <% end %>
<%= sort_courses(@s_type) %>
- <%= render_course_hierarchy(@courses)%> + <% if @courses %> + <%= render_course_hierarchy(@courses) %> + <% end %>
<% if User.current.logged? %> -

- <%= l(:label_my_courses) %> -

+

+ <%= l(:label_my_courses) %> +

<% end %> <% other_formats_links do |f| %> -<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> + <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <% end %> <% content_for :sidebar do %> -<%= form_tag({}, :method => :get) do %> -

<%= l(:label_course_plural) %>

- -

- <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> -

-<% end %> + <%= form_tag({}, :method => :get) do %> +

<%= l(:label_course_all) %>

+ +

+ <%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %> +

+ <% end %> <% end %> -<% html_title(l(:label_course_plural)) -%> +<% html_title(l(:label_course_all)) -%> diff --git a/config/routes.rb b/config/routes.rb index 4ccd4195d..b9b44d767 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -546,6 +546,7 @@ RedmineApp::Application.routes.draw do post 'restartcourse' end end + match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] #match 'project/enterprise_course', :to => 'projects#enterprise_course' #match 'project/course_enterprise', :to => 'projects#course_enterprise' #match 'project/course', :to => 'projects#course', :as => 'course' diff --git a/db/migrate/20140530102016_add_status_to_course.rb b/db/migrate/20140530102014_add_status_to_course.rb similarity index 100% rename from db/migrate/20140530102016_add_status_to_course.rb rename to db/migrate/20140530102014_add_status_to_course.rb diff --git a/db/migrate/20140530102015_stored_course_procedure.rb b/db/migrate/20140530102015_stored_course_procedure.rb index 4489791dc..6c31279e1 100644 --- a/db/migrate/20140530102015_stored_course_procedure.rb +++ b/db/migrate/20140530102015_stored_course_procedure.rb @@ -4,7 +4,7 @@ class StoredCourseProcedure < ActiveRecord::Migration # project中所有的课程导入至course # Project_status导入至course_status # - Project.find_all.each do |project| + Project.all.each do |project| if project.project_type == 1 course = Course.find_by_extra(project.identifier) if course diff --git a/db/schema.rb b/db/schema.rb index 12bcab886..8c3bdca4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140522025721) do +ActiveRecord::Schema.define(:version => 20140530102015) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -220,6 +220,16 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.datetime "updated_on", :null => false end + create_table "course_statuses", :force => true do |t| + t.integer "changesets_count" + t.integer "watchers_count" + t.integer "course_id" + t.float "grade", :default => 0.0 + t.integer "course_ac_para", :default => 0 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "courses", :force => true do |t| t.integer "tea_id" t.string "name" @@ -227,8 +237,8 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.string "code" t.integer "time" t.string "extra" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "location" t.string "term" t.string "string" @@ -237,6 +247,11 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.string "endup_time" t.string "class_period" t.integer "school_id" + t.text "description" + t.integer "status", :default => 1 + t.integer "attachmenttype", :default => 2 + t.integer "lft" + t.integer "rgt" end create_table "custom_fields", :force => true do |t| @@ -482,12 +497,13 @@ ActiveRecord::Schema.define(:version => 20140522025721) do t.text "notes" t.integer "status" t.integer "reply_id" - t.datetime "created_on", :null => false - t.datetime "updated_on", :null => false + t.datetime "created_on", :null => false + t.datetime "updated_on", :null => false t.string "m_parent_id" t.boolean "is_readed" t.integer "m_reply_count" t.integer "m_reply_id" + t.integer "is_comprehensive_evaluation" end create_table "member_roles", :force => true do |t|