diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 0b746c675..41ea375e2 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -37,7 +37,7 @@ class SubjectsController < ApplicationController def create if params[:subject] - subject = Subject.create(:name => params[:subject][:name], :description => params[:subject][:description], :user_id => User.current.id, :visits => 0, :status => 0) + subject = Subject.create(:name => params[:subject][:name], :learning_notes => params[:subject][:learning_notes], :introduction => params[:subject][:introduction], :description => params[:subject][:description], :user_id => User.current.id, :visits => 0, :status => 0) end redirect_to subject_path(subject) end @@ -48,7 +48,7 @@ class SubjectsController < ApplicationController def update if params[:subject] - subject = @subject.update_attributes(:name => params[:subject][:name], :description => params[:subject][:description]) + subject = @subject.update_attributes(:name => params[:subject][:name], :learning_notes => params[:subject][:learning_notes], :introduction => params[:subject][:introduction], :description => params[:subject][:description]) end redirect_to subject_path(@subject) end @@ -103,15 +103,15 @@ class SubjectsController < ApplicationController if apply && apply.status == 0 @status = 0 else - if Shixun.where(:id => @subject.stage_shixuns.map(&:shixun_id), :status => [0, 1]).count > 0 - @status = 2 - else + #if Shixun.where(:id => @subject.stage_shixuns.map(&:shixun_id), :status => [0, 1]).count > 0 + # @status = 2 + #else @subject.update_attributes(:status => 1) ApplyAction.create(:container_type => "ApplySubject", :container_id => @subject.id, :user_id => User.current.id, :status => 0) notes = User.current.show_name.to_s + " 申请发布课程实训:#{@subject.name}" JournalsForMessage.create(:jour_id => 1, :jour_type => 'Principal', :user_id => User.current.id, :notes => notes, :private => 1, :reply_id => 0) @status = 1 - end + # end end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2ddc4fa90..5357839af 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1972,9 +1972,9 @@ module ApplicationHelper elsif params[:controller] == "shixuns" && params[:action] == "index" title << ("全部实训") elsif @subject - title << (@subject.name.nil? ? "实训套件" : @subject.name) + title << (@subject.name.nil? ? "实训课程" : @subject.name) elsif params[:controller] == "subjects" && params[:action] == "index" - title << ("实训套件") + title << ("实训课程") elsif @organization title << (@organization.name.nil? ? "创新源于实践" : @organization.name) elsif @forum || params[:controller] == "forums" diff --git a/app/models/subject.rb b/app/models/subject.rb index f5f46e7b1..7eb102bf5 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -3,11 +3,29 @@ class Subject < ActiveRecord::Base belongs_to :user belongs_to :course_list belongs_to :major - attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id, :major_id + attr_accessible :description, :name, :status, :visits, :user_id, :course_list_id, :major_id, :learning_notes, :introduction has_many :stages, :dependent => :destroy, :order => "stages.id ASC" has_many :stage_shixuns, :dependent => :destroy + def subject_choices + count = 0 + self.stage_shixuns.each do |stage_shixun| + shixun = stage_shixun.shixun + count += shixun.challenges.where(:st => [1, 2]).count + end + count + end + + def subject_shixuns + count = 0 + self.stage_shixuns.each do |stage_shixun| + shixun = stage_shixun.shixun + count += shixun.challenges.where(:st => 0).count + end + count + end + def subject_challenges count = 0 self.stage_shixuns.each do |stage_shixun| diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index be42b1e3a..3861be090 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -16,7 +16,7 @@
- kosasa > 实训套件 + kosasa > 实训课程 >新建
- 计算思维导论计算思维导论计算思维导论计算思维导论计算思维导论计算思维导论计算思维导论计算思维导论计算思 + <%= subject.introduction.blank? ? "轻松学习#{subject.name}~" : subject.introduction %>
- <%= subject.stage_shixuns.count %> - <%= subject.stage_shixuns.count %> - <%= subject.subject_score %> - <%= subject.subject_challenges %> + <%= subject.stages.count %> + <%= subject.stage_shixuns.count %> + <%= subject.subject_score %> + <%= subject.subject_challenges %>
<%= subject.user.try(:show_name) %>
-国防科学技术大学讲师国防科学技术大学讲师
+<%= subject.user.school_name + subject.user.identity %>
<%= @subject.name %> - <% if User.current.manager_of_subject?(@subject) && @subject.status == 0 %> - + <% if User.current.manager_of_subject?(@subject) %> + <% end %>
@@ -17,17 +17,15 @@ <%# end %> <%# if !User.current.manager_of_subject?(@subject) || @subject.status > 1 %>
- <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to "实训套件", subjects_path() %> + <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to "实训课程", subjects_path() %> > 编辑
- <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to "实训套件", subjects_path() %> + <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to "实训课程", subjects_path() %> > 新建
- <% if User.current.manager_of_subject?(@subject) && @subject.status == 0 %> + <% if User.current.manager_of_subject?(@subject) %> <% end %>
@@ -15,11 +15,11 @@- 第一章 <%= stage.name %> + 第<%= index + 1 %>章 <%= stage.name %> <% if @subject.status == 0 && User.current.manager_of_subject?(@subject) %> @@ -28,7 +28,7 @@ <% end %>
描述<%= stage.description %>
+<%= stage.description %>
<% stage.stage_shixuns.each_with_index do |stage_shixun, index| %> <% shixun = stage_shixun.shixun %>学习须知
-数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合。通常情况下,精心选择的数据结构可以带来更高的运行或者存储效率。数据结构往往同高效的检索算法和索引技术有关。
+学习须知 + <% if User.current.manager_of_subject?(@subject) %> + + <% end %> +
+<%= @subject.learning_notes.blank? ? "暂未填写" : @subject.learning_notes %>
教学名师
蔡世
-国防科学技术大学讲师
+<%= image_tag(url_to_avatar(@subject.user), :width =>"40", :height => "40", :class => "bor-radius-all", :alt=>"头像") %>
+<%= @subject.user.try(:show_name) %>
+<%= @subject.user.school_name + @subject.user.identity %>
数据结构是计算机存储、组织数据的方式。数据结构是指相互之间存在一种或多种特定关系的数据元素的集合。通常情况下,精心选择的数据结构可以带来更高的运行或者存储效率。数据结构往往同高效的检索算法和索引技术有关。
+<%= @subject.user.user_extensions.brief_introduction.blank? ? "暂未填写" : @subject.user.user_extensions.brief_introduction %>
diff --git a/db/migrate/20170824103529_add_learning_notes_to_subjects.rb b/db/migrate/20170824103529_add_learning_notes_to_subjects.rb new file mode 100644 index 000000000..e134875b9 --- /dev/null +++ b/db/migrate/20170824103529_add_learning_notes_to_subjects.rb @@ -0,0 +1,6 @@ +class AddLearningNotesToSubjects < ActiveRecord::Migration + def change + add_column :subjects, :learning_notes, :text + add_column :subjects, :introduction, :string + end +end diff --git a/public/javascripts/edu/base_edu.js b/public/javascripts/edu/base_edu.js index cf57c69d0..b19c4a6fc 100644 --- a/public/javascripts/edu/base_edu.js +++ b/public/javascripts/edu/base_edu.js @@ -1023,19 +1023,51 @@ function destroy_all_hb(url){ } function submit_new_subject(){ + var check = true; if($("#new_subject_name").val().trim() == ""){ + check = false; $("#new_subject_name_notice").show(); } else{ $("#new_subject_name_notice").hide(); + } + if($("#new_subject_intro").val().trim() == ""){ + check = false; + $("#new_subject_intro_notice").show(); + } else{ + $("#new_subject_intro_notice").hide(); + } + if($("#new_learning_notes").val().trim() == ""){ + check = false; + $("#new_learning_notes_notice").show(); + } else { + $("#new_learning_notes_notice").hide(); + } + if(check){ $("#new_subject").submit(); } } function submit_edit_subject(id){ + var check = true; if($("#new_subject_name").val().trim() == ""){ + check = false; $("#new_subject_name_notice").show(); } else{ $("#new_subject_name_notice").hide(); + } + if($("#new_subject_intro").val().trim() == ""){ + check = false; + $("#new_subject_intro_notice").show(); + } else{ + $("#new_subject_intro_notice").hide(); + } + if($("#new_learning_notes").val().trim() == ""){ + check = false; + $("#new_learning_notes_notice").show(); + } else { + $("#new_learning_notes_notice").hide(); + } + if(check){ $("#edit_subject_"+id).submit(); } } \ No newline at end of file