Multiplos semestres
This commit is contained in:
@@ -97,7 +97,7 @@ class AttachmentsController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def find_attachment
|
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])
|
@course = Course.find(params[:course_id])
|
||||||
@attachment = params[:id] ? @course.attachments.find(params[:id]) : Attachment.new
|
@attachment = params[:id] ? @course.attachments.find(params[:id]) : Attachment.new
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,9 +22,14 @@ class CoursesController < ApplicationController
|
|||||||
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
|
#after_filter :cache_sweep, :only => [ :create, :update, :destroy ]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@courses = Course.find(:all,
|
params[:period] = nil if params[:period] == App.current_period
|
||||||
:order => 'period asc, full_name asc',
|
@period = params[:period] || App.current_period
|
||||||
:conditions => (logged_in? and !@current_user.courses.empty? ? [ 'id not in (?)', @current_user.courses] : ''))
|
|
||||||
|
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|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
@@ -98,7 +103,7 @@ class CoursesController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def find_course
|
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])
|
@course = params[:id] ? Course.find(params[:id]) : Course.new(params[:course])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class EventsController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def find_event
|
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])
|
@course = Course.find(params[:course_id])
|
||||||
@event = params[:id] ? @course.events.find(params[:id]) : Event.new(params[:event])
|
@event = params[:id] ? @course.events.find(params[:id]) : Event.new(params[:event])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class LogController < ApplicationController
|
|||||||
protected
|
protected
|
||||||
def find_course
|
def find_course
|
||||||
unless params[:course_id].nil?
|
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])
|
@course = Course.find(params[:course_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class NewsController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def find_new
|
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])
|
@course = Course.find(params[:course_id])
|
||||||
|
|
||||||
@news = params[:id] ? @course.news.find(params[:id]) : News.new(params[:news])
|
@news = params[:id] ? @course.news.find(params[:id]) : News.new(params[:news])
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ class WikiController < ApplicationController
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
def find_wiki
|
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])
|
@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?
|
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
|
# Validacao
|
||||||
generate_validations
|
generate_validations
|
||||||
validates_uniqueness_of :short_name
|
|
||||||
validates_format_of :short_name, :with => /^[^0-9]/
|
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
|
def after_create
|
||||||
App.inital_wiki_pages.each do |page_title|
|
App.inital_wiki_pages.each do |page_title|
|
||||||
wiki_page = WikiPage.new(:title => page_title, :version => 1, :content => App.initial_wiki_page_content)
|
wiki_page = WikiPage.new(:title => page_title, :version => 1, :content => App.initial_wiki_page_content)
|
||||||
@@ -54,6 +57,7 @@ class Course < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
self.short_name
|
return self.short_name if self.period == App.current_period
|
||||||
|
return self.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class User < ActiveRecord::Base
|
|||||||
acts_as_paranoid
|
acts_as_paranoid
|
||||||
|
|
||||||
# Associacoes
|
# 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
|
# Validacao
|
||||||
validates_length_of :login, :within => 3..40
|
validates_length_of :login, :within => 3..40
|
||||||
|
|||||||
@@ -14,7 +14,11 @@
|
|||||||
%dd= text_field 'course', 'code'
|
%dd= text_field 'course', 'code'
|
||||||
|
|
||||||
%dt
|
%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'
|
%dd= text_field 'course', 'period'
|
||||||
|
|
||||||
%dt
|
%dt
|
||||||
|
|||||||
@@ -2,29 +2,35 @@
|
|||||||
= action_icon('add', 'Cadastrar nova disciplina', new_course_url) if admin?
|
= action_icon('add', 'Cadastrar nova disciplina', new_course_url) if admin?
|
||||||
|
|
||||||
%h4.title= App.title
|
%h4.title= App.title
|
||||||
%h1.title Disciplinas
|
%h1.title= "Disciplinas #{@period}"
|
||||||
|
|
||||||
.box
|
.box
|
||||||
%ul
|
%ul
|
||||||
- if logged_in?
|
- if logged_in?
|
||||||
%h3 Disciplinas Matriculadas
|
- if params[:period].nil?
|
||||||
- if @current_user.courses.empty?
|
%h3 Disciplinas Matriculadas
|
||||||
%li.no_itens Nenhuma disciplina matriculada
|
- if @current_user.courses.empty?
|
||||||
- for course in @current_user.courses
|
%li.no_itens Nenhuma disciplina matriculada
|
||||||
%li{highlight(course.id)}
|
- for course in @current_user.courses
|
||||||
.right
|
%li{highlight(course.id)}
|
||||||
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
.right
|
||||||
= link_to h(course.full_name), course_url(course)
|
= action_icon('subtract', 'Desmatricular-se', unenroll_course_url(course))
|
||||||
|
= link_to h(course.full_name), course_url(course)
|
||||||
|
|
||||||
-# cache(courses_path) do
|
-# cache(courses_path) do
|
||||||
- old_period = 0
|
- old_grade = 0
|
||||||
- for course in @courses
|
- for course in @courses
|
||||||
- if course.period != old_period
|
- if course.grade != old_grade
|
||||||
%h3= (course.period == 99 ? "Optativas" : "Semestre #{course.period}")
|
%h3= (course.grade == 99 ? "Optativas" : "Semestre #{course.grade}")
|
||||||
- old_period = course.period
|
- old_grade = course.grade
|
||||||
|
|
||||||
%li{highlight(course.id)}
|
%li{highlight(course.id)}
|
||||||
.right
|
- if course.period == App.current_period
|
||||||
= action_icon('add', 'Matricular-se', enroll_course_url(course))
|
.right
|
||||||
|
= action_icon('add', 'Matricular-se', enroll_course_url(course))
|
||||||
= link_to h(course.full_name), 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>
|
<li><%= link_to "Mudanças recentes", course_log_url(@course) %></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</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.default_host = "wikiufc.gelsol.org"
|
||||||
App.base_path = ""
|
App.base_path = ""
|
||||||
|
|
||||||
|
App.current_period = "2008.1"
|
||||||
|
|
||||||
# Limites
|
# Limites
|
||||||
App.max_upload_file_size = 5.megabytes
|
App.max_upload_file_size = 5.megabytes
|
||||||
|
|
||||||
|
|||||||
@@ -8,3 +8,19 @@ class String
|
|||||||
Float self rescue false
|
Float self rescue false
|
||||||
end
|
end
|
||||||
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.
|
# 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|
|
create_table "attachments", :force => true do |t|
|
||||||
t.string "file_name", :null => false
|
t.string "file_name", :null => false
|
||||||
@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 35) do
|
|||||||
t.integer "size"
|
t.integer "size"
|
||||||
t.integer "course_id"
|
t.integer "course_id"
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
|
t.string "path"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "courses", :force => true do |t|
|
create_table "courses", :force => true do |t|
|
||||||
@@ -26,11 +27,12 @@ ActiveRecord::Schema.define(:version => 35) do
|
|||||||
t.string "full_name", :null => false
|
t.string "full_name", :null => false
|
||||||
t.text "description"
|
t.text "description"
|
||||||
t.string "code", :default => "CK000", :null => false
|
t.string "code", :default => "CK000", :null => false
|
||||||
t.integer "period", :default => 1, :null => false
|
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
|
t.integer "grade", :default => 1
|
||||||
|
t.string "period"
|
||||||
end
|
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|
|
create_table "courses_users", :id => false, :force => true do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
|
|||||||
Reference in New Issue
Block a user