OSDN Git Service

manifest view profiler
[pettanr/pettanr.git] / app / controllers / resource_pictures_controller.rb
1 class ResourcePicturesController < ApplicationController
2   if Manifest.manifest.magic_numbers['run_mode'] == 0
3     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
4     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
5   else
6     before_filter :authenticate_resource_reader, :only => [
7       :index, :show, :credit, :by_license, :by_artist, :count, :count_by_license, :count_by_artist
8     ]
9     before_filter :authenticate_user, :only => [:new, :create, :update, :destroy]
10     before_filter :authenticate_artist, :only => [:new, :create, :update, :destroy]
11   end
12
13   def self.model
14     ResourcePicture
15   end
16   
17   def index
18     filer_list
19   end
20   
21   def by_license
22     filer_list
23   end
24   
25   def by_artist
26     filer_list
27   end
28   
29   def show_html_format format
30     format.html {
31       @resource_picture = @item
32     }
33   end
34   
35   def show
36     set_show
37     respond_to do |format|
38       opt = {:type => @item.mime_type, :disposition=>"inline"}
39       format.png { send_data(@item.restore(params[:subdir]), opt ) }
40       format.gif { send_data(@item.restore(params[:subdir]), opt ) }
41       format.jpeg { send_data(@item.restore(params[:subdir]), opt ) }
42       show_html_format format
43       show_prof_format format
44       show_json_format format
45     end
46   end
47   
48   def credit
49     @resource_picture = ResourcePicture.show(params[:id], @operators)
50
51     respond_to do |format|
52       format.html { render :layout => false } # show.html.erb
53       format.json { render :json => @resource_picture.to_json(ResourcePicture.show_json_opt)}
54     end
55   end
56   
57   def count
58     list_count
59   end
60   
61   def count_by_license
62     list_count
63   end
64   
65   def count_by_artist
66     list_count
67   end
68   
69   def new
70     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
71     @imager = PettanImager.load @original_picture.restore
72     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
73     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id
74     @resource_picture = @original_picture.resource_picture
75     unless @resource_picture
76       @resource_picture = ResourcePicture.new
77       @resource_picture.supply_default
78     end
79     @resource_picture.attributes = params[:resource_picture]
80     @resource_picture.overwrite @original_picture
81     @license = @resource_picture.license
82     
83     respond_to do |format|
84       format.html # new.html.erb
85       format.js
86     end
87   end
88   
89   def create
90     @original_picture = OriginalPicture.edit params[:original_picture_id], @operators
91     @imager = PettanImager.load @original_picture.restore
92     @original_picture_license_group = OriginalPictureLicenseGroup.new params[:original_picture_license_group]
93     @license_group = LicenseGroup.show @original_picture_license_group.license_group_id, @operators
94     @resource_picture = @original_picture.resource_picture
95     unless @resource_picture
96       @resource_picture = ResourcePicture.new
97       @resource_picture.supply_default
98     end
99     @resource_picture.attributes = params[:resource_picture]
100     @resource_picture.overwrite @original_picture
101     @license = @resource_picture.license
102
103     respond_to do |format|
104       if @resource_picture.store(@imager)
105         format.html { redirect_to @resource_picture }
106         format.json { render json: @resource_picture.to_json(ResourcePicture.show_json_opt), status: :created, location: @resource_picture }
107       else
108         format.html { render action: "new" }
109         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
110       end
111     end
112   end
113   
114   def destroy
115     @resource_picture = ResourcePicture.edit(params[:id], @operators)
116
117     respond_to do |format|
118       if @resource_picture.unpublish
119         format.html { redirect_to :controller => '/home', :action => :resource_pictures }
120         format.json { head :ok }
121       else
122         format.html { redirect_to resource_picture_path(@resource_picture) }
123         format.json { render json: @resource_picture.errors, status: :unprocessable_entity }
124       end
125     end
126   end
127   
128   def count
129     @resource_picture = {:count => ResourcePicture.visible_count}
130     respond_to do |format|
131       format.json { render json: @resource_picture.to_json }
132     end
133   end
134   
135 end