From 44af3aadf40c4a490977020053f7c065916fa63c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 22 Aug 2019 11:15:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E8=AE=A4=E8=AF=81=EF=BC=9A?= =?UTF-8?q?=E6=AF=95=E4=B8=9A=E8=A6=81=E6=B1=82=E5=92=8C=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E7=82=B9=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BC=9A=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=85=B6=E5=AE=83=E5=87=A0=E4=B8=AA=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=9F=A9=E9=98=B5=E7=9A=84=E9=A1=B5=E9=9D=A2=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=A2=E5=A4=B1=EF=BC=8C=E9=9C=80=E8=A6=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ec_graduation_requirements_controller.rb | 9 ++++-- .../ec_graduation_subitems_controller.rb | 4 +++ .../_requirement_item.html.erb | 25 ++++++++++++++++ .../_requirement_lists.html.erb | 30 ++----------------- .../ec_graduation_requirements/edit.js.erb | 13 ++++---- .../ec_graduation_subitems/destroy.js.erb | 9 ++++++ .../ec_years/graduation_requirement.html.erb | 8 ++--- 7 files changed, 59 insertions(+), 39 deletions(-) create mode 100644 app/views/ec_graduation_requirements/_requirement_item.html.erb create mode 100644 app/views/ec_graduation_subitems/destroy.js.erb diff --git a/app/controllers/ec_graduation_requirements_controller.rb b/app/controllers/ec_graduation_requirements_controller.rb index 091588cd..79c678de 100644 --- a/app/controllers/ec_graduation_requirements_controller.rb +++ b/app/controllers/ec_graduation_requirements_controller.rb @@ -50,9 +50,14 @@ class EcGraduationRequirementsController < ApplicationController @year = requirement.ec_year @template_major = admin_or_business? || @year.ec_major_school.school.ec_school_users.pluck(:user_id).include?(User.current.id) requirement.update_attribute(:content, params[:requirement]) - requirement.ec_graduation_subitems.destroy_all + # requirement.ec_graduation_subitems.destroy_all params[:subitems].try(:each_with_index) do |sub, index| - EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) + subitem = requirement.ec_graduation_subitems.where(position: index+1).first + if subitem.present? + subitem.update_attributes(:content => sub) + else + EcGraduationSubitem.create(:content => sub, :position => index+1, :ec_graduation_requirement_id => requirement.id) + end end @ec_graduation_requirements = requirement.ec_year.ec_graduation_requirements diff --git a/app/controllers/ec_graduation_subitems_controller.rb b/app/controllers/ec_graduation_subitems_controller.rb index b281e3f3..1248f450 100644 --- a/app/controllers/ec_graduation_subitems_controller.rb +++ b/app/controllers/ec_graduation_subitems_controller.rb @@ -82,9 +82,13 @@ class EcGraduationSubitemsController < ApplicationController # DELETE /ec_graduation_subitems/1.json def destroy @ec_graduation_subitem = EcGraduationSubitem.find(params[:id]) + @ec_graduation_requirement = @ec_graduation_subitem.ec_graduation_requirement + @ec_graduation_requirement.ec_graduation_subitems.where("position > #{@ec_graduation_subitem.position}").update_all("position = position - 1") + @ec_graduation_requirements = @ec_graduation_requirement.ec_year.ec_graduation_requirements @ec_graduation_subitem.destroy respond_to do |format| + format.js format.html { redirect_to ec_graduation_subitems_url } format.json { head :no_content } end diff --git a/app/views/ec_graduation_requirements/_requirement_item.html.erb b/app/views/ec_graduation_requirements/_requirement_item.html.erb new file mode 100644 index 00000000..95aed9a9 --- /dev/null +++ b/app/views/ec_graduation_requirements/_requirement_item.html.erb @@ -0,0 +1,25 @@ +
+ <%= requirement.position %> + <%= requirement.content %> + + <% if template_major %> + <% if requirement.position == @ec_graduation_requirements.count %> + + <% end %> + + + <% end %> + +
+ <% if requirement.ec_graduation_subitems.present? %> ++ <%= "#{requirement.position}-#{sub.position}" %> + <%= sub.content %> +
+ <% end %> +- <%= requirement.position %> - <%= requirement.content %> - - <% if @template_major %> - <% if index+1 == @ec_graduation_requirements.count %> - - <% end %> - - - <% end %> - -
- <% if requirement.ec_graduation_subitems.present? %> -- <%= "#{requirement.position}-#{sub.position}" %> - <%= sub.content %> -
- <% end %> -