Multiplos semestres
This commit is contained in:
@@ -97,7 +97,7 @@ class AttachmentsController < ApplicationController
|
||||
|
||||
protected
|
||||
def find_attachment
|
||||
params[:course_id] = Course.find_by_short_name(params[:course_id]).id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
@course = Course.find(params[:course_id])
|
||||
@attachment = params[:id] ? @course.attachments.find(params[:id]) : Attachment.new
|
||||
end
|
||||
|
||||
@@ -22,9 +22,14 @@ class CoursesController < ApplicationController
|
||||
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
|
||||
|
||||
def index
|
||||
@courses = Course.find(:all,
|
||||
:order => 'period asc, full_name asc',
|
||||
:conditions => (logged_in? and !@current_user.courses.empty? ? [ 'id not in (?)', @current_user.courses] : ''))
|
||||
params[:period] = nil if params[:period] == App.current_period
|
||||
@period = params[:period] || App.current_period
|
||||
|
||||
conditions = []
|
||||
conditions.add_condition!(['period = ?', @period])
|
||||
conditions.add_condition!(['id not in (?)', @current_user.courses]) if logged_in? and !@current_user.courses.empty?
|
||||
@courses = Course.find(:all, :order => 'grade asc, full_name asc', :conditions => conditions)
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
@@ -98,7 +103,7 @@ class CoursesController < ApplicationController
|
||||
|
||||
protected
|
||||
def find_course
|
||||
params[:id] = Course.find_by_short_name(params[:id]).id if params[:id] and !params[:id].is_numeric? and !Course.find_by_short_name(params[:id]).nil?
|
||||
params[:id] = Course.find(:first, :conditions => ['short_name = ?', params[:id]], :order => 'period desc').id if !params[:id].is_numeric? and !Course.find_by_short_name(params[:id]).nil?
|
||||
@course = params[:id] ? Course.find(params[:id]) : Course.new(params[:course])
|
||||
end
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class EventsController < ApplicationController
|
||||
|
||||
protected
|
||||
def find_event
|
||||
params[:course_id] = Course.find_by_short_name(params[:course_id]).id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
@course = Course.find(params[:course_id])
|
||||
@event = params[:id] ? @course.events.find(params[:id]) : Event.new(params[:event])
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ class LogController < ApplicationController
|
||||
protected
|
||||
def find_course
|
||||
unless params[:course_id].nil?
|
||||
params[:course_id] = Course.find_by_short_name(params[:course_id]).id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
@course = Course.find(params[:course_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -105,7 +105,7 @@ class NewsController < ApplicationController
|
||||
|
||||
protected
|
||||
def find_new
|
||||
params[:course_id] = Course.find_by_short_name(params[:course_id]).id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
@course = Course.find(params[:course_id])
|
||||
|
||||
@news = params[:id] ? @course.news.find(params[:id]) : News.new(params[:news])
|
||||
|
||||
@@ -159,7 +159,7 @@ class WikiController < ApplicationController
|
||||
|
||||
protected
|
||||
def find_wiki
|
||||
params[:course_id] = Course.find_by_short_name(params[:course_id]).id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
params[:course_id] = Course.find(:first, :conditions => ['short_name = ?', params[:course_id]], :order => 'period desc').id if !params[:course_id].is_numeric? and !Course.find_by_short_name(params[:course_id]).nil?
|
||||
@course = Course.find(params[:course_id])
|
||||
|
||||
params[:id] = @course.wiki_pages.find_by_title(params[:id]).id if params[:id] and !params[:id].is_numeric? and !@course.wiki_pages.find_by_title(params[:id]).nil?
|
||||
|
||||
@@ -43,9 +43,12 @@ class Course < ActiveRecord::Base
|
||||
|
||||
# Validacao
|
||||
generate_validations
|
||||
validates_uniqueness_of :short_name
|
||||
validates_format_of :short_name, :with => /^[^0-9]/
|
||||
|
||||
def related_courses
|
||||
Course.find(:all, :conditions => [ 'short_name = ?', self.short_name], :limit => 4, :order => 'period desc')
|
||||
end
|
||||
|
||||
def after_create
|
||||
App.inital_wiki_pages.each do |page_title|
|
||||
wiki_page = WikiPage.new(:title => page_title, :version => 1, :content => App.initial_wiki_page_content)
|
||||
@@ -54,6 +57,7 @@ class Course < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def to_param
|
||||
self.short_name
|
||||
return self.short_name if self.period == App.current_period
|
||||
return self.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,7 +22,7 @@ class User < ActiveRecord::Base
|
||||
acts_as_paranoid
|
||||
|
||||
# Associacoes
|
||||
has_and_belongs_to_many :courses, :order => 'full_name'
|
||||
has_and_belongs_to_many :courses, :order => 'full_name', :conditions => "period = #{App.current_period}"
|
||||
|
||||
# Validacao
|
||||
validates_length_of :login, :within => 3..40
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
%dd= text_field 'course', 'code'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_period"} Semestre
|
||||
%label{:for => "course_grade"} Semestre
|
||||
%dd= text_field 'course', 'grade'
|
||||
|
||||
%dt
|
||||
%label{:for => "course_period"} Data
|
||||
%dd= text_field 'course', 'period'
|
||||
|
||||
%dt
|
||||
|
||||
@@ -2,29 +2,35 @@
|
||||
= action_icon('add', 'Cadastrar nova disciplina', new_course_url) if admin?
|
||||
|
||||
%h4.title= App.title
|
||||
%h1.title Disciplinas
|
||||
%h1.title= "Disciplinas #{@period}"
|
||||
|
||||
.box
|
||||
%ul
|
||||
- if logged_in?
|
||||
%h3 Disciplinas Matriculadas
|
||||
- if @current_user.courses.empty?
|
||||
%li.no_itens Nenhuma disciplina matriculada
|
||||
- for course in @current_user.courses
|
||||
%li{highlight(course.id)}
|
||||
.right
|
||||
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
||||
= link_to h(course.full_name), course_url(course)
|
||||
- if params[:period].nil?
|
||||
%h3 Disciplinas Matriculadas
|
||||
- if @current_user.courses.empty?
|
||||
%li.no_itens Nenhuma disciplina matriculada
|
||||
- for course in @current_user.courses
|
||||
%li{highlight(course.id)}
|
||||
.right
|
||||
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
||||
= link_to h(course.full_name), course_url(course)
|
||||
|
||||
-# cache(courses_path) do
|
||||
- old_period = 0
|
||||
- old_grade = 0
|
||||
- for course in @courses
|
||||
- if course.period != old_period
|
||||
%h3= (course.period == 99 ? "Optativas" : "Semestre #{course.period}")
|
||||
- old_period = course.period
|
||||
- if course.grade != old_grade
|
||||
%h3= (course.grade == 99 ? "Optativas" : "Semestre #{course.grade}")
|
||||
- old_grade = course.grade
|
||||
|
||||
%li{highlight(course.id)}
|
||||
.right
|
||||
= action_icon('add', 'Matricular-se', enroll_course_url(course))
|
||||
- if course.period == App.current_period
|
||||
.right
|
||||
= action_icon('add', 'Matricular-se', enroll_course_url(course))
|
||||
= link_to h(course.full_name), course_url(course)
|
||||
|
||||
%h3
|
||||
Outros Semestres
|
||||
%li= link_to "2008.2", :period => '2008.2'
|
||||
%li= link_to "2008.1", :period => '2008.1'
|
||||
|
||||
@@ -8,3 +8,14 @@
|
||||
<li><%= link_to "Mudanças recentes", course_log_url(@course) %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<% if @course.related_courses.length > 1 %>
|
||||
<div class="menu">
|
||||
<h1>Semestres</h1>
|
||||
<ul>
|
||||
<% for c in @course.related_courses %>
|
||||
<li><%= (c == @course) ? c.period : link_to(c.period, course_url(c)) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -6,6 +6,8 @@ App.webmaster_email = "webmaster@wikiufc.gelsol.org"
|
||||
App.default_host = "wikiufc.gelsol.org"
|
||||
App.base_path = ""
|
||||
|
||||
App.current_period = "2008.1"
|
||||
|
||||
# Limites
|
||||
App.max_upload_file_size = 5.megabytes
|
||||
|
||||
|
||||
@@ -8,3 +8,19 @@ class String
|
||||
Float self rescue false
|
||||
end
|
||||
end
|
||||
|
||||
class Array
|
||||
def add_condition! (condition, conjunction = 'AND')
|
||||
if String === condition
|
||||
add_condition!([condition])
|
||||
elsif Hash === condition
|
||||
add_condition!([condition.keys.map { |attr| "#{attr}=?" }.join(' AND ')] + condition.values)
|
||||
elsif Array === condition
|
||||
self[0] = "(#{self[0]}) #{conjunction} (#{condition.shift})" unless empty?
|
||||
(self << condition).flatten!
|
||||
else
|
||||
raise "don't know how to handle this condition type"
|
||||
end
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
19
db/migrate/036_semestres.rb
Normal file
19
db/migrate/036_semestres.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class Semestres < ActiveRecord::Migration
|
||||
def self.up
|
||||
rename_column :courses, :period, :grade
|
||||
add_column :courses, :period, :string
|
||||
Course.find(:all).each do |c|
|
||||
c.update_attribute(:period, "2008.1")
|
||||
end
|
||||
|
||||
remove_index :courses, :short_name
|
||||
add_index :courses, :short_name, :unique => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :courses, :period
|
||||
rename_column :courses, :grade, :period
|
||||
remove_index :courses, :short_name
|
||||
add_index :courses, :short_name, :unique => true
|
||||
end
|
||||
end
|
||||
@@ -9,7 +9,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 35) do
|
||||
ActiveRecord::Schema.define(:version => 36) do
|
||||
|
||||
create_table "attachments", :force => true do |t|
|
||||
t.string "file_name", :null => false
|
||||
@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 35) do
|
||||
t.integer "size"
|
||||
t.integer "course_id"
|
||||
t.datetime "deleted_at"
|
||||
t.string "path"
|
||||
end
|
||||
|
||||
create_table "courses", :force => true do |t|
|
||||
@@ -26,11 +27,12 @@ ActiveRecord::Schema.define(:version => 35) do
|
||||
t.string "full_name", :null => false
|
||||
t.text "description"
|
||||
t.string "code", :default => "CK000", :null => false
|
||||
t.integer "period", :default => 1, :null => false
|
||||
t.datetime "deleted_at"
|
||||
t.integer "grade", :default => 1
|
||||
t.string "period"
|
||||
end
|
||||
|
||||
add_index "courses", ["short_name"], :name => "index_courses_on_short_name", :unique => true
|
||||
add_index "courses", ["short_name"], :name => "index_courses_on_short_name"
|
||||
|
||||
create_table "courses_users", :id => false, :force => true do |t|
|
||||
t.integer "user_id"
|
||||
|
||||
Reference in New Issue
Block a user