diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 3ebe9c7..4c01358 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -35,6 +35,7 @@ class AttachmentsController < ApplicationController def create @attachment.course_id = @course.id @attachment.path = params[:attachment][:path] + @attachment.front_page = params[:attachment][:front_page] @attachment.description = params[:attachment][:description] @attachment.file_name = "blank" unless params[:attachment][:file].nil? @@ -58,6 +59,7 @@ class AttachmentsController < ApplicationController def update @attachment.path = params[:attachment][:path] + @attachment.front_page = params[:attachment][:front_page] @attachment.description = params[:attachment][:description] unless params[:attachment][:file].nil? @attachment.file = params[:attachment][:file] @@ -93,10 +95,11 @@ class AttachmentsController < ApplicationController end def download + send_file("#{RAILS_ROOT}/public/upload/#{@course.id}/#{@attachment.id}", :filename => @attachment.file_name, :type => @attachment.content_type, - :disposition => 'attachment', + :disposition => 'inline', :streaming => 'true') end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 89c47a7..63187dc 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -26,9 +26,9 @@ class CoursesController < ApplicationController @period = params[:period] || App.current_period if logged_in? and !@current_user.courses.empty? - @courses = Course.find(:all, :order => 'grade asc, full_name asc', :conditions => ['period = ? and id not in (?)', @period, @current_user.courses]) + @courses = Course.find(:all, :order => 'grade asc, full_name asc', :conditions => ['period = ? and hidden = ? and id not in (?)', @period, false, @current_user.courses]) else - @courses = Course.find(:all, :order => 'grade asc, full_name asc', :conditions => ['period = ?', @period]) + @courses = Course.find(:all, :order => 'grade asc, full_name asc', :conditions => ['period = ? and hidden = ?', @period, false]) end respond_to do |format| diff --git a/app/controllers/log_controller.rb b/app/controllers/log_controller.rb index dcbbd86..25edf53 100644 --- a/app/controllers/log_controller.rb +++ b/app/controllers/log_controller.rb @@ -22,7 +22,9 @@ class LogController < ApplicationController if @course @log_entries = @course.log_entries.paginate(:page => params[:page], :per_page => 30, :order => "created_at desc") else - @log_entries = LogEntry.paginate(:page => params[:page], :per_page => 30, :order => "created_at desc") + @log_entries = LogEntry.paginate(:page => params[:page], :per_page => 30, + :conditions => [ "course_id not in (select id from courses where hidden = ?)", true], + :order => "created_at desc") end respond_to do |format| diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 3395a75..496e90d 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -29,7 +29,7 @@ class WikiController < ApplicationController def index respond_to do |format| - format.html { redirect_to course_url(@course) } + format.html format.xml { render :xml => @wiki_pages } end end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index ce4344f..bd95abb 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -27,6 +27,10 @@ class Attachment < ActiveRecord::Base # Validacao generate_validations + def self.find_front_page + Attachment.find(:all, :conditions => [ "front_page = ?", true ]) + end + # Atributo virtual file def file=(new_file) @tmp_file = new_file diff --git a/app/models/course.rb b/app/models/course.rb index bfc64f3..52db217 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -51,6 +51,10 @@ class Course < ActiveRecord::Base def related_courses Course.find(:all, :conditions => [ 'short_name = ?', self.short_name], :limit => 4, :order => 'period desc') end + + def recent_news + self.news.find(:all, :conditions => [ 'timestamp > ?', 7.days.ago ]) + end def after_create App.inital_wiki_pages.each do |page_title| diff --git a/app/models/log_entry/news_log_entry.rb b/app/models/log_entry/news_log_entry.rb index 24e6f3e..dfedcea 100644 --- a/app/models/log_entry/news_log_entry.rb +++ b/app/models/log_entry/news_log_entry.rb @@ -25,7 +25,7 @@ class NewsDeleteLogEntry < NewsLogEntry news.deleted? end def undo!(current_user) - news.restore! + news.recover! NewsRestoreLogEntry.create!(:target_id => news.id, :user_id => current_user.id, :course => news.course, :version => news.version) end end diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 30ba4ab..369d6d4 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -25,6 +25,7 @@ class WikiPage < ActiveRecord::Base acts_as_list :scope => 'course_id = #{course_id}' acts_as_versioned :if_changed => [ :content, :description, :title ] acts_as_paranoid_versioned + self.non_versioned_columns << 'front_page' self.non_versioned_columns << 'position' self.non_versioned_columns << 'deleted_at' self.non_versioned_columns << 'canonical_title' @@ -43,6 +44,14 @@ class WikiPage < ActiveRecord::Base self.canonical_title = self.title.pretty_url end + def before_save + if !self.front_page + self.remove_from_list + elsif self.position.nil? + self.insert_at(1) + end + end + def validate begin self.content.format_wiki @@ -55,6 +64,10 @@ class WikiPage < ActiveRecord::Base self.canonical_title end + def self.find_front_page + WikiPage.find(:all, :conditions => [ "front_page = ?", true ]) + end + def WikiPage.diff(from, to) # Cria um arquivo com o conteudo da versao antiga original_content_file = Tempfile.new("old") diff --git a/app/views/attachments/_form.html.haml b/app/views/attachments/_form.html.haml index ef64ca1..b9f9914 100644 --- a/app/views/attachments/_form.html.haml +++ b/app/views/attachments/_form.html.haml @@ -13,4 +13,6 @@ %dt %label{:for => "attachment_description"} Descrição - %dd= preserve(text_area 'attachment', 'description') + %dd= preserve(text_area 'attachment', 'description', {:rows => 10}) + + %dt= check_box('attachment', 'front_page') + " Exibir arquivo na página inicial do curso" diff --git a/app/views/attachments/index.html.haml b/app/views/attachments/index.html.haml new file mode 100644 index 0000000..e3ef1a8 --- /dev/null +++ b/app/views/attachments/index.html.haml @@ -0,0 +1,15 @@ +.cmd + = action_icon 'add', 'Adicionar', new_course_attachment_url(@course) + +%h4.title= h(@course.full_name) +%h1.title Repositório de Arquivos + +.box.repositorio + - if !@course.attachments.empty? + %ul + = nested_attachments_to_html(attachments_to_nested_hash(@course.attachments)) + + - else + .box + %ul + %li.no_itens Nenhum arquivo diff --git a/app/views/attachments/show.html.haml b/app/views/attachments/show.html.haml index 25a9426..cdb5ea0 100644 --- a/app/views/attachments/show.html.haml +++ b/app/views/attachments/show.html.haml @@ -3,7 +3,7 @@ = action_icon 'trash', 'Excluir', course_attachment_url, :confirm => 'Tem certeza que deseja excluir o arquivo?', :method => :delete %h4.title= h(@attachment.course.full_name) -%h1.title Repositório +%h1.title Repositório de Arquivos %p %dl diff --git a/app/views/courses/_form.html.haml b/app/views/courses/_form.html.haml index 3209d8a..9e5ab98 100644 --- a/app/views/courses/_form.html.haml +++ b/app/views/courses/_form.html.haml @@ -21,6 +21,10 @@ %label{:for => "course_period"} Data %dd= text_field 'course', 'period' + %dt + %label{:for => "course_hidden"} Ocultar + %dd= check_box 'course', 'hidden' + %dt %label{:for => "course_description"} Descrição %dd= preserve(text_area('course', 'description', :cols => 60, :rows => 10)) diff --git a/app/views/courses/show.html.haml b/app/views/courses/show.html.haml index ccff2a6..13482c2 100644 --- a/app/views/courses/show.html.haml +++ b/app/views/courses/show.html.haml @@ -10,13 +10,32 @@ %p= @course.description.format_wiki +-#.box +-# .cmd +-# = action_icon 'add', 'Adicionar notícia', new_course_news_instance_url(@course) +-# +-# %h3 Notícias Recentes +-# %ul.news +-# - @course.recent_news.each do |news| +-# %li{highlight(news.id)} +-# .cmd{:style => 'margin-top: -9px;'} +-# = action_icon 'edit', 'Editar', edit_course_news_instance_url(@course, news, :version => news.version) +-# = action_icon 'trash', 'Excluir', course_news_instance_url(@course, news), :confirm => 'Tem certeza que deseja excluir?', :method => :delete +-# = link_to h(news.title), course_news_instance_url(@course, news) +-# = formatted(news.body) +-# = "Enviada por %s há %s." % [link_to(news.user.display_name, user_url(news.user)), distance_of_time_in_words(Time.now, news.timestamp)] +-# - if @course.news.empty? +-# %li.no_itens Nenhuma notícia recente +-# - else +-# %li.see_all= link_to "Ver todas as noticias", course_news_url(@course) + .box .cmd = action_icon 'add', 'Adicionar página wiki', new_course_wiki_instance_url(@course) %h3 Páginas Wiki %ul.wiki - - @course.wiki_pages.each do |wiki| + - @course.wiki_pages.find_front_page.each do |wiki| %li{highlight(wiki.id)} .cmd{:style => 'margin-bottom: -27px; margin-top: -9px;'} =action_icon 'arrow2_n', 'Mover para cima', move_up_course_wiki_instance_url(@course, wiki) unless wiki.first? @@ -26,14 +45,18 @@ =link_to h(wiki.title), course_wiki_instance_url(@course, wiki) - if @course.wiki_pages.empty? %li.no_itens Nenhuma página wiki + - else + %li.show_all= link_to "Ver todas as páginas wiki", course_wiki_url(@course) .box .cmd= action_icon 'add', 'Adicionar anexo', new_course_attachment_url(@course) %h3 Repositório de Arquivos .repositorio - = nested_attachments_to_html(attachments_to_nested_hash(@course.attachments)) + = nested_attachments_to_html(attachments_to_nested_hash(@course.attachments.find_front_page)) - if @course.attachments.empty? %ul.wiki %li.no_itens Nenhum arquivo + - else + %li.show_all= link_to "Ver todos os arquivos", course_attachments_url(@course) diff --git a/app/views/layouts/attachments.html.haml b/app/views/layouts/attachments.html.haml index f65513c..74b7b33 100644 --- a/app/views/layouts/attachments.html.haml +++ b/app/views/layouts/attachments.html.haml @@ -3,7 +3,7 @@ = link_to(App.title, index_url) + "›" = link_to("Disciplinas", courses_url) + "›" = link_to(h(@course.full_name), course_url(@course)) + "›" - = link_to("Arquivos", course_url(@course)) + = link_to("Arquivos", course_attachments_url(@course)) - if @attachment.id = "›" + link_to(truncate(h(@attachment.file_name)), course_attachment_url) - @title = @title + " - #{truncate(h(@attachment.file_name))}" diff --git a/app/views/layouts/wiki.html.haml b/app/views/layouts/wiki.html.haml index 3ce1a45..30362d1 100644 --- a/app/views/layouts/wiki.html.haml +++ b/app/views/layouts/wiki.html.haml @@ -3,7 +3,7 @@ = link_to(App.title, index_url) + "›" = link_to("Disciplinas", courses_url) + "›" = link_to(h(@course.full_name), course_url(@course)) + "›" - = link_to("Wiki", course_url(@course)) + = link_to("Wiki", course_wiki_url(@course)) - if @wiki_page.title = "›" + link_to(h(@wiki_page.title), course_wiki_instance_url(@course, @wiki_page)) - @title = @title + " - #{h(@wiki_page.title)}" diff --git a/app/views/news/index.html.haml b/app/views/news/index.html.haml index 0ccff31..37f72e3 100644 --- a/app/views/news/index.html.haml +++ b/app/views/news/index.html.haml @@ -1,7 +1,5 @@ = javascript_include_tag 'news' --# cache(course_news_path(@course.id)) do - .cmd = action_icon 'add', 'Adicionar', new_course_news_instance_url @@ -22,7 +20,7 @@ = n.timestamp.strftime("%d de %B") %td .title= link_to h(n.title), course_news_instance_url(@course, n) - .description{:style => (n.id == params[:id].to_i ? '' : 'display: none')} + .description .cmd = action_icon 'edit', 'Editar', edit_course_news_instance_url(@course, n, :version => n.version) = action_icon 'trash', 'Excluir', course_news_instance_url(@course, n), :confirm => 'Tem certeza que deseja excluir?', :method => :delete diff --git a/app/views/stylesheets/wiki.css.erb b/app/views/stylesheets/wiki.css.erb index f84d184..0073c7b 100644 --- a/app/views/stylesheets/wiki.css.erb +++ b/app/views/stylesheets/wiki.css.erb @@ -231,7 +231,7 @@ body { list-style: none; } -.menu li, .news li, #shoutbox li { +.menu li, #shoutbox li { border-top: 1px solid #eee; margin-top: -1px; padding: 9px 10px; @@ -295,17 +295,10 @@ body { border-bottom: 0px solid #ccc; } -.widget_users li, .widget_news li, .widget_events li { +.widget_users li { font-size: 11px; } -.widget_news li, #shoutbox li { - line-height: 18px; - margin: 0px; margin-top: -1px; - padding: 9px 0px; -} - - #shoutbox textarea { font-family: sans-serif; font-size: 11px; @@ -559,10 +552,16 @@ textarea { width: 100%; } -.no_itens { +.no_itens, .see_all { color: #aaa; } +.box .see_all { + font-size: 11px; + background-image: none; + border-bottom-width: 0px; +} + .history input { margin: 0px 10px 0px 0px; @@ -889,6 +888,12 @@ ul.nested li { padding: 0px 0px 0px 18px; } +.box li.show_all { + background-image: none; + font-size: 11px; +} + + /*body { background-image: url(<%= App.base_path %>/prototype/line.png); background-repeat: repeat; } html * { background-color: transparent !important; }*/ diff --git a/app/views/widgets/_menu_disciplina.html.erb b/app/views/widgets/_menu_disciplina.html.erb index e03a698..a116b7d 100644 --- a/app/views/widgets/_menu_disciplina.html.erb +++ b/app/views/widgets/_menu_disciplina.html.erb @@ -3,9 +3,11 @@

Disciplina

diff --git a/app/views/wiki/_form.html.haml b/app/views/wiki/_form.html.haml index d7fa767..abb2063 100644 --- a/app/views/wiki/_form.html.haml +++ b/app/views/wiki/_form.html.haml @@ -15,3 +15,5 @@ %dt %label{:for => 'wiki_page_description'} Descrição das alterações %dd= text_field('wiki_page', 'description', { :size => '80' }) + + %dt= check_box('wiki_page', 'front_page') + " Exibir página wiki na página inicial do curso" diff --git a/app/views/wiki/index.html.haml b/app/views/wiki/index.html.haml new file mode 100644 index 0000000..326f464 --- /dev/null +++ b/app/views/wiki/index.html.haml @@ -0,0 +1,16 @@ +.cmd + = action_icon 'add', 'Adicionar', new_course_wiki_instance_url(@course) + +%h4.title= h(@course.full_name) +%h1.title Páginas Wiki + +.box.div_news + - if !@course.wiki_pages.empty? + %ul + - @course.wiki_pages.find(:all, :order => 'title').each do |w| + %li= link_to(w.title, course_wiki_instance_url(@course, w)) + + - else + .box + %ul + %li.no_itens Nenhuma página wiki diff --git a/db/migrate/20090908200528_hidden.rb b/db/migrate/20090908200528_hidden.rb new file mode 100644 index 0000000..d4c4795 --- /dev/null +++ b/db/migrate/20090908200528_hidden.rb @@ -0,0 +1,13 @@ +class Hidden < ActiveRecord::Migration + def self.up + add_column :courses, :hidden, :boolean, :null => false, :default => false + add_column :wiki_pages, :front_page, :boolean, :null => false, :default => true + add_column :attachments, :front_page, :boolean, :null => false, :default => true + end + + def self.down + remove_column :courses, :hidden + remove_column :wiki_pages, :front_page + remove_column :attachments, :front_page + end +end diff --git a/db/schema.rb b/db/schema.rb index fba8f11..b44b079 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,10 +9,10 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20090907095812) do +ActiveRecord::Schema.define(:version => 20090908200528) do create_table "attachments", :force => true do |t| - t.string "file_name", :null => false + t.string "file_name", :null => false t.string "content_type" t.datetime "last_modified" t.text "description" @@ -20,6 +20,7 @@ ActiveRecord::Schema.define(:version => 20090907095812) do t.integer "course_id" t.datetime "deleted_at" t.string "path" + t.boolean "front_page", :default => true, :null => false end create_table "courses", :force => true do |t| @@ -30,6 +31,7 @@ ActiveRecord::Schema.define(:version => 20090907095812) do t.datetime "deleted_at" t.integer "grade", :default => 1 t.string "period" + t.boolean "hidden", :default => false, :null => false end add_index "courses", ["short_name"], :name => "index_courses_on_short_name" @@ -137,17 +139,18 @@ ActiveRecord::Schema.define(:version => 20090907095812) do end create_table "wiki_pages", :force => true do |t| - t.integer "course_id", :null => false - t.integer "user_id", :null => false - t.integer "version", :null => false - t.string "description", :null => false - t.string "title", :null => false - t.text "content", :null => false + t.integer "course_id", :null => false + t.integer "user_id", :null => false + t.integer "version", :null => false + t.string "description", :null => false + t.string "title", :null => false + t.text "content", :null => false t.datetime "created_at" t.datetime "updated_at" t.integer "position" t.datetime "deleted_at" t.string "canonical_title" + t.boolean "front_page", :default => true, :null => false end end