From 18d0f6215b5d0c9ff2f95170237ded2c1b02eda9 Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Fri, 10 Mar 2017 00:36:22 +0530 Subject: [PATCH] Fixes #1081, Add more profile info on user Profile --- app/controllers/users_controller.rb | 22 +++++-- app/models/user.rb | 3 + .../users/_personal_info_fields.html.haml | 18 ++++++ app/views/users/_social_code_fields.html.haml | 6 ++ .../users/_social_media_fields.html.haml | 7 +++ app/views/users/edit.html.haml | 32 +++++----- app/views/users/field_select.js.erb | 11 ++++ app/views/users/show.html.haml | 58 +++++++++++++++++++ app/views/users/update.js.erb | 1 + 9 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 app/views/users/_personal_info_fields.html.haml create mode 100644 app/views/users/_social_code_fields.html.haml create mode 100644 app/views/users/_social_media_fields.html.haml create mode 100644 app/views/users/field_select.js.erb create mode 100644 app/views/users/update.js.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a453c83f..7714d784 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -8,15 +8,25 @@ class UsersController < ApplicationController # GET /users/1/edit def edit + @tab_select = params[:tab] + if @tab_select.present? + respond_to do |format| + format.js { render action: 'field_select' } + end + else + render :edit + end end # PATCH/PUT /users/1 def update - if @user.update(user_params) - redirect_to @user, notice: 'User was successfully updated.' - else - flash[:error] = "An error prohibited your Profile from being saved: #{@user.errors.full_messages.join('. ')}." - render :edit + respond_to do |format| + if @user.update(user_params) + flash[:notice] = 'User was successfully updated.' + else + flash[:error] = "An error prohibited your Profile from being saved: #{@user.errors.full_messages.join('. ')}." + end + format.js end end @@ -24,6 +34,6 @@ class UsersController < ApplicationController # Only allow a trusted parameter "white list" through. def user_params - params.require(:user).permit(:name, :biography, :nickname, :affiliation) + params.require(:user).permit(:name, :biography, :nickname, :affiliation, :googleplus, :twitter, :gna, :gnu, :github, :gitlab, :website_url, :linkedin, :diaspora, :savannah) end end diff --git a/app/models/user.rb b/app/models/user.rb index 29640ab3..54fb2a51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -63,6 +63,9 @@ class User < ActiveRecord::Base validate :biography_limit + validates :website_url, :linkedin, :googleplus, :gnu, :twitter, :gitlab, :github, :gna, :savannah, :diaspora, + format: { with: URI.regexp(%w(http https)), message: 'This is an invalid URL. It should start with http or https'}, allow_blank: true + ## # Checkes if the user attended the event # This is used for events that require registration diff --git a/app/views/users/_personal_info_fields.html.haml b/app/views/users/_personal_info_fields.html.haml new file mode 100644 index 00000000..c824b846 --- /dev/null +++ b/app/views/users/_personal_info_fields.html.haml @@ -0,0 +1,18 @@ += semantic_form_for(user, url: user_path(user.id), remote: true) do |f| + = f.input :name, as: :string + = f.input :nickname, as: :string + .control-label + = "Avatar" + = image_tag(user.gravatar_url(size: '48'), title: "Yo #{user.name}!", :alt => '') + = link_to 'Change your avatar here', 'https://gravatar.com' + = f.input :affiliation, as: :string, + hint: 'This could be a company, a user group, or nothing at all.' + = f.input :website_url, type: :url, label: 'Personal Website' + = f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' }, 'onkeyup' => "word_count(this, 'biography-count', 150)" },hint: markdown_hint + You have used + %span#bio_length + = user.biography ? user.biography.split.length : 0 + words. Biographies are limited to 150 words. + %br + %br + = f.action :submit, as: :button, label: 'Update', button_html: {class: 'btn btn-primary'} diff --git a/app/views/users/_social_code_fields.html.haml b/app/views/users/_social_code_fields.html.haml new file mode 100644 index 00000000..0cfde3de --- /dev/null +++ b/app/views/users/_social_code_fields.html.haml @@ -0,0 +1,6 @@ += semantic_form_for(user, url: user_path(user.id), remote: true) do |f| + = f.input :github, type: :url, as: :string, hint: 'e.g http://github.com/osem' + = f.input :gitlab, type: :url, as: :string, hint: 'e.g http://gitlab.com/osem' + = f.input :savannah, type: :url, as: :string, hint: 'e.g http://savannah.gnu.org/osem' + = f.input :gna, type: :url, label: 'Gna', as: :string, hint: 'e.g http://gna.com/osem' + = f.action :submit, as: :button, label: 'Update', button_html: {class: 'btn btn-primary'} diff --git a/app/views/users/_social_media_fields.html.haml b/app/views/users/_social_media_fields.html.haml new file mode 100644 index 00000000..02ea35af --- /dev/null +++ b/app/views/users/_social_media_fields.html.haml @@ -0,0 +1,7 @@ += semantic_form_for(user, url: user_path(user.id), remote: true) do |f| + = f.input :linkedin, type: :url, as: :string, hint: 'e.g. https://linkedin.com/osem' + = f.input :twitter, type: :url, as: :string, hint: 'e.g. https://twitter.com/osem' + = f.input :googleplus, type: :url, label: 'Google+ url', as: :string, hint: 'e.g. https://googleplus.com/78458952' + = f.input :gnu, type: :url, label: 'Gnu Social', as: :string, hint: 'e.g. https://gnu.io/osem' + = f.input :diaspora, type: :url, as: :string, hint: 'e.g. https://joindiaspora.com/osem' + = f.action :submit, as: :button, label: 'Update', button_html: {class: 'btn btn-primary'} diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index f4569255..4dc57340 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -2,24 +2,18 @@ .row .col-md-12 .page-header - %h1 Edit your profile + %h1 + Edit your profile + = link_to 'My Profile', user_path(@user), class: 'btn btn-primary pull-right' .row .col-md-12 - = semantic_form_for(@user, url: user_path(@user.id)) do |f| - = f.input :name, as: :string - = f.input :nickname, as: :string - .control-label - = "Avatar" - = image_tag(@user.gravatar_url(size: '48'), title: "Yo #{@user.name}!", :alt => '') - = link_to 'Change your avatar here', 'https://gravatar.com' - = f.input :affiliation, as: :string, - hint: 'This could be a company, a user group, or nothing at all.' - = f.input :biography, input_html: { rows: 5, data: { provide: 'markdown-editable' } }, - hint: markdown_hint - You have used - %span#bio_length - = @user.biography ? @user.biography.split.length : 0 - words. Biographies are limited to 150 words. - %br - %br - = f.action :submit, as: :button, label: 'Update', button_html: {class: 'btn btn-primary'} + %ul.nav.nav-pills + %li.active + = link_to 'Personal Info', edit_user_path({ tab: 'personal_info' }), remote: true, id: 'personal_info' + %li + = link_to 'Social Media', edit_user_path({ tab: 'social_media' }), remote: true, id: 'social_media' + %li + = link_to 'Social Code', edit_user_path({ tab: 'social_code' }), remote: true, id: 'social_code' + %br/ + #form + = render partial: 'personal_info_fields', locals: { user: @user } diff --git a/app/views/users/field_select.js.erb b/app/views/users/field_select.js.erb new file mode 100644 index 00000000..3d2c85ca --- /dev/null +++ b/app/views/users/field_select.js.erb @@ -0,0 +1,11 @@ +$('.active').removeClass('active'); +<% if @tab_select == "personal_info" %> + $('#personal_info').closest('li').addClass('active'); + $('#form').html('<%= j render partial: "personal_info_fields", locals: { user: @user } %>'); +<% elsif @tab_select == "social_code" %> + $('#social_code').closest('li').addClass('active'); + $('#form').html('<%= j render partial: "social_code_fields", locals: { user: @user } %>'); +<% else %> + $('#social_media').closest('li').addClass('active'); + $('#form').html('<%= j render partial: "social_media_fields", locals: { user: @user } %>'); +<% end %> diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index 355cda88..cdfb3e7a 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -7,6 +7,64 @@ = @user.name %small = @user.nickname + %h3.text-center + Social Media and Social Code + %ul.list-inline.list-unstyled.text-center + - if @user.website_url.present? + %li + = link_to(@user.website_url) do + .user_profile-icon + %icon.fa.fa-external-link.fa-3x + %span.concat-text Blog + - if @user.twitter.present? + %li + = link_to(@user.twitter) do + .user_profile-icon + %icon.fa.fa-twitter.fa-3x + %span.concat-text Twitter + - if @user.linkedin.present? + %li + = link_to(@user.linkedin) do + .user_profile-icon + %icon.fa.fa-linkedin.fa-3x + %span.concat-text Linkedin + - if @user.googleplus.present? + %li + = link_to(@user.googleplus) do + .user_profile-icon + %icon.fa.fa-googleplus.fa-3x + %span.concat-text Google+ + - if @user.gnu.present? + %li + = link_to(@user.gnu) do + .user_profile-icon + %icon.fa.fa-linux.fa-3x + %span.concat-text GNU + - if @user.diaspora.present? + %li + = link_to(@user.diaspora) do + .user_profile-icon + %icon.fa.fa-asterisk.fa-3x + %span.concat-text Diaspora + - if @user.savannah.present? + %li + = link_to(@user.savannah) do + .user_profile-icon + %icon.fa.fa-linux.fa-3x + %span.concat-text Savannah + - if @user.github.present? + %li + = link_to(@user.github) do + .user_profile-icon + %icon.fa.fa-github.fa-3x + %span.concat-text Github + - if @user.gitlab.present? + %li + = link_to(@user.gitlab) do + .user_profile-icon + %icon.fa.fa-gitlab.fa-3x + %span.concat-text Gitlab + %h3.text-center Bio %p = markdown(@user.biography) .row diff --git a/app/views/users/update.js.erb b/app/views/users/update.js.erb new file mode 100644 index 00000000..1937e877 --- /dev/null +++ b/app/views/users/update.js.erb @@ -0,0 +1 @@ +$('#messages').html("<%= j render 'layouts/messages' %>");