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_admin
74 authenticate_admin! unless @operators.admin?
77 def authenticate_author
81 respond_to do |format|
82 format.html { redirect_to main_app.new_author_path, :status => :found }
83 format.js { render "authors/new" }
85 raise ActiveRecord::Forbidden
92 def authenticate_artist
96 respond_to do |format|
97 format.html { redirect_to main_app.new_artist_path, :status => :found }
98 format.js { render "artists/new" }
100 raise ActiveRecord::Forbidden
108 Manifest.manifest.controllers[self.model.item_name]
111 def self.profiler_manager
112 Manifest.manifest.profiler_managers[self.model.item_name]
116 @my_controller = Manifest.manifest.controllers[params[:controller].to_s]
117 @my_action = @my_controller.actions[params[:action].to_s]
118 @my_model = Manifest.manifest.models[@my_action.item_name]
119 @my_model_class = @my_model.classify
124 @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
129 list_result = @list.open(@operators,
130 {:id => params[:id], :page => params[:page], :page_size => params[:page_size]}
132 @items = list_result.items
133 respond_to do |format|
135 @filer = Locmare::Filer.new @list.item_name, list_result.items, list_result, :default, @operators
136 render @filer.template_name, :locals => {
140 format.json { render json: @items.to_json }
148 @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
152 @options = {:id => params[:id], :my_play => @item.own?(@operators),
153 :offset => params[:offset], :count => params[:count],
154 :page => params[:page], :page_size => params[:page_size]
156 list_result = @list.open(@operators, @options)
157 @items = list_result.items
158 @count = list_result.count
159 @pager = list_result.paginate
164 @item = @my_model_class.show(params[:id], @operators)
167 def show_prof_format format
169 self.formats = [:html]
170 @profiler = Locmare::Profiler.new @my_model.model_name, @item, @operators
171 render @profiler.template_name, :locals => {
172 :profiler => @profiler
177 def show_json_format format
178 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
183 @item = @my_model_class.new
190 @item = @my_model_class.edit(params[:id], @operators)
195 respond_to do |format|
197 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
198 render @form.template_name, :locals => {
202 format.json { render json: @item.to_json }
216 def created_html_format format
218 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
223 def created_json_format format
225 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
229 def not_created_html_format format
231 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
236 def not_created_json_format format
238 render json: @item.errors, status: :unprocessable_entity
244 respond_to do |format|
245 created_html_format format
246 created_json_format format
249 respond_to do |format|
250 not_created_html_format format
251 not_created_json_format format
256 def updated_html_format format
258 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
263 def updated_json_format format
269 def not_update_html_format format
271 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
276 def not_updated_json_format format
278 render json: @item.errors, status: :unprocessable_entity
284 respond_to do |format|
285 updated_html_format format
286 updated_json_format format
289 respond_to do |format|
290 not_updated_html_format format
291 not_updated_json_format format
298 j = {:count => @list.count(@operators, {:id => params[:id]})}
299 respond_to do |format|
300 format.json { render json: j.to_json }
304 def format_filer format
306 @paginate = @@model.list_paginate(@page, @page_size)
307 render :template => 'system/filer', :locals => {
308 :items => @items, :model => @@model,
309 :operators => @operators, :pager => @paginate
314 def format_prof format
316 @profiler = self.class.profiler_manager.open(@item, @operators)
317 render :template => 'system/prof', :locals => {
318 :profiler => @profiler
323 def assist_items item_name, list_name
324 list = Locmare::ListGroup.list item_name, list_name
325 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
330 if file.respond_to?(:read)
333 Base64.decode64(file.to_s.gsub(' ', '+'))
337 def ymd_to_time ymd_str
338 return nil if ymd_str.blank?
341 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
348 def export_url demander_url, action, token, date
349 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
350 prm = '?auth_token=' + token
351 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
352 u = URI.join(u, action + '.json' + prm)
356 def export_from_provider url
359 json = RestClient.get url
360 res = JSON.parse json
366 def export_by action, provider_status, ymd
368 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
369 export_from_provider(url)
372 rescue_from Pettanr::NotWork, :with => :render_not_work
373 def render_not_work(exception = nil)
375 logger.info "Rendering , :: #{exception.message}"
377 respond_to do |format|
379 render :file => "#{Rails.root}/public/not_work.html", :layout => false
382 render :text => "400 Not work", :status => 400
387 if Rails.env == 'production'
388 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
389 rescue_from ActiveRecord::Forbidden, :with => :render_403
392 def render_404(exception = nil)
394 logger.info "Rendering 404: #{exception.message}"
396 respond_to do |format|
398 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
401 render :text => "404 Not found", :status => 404
406 def render_403(exception = nil)
408 logger.info "Rendering 403: #{exception.message}"
410 respond_to do |format|
412 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
415 render :text => "403 Forbidden", :status => 403