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_list = my_model.lists[my_action.list_name]
116 my_list = Manifest.manifest.lists[my_action.item_name]
117 @list = my_list[my_action.list_name]
122 list_result = @list.open(@operators, {:id => params[:id]})
123 @items = list_result.items
124 respond_to do |format|
126 @filer = Manifest::View::Filer.new @list.item_name, list_result.items, list_result.paginate, @operators
127 render @filer.template_name, :locals => {
131 format.json { render json: @items.to_json(self.class.model.list_json_opt) }
139 j = {:count => @list.count(@operators, {:id => params[:id]})}
140 respond_to do |format|
141 format.json { render json: j.to_json }
145 def format_filer format
147 @paginate = @@model.list_paginate(@page, @page_size)
148 render :template => 'system/filer', :locals => {
149 :items => @items, :model => @@model,
150 :operators => @operators, :pager => @paginate
155 def format_prof format
157 @profiler = self.class.profiler_manager.open(@item, @operators)
158 render :template => 'system/prof', :locals => {
159 :profiler => @profiler
164 def assist_items item_name, list_name
165 list_manager = Pettanr::Application::manifest.list_managers[item_name]
166 list = list_manager.open list_name, 1, 5, @operators
170 def assist_filer item_name, items
171 filer_manager = Pettanr::Application::manifest.filer_managers[item_name]
172 filer_manager.open(item_name, items, @operators, nil)
176 if file.respond_to?(:read)
179 Base64.decode64(file.to_s.gsub(' ', '+'))
183 def ymd_to_time ymd_str
184 return nil if ymd_str.blank?
187 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
194 def export_url demander_url, action, token, date
195 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
196 prm = '?auth_token=' + token
197 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
198 u = URI.join(u, action + '.json' + prm)
202 def export_from_provider url
205 json = RestClient.get url
206 res = JSON.parse json
212 def export_by action, provider_status, ymd
214 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
215 export_from_provider(url)
218 rescue_from Pettanr::NotWork, :with => :render_not_work
219 def render_not_work(exception = nil)
221 logger.info "Rendering , :: #{exception.message}"
223 respond_to do |format|
225 render :file => "#{Rails.root}/public/not_work.html", :layout => false
228 render :text => "400 Not work", :status => 400
233 if Rails.env == 'production'
234 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
235 rescue_from ActiveRecord::Forbidden, :with => :render_403
238 def render_404(exception = nil)
240 logger.info "Rendering 404: #{exception.message}"
242 respond_to do |format|
244 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
247 render :text => "404 Not found", :status => 404
252 def render_403(exception = nil)
254 logger.info "Rendering 403: #{exception.message}"
256 respond_to do |format|
258 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
261 render :text => "403 Forbidden", :status => 403