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 @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
120 list_result = @list.open(@operators,
121 {:id => params[:id], :page => params[:page], :page_size => params[:page_size]}
123 @items = list_result.items
124 respond_to do |format|
126 @filer = Locmare::Filer.new @list.item_name, list_result.items, list_result, :default, @operators
127 render @filer.template_name, :locals => {
131 format.json { render json: @items.to_json }
139 @list = Locmare::ListGroup.list @my_action.item_name, @my_action.list_name
143 @options = {:id => params[:id], :my_play => @item.own?(@operators),
144 :offset => params[:offset], :count => params[:count],
145 :page => params[:page], :page_size => params[:page_size]
147 list_result = @list.open(@operators, @options)
148 @items = list_result.items
149 @count = list_result.count
150 @pager = list_result.paginate
155 @item = @my_model_class.show(params[:id], @operators)
158 def show_prof_format format
160 self.formats = [:html]
161 @profiler = Locmare::Profiler.new @my_model.model_name, @item, @operators
162 render @profiler.template_name, :locals => {
163 :profiler => @profiler
168 def show_json_format format
169 format.json { render json: @item.to_json(@my_model_class.show_json_opt) }
172 def show_json_format_for_root format
173 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
178 @item = @my_model_class.new
185 @item = @my_model_class.edit(params[:id], @operators)
190 respond_to do |format|
192 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
193 render @form.template_name, :locals => {
197 format.json { render json: @item.to_json }
211 def created_html_format format, redirect_url = nil
213 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
214 redirect_to (redirect_url ? redirect_url : @item)
218 def created_json_format format
220 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
224 def not_created_html_format format
226 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
231 def not_created_json_format format
233 render json: @item.errors, status: :unprocessable_entity
237 def render_create redirect_url = nil
239 respond_to do |format|
240 created_html_format format, redirect_url
241 created_json_format format
244 respond_to do |format|
245 not_created_html_format format
246 not_created_json_format format
251 def leaf_created_html_format format, redirect_url
253 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
254 redirect_to redirect_url
258 def leaf_not_created_html_format format, redirect_url
260 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
261 redirect_to redirect_url
265 def leaf_render_create redirect_url
266 if @item.store @operators
267 respond_to do |format|
268 leaf_created_html_format format, redirect_url
269 created_json_format format
272 respond_to do |format|
273 leaf_not_created_html_format format, redirect_url
274 not_created_json_format format
279 def updated_html_format format, redirect_url = nil
281 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
282 redirect_to (redirect_url ? redirect_url : @item)
286 def updated_json_format format
292 def not_updated_html_format format
294 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
299 def not_updated_json_format format
301 render json: @item.errors, status: :unprocessable_entity
305 def render_update redirect_url = nil
307 respond_to do |format|
308 updated_html_format format, redirect_url
309 updated_json_format format
312 respond_to do |format|
313 not_updated_html_format format
314 not_updated_json_format format
319 def leaf_updated_html_format format, redirect_url
321 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
322 redirect_to redirect_url
326 def leaf_not_updated_html_format format, redirect_url
328 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
329 redirect_to redirect_url
333 def leaf_render_update ot, redirect_url
334 if @item.store @operators, ot
335 respond_to do |format|
336 leaf_updated_html_format format, redirect_url
337 updated_json_format format
340 respond_to do |format|
341 leaf_not_updated_html_format format, redirect_url
342 not_updated_json_format format
347 def destroyed_html_format format, redirect_url
349 flash[:notice] = I18n.t('flash.notice.destroyed', :model => @my_model_class.model_name.human)
350 redirect_to redirect_url
354 def destroyed_json_format format
360 def not_destroyed_html_format format
362 flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => @my_model_class.model_name.human)
367 def not_destroyed_json_format format
369 render json: @item.errors, status: :unprocessable_entity
373 def render_destroy redirect_url = nil
375 respond_to do |format|
376 destroyed_html_format format, redirect_url
377 destroyed_json_format format
380 respond_to do |format|
381 not_destroyed_html_format format
382 not_destroyed_json_format format
389 j = {:count => @list.count(@operators, {:id => params[:id]})}
390 respond_to do |format|
391 format.json { render json: j.to_json }
395 def format_filer format
397 @paginate = @@model.list_paginate(@page, @page_size)
398 render :template => 'system/filer', :locals => {
399 :items => @items, :model => @@model,
400 :operators => @operators, :pager => @paginate
405 def format_prof format
407 @profiler = self.class.profiler_manager.open(@item, @operators)
408 render :template => 'system/prof', :locals => {
409 :profiler => @profiler
414 def assist_items item_name, list_name
415 list = Locmare::ListGroup.list item_name, list_name
416 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
421 if file.respond_to?(:read)
424 Base64.decode64(file.to_s.gsub(' ', '+'))
428 def ymd_to_time ymd_str
429 return nil if ymd_str.blank?
432 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
439 def export_url demander_url, action, token, date
440 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
441 prm = '?auth_token=' + token
442 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
443 u = URI.join(u, action + '.json' + prm)
447 def export_from_provider url
450 json = RestClient.get url
451 res = JSON.parse json
457 def export_by action, provider_status, ymd
459 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
460 export_from_provider(url)
463 rescue_from Pettanr::NotWork, :with => :render_not_work
464 def render_not_work(exception = nil)
466 logger.info "Rendering , :: #{exception.message}"
468 respond_to do |format|
470 render :file => "#{Rails.root}/public/not_work.html", :layout => false
473 render :text => "400 Not work", :status => 400
478 if Rails.env == 'production'
479 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
480 rescue_from ActiveRecord::Forbidden, :with => :render_403
483 def render_404(exception = nil)
485 logger.info "Rendering 404: #{exception.message}"
487 respond_to do |format|
489 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
492 render :text => "404 Not found", :status => 404
497 def render_403(exception = nil)
499 logger.info "Rendering 403: #{exception.message}"
501 respond_to do |format|
503 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
506 render :text => "403 Forbidden", :status => 403