From 6f4deb193bb64664b7e45d068ddd8d668e61a66b Mon Sep 17 00:00:00 2001 From: Novikov Andrey Date: Thu, 31 Oct 2013 00:22:08 +0400 Subject: [PATCH] Added groups' forming year to teaching plan entries --- .../concerns/specialities_teaching_plans_concern.rb | 8 ++++++-- app/models/group.rb | 1 + app/models/teaching_plan.rb | 5 +++-- .../specialities/teaching_plans/fill.html.haml | 2 +- .../specialities/teaching_plans/new.html.haml | 3 ++- .../specialities/teaching_plans/show.html.haml | 8 +++++--- ...30162804_add_groups_forming_year_to_teaching_plans.rb | 6 ++++++ db/schema.rb | 5 ++++- lib/gosinsp_parser.rb | 9 +++++---- 9 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20131030162804_add_groups_forming_year_to_teaching_plans.rb diff --git a/app/controllers/concerns/specialities_teaching_plans_concern.rb b/app/controllers/concerns/specialities_teaching_plans_concern.rb index 43f44bd..ce36cb6 100644 --- a/app/controllers/concerns/specialities_teaching_plans_concern.rb +++ b/app/controllers/concerns/specialities_teaching_plans_concern.rb @@ -13,7 +13,11 @@ module SpecialitiesTeachingPlansConcern def teaching_plan @speciality = Speciality.find(params[:id]) - @teaching_plans = TeachingPlan.where(speciality_id: @speciality.id) + tp_years = @speciality.teaching_plans.group(:forming_year).pluck(:forming_year) + sg_years = @speciality.groups.group(:forming_year).pluck(:forming_year) + @years = (tp_years | sg_years).sort + @year = params[:forming_year].present? && params[:forming_year].to_i.in?(@years) ? params[:forming_year].to_i : @years.max + @teaching_plans = @speciality.teaching_plans.where(forming_year: @year) @courses = @teaching_plans.uniq.reorder(:course).pluck(:course) @display_courses = params[:course].present? ? [params[:course].to_i] : @courses @teaching_plans = @teaching_plans.where(course: params[:course]) if params[:course].present? @@ -26,7 +30,7 @@ def teaching_plan_import if params[:plan] and params[:plan].class == ActionDispatch::Http::UploadedFile @specialities = can?(:manage, :all) ? nil : Speciality.accessible_by(current_ability, :update) params[:plan].rewind # In case if someone have already read our file - @speciality, @results, @errors = parse_and_fill_teaching_plan(params[:plan].read, @specialities) + @speciality, @results, @errors = parse_and_fill_teaching_plan(params[:plan].read, params[:forming_year], @specialities) render "application/specialities/teaching_plans/fill" return end diff --git a/app/models/group.rb b/app/models/group.rb index 336cbca..607931c 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,6 +1,7 @@ # -*- encoding : utf-8 -*- class Group < ActiveRecord::Base belongs_to :speciality + has_many :teaching_plans, through: :speciality, conditions: proc { {forming_year: forming_year} } has_many :jets, :dependent => :destroy has_many :subgroups, :through => :jets has_many :charge_cards, :through => :jets diff --git a/app/models/teaching_plan.rb b/app/models/teaching_plan.rb index 5cdc222..a2b69ea 100644 --- a/app/models/teaching_plan.rb +++ b/app/models/teaching_plan.rb @@ -2,9 +2,10 @@ class TeachingPlan < ActiveRecord::Base belongs_to :speciality belongs_to :discipline + has_many :groups, through: :speciality, conditions: -> { {forming_year: forming_year} } - validates_presence_of :speciality_id, :discipline_id, :course, :semester - validates_numericality_of :course, :semester + validates_presence_of :speciality_id, :discipline_id, :course, :semester, :forming_year + validates_numericality_of :course, :semester, :forming_year validates_numericality_of :lections, :practics, :lab_works, :allow_nil => true validates_inclusion_of :semester, :in => [1, 2] diff --git a/app/views/application/specialities/teaching_plans/fill.html.haml b/app/views/application/specialities/teaching_plans/fill.html.haml index bdc04e0..1b6e3dc 100644 --- a/app/views/application/specialities/teaching_plans/fill.html.haml +++ b/app/views/application/specialities/teaching_plans/fill.html.haml @@ -8,7 +8,7 @@ - if @speciality %h1 Внесение учебного плана для специальности #{@speciality.code} «#{@speciality.name}» - %p Изменение затронуло следующие группы: #{@speciality.groups.map{|group| group.name}.join(", ")} + %p Изменение затронуло следующие группы: #{@speciality.groups.where(forming_year: params[:forming_year]).pluck(:name).to_sentence} - if @results.any? %ol - @results.each do |r| diff --git a/app/views/application/specialities/teaching_plans/new.html.haml b/app/views/application/specialities/teaching_plans/new.html.haml index 28cfba8..e4de514 100644 --- a/app/views/application/specialities/teaching_plans/new.html.haml +++ b/app/views/application/specialities/teaching_plans/new.html.haml @@ -5,5 +5,6 @@ %p Это файлы с расширениями PLI.XML и PLM.XML. %fieldset = form_tag({}, :method => :post, :multipart => true) do - = file_field_tag :plan, :accept => "application/xml" + = file_field_tag :plan, accept: "application/xml", required: true + = number_field_tag :forming_year, Date.today.year, min: 2000, max: 2100, required: true = submit_tag "Импортировать" diff --git a/app/views/application/specialities/teaching_plans/show.html.haml b/app/views/application/specialities/teaching_plans/show.html.haml index a1232c7..fc74b7d 100644 --- a/app/views/application/specialities/teaching_plans/show.html.haml +++ b/app/views/application/specialities/teaching_plans/show.html.haml @@ -1,4 +1,4 @@ -- title "Учебный план #{@speciality.code}" +- title "Учебный план #{@speciality.code} на #{@year} г." @@ -13,12 +13,14 @@ = link_to_if params[:course].present?, "Общий", url_for(params.merge(course: nil)) - @courses.each do |course| = link_to_unless (params[:course].to_i == course), "Курс #{course}", url_for(params.merge(course: course)) - + | + - @years.each do |year| + = link_to_unless (@year == year), year, url_for(params.merge(forming_year: year)) %p.noprint= link_to "Сгенерировать учебные поручения", generate_training_assignments_supervisor_speciality_path(@speciality, course: params[:course]), method: :post %p Группы: %ul - - @speciality.groups.each do |group| + - @speciality.groups.where(forming_year: @year).each do |group| - next if params[:course].present? and group.course != params[:course].to_i %li #{group.name}, #{group.course} курс, #{group.population or "(не указано)"} человек diff --git a/db/migrate/20131030162804_add_groups_forming_year_to_teaching_plans.rb b/db/migrate/20131030162804_add_groups_forming_year_to_teaching_plans.rb new file mode 100644 index 0000000..7719f95 --- /dev/null +++ b/db/migrate/20131030162804_add_groups_forming_year_to_teaching_plans.rb @@ -0,0 +1,6 @@ +class AddGroupsFormingYearToTeachingPlans < ActiveRecord::Migration + def change + add_column :teaching_plans, :forming_year, :integer, null: false, default: 2013 + add_index :teaching_plans, [:speciality_id, :discipline_id, :course, :semester, :forming_year], unique: true, name: 'teaching_plans_main_index' + end +end diff --git a/db/schema.rb b/db/schema.rb index 08d4f25..1b527d9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20131024055705) do +ActiveRecord::Schema.define(:version => 20131030162804) do create_table "buildings", :force => true do |t| t.string "name" @@ -217,8 +217,11 @@ t.boolean "exam", :default => false t.datetime "created_at" t.datetime "updated_at" + t.integer "forming_year", :default => 2013, :null => false end + add_index "teaching_plans", ["speciality_id", "discipline_id", "course", "semester", "forming_year"], :name => "teaching_plans_main_index", :unique => true + create_table "training_assignments", :force => true do |t| t.integer "lesson_type_id" t.integer "weeks_quantity" diff --git a/lib/gosinsp_parser.rb b/lib/gosinsp_parser.rb index b337425..a794671 100644 --- a/lib/gosinsp_parser.rb +++ b/lib/gosinsp_parser.rb @@ -1,7 +1,7 @@ # -*- encoding : utf-8 -*- module GosinspParser - def parse_and_fill_teaching_plan(file_plan_contents, allowed_specialities = nil) + def parse_and_fill_teaching_plan(file_plan_contents, forming_year, allowed_specialities = nil) plan = Nokogiri::XML(file_plan_contents) errors = [] results = [] @@ -40,9 +40,10 @@ def parse_and_fill_teaching_plan(file_plan_contents, allowed_specialities = nil) semnum = sem["Ном"].to_i semester = (semnum % 2 != 0) ? 1 : 2 course = (semnum + (semnum % 2)) / 2 - plan = TeachingPlan.find_or_initialize_by_speciality_id_and_discipline_id_and_course_and_semester( - speciality.id, discipline.id, course, semester - ) + plan = TeachingPlan.where( + speciality_id: speciality.id, discipline_id: discipline.id, + course: course, semester: semester, forming_year: forming_year, + ).first_or_initialize plan.lections = sem["Лек"] plan.practics = sem["Пр"] plan.lab_works = sem["Лаб"]