From d22ffa84b45367e37ac9d5bb254b1444c5f33d36 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 5 Jun 2014 15:20:09 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AF=BE=E7=A8=8B=E6=A0=87=E7=AD=BE=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=EF=BC=8C=E4=BB=8E=E9=A1=B9=E7=9B=AE=E4=B8=AD=E5=88=86?= =?UTF-8?q?=E7=A6=BB=202.=E6=A0=87=E7=AD=BEcontrol\view=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E8=AF=BE=E7=A8=8B=E7=B1=BB=E6=A0=87=E7=AD=BE=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/tags_controller.rb | 13 ++++++++++++- app/models/course.rb | 4 +++- app/views/layouts/base_courses.html.erb | 9 +++------ app/views/tags/_tag_name.html.erb | 9 ++++++++- config/routes.rb | 9 ++++++++- db/migrate/20140605025303_migrate_course_tags.rb | 16 ++++++++++++++++ db/schema.rb | 2 +- 7 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20140605025303_migrate_course_tags.rb diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 84c3aff0..175041de 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -4,7 +4,8 @@ class TagsController < ApplicationController layout "base_tags" before_filter :require_admin,:only => :show - + + include CoursesHelper include ProjectsHelper include IssuesHelper include UsersHelper @@ -64,6 +65,7 @@ class TagsController < ApplicationController # 获取搜索结果 @obj,@obj_pages,@results_count,@users_results, @projects_results, + @@courses_results, @issues_results, @bids_results, @forums_results, @@ -96,6 +98,7 @@ class TagsController < ApplicationController # 获取搜索结果 @obj,@obj_pages,@results_count,@users_results, @projects_results, + @@courses_results, @issues_results, @bids_results, @forums_results, @@ -114,6 +117,7 @@ class TagsController < ApplicationController # 获取搜索结果 @obj,@obj_pages,@results_count,@users_results, @projects_results, + @@courses_results, @issues_results, @bids_results, @forums_results, @@ -188,6 +192,7 @@ class TagsController < ApplicationController @obj_pages = nil @obj = nil @result = nil + @courses_results = nil # 这里为了提高系统的响应速度 把搜索结果放到case中去了 case obj_flag @@ -219,6 +224,9 @@ class TagsController < ApplicationController when '8' @obj = OpenSourceProject.find_by_id(obj_id) @obj_pages, @open_source_projects_results, @results_count = for_pagination(get_open_source_projects_by_tag(selected_tags)) + when '9' then + @obj = Course.find_by_id(obj_id) + @obj_pages, @courses_results, @results_count = for_pagination(get_courses_by_tag(selected_tags)) else @obj = nil end @@ -232,6 +240,7 @@ class TagsController < ApplicationController @forums_results, attachments_results, @contests_results, + @courses_results, @open_source_projects_results] end @@ -279,6 +288,8 @@ class TagsController < ApplicationController return 'Contest' when '8' return 'OpenSourceProject' + when '9' + return 'Course' else render_error :message => e.message return diff --git a/app/models/course.rb b/app/models/course.rb index df063cec..e47fb52c 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -23,8 +23,10 @@ class Course < ActiveRecord::Base has_many :student, :through => :students_for_courses, :source => :user has_many :course_infos, :dependent => :destroy + acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy - + acts_as_attachable :view_permission => :view_files, + :delete_permission => :manage_files validates_presence_of :password, :term validates_format_of :class_period, :message => "class period can only digital!", :with =>/^[1-9]\d*$/ diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 73c46b68..8e32e219 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -96,9 +96,6 @@ <% files_count = @course.attachments.count %> - <% @course.versions.each do |version| %> - <% files_count += version.attachments.count %> - <% end %>
@@ -188,7 +185,7 @@
- <% if @course.description.size>0 %> + <% if @course.description && @course.description.size>0 %>
<%= textilizable @course.description %> @@ -199,7 +196,7 @@
<% end %>
- <%= l(:label_create_time) %>:<%= format_time(@course.created_on) %> + <%= l(:label_create_time) %>:<%= format_time(@course.created_at) %>
@@ -210,7 +207,7 @@
- <%= render :partial => 'tags/tag', :locals => {:obj => @course, :object_flag => "2"} %> + <%= render :partial => 'tags/tag', :locals => {:obj => @course, :object_flag => "5"} %>
diff --git a/app/views/tags/_tag_name.html.erb b/app/views/tags/_tag_name.html.erb index dad5d53f..0b94264d 100644 --- a/app/views/tags/_tag_name.html.erb +++ b/app/views/tags/_tag_name.html.erb @@ -7,7 +7,7 @@ // }); // }) - + <% @tags = obj.reload.tag_list %> <% if non_list_all and (@tags.size > 0) %> @@ -70,6 +70,7 @@ :taggable_id => obj.id, :taggable_type => object_flag %> <% end %> + <% when '6' %> <% if (User.current.logged? && User.current.admin? @@ -86,6 +87,12 @@ :taggable_id => obj.id, :taggable_type => object_flag %> <% end %> + <% when '9' %> + + <% if (CourseInfo.find_by_course_id(obj.id)).try(:user_id) == User.current.id %> + <%= link_to 'x', :controller => "tags", :action => "remove_tag", :remote => true, :tag_name => tag, + :taggable_id => obj.id, :taggable_type => object_flag %> + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 7074965f..3057955a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -550,9 +550,16 @@ RedmineApp::Application.routes.draw do get 'settings(/:tab)', :action => 'settings', :as => 'settings' get 'homework', :action => 'homework', :as => 'homework' get 'new_homework', :action => 'new_homework', :as => 'new_homework' + get 'file', :action => 'file', :as => 'file' post 'finishcourse' post 'restartcourse' - end + end + + resources :files, :only => [:index, :new, :create] do + collection do + match "getattachtype" , via: [:get, :post] + end + end end match '/courses/search', :controller => 'courses', :action => 'search', :via => [:get, :post] #match 'project/enterprise_course', :to => 'projects#enterprise_course' diff --git a/db/migrate/20140605025303_migrate_course_tags.rb b/db/migrate/20140605025303_migrate_course_tags.rb new file mode 100644 index 00000000..17f93d40 --- /dev/null +++ b/db/migrate/20140605025303_migrate_course_tags.rb @@ -0,0 +1,16 @@ +class MigrateCourseTags < ActiveRecord::Migration + def self.up + # 原课程的标签数据迁移成新模式 + taggings = ActsAsTaggableOn::Tagging.find_all_by_taggable_type('Project') + taggings.each do |tagging| + project = Project.find_by_id(tagging.taggable_id) + if project && project.project_type == 1 + tagging.taggable_type= 'Course' + tagging.save + end + end + end + + def self.down + end +end diff --git a/db/schema.rb b/db/schema.rb index d559d41f..f642770a 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 => 20140605025302) do +ActiveRecord::Schema.define(:version => 20140605025303) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false