Permalink
Browse files

Timetable showing (alpha version, only for monday now).

  • Loading branch information...
1 parent e19d484 commit db8d88a3e29748b746287149cbba85cf44ba9a3d @Loremaster committed May 5, 2012
@@ -4,6 +4,13 @@ class TimetablesController < ApplicationController
def index
@classes = SchoolClass.order( :class_code )
+ @tts = []
+
+ if params.has_key?( :class_code )
+ school_class = SchoolClass.where( "class_code = ?", params[:class_code] ).first
+ @tts = timetable_for_class( school_class )
+ @tt_monday = @tts.select{|t| t.tt_day_of_week == "Mon"} # Timetable for monday.
+ end
end
def new
@@ -48,4 +55,16 @@ def collect_subjects_with_curriculums( school_class )
[ c.qualification.subject.subject_name, c.id ]
end
end
+
+ def timetable_for_class( school_class )
+ timetable = []
+ school_class.curriculums.each { |c| c.timetables.each{ |t| timetable << t } }
+ timetable
+ end
+
+ def subjects_of_class( school_class )
+ subjects = school_class.curriculums.collect do |c|
+ c.qualification.subject.subject_name
+ end
+ end
end
@@ -23,8 +23,7 @@
<th>Дата</th>
<th>Время</th>
<th>Класс</th>
- <th>Кабинет</th>
-
+ <th>Кабинет</th>
</tr>
</thead>
<tbody>
@@ -2,14 +2,57 @@
<div style="margin-top: 18px;" class="btn-toolbar">
<div class="btn-group">
+ <a href="#" data-toggle="dropdown" class="btn dropdown-toggle">
+ Показать расписание для класса
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+
+ <% @classes.each do |c| %>
+ <li>
+ <%= link_to c.class_code, timetables_path( :class_code => c.class_code ) %>
+ </li>
+ <% end %>
+ </ul>
+ </div>
+</div>
+
+<table class="table table-bordered table-striped" name="teachers">
+ <thead>
+ <tr>
+ <th>Понедельник</th>
+ </tr>
+ <tr>
+ <th>Номер урока</th>
+ <th>Предмет</th>
+ <th>Номер кабинета</th>
+ <th>Тип занятия</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% @tt_monday.each do |t| %>
+ <tr>
+ <td><%= t.tt_number_of_lesson %></td>
+ <td><%= t.curriculum.qualification.subject.subject_name %></td>
+ <td><%= t.tt_room %></td>
+ <td><%= t.tt_type %></td>
+ </tr>
+ <% end %>
+ </tbody>
+</table>
+
+<div style="margin-top: 18px;" class="btn-toolbar">
+ <div class="btn-group">
<a href="#" data-toggle="dropdown" class="btn btn-primary btn-large dropdown-toggle">
Создать расписание для класса
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<% @classes.each do |c| %>
- <li><%= link_to c.class_code, new_timetable_path( :class_code => c.class_code ) %></li>
+ <li>
+ <%= link_to c.class_code, new_timetable_path( :class_code => c.class_code ) %>
+ </li>
<% end %>
</ul>
</div>
@@ -2,10 +2,9 @@
<%= form_for @tt, :html => {:class => "form-horizontal"} do |f| %>
<%= field_set_tag do %>
- <table class="table-bordered table-striped" name="teachers">
+ <table class="table-bordered table-striped" name="timetable">
<%= render :partial => 'theads', :locals => { :day => 'Понедельник' } %>
-
<tbody>
<% 1.upto(8) do |i| %> <%# i is key for timetable part. Should be unique. %>
<tr>
@@ -17,8 +16,7 @@
</tbody>
- <%= render :partial => 'theads', :locals => { :day => 'Вторник' } %>
-
+ <%= render :partial => 'theads', :locals => { :day => 'Вторник' } %>
<tbody>
<% 9.upto(16) do |i| %>
<tr>
@@ -29,9 +27,8 @@
<% end %>
</tbody>
-
+
<%= render :partial => 'theads', :locals => { :day => 'Среда' } %>
-
<tbody>
<% 17.upto(24) do |i| %>
<tr>
@@ -43,8 +40,7 @@
</tbody>
- <%= render :partial => 'theads', :locals => { :day => 'Четверг' } %>
-
+ <%= render :partial => 'theads', :locals => { :day => 'Четверг' } %>
<tbody>
<% 25.upto(32) do |i| %>
<tr>
@@ -56,8 +52,7 @@
</tbody>
- <%= render :partial => 'theads', :locals => { :day => 'Пятница' } %>
-
+ <%= render :partial => 'theads', :locals => { :day => 'Пятница' } %>
<tbody>
<% 33.upto(40) do |i| %>
<tr>
@@ -68,7 +63,9 @@
<% end %>
</tbody>
</table>
-
+
+ <br/>
+
<%= f.submit "Создать", :class => "btn btn-large btn-success" %>
<% end %>
<% end %>

0 comments on commit db8d88a

Please sign in to comment.