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 @@
@@ -188,7 +185,7 @@
- <% if @course.description.size>0 %>
+ <% if @course.description && @course.description.size>0 %>
@@ -210,7 +207,7 @@
<% end %>
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
- <%= l(:label_create_time) %>:<%= format_time(@course.created_on) %>
+ <%= l(:label_create_time) %>:<%= format_time(@course.created_at) %>
|