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) }
181 def show_json_format_for_root format
182 format.json { render json: @item.to_json(@my_model_class.show_json_opt_for_root) }
187 @item = @my_model_class.new
194 @item = @my_model_class.edit(params[:id], @operators)
199 respond_to do |format|
201 @form = Locmare::Bucket.factory @item.item_name, @item, true, true, @operators
202 render @form.template_name, :locals => {
206 format.json { render json: @item.to_json }
220 def created_html_format format, redirect_url = nil
222 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
223 redirect_to (redirect_url ? redirect_url : @item)
227 def created_json_format format
229 render json: @item.to_json(@my_model_class.show_json_opt), status: :created, location: @item
233 def not_created_html_format format
235 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
240 def not_created_json_format format
242 render json: @item.errors, status: :unprocessable_entity
246 def render_create redirect_url = nil
248 respond_to do |format|
249 created_html_format format, redirect_url
250 created_json_format format
253 respond_to do |format|
254 not_created_html_format format
255 not_created_json_format format
260 def leaf_created_html_format format, redirect_url
262 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
263 redirect_to redirect_url
267 def leaf_not_created_html_format format, redirect_url
269 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
270 redirect_to redirect_url
274 def leaf_render_create redirect_url
275 if @item.store @operators
276 respond_to do |format|
277 leaf_created_html_format format, redirect_url
278 created_json_format format
281 respond_to do |format|
282 leaf_not_created_html_format format, redirect_url
283 not_created_json_format format
288 def updated_html_format format, redirect_url = nil
290 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
291 redirect_to (redirect_url ? redirect_url : @item)
295 def updated_json_format format
301 def not_update_html_format format
303 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
308 def not_updated_json_format format
310 render json: @item.errors, status: :unprocessable_entity
314 def render_update redirect_url = nil
316 respond_to do |format|
317 updated_html_format format, redirect_url
318 updated_json_format format
321 respond_to do |format|
322 not_updated_html_format format
323 not_updated_json_format format
328 def leaf_updated_html_format format, redirect_url
330 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
331 redirect_to redirect_url
335 def leaf_not_update_html_format format, redirect_url
337 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
338 redirect_to redirect_url
342 def leaf_render_update ot, redirect_url
343 if @item.store @operators, ot
344 respond_to do |format|
345 leaf_updated_html_format format, redirect_url
346 updated_json_format format
349 respond_to do |format|
350 leaf_not_updated_html_format format, redirect_url
351 not_updated_json_format format
358 j = {:count => @list.count(@operators, {:id => params[:id]})}
359 respond_to do |format|
360 format.json { render json: j.to_json }
364 def format_filer format
366 @paginate = @@model.list_paginate(@page, @page_size)
367 render :template => 'system/filer', :locals => {
368 :items => @items, :model => @@model,
369 :operators => @operators, :pager => @paginate
374 def format_prof format
376 @profiler = self.class.profiler_manager.open(@item, @operators)
377 render :template => 'system/prof', :locals => {
378 :profiler => @profiler
383 def assist_items item_name, list_name
384 list = Locmare::ListGroup.list item_name, list_name
385 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
390 if file.respond_to?(:read)
393 Base64.decode64(file.to_s.gsub(' ', '+'))
397 def ymd_to_time ymd_str
398 return nil if ymd_str.blank?
401 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
408 def export_url demander_url, action, token, date
409 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
410 prm = '?auth_token=' + token
411 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
412 u = URI.join(u, action + '.json' + prm)
416 def export_from_provider url
419 json = RestClient.get url
420 res = JSON.parse json
426 def export_by action, provider_status, ymd
428 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
429 export_from_provider(url)
432 rescue_from Pettanr::NotWork, :with => :render_not_work
433 def render_not_work(exception = nil)
435 logger.info "Rendering , :: #{exception.message}"
437 respond_to do |format|
439 render :file => "#{Rails.root}/public/not_work.html", :layout => false
442 render :text => "400 Not work", :status => 400
447 if Rails.env == 'production'
448 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
449 rescue_from ActiveRecord::Forbidden, :with => :render_403
452 def render_404(exception = nil)
454 logger.info "Rendering 404: #{exception.message}"
456 respond_to do |format|
458 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
461 render :text => "404 Not found", :status => 404
466 def render_403(exception = nil)
468 logger.info "Rendering 403: #{exception.message}"
470 respond_to do |format|
472 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
475 render :text => "403 Forbidden", :status => 403