1 class ApplicationController < ActionController::Base
23 :location => {:controller => params[:controller], :action => params[:action]}
25 @server_result[:location][:id] = params[:id] if params[:id]
26 if Admin.count.to_i == 0 or License.count.to_i == 0
27 if params[:controller] == 'system' and params[:action] == 'start'
29 redirect_to :controller => '/system', :action => 'start'
32 user = if user_signed_in?
47 admin = if admin_signed_in?
52 demand_user = if demand_user_signed_in?
57 @operators = Operator.new [user, author, artist, admin, demand_user]
61 def authenticate_reader
62 authenticate_user! unless @operators.reader?
66 authenticate_user! unless @operators.user?
69 def authenticate_resource_reader
70 authenticate_user! unless @operators.resource_reader?
73 def authenticate_author
77 respond_to do |format|
78 format.html { redirect_to main_app.new_author_path, :status => :found }
79 format.js { render "authors/new" }
81 raise ActiveRecord::Forbidden
88 def authenticate_artist
92 respond_to do |format|
93 format.html { redirect_to main_app.new_artist_path, :status => :found }
94 format.js { render "artists/new" }
96 raise ActiveRecord::Forbidden
104 Manifest.manifest.controllers[self.model.item_name]
107 def self.profiler_manager
108 Manifest.manifest.profiler_managers[self.model.item_name]
112 @my_controller = Manifest.manifest.controllers[params[:controller].to_s]
113 @my_action = @my_controller.actions[params[:action].to_s]
114 @my_model = Manifest.manifest.models[@my_action.item_name]
115 @my_model_class = @my_model.classify
120 @my_model_list = @my_model.lists[@my_action.list_name]
121 @my_list = Manifest.manifest.lists[@my_action.item_name]
122 @list = @my_list[@my_action.list_name]
127 list_result = @list.open(@operators, {:id => params[:id]})
128 @items = list_result.items
129 respond_to do |format|
131 @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators
132 render @filer.template_name, :locals => {
136 format.json { render json: @items.to_json(@my_model_class.list_json_opt) }
144 @item = @my_model_class.show(params[:id], @operators)
149 @item = @my_model_class.new
155 @item = @my_model_class.edit(params[:id], @operators)
159 respond_to do |format|
161 @form = Manifest::View::Form.new @item.item_name, @item, true, true, @operators
162 render @form.template_name, :locals => {
166 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
182 j = {:count => @list.count(@operators, {:id => params[:id]})}
183 respond_to do |format|
184 format.json { render json: j.to_json }
188 def format_filer format
190 @paginate = @@model.list_paginate(@page, @page_size)
191 render :template => 'system/filer', :locals => {
192 :items => @items, :model => @@model,
193 :operators => @operators, :pager => @paginate
198 def format_prof format
200 @profiler = self.class.profiler_manager.open(@item, @operators)
201 render :template => 'system/prof', :locals => {
202 :profiler => @profiler
207 def assist_items item_name, list_name
208 list = Manifest.manifest.lists[item_name][list_name]
209 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
213 def assist_filer item_name, items
214 @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators
215 filer_manager = Pettanr::Application::manifest.filer_managers[item_name]
216 filer_manager.open(item_name, items, @operators, nil)
220 if file.respond_to?(:read)
223 Base64.decode64(file.to_s.gsub(' ', '+'))
227 def ymd_to_time ymd_str
228 return nil if ymd_str.blank?
231 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
238 def export_url demander_url, action, token, date
239 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
240 prm = '?auth_token=' + token
241 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
242 u = URI.join(u, action + '.json' + prm)
246 def export_from_provider url
249 json = RestClient.get url
250 res = JSON.parse json
256 def export_by action, provider_status, ymd
258 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
259 export_from_provider(url)
262 rescue_from Pettanr::NotWork, :with => :render_not_work
263 def render_not_work(exception = nil)
265 logger.info "Rendering , :: #{exception.message}"
267 respond_to do |format|
269 render :file => "#{Rails.root}/public/not_work.html", :layout => false
272 render :text => "400 Not work", :status => 400
277 if Rails.env == 'production'
278 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
279 rescue_from ActiveRecord::Forbidden, :with => :render_403
282 def render_404(exception = nil)
284 logger.info "Rendering 404: #{exception.message}"
286 respond_to do |format|
288 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
291 render :text => "404 Not found", :status => 404
296 def render_403(exception = nil)
298 logger.info "Rendering 403: #{exception.message}"
300 respond_to do |format|
302 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
305 render :text => "403 Forbidden", :status => 403