Class: PhotosController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PhotosController
- Defined in:
- app/controllers/photos_controller.rb
Overview
Copyright © 2010, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
Instance Method Summary (collapse)
- - (Object) create
- - (Object) destroy
- - (Object) edit
- - (Object) index
- - (Object) make_profile_photo
- - (Object) show
- - (Object) update
Methods inherited from ApplicationController
#after_sign_in_path_for, #clear_gc_stats, #ensure_http_referer_is_set, #ensure_page, #grammatical_gender, #redirect_unless_admin, #set_git_header, #set_grammatical_gender, #set_header_data, #set_invites, #set_locale, #which_action_and_user
Instance Method Details
- (Object) create
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/photos_controller.rb', line 40 def create begin raise unless params[:photo][:aspect_ids] if params[:photo][:aspect_ids] == "all" params[:photo][:aspect_ids] = current_user.aspects.collect{|x| x.id} elsif params[:photo][:aspect_ids].is_a?(Hash) params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values end params[:photo][:user_file] = file_handler(params) @photo = current_user.build_post(:photo, params[:photo]) if @photo.save aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids]) unless @photo.pending current_user.add_to_streams(@photo, aspects) current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) end if params[:photo][:set_profile_photo] profile_params = {:image_url => @photo.url(:thumb_large), :image_url_medium => @photo.url(:thumb_medium), :image_url_small => @photo.url(:thumb_small)} current_user.update_profile(profile_params) end respond_to do |format| format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} end else respond_with @photo, :location => photos_path, :error => end rescue TypeError = I18n.t 'photos.create.type_error' respond_with @photo, :location => photos_path, :error => rescue CarrierWave::IntegrityError = I18n.t 'photos.create.integrity_error' respond_with @photo, :location => photos_path, :error => rescue RuntimeError => e = I18n.t 'photos.create.runtime_error' respond_with @photo, :location => photos_path, :error => raise e end end |
- (Object) destroy
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/photos_controller.rb', line 118 def destroy photo = current_user.posts.where(:id => params[:id]).first if photo current_user.retract(photo) respond_to do |format| format.json{ render :nothing => true, :status => 204 } format.html do flash[:notice] = I18n.t 'photos.destroy.notice' if photo. respond_with photo, :location => photo. else respond_with photo, :location => person_photos_path(current_user.person) end end end else respond_with photo, :location => person_photos_path(current_user.person) end end |
- (Object) edit
175 176 177 178 179 180 181 |
# File 'app/controllers/photos_controller.rb', line 175 def edit if @photo = current_user.posts.where(:id => params[:id]).first respond_with @photo else redirect_to person_photos_path(current_user.person) end end |
- (Object) index
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/photos_controller.rb', line 10 def index @post_type = :photos @person = Person.find_by_id(params[:person_id]) if @person @profile = @person.profile @contact = current_user.contact_for(@person) @is_contact = @person != current_user.person && @contact @aspects_with_person = [] if @contact @aspects_with_person = @contact.aspects @contacts_of_contact = @contact.contacts @contacts_of_contact_count = @contact.contacts.count else @contact = Contact.new @contacts_of_contact = [] @contacts_of_contact_count = 0 end @posts = current_user.posts_from(@person).where(:type => 'Photo').paginate(:page => params[:page]) render 'people/show' else flash[:error] = I18n.t 'people.show.does_not_exist' redirect_to people_path end end |
- (Object) make_profile_photo
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/controllers/photos_controller.rb', line 92 def make_profile_photo = current_user.person.id @photo = Photo.where(:id => params[:photo_id], :author_id => ).first if @photo profile_hash = {:image_url => @photo.url(:thumb_large), :image_url_medium => @photo.url(:thumb_medium), :image_url_small => @photo.url(:thumb_small)} if current_user.update_profile(profile_hash) respond_to do |format| format.js{ render :json => { :photo_id => @photo.id, :image_url => @photo.url(:thumb_large), :image_url_medium => @photo.url(:thumb_medium), :image_url_small => @photo.url(:thumb_small), :author_id => }, :status => 201} end else render :nothing => true, :status => 422 end else render :nothing => true, :status => 422 end end |
- (Object) show
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/photos_controller.rb', line 140 def show @photo = current_user.find_visible_post_by_id(params[:id], :type => 'Photo') if @photo @parent = StatusMessage.where(:guid => @photo.).includes(:photos).first if @photo. #if photo is not an attachment, fetch comments for self if @parent @additional_photos = @photo..photos if @additional_photos @next_photo = @additional_photos[@additional_photos.index(@photo)+1] @prev_photo = @additional_photos[@additional_photos.index(@photo)-1] @next_photo ||= @additional_photos.first end else @parent = @photo end @object_aspect_ids = [] if @parent_aspects = @parent.aspects.where(:user_id => current_user.id) @object_aspect_ids = @parent_aspects.map{|a| a.id} end @ownership = current_user.owns? @photo respond_with @photo else begin redirect_to :back rescue redirect_to aspects_path end end end |
- (Object) update
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/controllers/photos_controller.rb', line 183 def update photo = current_user.posts.where(:id => params[:id]).first if photo if current_user.update_post( photo, params[:photo] ) flash.now[:notice] = I18n.t 'photos.update.notice' respond_to do |format| format.js{ render :json => photo, :status => 200 } end else flash.now[:error] = I18n.t 'photos.update.error' respond_to do |format| format.html{ redirect_to [:edit, photo] } format.js{ render :status => 403 } end end else redirect_to person_photos_path(current_user.person) end end |