OSDN Git Service

fix: rp update faild
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
index f422561..6850873 100644 (file)
 class ResourcePicturesController < ApplicationController
-  before_filter :authenticate_author!, :except => [:index, :show]
-
-  # GET /resource_pictures
-  # GET /resource_pictures.json
+  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_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
+  
   def index
-    @resource_pictures = ResourcePicture.all
-
+    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
+    set_show
     respond_to do |format|
-      format.html # index.html.erb
-      format.json { render json: @resource_pictures }
+      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 ) }
+      show_html_format format
+      show_prof_format format
+      show_json_format format
     end
   end
-
-  # GET /resource_pictures/1
-  # GET /resource_pictures/1.json
-  def show
-    @resource_picture = ResourcePicture.find(params[:id])
-
+  
+  def credit
+    @resource_picture = ResourcePicture.show(params[:id], @operators)
+    
     respond_to do |format|
-      opt = {:type => @resource_picture.mime_type, :disposition=>"inline"}
-      format.png { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.gif { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.jpeg { send_data(@resource_picture.restore(params[:subdir]), opt ) }
-      format.html # show.html.erb
-      format.json { render json: @resource_picture}
+      format.html { render :layout => false } # show.html.erb
     end
   end
-
-=begin
-  # GET /resource_pictures/new
-  # GET /resource_pictures/new.json
+  
   def new
-    @resource_picture = ResourcePicture.new
-
+    # use @item, @original_picture
     respond_to do |format|
-      format.html # new.html.erb
-      format.json { render json: @resource_picture }
+      format.html
     end
   end
-
-  # GET /resource_pictures/1/edit
-  def edit
-    @resource_picture = ResourcePicture.find(params[:id])
-  end
-
-  # POST /resource_pictures
-  # POST /resource_pictures.json
+  
   def create
-    @resource_picture = ResourcePicture.new(params[:resource_picture])
-
+    @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
+    @imager = PettanImager.load @original_picture.restore
+    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
+    @prm.delete 'id'
+    @item.attributes = @prm
+    @item.overwrite @original_picture
+    @item.boosts 'post'
+    
     respond_to do |format|
-      if @resource_picture.save
-        format.html { redirect_to @resource_picture, notice: 'Resource picture was successfully created.' }
-        format.json { render json: @resource_picture, 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
-
-  # PUT /resource_pictures/1
-  # PUT /resource_pictures/1.json
-  def update
-    @resource_picture = ResourcePicture.find(params[:id])
-
+  
+  def destroy
+    set_model
+    @item = @my_model_class.edit(params[:id], @operators)
+    render_destroy_by 'unpublish', '/home/' + @item.path_name
+  end
+  
+  def count
+    @resource_picture = {:count => ResourcePicture.visible_count}
     respond_to do |format|
-      if @resource_picture.update_attributes(params[:resource_picture])
-        format.html { redirect_to @resource_picture, notice: 'Resource picture was successfully updated.' }
-        format.json { head :ok }
-      else
-        format.html { render action: "edit" }
-        format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
-      end
+      format.json { render json: @resource_picture.to_json }
     end
   end
-
-  # DELETE /resource_pictures/1
-  # DELETE /resource_pictures/1.json
-  def destroy
-    @resource_picture = ResourcePicture.find(params[:id])
-    @resource_picture.destroy
-
+  
+  def search
+    @resource_pictures = ResourcePicture.find_by_md5(params[:md5])
+    
     respond_to do |format|
-      format.html { redirect_to resource_pictures_url }
-      format.json { head :ok }
+      format.html
+      format.json { render json: @resource_pictures.to_json }
     end
   end
-=end
+  
 end