OSDN Git Service

fix: rp update faild
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index 1148e8d..6850873 100644 (file)
 class ResourcePicturesController < ApplicationController
-  layout 'test' if MagicNumber['test_layout']
-  if MagicNumber['run_mode'] == 0
-    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
-    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+  if Manifest.manifest.magic_numbers['run_mode'] == 0
+    before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
   else
-    before_filter :authenticate_resource_reader, :only => [:index, :show, :credit]
-    before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
-    before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_resource_reader, :only => [
+      :index, :show, :credit, 
+      :by_original_picture, :by_license_group, :by_license, :by_artist, :search
+    ]
+    before_action :authenticate_user, :only => [:new, :create, :update, :destroy]
+    before_action :authenticate_artist, :only => [:new, :create, :update, :destroy]
   end
-  before_filter :authenticate_admin!, :only => [:list, :browse]
-
+  
   def index
-    @page = ResourcePicture.page params[:page]
-    @page_size = ResourcePicture.page_size params[:page_size]
-    @resource_pictures = ResourcePicture.list(@page, @page_size)
-
-    respond_to do |format|
-      format.html {
-        @paginate = ResourcePicture.list_paginate(@page, @page_size)
-        render :template => 'system/filer', :locals => {
-          :items => @resource_pictures, :model => ResourcePicture, 
-          :roles => [@user, @admin], :pager => @paginate
-        }
-      }
-      format.json { render :json => @resource_pictures.to_json(ResourcePicture.list_json_opt) }
-    end
+    filer_list
+  end
+  
+  def by_original_picture
+    filer_list param: params[:id]
+  end
+  
+  def by_license_group
+    filer_list param: params[:id]
   end
-
+  
+  def by_license
+    filer_list param: params[:id]
+  end
+  
+  def by_artist
+    filer_list param: params[:id]
+  end
+  
+  def show_html_format format
+    format.html {
+      @item.boosts 'post'
+    }
+  end
+  
   def show
-    @item = ResourcePicture.show(params[:id], [@user, @admin, @demand_user])
-
+    set_show
     respond_to do |format|
       opt = {:type => @item.mime_type, :disposition=>"inline"}
       format.png { send_data(@item.restore(params[:subdir]), opt ) }
       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
-      format.html {
-        @resource_picture = @item
-      }
-      format_prof format
-      format.json { render :json => @item.to_json(ResourcePicture.show_json_opt)}
+      show_html_format format
+      show_prof_format format
+      show_json_format format
     end
   end
   
   def credit
-    @resource_picture = ResourcePicture.show(params[:id], [@user, @admin, @demand_user])
-
+    @resource_picture = ResourcePicture.show(params[:id], @operators)
+    
     respond_to do |format|
       format.html { render :layout => false } # show.html.erb
-      format.json { render :json => @resource_picture.to_json(ResourcePicture.show_json_opt)}
     end
   end
   
   def new
-    @original_picture = OriginalPicture.edit params[:original_picture_id], @artist
-    @imager = PettanImager.load @original_picture.restore
-    @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
-    @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
-    @resource_picture = @original_picture.resource_picture
-    unless @resource_picture
-      @resource_picture = ResourcePicture.new
-      @resource_picture.supply_default
-    end
-    @resource_picture.attributes = params[:resource_picture]
-    @resource_picture.overwrite @original_picture
-    @license = @resource_picture.license
-    
+    # use @item, @original_picture
     respond_to do |format|
-      format.html # new.html.erb
-      format.js
+      format.html
     end
   end
   
   def create
-    @original_picture = OriginalPicture.edit params[:original_picture_id], @artist
+    @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
     @imager = PettanImager.load @original_picture.restore
-    @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
-    @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
-    @resource_picture = @original_picture.resource_picture
-    unless @resource_picture
-      @resource_picture = ResourcePicture.new
-      @resource_picture.supply_default
+    jsn = nil
+    if params[:json]
+      jsn = JSON.parse_no_except(params[:json])
+    end
+    @item = @original_picture.resource_picture || ResourcePicture.new
+    @prm = if params[:resource_picture] == nil or params[:resource_picture].empty?
+      jsn
+    else
+      @item.permit_params(params)
     end
-    @resource_picture.attributes = params[:resource_picture]
-    @resource_picture.overwrite @original_picture
-    @license = @resource_picture.license
-
+    @prm.delete 'id'
+    @item.attributes = @prm
+    @item.overwrite @original_picture
+    @item.boosts 'post'
+    
     respond_to do |format|
-      if @resource_picture.store(@imager)
-        format.html { redirect_to @resource_picture }
-        format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created, location: @resource_picture }
+      if @item.store(@imager)
+        format.html { redirect_to @item }
+        format.json { render json: @item.to_json, status: :created, location: @item }
       else
         format.html { render action: "new" }
-        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
+        format.json { render json: @item.errors, status: :unprocessable_entity }
       end
     end
   end
   
   def destroy
-    @resource_picture = ResourcePicture.edit(params[:id], @artist)
-
-    respond_to do |format|
-      if @resource_picture.unpublish
-        format.html { redirect_to :controller => '/home', :action => :resource_picture }
-        format.json { head :ok }
-      else
-        format.html { redirect_to resource_picture_path(@resource_picture) }
-        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
-      end
-    end
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy_by 'unpublish', '/home/' + @item.path_name
   end
   
   def count
@@ -118,22 +107,13 @@ class ResourcePicturesController < ApplicationController
     end
   end
   
-  def list
-    @resource_pictures = ResourcePicture.all
-
-    respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @resource_pictures }
-    end
-  end
-
-  def browse
-    @resource_picture = ResourcePicture.find(params[:id])
-
+  def search
+    @resource_pictures = ResourcePicture.find_by_md5(params[:md5])
+    
     respond_to do |format|
-      format.html { render layout: 'system' }
-      format.json { render json: @resource_picture }
+      format.html
+      format.json { render json: @resource_pictures.to_json }
     end
   end
-
+  
 end