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_action.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.controller.name, @my_action.action_name, @operators, params
123 respond_to do |format|
125 @filer = Locmare::Filer.new @list.item_name, @items, @list.page_status, @operators
126 render @filer.template_name, :locals => {
130 list_json_format @list, format
136 def list_json_format list, format
139 :page_status => list.page_status.to_hash,
140 # rails3.2 has problem
141 # y method defined as private
142 # attribute y conflict at PanelPicture, balloon ..etc
143 # use i.attributes[name]
144 :list => list.items.map{|i| i.attributes}
145 # :list => @items.to_json
147 render json: res.to_json
153 @binder_action = @my_action.original
154 @binder_controller = @binder_action.controller
155 @binder_model = Manifest.manifest.models[@binder_action.item_name]
156 @binder_model_class = @binder_model.classify
157 @item = @binder_model_class.show(params[:id], @operators)
161 @items = @list.items #.map {|sp| sp.root }
163 @pager = @list.page_status.pager
168 @item = @my_model_class.show(params[:id], @operators)
171 def show_prof_format format
173 self.formats = [:html]
174 @profiler = Locmare::Profiler.new @my_model_class.item_name, @item, @operators
175 render @profiler.template_name, :locals => {
176 :profiler => @profiler
181 def show_json_format format
182 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
185 def show_json_format_for_root format
186 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
191 @item = @my_model_class.new
198 @item = @my_model_class.edit(params[:id], @operators)
203 respond_to do |format|
205 @form = Locmare::Bucket.factory @item.item_name, 'default', @item, true, true, @operators
206 render @form.template_name, :locals => {
210 format.json { render json: @item.to_json }
224 def created_html_format format, redirect_url = nil
226 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
227 redirect_to (redirect_url ? redirect_url : @item)
231 def created_json_format format
233 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
237 def not_created_html_format format
239 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
244 def not_created_json_format format
246 render json: @item.errors, status: :unprocessable_entity
250 def render_create redirect_url = nil
252 respond_to do |format|
253 created_html_format format, redirect_url
254 created_json_format format
257 respond_to do |format|
258 not_created_html_format format
259 not_created_json_format format
264 def leaf_created_html_format format, redirect_url
266 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
267 redirect_to redirect_url
271 def leaf_not_created_html_format format, redirect_url
273 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
274 redirect_to redirect_url
278 def leaf_render_create redirect_url
279 if @item.store @operators
280 respond_to do |format|
281 leaf_created_html_format format, redirect_url
282 created_json_format format
285 respond_to do |format|
286 leaf_not_created_html_format format, redirect_url
287 not_created_json_format format
292 def updated_html_format format, redirect_url = nil
294 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
295 redirect_to (redirect_url ? redirect_url : @item)
299 def updated_json_format format
301 render json: '{}', status: :ok
305 def not_updated_html_format format
307 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
312 def not_updated_json_format format
314 render json: @item.errors, status: :unprocessable_entity
318 def render_update redirect_url = nil
320 respond_to do |format|
321 updated_html_format format, redirect_url
322 updated_json_format format
325 respond_to do |format|
326 not_updated_html_format format
327 not_updated_json_format format
332 def leaf_updated_html_format format, redirect_url
334 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
335 redirect_to redirect_url
339 def leaf_not_updated_html_format format, redirect_url
341 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
342 redirect_to redirect_url
346 def leaf_render_update ot, redirect_url
347 if @item.store @operators, ot
348 respond_to do |format|
349 leaf_updated_html_format format, redirect_url
350 updated_json_format format
353 respond_to do |format|
354 leaf_not_updated_html_format format, redirect_url
355 not_updated_json_format format
360 def destroyed_html_format format, redirect_url
362 flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human)
363 redirect_to redirect_url
367 def destroyed_json_format format
369 render json: '{}', status: :ok
373 def not_destroyed_html_format format
375 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human)
380 def not_destroyed_json_format format
382 render json: @item.errors, status: :unprocessable_entity
386 def render_destroy redirect_url = nil
388 respond_to do |format|
389 destroyed_html_format format, redirect_url
390 destroyed_json_format format
393 respond_to do |format|
394 not_destroyed_html_format format
395 not_destroyed_json_format format
400 def format_filer format
402 @paginate = @@model.list_paginate(@page, @page_size)
403 render :template => 'system/filer', :locals => {
404 :items => @items, :model => @@model,
405 :operators => @operators, :pager => @paginate
410 def format_prof format
412 @profiler = self.class.profiler_manager.open(@item, @operators)
413 render :template => 'system/prof', :locals => {
414 :profiler => @profiler
419 def assist_items controller_name, action_name
420 list = Locmare::ListGroup.list controller_name, action_name, @operators, {:id => @item.id, :page => 1, :page_size => 5}
425 if file.respond_to?(:read)
428 Base64.decode64(file.to_s.gsub(' ', '+'))
432 def ymd_to_time ymd_str
433 return nil if ymd_str.blank?
436 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
443 def export_url demander_url, action, token, date
444 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
445 prm = '?auth_token=' + token
446 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
447 u = URI.join(u, action + '.json' + prm)
451 def export_from_provider url
454 json = RestClient.get url
455 res = JSON.parse json
461 def export_by action, provider_status, ymd
463 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
464 export_from_provider(url)
467 rescue_from Pettanr::NotWork, :with => :render_not_work
468 def render_not_work(exception = nil)
470 logger.info "Rendering , :: #{exception.message}"
472 respond_to do |format|
474 render :file => "#{Rails.root}/public/not_work.html", :layout => false
477 render :text => "400 Not work", :status => 400
482 if Rails.env == 'production'
483 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
484 rescue_from ActiveRecord::Forbidden, :with => :render_403
487 def render_404(exception = nil)
489 logger.info "Rendering 404: #{exception.message}"
491 respond_to do |format|
493 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
496 render :text => "404 Not found", :status => 404
501 def render_403(exception = nil)
503 logger.info "Rendering 403: #{exception.message}"
505 respond_to do |format|
507 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
510 render :text => "403 Forbidden", :status => 403