From 10d58ef050a4cb46bb7c9f11849edd8e8b8ff981 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Wed, 15 Jul 2020 23:27:22 -0700 Subject: [PATCH] Support selecting various sizes of profile pics --- app/assets/stylesheets/osem.scss | 5 +++++ app/models/user.rb | 14 +++++++++++--- app/uploaders/picture_uploader.rb | 4 ++++ app/views/layouts/_navigation.html.haml | 2 +- app/views/users/edit.html.haml | 9 +++++---- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/osem.scss b/app/assets/stylesheets/osem.scss index bcf37d4f..7b913fe6 100644 --- a/app/assets/stylesheets/osem.scss +++ b/app/assets/stylesheets/osem.scss @@ -51,6 +51,11 @@ body { margin: 0 auto; } +nav #current-user-detail .profile-thumnail { + max-height: 20px; + max-width: 20px; +} + /* centered columns styles */ .row-centered { text-align:center; diff --git a/app/models/user.rb b/app/models/user.rb index 4ff39043..8d5a935c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -158,9 +158,17 @@ class User < ApplicationRecord ## # Returns a user's profile picture URL. # Partials should *not* directly call `gravatar_url` - def profile_picture(opts) - # TODO: Figure out how to align sizes? - picture.thumb.url || gravatar_url(opts) + def profile_picture(opts = {}) + return gravatar_url(opts) unless picture.present? + puts "ASKED FOR PROFILE PIC!! #{opts[:size]}" + size = (opts[:size] || 0).to_i + if size < 50 + picture.tiny.url + elsif size <= 100 + picture.thumb.url + else + picture.large.url + end end def self.for_ichain_username(username, attributes) diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 4cad1594..47e86f8b 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -62,6 +62,10 @@ class PictureUploader < CarrierWave::Uploader::Base process resize_to_fit: [100, 100] end + version :tiny do + process resize_to_fit: [32, 32] + end + version :first, if: :sponsor? version :first do process resize_and_pad: [320, 180, 'white'] diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 97779a45..239c053f 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -29,7 +29,7 @@ %li.dropdown %a.dropdown-toggle{"data-toggle" => "dropdown", href: '#', id: "current-user-detail"} = current_user.name - = image_tag(current_user.profile_picture(size: '18'), title: "Yo #{current_user.name}!", alt: '') + = image_tag(current_user.profile_picture(size: '18'), class: 'profile-thumbnail', alt: '') %b.caret %ul.dropdown-menu = render 'layouts/user_menu' diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 73d4f4b1..e5235099 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -12,13 +12,14 @@ = "Avatar" = image_tag(@user.profile_picture(size: '48'), title: "Yo #{@user.name}!", alt: '') = link_to 'Change your avatar here', 'https://gravatar.com' - %br %p Or upload a picture. - = image_tag f.object.picture.thumb.url if f.object.picture? - - if @user.picture? - = image_tag(@user.picture.thumb.url, width: '20%') = f.input :picture, hint: 'If you upload a picture, it will be used in place of Gravatar.' + - if @user.picture? + %p + Current Picture + %br + = image_tag(@user.picture.thumb.url, width: '20%') = f.input :affiliation, as: :string, hint: 'This could be a company, a user group, or nothing at all.'