Skip to content

Commit

Permalink
Teaching plans viewing UI for supervisor and dept_heads
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Mar 5, 2012
1 parent 7fa8bb3 commit 2f5f1ba
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/controllers/dept_head/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,19 @@ class DeptHead::GroupsController < DeptHead::BaseController
config.columns = [:name, :forming_year, :course, :population]
config.create.columns.exclude :course
config.update.columns.exclude :course
config.action_links.add :teaching_plan, :label => "Учебный план", :type => :member, :page => true
end

def teaching_plan
@group = Group.find(params[:id])
@charge_cards = @group.charge_cards
@lesson_types = LessonType.all(:order => :id)
@teaching_plans = TeachingPlan.find_all_by_speciality_id_and_course_and_semester(
@group.speciality_id, @group.course, TAURUS_CONFIG["semester"]["current"]["number"]
)
discipline_ids = (@charge_cards.map{|cc| cc.discipline_id} + @teaching_plans.map{|tp| tp.discipline_id}).uniq
@disciplines = Discipline.find(discipline_ids, :order => :name)
render "application/groups/teaching_plans/show"
end

end
10 changes: 10 additions & 0 deletions app/controllers/dept_head/specialities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ class DeptHead::SpecialitiesController < DeptHead::BaseController
config.actions << :delete
config.columns = [:code, :name]
config.nested.add_link('Группы', [:groups])
config.action_links.add :teaching_plan, :label => "Учебный план", :type => :member, :page => true
end

def teaching_plan
@speciality = Speciality.find(params[:id])
@teaching_plans = TeachingPlan.find_all_by_speciality_id(@speciality.id)
discipline_ids = @teaching_plans.map{|tp| tp.discipline_id}.uniq
@disciplines = Discipline.find(discipline_ids, :order => :name)
@courses = @teaching_plans.map{|tp| tp.course}.uniq.sort
render "application/specialities/teaching_plans/show"
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def show
)
discipline_ids = (@charge_cards.map{|cc| cc.discipline_id} + @teaching_plans.map{|tp| tp.discipline_id}).uniq
@disciplines = Discipline.find(discipline_ids, :order => :name)
render "application/groups/teaching_plans/show"
end

end
14 changes: 14 additions & 0 deletions app/controllers/supervisor/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@ class Supervisor::GroupsController < Supervisor::BaseController
config.create.columns.exclude :course
config.update.columns.exclude :course
config.columns[:speciality].form_ui = :select
config.action_links.add :teaching_plan, :label => "Учебный план", :type => :member, :page => true
end

def teaching_plan
@group = Group.find(params[:id])
@charge_cards = @group.charge_cards
@lesson_types = LessonType.all(:order => :id)
@teaching_plans = TeachingPlan.find_all_by_speciality_id_and_course_and_semester(
@group.speciality_id, @group.course, TAURUS_CONFIG["semester"]["current"]["number"]
)
discipline_ids = (@charge_cards.map{|cc| cc.discipline_id} + @teaching_plans.map{|tp| tp.discipline_id}).uniq
@disciplines = Discipline.find(discipline_ids, :order => :name)
render "application/groups/teaching_plans/show"
end

end
10 changes: 10 additions & 0 deletions app/controllers/supervisor/specialities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ class Supervisor::SpecialitiesController < Supervisor::BaseController
config.columns = [:code, :name, :department]
config.nested.add_link('Группы', [:groups])
config.columns[:department].form_ui = :select
config.action_links.add :teaching_plan, :label => "Учебный план", :type => :member, :page => true
end

def teaching_plan
@speciality = Speciality.find(params[:id])
@teaching_plans = TeachingPlan.find_all_by_speciality_id(@speciality.id)
discipline_ids = @teaching_plans.map{|tp| tp.discipline_id}.uniq
@disciplines = Discipline.find(discipline_ids, :order => :name)
@courses = @teaching_plans.map{|tp| tp.course}.uniq.sort
render "application/specialities/teaching_plans/show"
end

end
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%h1 Группа #{@group.name}
%h1 Учебный план группы #{@group.name}

%p На #{TAURUS_CONFIG["semester"]["current"]["title"]} семестр. Специальность: #{@group.speciality.code} «#{@group.speciality.name}»

%table.teaching_plan.infotable.fullwidth-table
%thead
Expand Down
53 changes: 53 additions & 0 deletions app/views/application/specialities/teaching_plans/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
%h1 Учебный план специальности #{@speciality.code} «#{@speciality.name}»

%p Группы: #{@speciality.groups.map{|g| g.name}.join(", ")}

- conditions = {:speciality_id => @speciality.id}

- if @teaching_plans.empty?
%p Для данной специальности учебный план ещё не загружен.

- else
%table.teaching_plan.infotable.fullwidth-table
%thead
%tr
%th{:rowspan => 3} Дисциплина
- @courses.each do |course|
%th{:colspan => 8} Курс #{course}
%th{:rowspan => 3} Всего
%tr
- @courses.each do |course|
%th{:colspan => 4} Семестр 1
%th{:colspan => 4} Семестр 2
%tr
- (@courses.count*2).times do |course|
- ["Лек", "Прт", "Лаб"].each do |typename|
%th #{typename}
%th{:rowspan => 3} Экз
%tfoot
%tr
%th Всего
- @courses.each do |course|
- (1..2).each do |semester|
- conditions.merge!({:course => course, :semester => semester})
- plans = TeachingPlan.all(:conditions => conditions)
%th #{plans.sum{|p| p.lections or 0 } if plans.any?}
%th #{plans.sum{|p| p.practics or 0} if plans.any?}
%th #{plans.sum{|p| p.lab_works or 0} if plans.any?}
%th
%th
%tbody
- @disciplines.each do |discipline|
%tr
%th= discipline.name
- plans = []
- @courses.each do |course|
- (1..2).each do |semester|
- conditions.merge!({:discipline_id => discipline.id, :course => course, :semester => semester})
- plan = TeachingPlan.first(:conditions => conditions)
- plans << plan if plan
%td #{plan.lections if plan}
%td #{plan.practics if plan}
%td #{plan.lab_works if plan}
%td #{(plan.exam ? "Экз" : "Зач") if plan}
%th= plans.sum{|p| (p.lections or 0) + (p.practics or 0) + (p.lab_works or 0)} if plans.any?
44 changes: 44 additions & 0 deletions app/views/dept_head/specialities/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
%h1 Специальность #{@speciality.code} «#{@speciality.name}»

%p Учебный план на #{TAURUS_CONFIG["semester"]["current"]["title"]} семестр.

%table.teaching_plan.infotable.fullwidth-table
%thead
%tr
%th{:rowspan => 2} Дисциплина
%th{:rowspan => 2} Часов в неделю
- @courses.each do |course|
%th{:colspan => 3} #{course}
%th{:rowspan => 2} Экзамен/зачёт
%tr
- 3.times do
%th Лекции
%th Практики
%th Лаб. работы
%tfoot
%tr
%th Всего
%th.numeric-cell= @charge_cards.map{|cc| cc.hours_per_week}.sum
- [[1, :lections], [2, :practics], [3, :lab_works]].each do |type|
- plan = @teaching_plans.map{|tp| tp[type[1]]}.compact.sum
- card = @charge_cards.select{|cc| cc.lesson_type_id == type[0]}.map{|cc| cc.try(:hours_quantity)}.sum
- err = (plan - card).abs unless plan.zero? or card.zero? or (plan - card).abs.zero?
%th.numeric-cell= plan unless plan.zero?
%th.numeric-cell= card
%th.numeric-cell.error-cell= err
%th
%tbody
- @disciplines.each do |discipline|
%tr
%th= discipline.name
- cards = @charge_cards.select{|cc| cc.discipline_id == discipline.id}
- plan = @teaching_plans.select{|tp| tp.discipline_id == discipline.id}.first
%td.numeric-cell= cards.map{|cc| cc.hours_per_week}.sum
- [[1, :lections], [2, :practics], [3, :lab_works]].each do |type|
- val = plan[type[1]] if plan
- card = cards.select{|cc| cc.lesson_type_id == type[0]}.first.try(:hours_quantity)
- err = (val - card).abs if val and card and not (val - card).abs.zero?
%td.numeric-cell= val
%td.numeric-cell= card
%td.numeric-cell.error-cell= err
%td #{(plan.exam ? "Экзамен" : "Зачёт") if plan}
8 changes: 4 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@
map.namespace :dept_head do |d|
d.resources :teaching_places, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post}
d.resources :disciplines, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post}
d.resources :groups, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post}
d.resources :groups, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post, :teaching_plan => :get}
d.resources :lecturers, :active_scaffold => true, :collection => {:browse => :get}, :member => {:select => :post}
d.resources :specialities, :active_scaffold => true
d.resources :specialities, :active_scaffold => true, :member => {:teaching_plan => :get}
d.root :controller => 'teaching_places'
end

map.namespace :supervisor do |s|
s.resources :faculties, :active_scaffold => true
s.resources :specialities, :active_scaffold => true
s.resources :groups, :active_scaffold => true
s.resources :specialities, :active_scaffold => true, :member => {:teaching_plan => :get}
s.resources :groups, :active_scaffold => true, :member => {:teaching_plan => :get}
s.resources :classrooms, :active_scaffold => true
s.resources :lecturers, :active_scaffold => true
s.connect 'teaching_plans', :controller => "teaching_plans", :action => "new", :method => :get
Expand Down

0 comments on commit 2f5f1ba

Please sign in to comment.