From 08a43574056385cc6efb3caa6149cbc1beab4007 Mon Sep 17 00:00:00 2001
From: daiao <35855898@qq.com>
Date: Thu, 7 Mar 2019 17:14:49 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B=E7=AD=89?=
=?UTF-8?q?=E7=BA=A7=E7=B3=BB=E7=BB=9F=E9=A1=B5=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/controllers/managements_controller.rb | 37 ++++++
app/models/subject.rb | 1 +
app/models/subject_level_system.rb | 5 +
app/views/layouts/base_management.html.erb | 2 +-
.../managements/_class_level_system.html.erb | 88 --------------
.../managements/_subject_level_list.html.erb | 107 ++++++++++++++++++
.../managements/subject_level_system.html.erb | 3 +
.../managements/subject_level_system.js.erb | 1 +
config/routes.rb | 4 +
...0307070917_create_subject_level_systems.rb | 9 ++
...dd_subject_level_system_id_for_subjects.rb | 9 ++
spec/factories/subject_level_systems.rb | 5 +
spec/models/subject_level_system_spec.rb | 5 +
13 files changed, 187 insertions(+), 89 deletions(-)
create mode 100644 app/models/subject_level_system.rb
delete mode 100644 app/views/managements/_class_level_system.html.erb
create mode 100644 app/views/managements/_subject_level_list.html.erb
create mode 100644 app/views/managements/subject_level_system.html.erb
create mode 100644 app/views/managements/subject_level_system.js.erb
create mode 100644 db/migrate/20190307070917_create_subject_level_systems.rb
create mode 100644 db/migrate/20190307074011_add_subject_level_system_id_for_subjects.rb
create mode 100644 spec/factories/subject_level_systems.rb
create mode 100644 spec/models/subject_level_system_spec.rb
diff --git a/app/controllers/managements_controller.rb b/app/controllers/managements_controller.rb
index f7c37d97..9502ee76 100644
--- a/app/controllers/managements_controller.rb
+++ b/app/controllers/managements_controller.rb
@@ -16,6 +16,43 @@ class ManagementsController < ApplicationController
CODES = %W(2 3 4 5 6 7 8 9 A B C D E F G H J K L N M O P Q R S T U V W X Y Z)
+ # 实训课程等级体系
+ def subject_level_system
+ @levels = SubjectLevelSystem.all
+ end
+
+ # 创建课程等级体系
+ def create_subject_level
+ raise("名称不能为空") if params[:name].blank?
+ repeat_name = SubjectLevelSystem.where(name: params[:name]).count
+ raise("名称不能重复") if repeat_name > 0
+ level = SubjectLevelSystem.pluck(:level).max.to_i + 1
+ SubjectLevelSystem.create(name: params[:name], level: level)
+ redirect_to subject_level_system_managements_path(:format => "js")
+ end
+
+ # 重命名课程等级
+ def rename_subject_level
+ raise("名称不能为空!") if params[:name].blank?
+ repeat_name = SubjectLevelSystem.where("name = ? and id != ?", params[:name], params[:id]).count
+ raise("名称不能重复") if repeat_name > 0
+ level = SubjectLevelSystem.find params[:id]
+ level.update_attribute(:name, params[:name])
+ redirect_to subject_level_system_managements_path(:format => "js")
+ end
+
+ # 删除课程等级
+ def delete_subject_level
+ level = SubjectLevelSystem.find params[:id]
+ Subject.where(:subject_level_system_id => level).update_all(:subject_level_system_id => nil)
+ levels = SubjectLevelSystem.where("level > ?", level.level)
+ levels.each do |l|
+ l.update_attribute(:level, l.level-1)
+ end
+ level.delete
+ redirect_to subject_level_system_managements_path(:format => "js")
+ end
+
# 工程认证视频导入模板
def ec_template
@template = EcTemplate.where(nil)
diff --git a/app/models/subject.rb b/app/models/subject.rb
index c416974e..bd92c39c 100644
--- a/app/models/subject.rb
+++ b/app/models/subject.rb
@@ -18,6 +18,7 @@ class Subject < ActiveRecord::Base
has_many :tidings, :as => :container, :dependent => :destroy
belongs_to :repertoire
belongs_to :user
+ has_one :subject_level_system
scope :visible, lambda{where(status: 2)}
diff --git a/app/models/subject_level_system.rb b/app/models/subject_level_system.rb
new file mode 100644
index 00000000..6ba73437
--- /dev/null
+++ b/app/models/subject_level_system.rb
@@ -0,0 +1,5 @@
+class SubjectLevelSystem < ActiveRecord::Base
+ # attr_accessible :title, :body
+ has_many :subjects
+
+end
diff --git a/app/views/layouts/base_management.html.erb b/app/views/layouts/base_management.html.erb
index 4f188f78..c6e87870 100644
--- a/app/views/layouts/base_management.html.erb
+++ b/app/views/layouts/base_management.html.erb
@@ -55,7 +55,7 @@