Class | SitesController
In: | test/functional/sites_controller_test.rb app/controllers/sites_controller.rb
Parent: | Object

Copyright (c) 2006 Logica

### Methods

comments csv description edit feedback index list new new_wiki obsolete pages rescue_action update update_cancel update_now uploads versions

### Constants

FLASH_WIKI_SITE_CREATED | = | 'An empty Wiki site has been created. Now you can schedule a job to update the Wiki with a Baseline Process'
FLASH_WIKI_UPDATE_SUCCESS | = | 'Wiki succesfully updated'

### Public Instance methods

comments()

[Source]

         # File app/controllers/sites_controller.rb, line 137
    137:   def comments
    138:     @site = Site.find(params[:id])
    139:     #logger.debug("params.inspect: #{params.inspect}")
    140:     @filter = Comment.new(params[:filter]) # done is default 'N'
    141:     cond = ['site_id = ?', @site.id ]
    142:     cond = ['site_id = ? and done = ?', @site.id, 'N' ] if @filter.done == 'N'
    143:     @comment_pages, @comments = paginate :comment, :per_page => 25, :order => 'created_on DESC', :conditions => cond
    144:     render :action => 'description'
    145:   end

csv()

[Source]

         # File app/controllers/sites_controller.rb, line 189
    189:   def csv
    190:     site = Site.find(params[:id])
    191:     content_type = if request.user_agent =~ /windows/i
    192:       'application/vnd.ms-excel'
    193:     else
    194:       'text/csv'
    195:     end
    196:     site.export_csv if !File.exists?(site.path + '.csv')
    197:     send_data(IO.readlines(site.path + '.csv').join, :type => content_type, :filename => site.folder + '.csv')
    198:   end

description()

[Source]

         # File app/controllers/sites_controller.rb, line 110
    110:   def description
    111:     @site = Site.find(params[:id])
    112:   end

edit()

[Source]

         # File app/controllers/sites_controller.rb, line 159
    159:   def edit
    160:     @site = Site.find(params[:id])
    161:     if request.get?
    162:       flash.now['warning'] = 'Updating the folder here won\'t update the file system. If you want to change the folder you will have to rename the folder manually on the filesystem'
    163:     else
    164:       @site = Site.find(params[:id])
    165:       if @site.update_attributes(params[:site])
    166:         flash['success'] = 'Site was successfully updated.'
    167:         redirect_to :action => 'description', :id => @site
    168:       else
    169:         render :action => 'edit'
    170:       end
    171:     end
    172:   end

feedback()

[Source]

         # File app/controllers/sites_controller.rb, line 153
    153:   def feedback
    154:     @site = Site.find(params[:id])
    155:     @feedback_pages, @feedbacks = paginate :feedbacks, :order => 'created_on DESC',  :per_page => 25
    156:     render :action => 'description'
    157:   end

index()

[Source]

        # File app/controllers/sites_controller.rb, line 34
    34:   def index
    35:     list
    36:     render :action => 'list'
    37:   end

list()

[Source]

        # File app/controllers/sites_controller.rb, line 39
    39:   def list
    40:     @baseline_processes = BaselineProcess.find(:all)
    41:     @wikis = Wiki.find(:all)
    42:   end

new()

Action new creates a BaselineProcess. A BaselineProcess is created from content in a server folder (that you uploaded with FTP or a folder share or something) or from a zip file submitted with the form

[Source]

        # File app/controllers/sites_controller.rb, line 46
    46:   def new
    47:     @baseline_processes = BaselineProcess.find(:all, :conditions => ['obsolete_on is null'])
    48:     @folders = BaselineProcess.unused_folders
    49:     if request.get?
    50:       @site = Site.new
    51:       flash['notice'] =  "<p>Although you can upload zip files with EPFC published sites here, it is recommended to upload content using some other means (FTP, SCP).  You need to upload to the location #{ENV['EPFWIKI_ROOT_DIR']}#{ENV['EPFWIKI_PUBLIC_FOLDER']}/#{ENV['EPFWIKI_SITES_FOLDER']}. Server folder created there can be used to create a new Baseline Process.</p>"
    52:       flash['notice'] += "<p>It is also recommended to use version info or baseline info in your zip file names. The name is used to derive other attributes (server folder and title). Example: oup_20060721.zip</p>"
    53:     else
    54:       logger.info("Creating a new Baseline Process with params #{params.inspect}")
    55:       if params[:site][:file].nil?
    56:         logger.info("Creating a new Baseline Process from server folder")
    57:         @site = BaselineProcess.new(params[:site].merge(:user => session['user']))
    58:       else
    59:         logger.info("Creating a new Baseline Process using zip")
    60:         @site = BaselineProcess.new_from_upload(params[:site].merge(:user => session['user']))
    61:       end
    62:       if @site.errors.empty? && @site.save
    63:         flash['success'] = ::FLASH_RECORD_CREATED
    64:         redirect_to :action => 'list'
    65:       end
    66:     end
    67:   end

new_wiki()

Action new_wiki creates a new Wiki. The typical next step is to schedule an update to add content to this empty Wiki

[Source]

        # File app/controllers/sites_controller.rb, line 70
    70:   def new_wiki
    71:     if request.get?
    72:       @wiki = Wiki.new
    73:     else
    74:       @wiki = Wiki.new(params[:wiki].merge(:user => session['user']))
    75:       if  @wiki.save
    76:         flash['success'] = FLASH_WIKI_SITE_CREATED
    77:         redirect_to :action => 'description', :id => @wiki.id
    78:       end
    79:     end
    80:   end

obsolete()

[Source]

         # File app/controllers/sites_controller.rb, line 174
    174:   def obsolete
    175:     site = Site.find(params[:id])
    176:     site.obsolete_by = session['user']
    177:     if site.obsolete_on.nil?
    178:       site.obsolete_on = Time.now
    179:       flash.now['success'] = "#{site.title} succesfully made obsolete"
    180:     else
    181:       site.obsolete_on = nil
    182:       flash.now['success'] = "#{site.title} is no longer obsolete"
    183:     end
    184:     site.save!
    185:     list
    186:     render :action => 'list'
    187:   end

pages()

[Source]

         # File app/controllers/sites_controller.rb, line 131
    131:   def pages
    132:     @site = Site.find(params[:id])
    133:     @page_pages, @pages = paginate :page, :per_page => 25, :order => 'created_on DESC', :conditions => ['site_id=?', @site.id]
    134:     render :action => 'description'
    135:   end

rescue_action(e)

[Source]

        # File test/functional/sites_controller_test.rb, line 18
    18:                        def rescue_action(e) raise e end

update()

Action update schedules an update. The actual update is typically performed with a job (‘job_daily’) but could also be forced by update_now

[Source]

        # File app/controllers/sites_controller.rb, line 84
    84:   def update
    85:     site = Site.find(params[:id])
    86:     bp = BaselineProcess.find(params[:baseline_process_id])
    87:     u = Update.new(:user => session['user'], :wiki => site, :baseline_process => bp)
    88:     u.save!
    89:     flash['success'] = "Update of #{site.title} to #{u.baseline_process.title} scheduled"
    90:     redirect_to :action => 'description', :id => site.id
    91:   end

update_cancel()

Action update_cancel to cancel an scheduled updated

[Source]

         # File app/controllers/sites_controller.rb, line 94
     94:   def update_cancel
     95:     site = Site.find(params[:id])
     96:     u = Update.find(params[:update_id])
     97:     u.destroy
     98:     flash['success'] = "Cancelled update of #{site.title} to #{u.baseline_process.title}"
     99:     redirect_to :action => 'description', :id => site.id
    100:   end

update_now()

action update_now allows the administrator to do the update immediately, see also update_wiki

[Source]

         # File app/controllers/sites_controller.rb, line 103
    103:   def update_now
    104:     u = Update.find(params[:update_id])
    105:     u.do_update
    106:     flash['success'] = FLASH_WIKI_UPDATE_SUCCESS
    107:     redirect_to :action => 'description', :id => u.wiki.id
    108:   end

uploads()

[Source]

         # File app/controllers/sites_controller.rb, line 147
    147:   def uploads
    148:     @site = Site.find(params[:id])
    149:     @upload_pages, @uploads = paginate :uploads, :order => 'created_on DESC',  :per_page => 25
    150:     render :action => 'description'
    151:   end

versions()

[Source]

         # File app/controllers/sites_controller.rb, line 114
    114:   def versions
    115:     @site = Site.find(params[:id])
    116:     logger.debug("params.inspect: #{params.inspect}")
    117:     @filter = UserVersion.new(params[:filter]) # done is default 'N'
    118:     @filter.type_filter = 'UserVersion' if @filter.type_filter.blank?
    119:     logger.debug("@filter: #{@filter.inspect}")
    120:     case @filter.done + @filter.type_filter
    121:     when 'NAll': cond = ['wiki_id = ? and done = ?', @site.id, 'N',] # default
    122:     when 'AllUserVersion': cond = ['wiki_id = ? and type = ?', @site.id, 'UserVersion' ] # all userversions
    123:     when 'AllAll': cond = ['wiki_id = ?', @site.id] # all versions
    124:     when 'NUserVersion': cond = ['wiki_id = ? and done = ? and type = ?', @site.id, 'N', 'UserVersion' ] # all todo userversions
    125:     end
    126:     logger.debug("cond: #{cond.inspect}")
    127:     @version_pages, @versions = paginate :version, :per_page => 25, :order => 'created_on DESC', :conditions => cond
    128:     render :action => 'description'
    129:   end

[Validate]