class ProgramsController < ApplicationController PATCHES_PER_PAGE = 20 def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @program_pages, @programs = paginate :programs, :per_page => 10 end def show edit render :action => 'edit' end def new @program = Program.new end def create @program = Program.new(params[:program]) if @program.save flash[:notice] = 'Program was successfully created.' redirect_to :action => 'list' else render :action => 'new' end end def edit @program = Program.find(params[:id]) session[:program_id] = @program.id @paginator, @unapplied_patches = paginate :patches, :per_page => PATCHES_PER_PAGE, :class_name => 'PatchView', :conditions => ["#{PatchView::UNAPPLIED_CONDITION} AND program_id = :pid", {:pid => @program.id}] end def update @program = Program.find(params[:id]) if @program.update_attributes(params[:program]) flash[:notice] = 'Program was successfully updated.' redirect_to :action => 'show', :id => @program else render :action => 'edit' end end def destroy Program.find(params[:id]).destroy redirect_to :action => 'list' end def unapplied_patches_tar_gz program = Program.find(params[:id]) send_patches(program.unapplied_patches, :filename => "unapplied-#{program.name.downcase.gsub(/[^A-Za-z0-9-]/, '_')}-#{Date.today.strftime('%Y-%m-%d')}.tar.gz") end def patches_rss @headers["Content-Type"] = "application/xml" program = Program.find(params[:id]) @patches = program.patches @title = "PatchServer patches (#{program.name})" @description = "Patches for #{program.name}" render :template => 'shared/patches_rss', :layout => false end def directory @programs = Program.with_most_patches @n_columns = 3 end # Ajax actions def ajax_get_program_unapplied_patches @program = Program.find(session[:program_id]) @paginator, @unapplied_patches = paginate_unapplied_patches render :inline => < :ajax_get_program_unapplied_patches, :paginator => @paginator, :columns => 5) %> EOD end protected def paginate_unapplied_patches(user_options) options = {:per_page => PATCHES_PER_PAGE, :class_name => 'PatchView', :conditions => ["#{PatchView::UNAPPLIED_CONDITION} AND program_id = :pid", {:pid => @program.id}], :order => 'applied_since_version DESC, for_upstream_version DESC'}.merge(user_options) @paginator, @unapplied_patches = paginate :patches, options end end