1.课程标签迁移,从项目中分离

2.标签control\view添加对课程类标签的处理
This commit is contained in:
nwb 2014-06-05 15:20:09 +08:00
parent cd3c69af94
commit d22ffa84b4
7 changed files with 51 additions and 11 deletions

View File

@ -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

View File

@ -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*$/

View File

@ -96,9 +96,6 @@
<table width="240" border="0">
<tr align="center" width="80px">
<% files_count = @course.attachments.count %>
<% @course.versions.each do |version| %>
<% files_count += version.attachments.count %>
<% end %>
<td class="font_index">
<!-- 1 教师; 2 学生0 全部-->
@ -188,7 +185,7 @@
</div>
<div style="padding-bottom: 8px">
<% if @course.description.size>0 %>
<% if @course.description && @course.description.size>0 %>
<div class="font_lighter_sidebar">
<%= textilizable @course.description %>
@ -199,7 +196,7 @@
</div>
<% end %>
<div class="created_on_course">
<strong style="color: #068d9c"><%= l(:label_create_time) %></strong><%= format_time(@course.created_on) %>
<strong style="color: #068d9c"><%= l(:label_create_time) %></strong><%= format_time(@course.created_at) %>
</div>
</div>
<div class="user_underline"></div>
@ -210,7 +207,7 @@
<!-- added by william -for tag -->
<div class="user_tags">
<div id="tags">
<%= render :partial => 'tags/tag', :locals => {:obj => @course, :object_flag => "2"} %>
<%= render :partial => 'tags/tag', :locals => {:obj => @course, :object_flag => "5"} %>
</div>
</div>
</div>

View File

@ -7,7 +7,7 @@
// });
// })
</script>
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求-->
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求 9代表课程-->
<% @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 %> </span>
<% end %>
<% when '6' %>
<% if (User.current.logged? &&
User.current.admin?
@ -86,6 +87,12 @@
:taggable_id => obj.id, :taggable_type => object_flag %> </span>
<% end %>
<% when '9' %>
<% if (CourseInfo.find_by_course_id(obj.id)).try(:user_id) == User.current.id %>
<span class='del'> <%= link_to 'x', :controller => "tags", :action => "remove_tag", :remote => true, :tag_name => tag,
:taggable_id => obj.id, :taggable_type => object_flag %> </span>
<% end %>
<% end %>
</span>

View File

@ -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'

View File

@ -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

View File

@ -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