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 1/4] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=AD=89=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 @@
等级 | -名称 | -实训课程数 | -创建时间 | -操作 | - - -
---|---|---|---|---|
1 | -初级课程 | -500 | -2019-03-02 10:38 | -- 删除 - 重命名 - | -
2 | -初级课程 | --- | -2019-03-02 10:38 | -- 删除 - 重命名 - | -
- + 新建 - | -
等级 | +名称 | +实训课程数 | +创建时间 | +操作 | + + + <% @levels.each do |l| %> +
---|---|---|---|---|
<%= l.level %> | +<%= l.name %> | +<%= l.subjects.size %> | +<%= format_time l.created_at %> | ++ 删除 + 重命名 + | +
+ + 新建 + | +
- 平台拟于2019年3月7日00:00--8:00进行全面升级,带来不便,敬请谅解! + 平台拟于2019年3月8日00:00--8:00进行全面升级,带来不便,敬请谅解!
From e5165d1e28c113daa4990b786314e3f5efdc4fc1 Mon Sep 17 00:00:00 2001 From: daiao <35855898@qq.com> Date: Thu, 7 Mar 2019 17:58:10 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/managements/_subject_level_list.html.erb | 2 +- public/javascripts/application.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/views/managements/_subject_level_list.html.erb b/app/views/managements/_subject_level_list.html.erb index b637e261..1a4bf6d7 100644 --- a/app/views/managements/_subject_level_list.html.erb +++ b/app/views/managements/_subject_level_list.html.erb @@ -14,7 +14,7 @@