1 class ApplicationController < ActionController::Base
23 :location => {:controller => params[:controller], :action => params[:action]}
25 @server_result[:location][:id] = params[:id] if params[:id]
26 user = if user_signed_in?
41 admin = if admin_signed_in?
46 demand_user = if demand_user_signed_in?
51 @operators = Operator.new [user, author, artist, admin, demand_user]
54 def authenticate_reader
55 authenticate_user! unless @operators.reader?
59 authenticate_user! unless @operators.user?
62 def authenticate_resource_reader
63 authenticate_user! unless @operators.resource_reader?
66 def authenticate_admin
67 authenticate_admin! unless @operators.admin?
70 def authenticate_author
74 respond_to do |format|
75 format.html { redirect_to main_app.new_author_path, :status => :found }
77 raise ActiveRecord::Forbidden
84 def authenticate_artist
88 respond_to do |format|
89 format.html { redirect_to main_app.new_artist_path, :status => :found }
91 raise ActiveRecord::Forbidden
99 Manifest.manifest.controllers[self.model.item_name]
102 def self.profiler_manager
103 Manifest.manifest.profiler_managers[self.model.item_name]
107 @my_controller = Manifest.manifest.controllers[params[:controller].to_s]
108 @my_action = @my_controller.actions[params[:action].to_s]
109 @my_model = Manifest.manifest.models[@my_controller.item_name]
110 @my_model_class = @my_model.classify
115 @my_list_model = Manifest.manifest.models[@my_action.item_name]
116 @my_list_model_class = @my_list_model.classify
117 @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
122 list_result = @list.open(@operators,
123 {:id => params[:id], :page => params[:page], :page_size => params[:page_size]}
125 @items = list_result.items
126 respond_to do |format|
128 @filer = Locmare::Filer.new @list.item_name, list_result.items, list_result, :default, @operators
129 render @filer.template_name, :locals => {
133 format.json { render json: @items.to_json }
141 @item = @my_model_class.show(params[:id], @operators)
145 @options = {:id => params[:id], :my_play => @item.own?(@operators),
146 :offset => params[:offset], :count => params[:count],
147 :page => params[:page], :page_size => params[:page_size]
149 list_result = @list.open(@operators, @options)
150 @items = list_result.items
151 @count = list_result.count
152 @pager = list_result.paginate
157 @item = @my_model_class.show(params[:id], @operators)
160 def show_prof_format format
162 self.formats = [:html]
163 @profiler = Locmare::Profiler.new @my_model.model_name, @item, @operators
164 render @profiler.template_name, :locals => {
165 :profiler => @profiler
170 def show_json_format format
171 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
174 def show_json_format_for_root format
175 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
180 @item = @my_model_class.new
187 @item = @my_model_class.edit(params[:id], @operators)
192 respond_to do |format|
194 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
195 render @form.template_name, :locals => {
199 format.json { render json: @item.to_json }
213 def created_html_format format, redirect_url = nil
215 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
216 redirect_to (redirect_url ? redirect_url : @item)
220 def created_json_format format
222 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
226 def not_created_html_format format
228 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
233 def not_created_json_format format
235 render json: @item.errors, status: :unprocessable_entity
239 def render_create redirect_url = nil
241 respond_to do |format|
242 created_html_format format, redirect_url
243 created_json_format format
246 respond_to do |format|
247 not_created_html_format format
248 not_created_json_format format
253 def leaf_created_html_format format, redirect_url
255 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
256 redirect_to redirect_url
260 def leaf_not_created_html_format format, redirect_url
262 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
263 redirect_to redirect_url
267 def leaf_render_create redirect_url
268 if @item.store @operators
269 respond_to do |format|
270 leaf_created_html_format format, redirect_url
271 created_json_format format
274 respond_to do |format|
275 leaf_not_created_html_format format, redirect_url
276 not_created_json_format format
281 def updated_html_format format, redirect_url = nil
283 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
284 redirect_to (redirect_url ? redirect_url : @item)
288 def updated_json_format format
294 def not_updated_html_format format
296 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
301 def not_updated_json_format format
303 render json: @item.errors, status: :unprocessable_entity
307 def render_update redirect_url = nil
309 respond_to do |format|
310 updated_html_format format, redirect_url
311 updated_json_format format
314 respond_to do |format|
315 not_updated_html_format format
316 not_updated_json_format format
321 def leaf_updated_html_format format, redirect_url
323 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
324 redirect_to redirect_url
328 def leaf_not_updated_html_format format, redirect_url
330 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
331 redirect_to redirect_url
335 def leaf_render_update ot, redirect_url
336 if @item.store @operators, ot
337 respond_to do |format|
338 leaf_updated_html_format format, redirect_url
339 updated_json_format format
342 respond_to do |format|
343 leaf_not_updated_html_format format, redirect_url
344 not_updated_json_format format
349 def destroyed_html_format format, redirect_url
351 flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human)
352 redirect_to redirect_url
356 def destroyed_json_format format
362 def not_destroyed_html_format format
364 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human)
369 def not_destroyed_json_format format
371 render json: @item.errors, status: :unprocessable_entity
375 def render_destroy redirect_url = nil
377 respond_to do |format|
378 destroyed_html_format format, redirect_url
379 destroyed_json_format format
382 respond_to do |format|
383 not_destroyed_html_format format
384 not_destroyed_json_format format
391 j = {:count => @list.count(@operators, {:id => params[:id]})}
392 respond_to do |format|
393 format.json { render json: j.to_json }
397 def format_filer format
399 @paginate = @@model.list_paginate(@page, @page_size)
400 render :template => 'system/filer', :locals => {
401 :items => @items, :model => @@model,
402 :operators => @operators, :pager => @paginate
407 def format_prof format
409 @profiler = self.class.profiler_manager.open(@item, @operators)
410 render :template => 'system/prof', :locals => {
411 :profiler => @profiler
416 def assist_items item_name, list_name
417 list = Locmare::ListGroup.list item_name, list_name
418 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
423 if file.respond_to?(:read)
426 Base64.decode64(file.to_s.gsub(' ', '+'))
430 def ymd_to_time ymd_str
431 return nil if ymd_str.blank?
434 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
441 def export_url demander_url, action, token, date
442 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
443 prm = '?auth_token=' + token
444 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
445 u = URI.join(u, action + '.json' + prm)
449 def export_from_provider url
452 json = RestClient.get url
453 res = JSON.parse json
459 def export_by action, provider_status, ymd
461 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
462 export_from_provider(url)
465 rescue_from Pettanr::NotWork, :with => :render_not_work
466 def render_not_work(exception = nil)
468 logger.info "Rendering , :: #{exception.message}"
470 respond_to do |format|
472 render :file => "#{Rails.root}/public/not_work.html", :layout => false
475 render :text => "400 Not work", :status => 400
480 if Rails.env == 'production'
481 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
482 rescue_from ActiveRecord::Forbidden, :with => :render_403
485 def render_404(exception = nil)
487 logger.info "Rendering 404: #{exception.message}"
489 respond_to do |format|
491 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
494 render :text => "404 Not found", :status => 404
499 def render_403(exception = nil)
501 logger.info "Rendering 403: #{exception.message}"
503 respond_to do |format|
505 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
508 render :text => "403 Forbidden", :status => 403