From 49bbd36c12dc52f9bcab83e39b4713ed7310f239 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 24 Aug 2017 20:01:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=A5=97=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 12 +++--- app/helpers/application_helper.rb | 4 +- app/models/subject.rb | 20 +++++++++- app/views/layouts/_logined_header.html.erb | 2 +- app/views/layouts/_unlogin_header.html.erb | 2 +- app/views/layouts/base_management.html.erb | 4 +- app/views/subjects/_subject_createnew.html | 2 +- app/views/subjects/_subject_list.html.erb | 12 +++--- app/views/subjects/_subject_top.html.erb | 12 +++--- app/views/subjects/edit.html.erb | 14 ++++++- app/views/subjects/new.html.erb | 18 ++++++--- app/views/subjects/show.html.erb | 38 +++++++++++-------- ...24103529_add_learning_notes_to_subjects.rb | 6 +++ public/javascripts/edu/base_edu.js | 32 ++++++++++++++++ 14 files changed, 129 insertions(+), 49 deletions(-) create mode 100644 db/migrate/20170824103529_add_learning_notes_to_subjects.rb 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 @@ diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb index 7e372bbc4..5adbee8f3 100644 --- a/app/views/layouts/base_management.html.erb +++ b/app/views/layouts/base_management.html.erb @@ -30,7 +30,7 @@ <% when 3 %> <%= @sub_type == 1 ? "实训列表" :(@sub_type == 2 ? "已发布的实训": (@sub_type == 3 ? "已关闭的实训": "镜像管理")) %> <% when 4 %> - <%= @sub_type == 1 ? "实训套件" : "已发布实训套件" %> + <%= @sub_type == 1 ? "实训课程" : "已发布实训套件" %> <% when 5 %> 竞赛 <% when 6 %> @@ -66,7 +66,7 @@
  • <%= link_to "镜像管理", mirror_repository_managements_path %>
  • -
  • 实训套件+ +
  • 实训课程+