Skip to content

Commit

Permalink
Added timetable view by classrooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Mar 21, 2013
1 parent 93518ca commit 8e2e517
Show file tree
Hide file tree
Showing 18 changed files with 390 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/timetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
//= require timetable/timetable
//= require timetable/group
//= require timetable/lecturer
//= require timetable/classrooms
//= require timetable/terminal
56 changes: 56 additions & 0 deletions app/assets/javascripts/timetable/classrooms.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<%
building_c = <<eos
'<div class=\"building\">
<h2>'+building.name+' корпус</h2>'
eos
building_c.gsub!(/\n\s*/, "")
content = <<eos
'<div class=\"classroom\">
<h3>'+classroom.name+(classroom.title ? '<small>: '+classroom.title+'</small>' : '')+'</h3>
<a href=\"/timetable/classrooms/'+classroom.id+location.search+'\" class=\"button link_to_timetable\">Расписание</a>
</div>'
eos
content.gsub!(/\n\s*/, "")
%>

jQuery(document).ready(function($) {

$('#classroom_name_input').on('input', function () {
$.ajax({
url: "/timetable/classrooms.json",
data: {classroom: $(this).val()},
dataType: 'json',
timeout: 15000,
beforeSend: function (jqXHR, settings) {
$(".ajax_message").hide();
$(".ajax_spinner").show();
$(".ajax_loading").show();
},
error: function (jqXHR, textStatus, errorThrown) {
$(".ajax_error").show();
},
success: function (data, textStatus, jqXHR) {
if (data.length) {
$(".list_box").empty();
$.each(data, function (i, elem) {
var building = elem.building;
var html = <%= building_c %>;
$.each(building.classrooms, function (j, classroom) {
html += <%= content %>;
});
$(html+'</div>').appendTo(".list_box");
});
} else {
$(".ajax_not_found").show();
}
},
complete: function (jqXHR, textStatus) {
$(".ajax_spinner").hide();
$(".ajax_loading").hide();
}
});
});

if ($('#lecturer_name_input').val()) $('#lecturer_name_input').trigger('input');

});
2 changes: 1 addition & 1 deletion app/assets/javascripts/timetable/timetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jQuery(document).ready(function($){
timer = setTimeout("window.location.reload(true)", 45000);
});

$('.list_box').on('click', '.group, .lecturer', function () {
$('.list_box').on('click', '.group, .lecturer, .classroom', function () {
location.href = $('a', this).attr("href");
});

Expand Down
7 changes: 4 additions & 3 deletions app/assets/stylesheets/timetable.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*= require timetable/timetable
*= require timetable/group
*= require timetable/lecturer
*= require timetable/classrooms
*= require timetable/terminal
*= require about
*= require help
Expand Down Expand Up @@ -85,8 +86,8 @@ body.timetable {

& li {
float: left;
width: 250px;
font: normal 1.5em "Cuprum",sans-serif;
width: 175px;
font: normal 1.2em "Cuprum",sans-serif;
list-style: none;
border-right: 1px dotted silver;
border-left: 1px dotted silver;
Expand All @@ -97,7 +98,7 @@ body.timetable {
display: block;
width: 100%;
height: 100%;
padding: 0.3em 0;
padding: 0.5em 0;
text-align: center;
text-decoration: none;
text-shadow: white 1px 1px 2px;
Expand Down
121 changes: 121 additions & 0 deletions app/assets/stylesheets/timetable/classrooms.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* Keyboard preferences */
$key_width: 2em;
$key_margin: 0.25em;
$keyboard_width: 12*($key_width+2*$key_margin);

div.classroom_timetable_search {

label {
display: block;
margin-bottom: 1em;
}

.search_box {
-moz-box-sizing: border-box;
box-sizing: border-box;
font-size: 1.2em;
padding: 0.5em;
position: static;
overflow: hidden;
top: 49px;
width: 100%;
z-index: 0;
border-bottom: 1px solid silver;
background: #F0F0F9;
-moz-box-shadow: 1px 1px 10px 0 rgba(0,0,0,0.25);
-webkit-box-shadow: 1px 1px 10px 0 rgba(0,0,0,0.25);
box-shadow: 1px 1px 10px 0 rgba(0,0,0,0.25);
background-image: -o-linear-gradient(top, #dfdfe6 0%, #F0F0F9 50%, #dfdfe6 100%);
background-image: -moz-linear-gradient(top, #dfdfe6 0%, #F0F0F9 50%, #dfdfe6 100%);
background-image: -webkit-linear-gradient(top, #dfdfe6 0%, #F0F0F9 50%, #dfdfe6 100%);
background-image: -ms-linear-gradient(top, #dfdfe6 0%, #F0F0F9 50%, #dfdfe6 100%);
background-image: linear-gradient(top, #dfdfe6 0%, #F0F0F9 50%, #dfdfe6 100%);

form {
margin-left: $keyboard_width;
}

}

.keyboard {
margin: 0;
text-align: center;
float: left;
width: $keyboard_width;

.kbd_row {
overflow: hidden;
margin: 0 auto;
text-align: center;

&.large {
font-size: 120%;
}

}

@for $i from 9 through 12 {
.kbd_row.k#{$i} {
width: $i*($key_width+2*$key_margin);
}
}

.key {
float: left;
margin: $key_margin - 0.05em; // Strange Opera behaviour fix here
width: $key_width;
text-align: center;
font-size: 1em;
font-weight: bold;
}

.key.backspace, .key.clear {
color: maroon !important;
}

.key.whitespace {
width: 6*($key_width+2*$key_margin);
}

.key.backspace {
width: 1.5*$key_width;
}

}

.list_box {
margin: 0;

h2 {
font-size: 200%;
margin-bottom: 0.5em;
margin-top: 1.5em;
}

.classroom {
padding: 0.5em 1em;
border: 1px dotted silver;
margin: -1px;
clear: both;
overflow: hidden;

h3 {
margin: 0;
padding: 0.1em 1em 0.1em 0;
font-size: 2em;
float: left;
clear: left;
}

a.button {
display: block;
width: 200px;
float: right;
font-size: 1.5em;
}

}

}

}
35 changes: 35 additions & 0 deletions app/controllers/timetable/classrooms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class Timetable::ClassroomsController < Timetable::BaseController

def index
@buildings = Building.includes(:classrooms).reorder("buildings.id,(substring(classrooms.name, '^[0-9]+'))::int,substring(classrooms.name, '[^0-9_].*$')")
@buildings = @buildings.where("classrooms.name ILIKE ? OR classrooms.title ILIKE ? OR buildings.name ILIKE ?", *(["%#{params[:classroom]}%"]*3)) if params[:classroom]
respond_to do |format|
format.html do
if @buildings.count == 1 and @buildings.first.classrooms.count == 1
redirect_to timetable_classroom_path(@buildings.first.classrooms.first)
end
end
format.json do
render :json => @buildings.to_json(only: [:id, :name], include: {classrooms: {only: [:id, :title, :name]}})
end
end
end

def show
@id = params[:id].to_i
unless @classroom = Classroom.find_by_id(@id)
suffix = @terminal ? '?terminal=true' : ''
redirect_to :controller => 'timetable/classrooms' + suffix
else
pairs = @classroom.pairs.includes(:subgroups).in_semester(current_semester).flatten
@days = Timetable.days
@times = Timetable.times
@weeks = Timetable.weeks
@pairs = Array.new(@days.size).map!{Array.new(@times.size).map!{Array.new(@weeks.size + 1).map!{Array.new}}}
pairs.each do |pair|
@pairs[pair.day_of_the_week - 1][pair.pair_number - 1][pair.week] << pair
end
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/timetable/classrooms_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Timetable::ClassroomsHelper
end
2 changes: 2 additions & 0 deletions app/views/application/_timetable_main_menu.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#{link_to "Группы", timetable_groups_path}
%li
#{link_to "Преподаватели", timetable_lecturers_path}
%li
#{link_to "Аудитории", timetable_classrooms_path}
- if @terminal
%menu.help_menu
%li
Expand Down
25 changes: 25 additions & 0 deletions app/views/timetable/classrooms/_day.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
- both_week_pairs = @pairs[day_counter][time][0]
- first_week_pairs = @pairs[day_counter][time][1]
- second_week_pairs = @pairs[day_counter][time][2]
%td
-# Uncomment for debug purpose only!
=# both_week_pairs.size
=# first_week_pairs.size
=# second_week_pairs.size
- if both_week_pairs.empty? and first_week_pairs.empty? and second_week_pairs.empty?
.nopair
- else
.daycellcontainer{:title => day}
%table{:class => 'daycell'}
- if both_week_pairs.any? and !first_week_pairs.any? and !second_week_pairs.any?
%tr
= render 'week_in_day', :pairs => both_week_pairs, :skipcell => [], :singlerow => true
- else
- skipcell = []
%tr
- if first_week_pairs.any? or both_week_pairs.any?
= render 'week_in_day', :pairs => first_week_pairs+both_week_pairs, :skipcell => skipcell, :singlerow => false
%tr
- if second_week_pairs.any?
= render 'week_in_day', :pairs => second_week_pairs, :skipcell => skipcell, :singlerow => false

2 changes: 2 additions & 0 deletions app/views/timetable/classrooms/_day_header.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%th
= day_header
12 changes: 12 additions & 0 deletions app/views/timetable/classrooms/_pair.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- flow = p.charge_card.groups.map{|g| g.name }.join ", "
.pair
= "#{flow}"
%br
- if p.assistant && p.assistant_id
.lecturer #{p.lecturer}, #{p.assistant}
- else
.lecturer #{p.lecturer}
= "#{p.discipline}"
- if ![1,2,9].include?(p.active_at.month) or ![5,6,7,12].include?(p.expired_at.month)
%br
с #{p.active_at} по #{p.expired_at}
4 changes: 4 additions & 0 deletions app/views/timetable/classrooms/_time.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%tr.timetablerow
%th
= time
= render :partial => 'day', :collection => @days, :locals => {:time => time_counter}
37 changes: 37 additions & 0 deletions app/views/timetable/classrooms/_week_in_day.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- subgroups = []
- to_display = []
- pairs.sort_by { |p| p.expired_at }.each do |b|
- b.subgroups.each do |s|
- if !subgroups.include?(s.number)
- subgroups << s.number
- subgroups << 0 # Если есть пара с подгруппами, то пара без подгрупп уже не влезет
- to_display << [b, s.number]

- if to_display.size > 0
-# Если без подгрупп или есть только одна пара 3-ей или ещё какой подгруппы
- if subgroups.max == 0 or (subgroups.max > 2 and to_display.size == 1)
%td{:colspan => 2}
- pair = to_display.first[0]
= render 'pair', :p => pair, :s => to_display.first[1]
- else
-# Если есть пара третьей или большей подгруппы и есть место куда её воткнуть
- to_display.find_all{ |elem| elem[1] > 2 }.each do |elem|
- if subgroups.max > 2 and to_display.size == 2 and to_display.size - skipcell.size > 0
- elem[2] = elem[1] # elem[1] - подгруппа-позиция, elem[2] - реальная подгруппа пары
- elem[1] = to_display.find_all{ |elem| elem[1] == 1 }.size > 1 ? 2 : 1
- 1.upto(2) do |sub|
- if skipcell.include?(sub)
- skipcell - [sub]
- next
- sp = to_display.find_all{ |elem| elem[1] == sub }
- if sp.size > 0
- pair = sp.first[0]
- a = {}
- if pair.week == 0 and !singlerow
- skipcell << sub
- a = {:rowspan=>2}
%td{a}
= render 'pair', :p => pair, :s => sp.first[2]
- else
%td.empty

Loading

0 comments on commit 8e2e517

Please sign in to comment.