From 79ec02c6ada1cd3e1e6d40d4a20581ce1a7a628b Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 29 Oct 2010 12:20:25 -0700 Subject: [PATCH 1/2] photo uploader on edit profile page. --- app/controllers/people_controller.rb | 19 +++++++++-------- app/controllers/photos_controller.rb | 5 +++++ .../people/_profile_photo_upload.html.haml | 13 ++++++++++++ app/views/people/edit.html.haml | 21 +------------------ app/views/photos/_new_photo.haml | 2 +- .../users/getting_started/_step_1.html.haml | 21 +------------------ public/stylesheets/sass/application.sass | 14 +++++++++++++ 7 files changed, 45 insertions(+), 50 deletions(-) create mode 100644 app/views/people/_profile_photo_upload.html.haml diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f76f1c6e6..791d532b7 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -37,7 +37,6 @@ class PeopleController < ApplicationController @aspect = :person_edit @person = current_user.person @profile = @person.profile - @photos = current_user.visible_posts(:person_id => @person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' end def update @@ -64,15 +63,17 @@ class PeopleController < ApplicationController private def prep_image_url(params) - url = APP_CONFIG[:pod_url].dup - url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' - if params[:profile][:image_url].empty? - params[:profile].delete(:image_url) - else - if /^http:\/\// =~ params[:profile][:image_url] - params[:profile][:image_url] = params[:profile][:image_url] + if params[:profile] && params[:profile][:image_url] + url = APP_CONFIG[:pod_url].dup + url.chop! if APP_CONFIG[:pod_url][-1,1] == '/' + if params[:profile][:image_url].empty? + params[:profile].delete(:image_url) else - params[:profile][:image_url] = url + params[:profile][:image_url] + if /^http:\/\// =~ params[:profile][:image_url] + params[:profile][:image_url] = params[:profile][:image_url] + else + params[:profile][:image_url] = url + params[:profile][:image_url] + end end end end diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 3216fdf4c..c9671ac7f 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -51,6 +51,11 @@ class PhotosController < ApplicationController @photo = current_user.post(:photo, params[:photo]) + # set image as profile photo + if params[:set_profile_image] && !params[:set_profile_image].empty? + current_user.update_profile(:image_url=>@photo.url(:thumb_medium)) + end + respond_to do |format| format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} end diff --git a/app/views/people/_profile_photo_upload.html.haml b/app/views/people/_profile_photo_upload.html.haml new file mode 100644 index 000000000..b65672a10 --- /dev/null +++ b/app/views/people/_profile_photo_upload.html.haml @@ -0,0 +1,13 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + + +#profile_photo_upload + = owner_image_tag + = render 'photos/new_photo', :album_id => nil, :aspect_id => 'all', :set_profile_image => true + + %p + \...or select one from your already existing + = link_to 'photos', person_photos_path(@person) + \. diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index 29e10d757..18d08a542 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -42,26 +42,7 @@ %h4 Your photo - %div#image_picker - = profile.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' - - - unless @photos.nil? || @photos.empty? - - for photo in @photos - - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) - %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} - = check_box_tag 'checked_photo', true, true - = link_to image_tag(photo.url(:thumb_medium)), "#" - - else - %div.small_photo{:id => photo.url(:thumb_medium)} - = check_box_tag 'checked_photo' - = link_to image_tag(photo.url(:thumb_medium)), "#" - - - else - =t('.you_dont_have_any_photos') - = link_to t('.albums'), albums_path(:aspect => 'all') - =t('.page_to_upload_some') - - =will_paginate @photos + = render 'people/profile_photo_upload' .submit_block = link_to t('.cancel'), edit_user_path(current_user) diff --git a/app/views/photos/_new_photo.haml b/app/views/photos/_new_photo.haml index a5efe45da..dd029008e 100644 --- a/app/views/photos/_new_photo.haml +++ b/app/views/photos/_new_photo.haml @@ -6,7 +6,7 @@ function createUploader(){ var uploader = new qq.FileUploader({ element: document.getElementById('file-upload'), - params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}}, + params: {'photo' : { 'album_id' : "#{album_id}", 'to' : "#{aspect_id}"}, 'set_profile_image' : "#{set_profile_image if defined?(set_profile_image)}"}, allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'], action: "#{photos_path}" }); diff --git a/app/views/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml index 7778a39f8..1bb45760f 100644 --- a/app/views/users/getting_started/_step_1.html.haml +++ b/app/views/users/getting_started/_step_1.html.haml @@ -33,26 +33,7 @@ %h4 Your photo - %div#image_picker - = profile.hidden_field :image_url, :value => (@profile.image_url if @profile.image_url), :id => 'image_url_field' - - - unless @photos.nil? || @photos.empty? - - for photo in @photos - - if @profile.image_url && @profile.image_url.include?(photo.url(:thumb_medium)) - %div.small_photo{:id => photo.url(:thumb_medium), :class=>'selected'} - = check_box_tag 'checked_photo', true, true - = link_to image_tag(photo.url(:thumb_medium)), "#" - - else - %div.small_photo{:id => photo.url(:thumb_medium)} - = check_box_tag 'checked_photo' - = link_to image_tag(photo.url(:thumb_medium)), "#" - - - else - =t('.you_dont_have_any_photos') - = link_to t('.albums'), albums_path(:aspect => 'all') - =t('.page_to_upload_some') - - =will_paginate @photos + = render 'people/profile_photo_upload' = hidden_field_tag :getting_started, @step diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 16b8b4fc3..96fb467ed 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -1377,3 +1377,17 @@ ul.aspects :display inline :left 600px :top 0 + +#profile_photo_upload + :margin + :top 5px + img + :position absolute + :left 0 + :height 100px + :width 100px + :border-radius 5px + :-webkit-box-shadow 0 1px 2px #666 + + :padding + :left 120px From 6eb50ea93414b41c0ea7cb860f394c29fd3e372f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Fri, 29 Oct 2010 14:11:20 -0700 Subject: [PATCH 2/2] profile photo uploader is now a standard form file element. Upload new image through people#update, which calls current_user.post to do so. --- app/controllers/people_controller.rb | 9 +++++++++ app/controllers/photos_controller.rb | 5 ----- app/controllers/users_controller.rb | 1 - app/views/people/_profile_photo_upload.html.haml | 2 +- app/views/people/edit.html.haml | 4 ++-- app/views/users/getting_started/_step_1.html.haml | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 791d532b7..25fb5d0e4 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -46,6 +46,15 @@ class PeopleController < ApplicationController params[:person][:profile][:birthday] ||= Date.parse("#{birthday[:year]}-#{birthday[:month]}-#{birthday[:day]}") end + # upload and set new profile photo + if params[:person][:profile][:image] + raw_image = params[:person][:profile].delete(:image) + params[:profile_image_hash] = { :user_file => raw_image, :to => "all" } + + photo = current_user.post(:photo, params[:profile_image_hash]) + params[:person][:profile][:image_url] = photo.url(:thumb_medium) + end + prep_image_url(params[:person]) if current_user.update_profile params[:person][:profile] diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index c9671ac7f..3216fdf4c 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -51,11 +51,6 @@ class PhotosController < ApplicationController @photo = current_user.post(:photo, params[:photo]) - # set image as profile photo - if params[:set_profile_image] && !params[:set_profile_image].empty? - current_user.update_profile(:image_url=>@photo.url(:thumb_medium)) - end - respond_to do |format| format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 45182cd88..36f31c6b8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -75,7 +75,6 @@ class UsersController < ApplicationController @user = current_user @person = @user.person @profile = @user.profile - @photos = @user.visible_posts(:person_id => current_user.person.id, :_type => 'Photo').paginate :page => params[:page], :order => 'created_at DESC' @services = @user.services @step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1 diff --git a/app/views/people/_profile_photo_upload.html.haml b/app/views/people/_profile_photo_upload.html.haml index b65672a10..cd9577abe 100644 --- a/app/views/people/_profile_photo_upload.html.haml +++ b/app/views/people/_profile_photo_upload.html.haml @@ -5,7 +5,7 @@ #profile_photo_upload = owner_image_tag - = render 'photos/new_photo', :album_id => nil, :aspect_id => 'all', :set_profile_image => true + = form.file_field :image %p \...or select one from your already existing diff --git a/app/views/people/edit.html.haml b/app/views/people/edit.html.haml index 18d08a542..19d1bafb7 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/people/edit.html.haml @@ -12,7 +12,7 @@ %li=link_to 'Services', services_path .span-19.prepend-5.last - = form_for @person do |person| + = form_for @person, :html => { :multipart => true } do |person| %h3 Your Profile .description @@ -42,7 +42,7 @@ %h4 Your photo - = render 'people/profile_photo_upload' + = render 'people/profile_photo_upload', :form => profile .submit_block = link_to t('.cancel'), edit_user_path(current_user) diff --git a/app/views/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml index 1bb45760f..6ee900211 100644 --- a/app/views/users/getting_started/_step_1.html.haml +++ b/app/views/users/getting_started/_step_1.html.haml @@ -3,7 +3,7 @@ -# the COPYRIGHT file. -= form_for @person do |person| += form_for @person, :html => { :multipart => true } do |person| %h3 Your Profile .description @@ -33,7 +33,7 @@ %h4 Your photo - = render 'people/profile_photo_upload' + = render 'people/profile_photo_upload', :form => profile = hidden_field_tag :getting_started, @step