X-Git-Url: http://git.osdn.net/view?p=pettanr%2Fpettanr.git;a=blobdiff_plain;f=app%2Fcontrollers%2Foriginal_pictures_controller.rb;h=c902cf9e509882e4c90e4102b1c8671418a8b769;hp=85c77df03bcefd6fc35ff58091995ce9922d0a9a;hb=6733d61c6f0551647a023be3006cb70901497c36;hpb=3392e528d4f83ffdaf81b4d0babf5b06972e3f4a diff --git a/app/controllers/original_pictures_controller.rb b/app/controllers/original_pictures_controller.rb index 85c77df0..c902cf9e 100644 --- a/app/controllers/original_pictures_controller.rb +++ b/app/controllers/original_pictures_controller.rb @@ -1,211 +1,121 @@ +#原画 class OriginalPicturesController < ApplicationController - before_filter :authenticate_author!, :only => [:index, :show, :new, :edit, :create, :update, :destroy] - before_filter :authenticate_admin!, :only => [:list, :browse] - - private - - def set_image(prm) - img = nil - if (f = prm[:original_picture][:file]).respond_to?(:read) - if f.size > 1000000 - @original_picture.width = 0 - @original_picture.height = 0 - @original_picture.ext = 'none' - @original_picture.filesize = 1.megabytes - else - img = Magick::Image.from_blob(f.read).shift - @original_picture.width = img.columns - @original_picture.height = img.rows - @original_picture.ext = img.format.downcase - @original_picture.filesize = f.size - end - else - dat = Base64.decode64(prm[:original_picture][:file].to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる - img = Magick::Image.from_blob(dat).shift - @original_picture.width = img.columns - @original_picture.height = img.rows - @original_picture.ext = img.format.downcase - @original_picture.filesize = 1000 - end - img - end + before_filter :authenticate_reader, :only => [:show, :history] + before_filter :authenticate_user, :only => [:index, :new, :edit, :create, :update, :destroy] + before_filter :authenticate_artist, :only => [:index, :new, :edit, :create, :update, :destroy] - public - - # GET /original_pictures - # GET /original_pictures.json def index - @original_pictures = OriginalPicture.find(:all, - :include => [:artist, :license, :resource_picture], :order => 'updated_at', :limit => 20 - ) - - respond_to do |format| - format.html # index.html.erb - format.json { render :json => @original_pictures.to_json( - :include => [:resource_picture, :artist, :license] - ) } - end + filer_list end - # GET /original_pictures/1 - # GET /original_pictures/1.json - def show - @original_picture = OriginalPicture.find(params[:id]) -# if params[:subdir] == 'refresh' -# refresh -# return -# end - - respond_to do |format| - opt = {:type => @original_picture.mime_type, :disposition=>"inline"} - format.png { send_data(@original_picture.restore, opt ) } - format.gif { send_data(@original_picture.restore, opt ) } - format.jpeg { send_data(@original_picture.restore, opt ) } - format.html # show.html.erb - format.json { render json: @original_picture} - end + def show_html_format format + format.html { + #ライセンス付与のために原画ライセンスグループ作成準備 + @original_picture_license_group = OriginalPictureLicenseGroup.new :original_picture_id => @item.id + render + } end - - def list - @original_pictures = OriginalPicture.all - - respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @original_pictures } - end + + def show_json_format format + format.json { render json: @item.to_json( + {:include => {:resource_picture => {}} } + )} end - - def browse - @original_picture = OriginalPicture.find(params[:id]) - + + def show + set_show respond_to do |format| - format.html { render layout: 'system' } - format.json { render json: @original_picture } + 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 - def refresh - @original_picture = OriginalPicture.find(params[:id]) - img = Magick::Image.from_blob(@original_picture.restore).shift - @original_picture.store img + def history + set_show + @history = @item.history + respond_to do |format| - format.html { redirect_to original_pictures_url } + format.html + format.json { render json: @history.to_json } end end - # GET /original_pictures/new - # GET /original_pictures/new.json def new - @original_picture = OriginalPicture.new - + set_new respond_to do |format| - format.html # new.html.erb - format.js - format.json { render json: @original_picture } + format.html + format.json { render json: @item.to_json } end end - - # GET /original_pictures/1/edit + def edit - @original_picture = OriginalPicture.find(params[:id]) + set_edit + respond_to do |format| + format.html + format.json { render json: @item.to_json } + end end - - # POST /original_pictures - # POST /original_pictures.json + def create - unless @artist - respond_to do |format| - format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - return + set_model + p params[:file] + @imager = if params[:original_picture] + PettanImager.load set_image params[:original_picture][:file] + else + nil end - @original_picture = OriginalPicture.new - img = set_image params - @original_picture.artist_id = current_author.artist.id - @original_picture.license_id = current_author.artist.default_license_id - + @item = OriginalPicture.new + @item.supply_default + @item.overwrite @operators + respond_to do |format| - OriginalPicture.transaction do - if @original_picture.save - if @original_picture.store(img) - format.html { redirect_to @original_picture, notice: 'Original picture was successfully created.' } - format.json { render json: @original_picture, status: :created, location: @original_picture } - else - format.html { redirect_to @original_picture, notice: 'Failed! Original picture was NOT created.' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - else - format.html { render action: "new" } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end + if @item.store(@imager) + created_html_format format + created_json_format format + else + not_created_html_format format + not_created_json_format format end end end - - # PUT /original_pictures/1 - # PUT /original_pictures/1.json + def update - unless @artist - respond_to do |format| - format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - return - end - @original_picture = OriginalPicture.find(params[:id]) - unless @original_picture.own? current_author - respond_to do |format| - format.html { redirect_to @original_picture, notice: 'Failed! ' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - return + set_model + @imager = if params[:original_picture] + PettanImager.load set_image params[:original_picture][:file] + else + nil end - img = set_image params - + @item = OriginalPicture.edit(params[:id], @operators) + @item.overwrite @operators + respond_to do |format| - OriginalPicture.transaction do - if @original_picture.save - if @original_picture.store(img) - format.html { redirect_to @original_picture, notice: 'Original picture was successfully updated.' } - format.json { head :ok } - else - format.html { redirect_to @original_picture, notice: 'Failed! Original picture was NOT created.' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - else - format.html { render action: "edit" } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end + if @item.store(@imager) + updated_html_format format + updated_json_format format + else + not_updated_html_format format + not_updated_json_format format end end end - - # DELETE /original_pictures/1 - # DELETE /original_pictures/1.json + def destroy - unless @artist - respond_to do |format| - format.html { redirect_to @original_picture, notice: 'Failed! author does not artist.' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - return - end - @original_picture = OriginalPicture.find(params[:id]) - unless @original_picture.own? current_author - respond_to do |format| - format.html { redirect_to @original_picture, notice: 'Failed! ' } - format.json { render json: @original_picture.errors, status: :unprocessable_entity } - end - return - end - OriginalPicture.transaction do - @original_picture.destroy - end + @item = OriginalPicture.edit(params[:id], @operators) respond_to do |format| - format.html { redirect_to original_pictures_url } - format.json { head :ok } + if @item.destroy_with_resource_picture + format.html { redirect_to original_pictures_url } + format.json { head :ok } + else + format.html { redirect_to original_picture_path(@item) } + format.json { render json: @item.errors, status: :unprocessable_entity } + end end end end