班级模块整体功能完善

This commit is contained in:
daiao 2017-05-27 10:27:11 +08:00
parent 77cf39eb54
commit b050ebc2e8
15 changed files with 226 additions and 93 deletions

View File

@ -851,21 +851,23 @@ class CoursesController < ApplicationController
@orgs_not_in_course = User.current.organizations.where("organizations.id not in #{course_org_ids}")
end
course_module = CourseModule.where(:course_id => @course.id).first
@module = {
course_module.boards => 'boards',
course_module.message => 'message',
course_module.homework => 'homework',
course_module.exercises => 'exercises',
course_module.poll => 'poll',
course_module.statistics => 'statistics',
course_module.attachment => 'attachment'
}.sort {|a,b| a <=> b}
course_module = @course.course_modules
if course_module.blank?
type = ["news", "boards", "homework", "exercises", "poll", "statistics", "attachment"]
for i in 0..6
CourseModule.create(:course_id => @course.id, :type => type[i], :position => i + 1, :hidden => 0 )
end
course_module = @course.course_modules
end
@modules = course_module.order("position asc")
@course_board = @course.boards.where("parent_id is NULL").first
@board = @course_board.children.order("position asc")
@board_count = @board.count
@curr_page = '设置'
respond_to do |format|
format.html { render :layout => 'base_edu_course' }
@ -879,37 +881,36 @@ class CoursesController < ApplicationController
def update_position
course_module = CourseModule.where(:course_id => @course.id).first
course_module = @course.course_modules
for i in 0..6
case params[:position][i]
when "boards"
course_module.update_attribute('boards', i+1)
when "message"
course_module.update_attribute('message', i+1)
course_module.where(:module_type => 'boards').first.update_attribute('position', i+1)
when "news"
course_module.where(:module_type => 'news').first.update_attribute('position', i+1)
when "homework"
course_module.update_attribute('homework', i+1)
course_module.where(:module_type => 'homework').first.update_attribute('position', i+1)
when "exercises"
course_module.update_attribute('exercises', i+1)
course_module.where(:module_type => 'exercises').first.update_attribute('position', i+1)
when "poll"
course_module.update_attribute('poll', i+1)
course_module.where(:module_type => 'poll').first.update_attribute('position', i+1)
when "statistics"
course_module.update_attribute('statistics', i+1)
course_module.where(:module_type => 'statistics').first.update_attribute('position', i+1)
when "attachment"
course_module.update_attribute('attachment', i+1)
course_module.where(:module_type => 'attachment').first.update_attribute('position', i+1)
end
end
@module = {
course_module.boards => 'boards',
course_module.message => 'message',
course_module.homework => 'homework',
course_module.exercises => 'exercises',
course_module.poll => 'poll',
course_module.statistics => 'statistics',
course_module.attachment => 'attachment'
}.sort {|a,b| a <=> b}
# params[:message] 有值 就更行字段: 0为不隐藏1为隐藏
type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"]
hidden = type - params[:message]
course_module.where(:module_type => params[:message]).update_all(:hidden => 0)
course_module.where(:module_type => hidden).update_all(:hidden => 1)
@modules = @course.course_modules.order("position asc")
@course_board = @course.boards.where("parent_id is NULL").first
@board = @course_board.children.order("position asc")
@board_count = @board.count

View File

@ -63,7 +63,7 @@ module ApplicationHelper
case word
when "boards"
result = "讨论区"
when "message"
when "news"
result = "通知"
when "homework"
result = "作业"

View File

@ -66,6 +66,8 @@ class Course < ActiveRecord::Base
# 课程贡献榜
has_many :course_contributor_scores, :dependent => :destroy
#课程模块
has_many :course_modules, :dependent => :destroy
acts_as_taggable
acts_as_nested_set :order => 'name', :dependent => :destroy
acts_as_attachable :view_permission => :view_course_files,
@ -354,6 +356,19 @@ class Course < ActiveRecord::Base
end
end
# 创建课程模块
def create_course_modules
mod = self.course_modules
if mod.blank?
type = ["news", "boards", "attachment", "homework", "poll", "exercises", "statistics"]
for i in 0..6
CourseModule.create(:course_id => @course.id, :type => type[i], :position => i + 1, :hidden => 0 )
end
mod = self.course_modules
end
return mod
end
def get_endup_time
begin
end_time = Time.parse(self.endup_time)

View File

@ -1,5 +1,6 @@
class CourseModule < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :course
attr_accessible :course_id, :boards, :message, :homework, :exercises, :poll, :statistics
attr_accessible :course_id, :module_type, :position, :hidden
end

View File

@ -1,33 +1,33 @@
<ul>
<form action="<%= update_position_course_path() %>" method="post" id="update_position" data-remote="true" >
<% @module.each_with_index do |m, index| %>
<li class="clearfix mb10">
<p class="clearfix mb10">
<form action="<%= update_position_course_path() %>" method="post" id="update_position" data-remote="true" >
<% @modules.each_with_index do |m, index| %>
<li class="clearfix mb10">
<p class="clearfix mb10">
<span class="fl edu-txt-w280 font-bd">
<input class=" magic-checkbox" type="checkbox" value="<%= m[1] %>" name="message[]" id="message_<%= index %>" >
<label for="message_<%= index %>" ><%= switch_to_chinese m[1] %></label>
<input class="magic-checkbox" type="checkbox" value="<%= m.module_type %>" <%= m.hidden == 0 ? "checked" : "" %> name="message[]" id="message_<%= index %>" >
<label for="message_<%= index %>" ><%= switch_to_chinese m.module_type %></label>
</span>
<span class="fl mt3">
<% if m[0] > 1 %>
<% if m.position > 1 %>
<a href="javascript:void(0);" onclick="up_position(this);" class="fl ml30 up">上移</a>
<% end %>
<% if m[0] < @module.count %>
<% if m.position < @modules.count %>
<a href="javascript:void(0);" onclick="down_position(this);" class="fl ml30 down">下移</a>
<% end %>
<% if m[1] == "boards" %>
<% if m.module_type == "boards" %>
<a href="javascript:void(0);" class="color-green ml30" onclick="add_subtopic('<%= @course.id %>', '<%= @course_board.id %>');">添加子栏目</a>
<% end %>
</span>
</p>
<% if m[1] == "boards" %>
<div id="setting_boards_list">
<%= render :partial => 'courses/settings/boards_list' %>
</div>
</p>
<% if m.module_type == "boards" %>
<div id="setting_boards_list">
<%= render :partial => 'courses/settings/boards_list' %>
</div>
<% end %>
<input value="<%= m.module_type %>" name="position[]" class="undis" />
</li>
<% end %>
<input value="<%= m[1] %>" name="position[]" class="undis" />
</li>
<% end %>
</form>
</form>
</ul>
<a href="javascript:void(0);" class="task-btn task-btn-blue fl" onclick="$('#update_position').submit();" >保存</a>
<a href="javascript:void(0);" class="task-btn fl ml10" >取消</a>

View File

@ -1,11 +1,12 @@
<% unless course_board.children.empty? %>
<ul class="sub-menu">
<ul class="sub-edu-class-leftnav">
<% course_board.children.reorder("position asc").each do |board| %>
<li id="board_children_<%=board.id %>">
<li id="board_children_<%= board.id %>" class="clearfix">
<% count = board ? board.messages.count : 0 %>
<a href="<%=course_boards_path(@course, :board_id =>board.id) %>"><font class="hidden dis" style="max-width: 120px;"><%=board.name %></font><span style="vertical-align: top;"><%=count %></span></a>
<a href="<%= course_boards_path(@course, :board_id => board.id) %>" class="fl ml30 task-hide" style="max-width: 105px"><%= board.name %></a>
<span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<% if User.current.logged? %>
<%= link_to( "",course_boards_path(@course, :board_id =>board.id, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
<%= link_to( "", course_boards_path(@course, :board_id => board.id, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
<% end %>
</li>
<% end %>

View File

@ -0,0 +1,52 @@
<ul class="edu-class-leftnav">
<li class="clearfix" id="sy_01">
<a href="<%=course_path(@course) %>" class="fl ml15">动态</a>
</li>
<% course_board = @course.boards.where("parent_id is NULL").first %>
<li class="clearfix" id="sy_04">
<a href="<%= course_news_index_path(@course) %>" class="fl ml15 ">通知</a>
<span class="edu-cir-grey fl ml10 mt15"><%= @course.news.count %></span>
<%= link_to( "+",new_course_news_path(@course, :is_new => 1), :class => 'fr mr15 font-18 link-color-grey', :title => "#{l(:label_course_news_new)}") if is_teacher %>
</li>
<% count = course_board ? course_board.messages.count : 0 %>
<li class="clearfix" id="sy_02">
<a href="<%=course_boards_path(@course) %>" class="fl ml15 ">讨论</a>
<span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<%= link_to( "+", course_boards_path(@course, :flag => true, :is_new => 1), :class => 'fr mr15 font-18 link-color-grey', :title => "#{l(:label_message_new)}") if User.current.logged? %>
</li>
<li class="clearfix" id="sy_05">
<a href="<%=course_files_path(@course) %>" class="fl ml15 ">资源</a>
<span class="edu-cir-grey fl ml10 mt15"><%= course_file_num %></span>
<% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %>
<a class="fr mr15 font-18 link-color-grey" title="上传资源" href="javascript:void(0);" onclick="course_files_upload();">+</a>
<% end %>
</li>
<li class="clearfix" id="sy_03">
<a href="<%= homework_common_index_path(:course => @course.id) %>" class="fl ml15 ">作业</a>
<span class="edu-cir-grey fl ml10 mt15"><%=homework_num %></span>
<% if is_teacher %>
<a href="javascript:void(0);" onclick="alert_choose_homework_type('<%= @course.id %>');" class="fr mr15 font-18 link-color-grey" title="新建作业">+</a>
<% end %>
</li>
<% count = User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status <> 1").count %>
<li class="clearfix" id="sy_08">
<a href="<%= User.current.logged? ? exercise_index_path(:course_id => @course.id) : signin_url_without_domain %>" class="fl ml15 ">试卷</a>
<span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<%= link_to( "+", new_exercise_path(:course_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"新建试卷") if is_teacher %>
</li>
<li class="clearfix" id="sy_07">
<a href="<%=poll_index_path(:polls_type => "Course", :polls_group_id => @course.id) %>" class="fl ml15 ">问卷</a>
<span class="edu-cir-grey fl ml10 mt15"><%=course_poll_count %></span>
<%= link_to( "+", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"#{l(:label_new_poll)}") if is_teacher %>
</li>
<li class="clearfix" id="sy_010">
<a href="<%=course_statistics_course_path(@course) %>" class="fl ml15 ">统计</a>
</li>
</ul>

View File

@ -61,38 +61,70 @@
<%= link_to @course.name, course_path(@course), :title => '班级' %>
</p>
<div id="course_info_<%= @course.id %>">
<%=render :partial => 'layouts/course_base_info' %>
<%= render :partial => 'layouts/course_base_info' %>
</div>
<div class="edu-class-inner mb20 clearfix">
<div class="with15 fl ">
<div class="mb10">
<ul class="edu-class-leftnav">
<li class="clearfix" id="sy_01"><a href="<%=course_path(@course) %>" class="fl ml15">动态</a></li>
<li class="clearfix" id="sy_01">
<a href="<%= course_path(@course) %>" class="fl ml15">动态</a>
</li>
<% course_modules = @course.create_course_modules.where(:hidden => 0).order("position asc") %>
<% course_board = @course.boards.where("parent_id is NULL").first %>
<li class="clearfix" id="sy_04"><a href="<%=course_news_index_path(@course) %>" class="fl ml15 ">通知</a><span class="edu-cir-grey fl ml10 mt15"><%=@course.news.count %></span>
<%= link_to( "+",new_course_news_path(@course,:is_new=>1), :class => 'fr mr15 font-18 link-color-grey', :title =>"#{l(:label_course_news_new)}") if is_teacher %>
</li>
<% count = course_board ? course_board.messages.count : 0 %>
<li class="clearfix" id="sy_02"><a href="<%=course_boards_path(@course) %>" class="fl ml15 ">讨论</a><span class="edu-cir-grey fl ml10 mt15"><%=count %></span>
<%= link_to( "+",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'fr mr15 font-18 link-color-grey', :title =>"#{l(:label_message_new)}") if User.current.logged? %>
<li class="clearfix" id="sy_05"><a href="<%=course_files_path(@course) %>" class="fl ml15 ">资源</a><span class="edu-cir-grey fl ml10 mt15"><%=course_file_num %></span>
<% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %>
<a class="fr mr15 font-18 link-color-grey" title="上传资源" href="javascript:void(0);" onclick="course_files_upload();">+</a>
<% course_modules.each_with_index do |cm, i| %>
<% case cm.module_type %>
<% when "news" %>
<li class="clearfix" id="sy_04">
<a href="<%= course_news_index_path(@course) %>" class="fl ml15 ">通知</a>
<span class="edu-cir-grey fl ml10 mt15"><%= @course.news.count %></span>
<%= link_to( "+", new_course_news_path(@course, :is_new => 1), :class => 'fr mr15 font-18 link-color-grey', :title => "#{l(:label_course_news_new)}") if is_teacher %>
</li>
<% when "boards" %>
<% count = course_board ? course_board.messages.count : 0 %>
<li class="clearfix" id="sy_02">
<a href="<%=course_boards_path(@course) %>" class="fl ml15 ">讨论</a>
<span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<%= link_to( "+", course_boards_path(@course, :flag => true, :is_new => 1), :class => 'fr mr15 font-18 link-color-grey', :title => "#{l(:label_message_new)}") if User.current.logged? %>
</li>
<div id="board_children_list">
<%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %>
</div>
<% when "attachment" %>
<li class="clearfix" id="sy_05">
<a href="<%= course_files_path(@course) %>" class="fl ml15 ">资源</a>
<span class="edu-cir-grey fl ml10 mt15"><%= course_file_num %></span>
<% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %>
<a class="fr mr15 font-18 link-color-grey" title="上传资源" href="javascript:void(0);" onclick="course_files_upload();">+</a>
<% end %>
</li>
<% when "homework" %>
<li class="clearfix" id="sy_03">
<a href="<%= homework_common_index_path(:course => @course.id) %>" class="fl ml15 ">作业</a>
<span class="edu-cir-grey fl ml10 mt15"><%= homework_num %></span>
<% if is_teacher %>
<a href="javascript:void(0);" onclick="alert_choose_homework_type('<%= @course.id %>');" class="fr mr15 font-18 link-color-grey" title="新建作业">+</a>
<% end %>
</li>
<% when "exercises" %>
<% count = User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status <> 1").count %>
<li class="clearfix" id="sy_08">
<a href="<%= User.current.logged? ? exercise_index_path(:course_id => @course.id) : signin_url_without_domain %>" class="fl ml15 ">试卷</a>
<span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<%= link_to( "+", new_exercise_path(:course_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"新建试卷") if is_teacher %>
</li>
<% when "poll" %>
<li class="clearfix" id="sy_07">
<a href="<%= poll_index_path(:polls_type => "Course", :polls_group_id => @course.id) %>" class="fl ml15 ">问卷</a>
<span class="edu-cir-grey fl ml10 mt15"><%= course_poll_count %></span>
<%= link_to( "+", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"#{l(:label_new_poll)}") if is_teacher %>
</li>
<% when "statistics" %>
<li class="clearfix" id="sy_010">
<a href="<%= course_statistics_course_path(@course) %>" class="fl ml15 ">统计</a>
</li>
<% end %>
</li>
<li class="clearfix" id="sy_03"><a href="<%= homework_common_index_path(:course => @course.id) %>" class="fl ml15 ">作业</a><span class="edu-cir-grey fl ml10 mt15"><%=homework_num %></span>
<% if is_teacher %>
<a href="javascript:void(0);" onclick="alert_choose_homework_type('<%= @course.id %>');" class="fr mr15 font-18 link-color-grey" title="新建作业">+</a>
<% end %>
</li>
<% count = User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status <> 1").count %>
<li class="clearfix" id="sy_08"><a href="<%= User.current.logged? ? exercise_index_path(:course_id => @course.id) : signin_url_without_domain %>" class="fl ml15 ">试卷</a><span class="edu-cir-grey fl ml10 mt15"><%= count %></span>
<%= link_to( "+", new_exercise_path(:course_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"新建试卷") if is_teacher %>
</li>
<li class="clearfix" id="sy_07"><a href="<%=poll_index_path(:polls_type => "Course", :polls_group_id => @course.id) %>" class="fl ml15 ">问卷</a><span class="edu-cir-grey fl ml10 mt15"><%=course_poll_count %></span>
<%= link_to( "+", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'fr mr15 font-18 link-color-grey', :title =>"#{l(:label_new_poll)}") if is_teacher %>
</li>
<li class="clearfix" id="sy_010"><a href="<%=course_statistics_course_path(@course) %>" class="fl ml15 ">统计</a></li>
<% end %>
</ul>
<span class="font-12 fr" style="color:#ccc;"><i class="fa fa-eye mr5" ></i><%= @course.visits %> 次访问</span>
</div>

View File

@ -1,16 +0,0 @@
class CreateCourseModules < ActiveRecord::Migration
def change
create_table :course_modules do |t|
t.references :course
t.integer :news
t.integer :message
t.integer :homework
t.integer :exercises
t.integer :poll
t.integer :statistics
t.timestamps
end
add_index :course_modules, :course_id
end
end

View File

@ -0,0 +1,8 @@
class DelCourseModules < ActiveRecord::Migration
def up
drop_table :course_modules
end
def down
end
end

View File

@ -0,0 +1,12 @@
class CreateCourseModules < ActiveRecord::Migration
def change
create_table :course_modules do |t|
t.references :course_id
t.string :type
t.integer :position
t.integer :hidden
t.timestamps
end
end
end

View File

@ -0,0 +1,8 @@
class ChangeCourseIdForCourseModule < ActiveRecord::Migration
def up
rename_column :course_modules, :course_id_id, :course_id
end
def down
end
end

View File

@ -0,0 +1,8 @@
class RenameTypeForCourseModule < ActiveRecord::Migration
def up
rename_column :course_modules, :type, :module_type
end
def down
end
end

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :course_module do
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe CourseModule, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end