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 leaf_created_html_format format, redirect_url
258 flash[:notice] = I18n.t('flash.notice.created', :model => @my_model_class.model_name.human)
259 redirect_to redirect_url
263 def leaf_not_created_html_format format, redirect_url
265 flash[:notice] = I18n.t('flash.notice.not_created', :model => @my_model_class.model_name.human)
266 redirect_to redirect_url
270 def leaf_render_create redirect_url
271 if @item.store @operators
272 respond_to do |format|
273 leaf_created_html_format format, redirect_url
274 created_json_format format
277 respond_to do |format|
278 leaf_not_created_html_format format, redirect_url
279 not_created_json_format format
284 def updated_html_format format
286 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
291 def updated_json_format format
297 def not_update_html_format format
299 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
304 def not_updated_json_format format
306 render json: @item.errors, status: :unprocessable_entity
312 respond_to do |format|
313 updated_html_format format
314 updated_json_format format
317 respond_to do |format|
318 not_updated_html_format format
319 not_updated_json_format format
324 def leaf_updated_html_format format, redirect_url
326 flash[:notice] = I18n.t('flash.notice.updated', :model => @my_model_class.model_name.human)
327 redirect_to redirect_url
331 def leaf_not_update_html_format format, redirect_url
333 flash[:notice] = I18n.t('flash.notice.not_updated', :model => @my_model_class.model_name.human)
334 redirect_to redirect_url
338 def leaf_render_update ot, redirect_url
339 if @item.store @operators, ot
340 respond_to do |format|
341 leaf_updated_html_format format, redirect_url
342 updated_json_format format
345 respond_to do |format|
346 leaf_not_updated_html_format format, redirect_url
347 not_updated_json_format format
354 j = {:count => @list.count(@operators, {:id => params[:id]})}
355 respond_to do |format|
356 format.json { render json: j.to_json }
360 def format_filer format
362 @paginate = @@model.list_paginate(@page, @page_size)
363 render :template => 'system/filer', :locals => {
364 :items => @items, :model => @@model,
365 :operators => @operators, :pager => @paginate
370 def format_prof format
372 @profiler = self.class.profiler_manager.open(@item, @operators)
373 render :template => 'system/prof', :locals => {
374 :profiler => @profiler
379 def assist_items item_name, list_name
380 list = Locmare::ListGroup.list item_name, list_name
381 list_result = list.open(@operators, {:id => @item.id, :page => 1, :page_size => 5})
386 if file.respond_to?(:read)
389 Base64.decode64(file.to_s.gsub(' ', '+'))
393 def ymd_to_time ymd_str
394 return nil if ymd_str.blank?
397 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
404 def export_url demander_url, action, token, date
405 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
406 prm = '?auth_token=' + token
407 prm = prm + '&date=' + date.strftime("%Y%m%d") unless date.blank?
408 u = URI.join(u, action + '.json' + prm)
412 def export_from_provider url
415 json = RestClient.get url
416 res = JSON.parse json
422 def export_by action, provider_status, ymd
424 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
425 export_from_provider(url)
428 rescue_from Pettanr::NotWork, :with => :render_not_work
429 def render_not_work(exception = nil)
431 logger.info "Rendering , :: #{exception.message}"
433 respond_to do |format|
435 render :file => "#{Rails.root}/public/not_work.html", :layout => false
438 render :text => "400 Not work", :status => 400
443 if Rails.env == 'production'
444 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
445 rescue_from ActiveRecord::Forbidden, :with => :render_403
448 def render_404(exception = nil)
450 logger.info "Rendering 404: #{exception.message}"
452 respond_to do |format|
454 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
457 render :text => "404 Not found", :status => 404
462 def render_403(exception = nil)
464 logger.info "Rendering 403: #{exception.message}"
466 respond_to do |format|
468 render :file => "#{Rails.root}/public/403.html", :status => 404, :layout => false
471 render :text => "403 Forbidden", :status => 403