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

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

[Source]

     # File app/controllers/sites_controller.rb, line 126
126:   def comments
127:     @site = Site.find(params[:id])
128:     @comment_pages, @comments = paginate :comment, :per_page => 25, :order => 'created_on DESC', :conditions => ['site_id = ?', @site.id ]
129:     render :action => 'description'
130:   end

[Source]

     # File app/controllers/sites_controller.rb, line 174
174:   def csv
175:     site = Site.find(params[:id])
176:     content_type = if request.user_agent =~ /windows/i
177:       'application/vnd.ms-excel'
178:     else
179:       'text/csv'
180:     end
181:     site.export_csv if !File.exists?(site.path + '.csv')
182:     send_data(IO.readlines(site.path + '.csv').join, :type => content_type, :filename => site.folder + '.csv')
183:   end

[Source]

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

[Source]

     # File app/controllers/sites_controller.rb, line 144
144:   def edit
145:     @site = Site.find(params[:id])
146:     if request.get?
147:       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 manuall on the filesystem' 
148:     else 
149:       @site = Site.find(params[:id])
150:       if @site.update_attributes(params[:site])
151:         flash['success'] = 'Site was successfully updated.'
152:         redirect_to :action => 'description', :id => @site
153:       else
154:         render :action => 'edit'
155:       end
156:     end
157:   end

[Source]

     # File app/controllers/sites_controller.rb, line 138
138:   def feedback
139:     @site = Site.find(params[:id])
140:     @feedback_pages, @feedbacks = paginate :feedbacks, :order => 'created_on DESC',  :per_page => 25
141:     render :action => 'description'
142:   end

[Source]

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

[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

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

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

[Source]

     # File app/controllers/sites_controller.rb, line 159
159:   def obsolete
160:     site = Site.find(params[:id])
161:     site.obsolete_by = session['user']
162:     if site.obsolete_on.nil?
163:       site.obsolete_on = Time.now
164:       flash.now['success'] = "#{site.title} succesfully made obsolete"
165:     else
166:       site.obsolete_on = nil
167:       flash.now['success'] = "#{site.title} is no longer obsolete"      
168:     end
169:     site.save!
170:     list
171:     render :action => 'list'
172:   end

[Source]

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

[Source]

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

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

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

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

[Source]

     # File app/controllers/sites_controller.rb, line 132
132:   def uploads
133:     @site = Site.find(params[:id])
134:     @upload_pages, @uploads = paginate :uploads, :order => 'created_on DESC',  :per_page => 25
135:     render :action => 'description'
136:   end

[Source]

     # File app/controllers/sites_controller.rb, line 114
114:   def versions
115:     @site = Site.find(params[:id])
116:     @version_pages, @versions = paginate :version, :per_page => 25, :order => 'created_on DESC', :conditions => ['wiki_id = ?', @site.id ]    
117:     render :action => 'description'
118:   end

[Validate]