From 644c7a4675a007554fb969c7e3cd3699be6bf1c2 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 29 Jan 2015 17:38:39 -0500 Subject: [PATCH] FEATURE: Add an option to show custom user fields on profiles. Default is to not show them. --- .../controllers/admin-user-field-item.js.es6 | 7 +++++-- .../javascripts/admin/templates/user-fields.hbs | 5 +++++ .../javascripts/discourse/controllers/user.js.es6 | 15 +++++++++++++++ .../javascripts/discourse/templates/user/user.hbs | 13 +++++++++++++ app/assets/stylesheets/common/base/user.scss | 10 ++++++++++ app/controllers/admin/user_fields_controller.rb | 2 +- app/serializers/user_field_serializer.rb | 3 ++- config/locales/client.en.yml | 4 ++++ ...29204520_add_show_on_profile_to_user_fields.rb | 5 +++++ 9 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20150129204520_add_show_on_profile_to_user_fields.rb diff --git a/app/assets/javascripts/admin/controllers/admin-user-field-item.js.es6 b/app/assets/javascripts/admin/controllers/admin-user-field-item.js.es6 index 57cf7e02707..f4b9ba2a79a 100644 --- a/app/assets/javascripts/admin/controllers/admin-user-field-item.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-user-field-item.js.es6 @@ -17,15 +17,18 @@ export default Ember.ObjectController.extend(BufferedContent, { if (this.get('required')) { ret.push(I18n.t('admin.user_fields.required.enabled')); } + if (this.get('show_on_profile')) { + ret.push(I18n.t('admin.user_fields.show_on_profile.enabled')); + } return ret.join(', '); - }.property('editable', 'required'), + }.property('editable', 'required', 'show_on_profile'), actions: { save: function() { var self = this; - var attrs = this.get('buffered').getProperties('name', 'description', 'field_type', 'editable', 'required'); + var attrs = this.get('buffered').getProperties('name', 'description', 'field_type', 'editable', 'required', 'show_on_profile'); this.get('model').save(attrs).then(function(res) { self.set('model.id', res.user_field.id); diff --git a/app/assets/javascripts/admin/templates/user-fields.hbs b/app/assets/javascripts/admin/templates/user-fields.hbs index 32505f98c90..2412dfd1ad8 100644 --- a/app/assets/javascripts/admin/templates/user-fields.hbs +++ b/app/assets/javascripts/admin/templates/user-fields.hbs @@ -32,6 +32,11 @@ {{input type="checkbox" checked=f.buffered.required}} {{i18n 'admin.user_fields.required.title'}} +
+ +
{{else}}
diff --git a/app/assets/javascripts/discourse/controllers/user.js.es6 b/app/assets/javascripts/discourse/controllers/user.js.es6 index 247ebfffd4c..b0663627752 100644 --- a/app/assets/javascripts/discourse/controllers/user.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user.js.es6 @@ -42,6 +42,21 @@ export default ObjectController.extend(CanCheckEmails, { return this.get('can_be_deleted') && this.get('can_delete_all_posts'); }.property('can_be_deleted', 'can_delete_all_posts'), + publicUserFields: function() { + var siteUserFields = this.site.get('user_fields'); + if (!Ember.isEmpty(siteUserFields)) { + var userFields = this.get('user_fields'); + return siteUserFields.filterProperty('show_on_profile', true).sortBy('id').map(function(uf) { + var val = userFields ? userFields[uf.get('id').toString()] : null; + if (Ember.isEmpty(val)) { + return null; + } else { + return Ember.Object.create({value: val, field: uf}); + } + }).compact(); + } + }.property('user_fields.@each.value'), + privateMessagesActive: Em.computed.equal('pmView', 'index'), privateMessagesMineActive: Em.computed.equal('pmView', 'mine'), privateMessagesUnreadActive: Em.computed.equal('pmView', 'unread'), diff --git a/app/assets/javascripts/discourse/templates/user/user.hbs b/app/assets/javascripts/discourse/templates/user/user.hbs index cd1eecbd7a6..689d272989f 100644 --- a/app/assets/javascripts/discourse/templates/user/user.hbs +++ b/app/assets/javascripts/discourse/templates/user/user.hbs @@ -89,6 +89,19 @@ {{{bio_cooked}}}
+ {{#if publicUserFields}} +
+ {{#each uf in publicUserFields}} + {{#if uf.value}} +
+ {{uf.field.name}}: + {{uf.value}} +
+ {{/if}} + {{/each}} +
+ {{/if}} + {{plugin-outlet "user-profile-primary"}} diff --git a/app/assets/stylesheets/common/base/user.scss b/app/assets/stylesheets/common/base/user.scss index 004c09f5dbf..f1495540f7e 100644 --- a/app/assets/stylesheets/common/base/user.scss +++ b/app/assets/stylesheets/common/base/user.scss @@ -24,6 +24,16 @@ } } +.public-user-fields { + .user-field-name { + font-weight: bold; + } +} + +.collapsed-info .public-user-fields { + display: none; +} + .notification-buttons { margin: 10px 0; text-align: right; diff --git a/app/controllers/admin/user_fields_controller.rb b/app/controllers/admin/user_fields_controller.rb index 56ab3889deb..e5e8c9c3a9e 100644 --- a/app/controllers/admin/user_fields_controller.rb +++ b/app/controllers/admin/user_fields_controller.rb @@ -1,7 +1,7 @@ class Admin::UserFieldsController < Admin::AdminController def self.columns - [:name, :field_type, :editable, :description, :required] + [:name, :field_type, :editable, :description, :required, :show_on_profile] end def create diff --git a/app/serializers/user_field_serializer.rb b/app/serializers/user_field_serializer.rb index ff2da805e15..8638b2c04d9 100644 --- a/app/serializers/user_field_serializer.rb +++ b/app/serializers/user_field_serializer.rb @@ -4,5 +4,6 @@ class UserFieldSerializer < ApplicationSerializer :description, :field_type, :editable, - :required + :required, + :show_on_profile end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0f9efe06bbc..a29d3a4d723 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -2108,6 +2108,10 @@ en: title: "Editable after signup?" enabled: "editable" disabled: "not editable" + show_on_profile: + title: "Show on public profile?" + enabled: "shown on profile" + disabled: "not shown on profile" field_types: text: 'Text Field' diff --git a/db/migrate/20150129204520_add_show_on_profile_to_user_fields.rb b/db/migrate/20150129204520_add_show_on_profile_to_user_fields.rb new file mode 100644 index 00000000000..e4a641f98d1 --- /dev/null +++ b/db/migrate/20150129204520_add_show_on_profile_to_user_fields.rb @@ -0,0 +1,5 @@ +class AddShowOnProfileToUserFields < ActiveRecord::Migration + def change + add_column :user_fields, :show_on_profile, :boolean, default: false, null: false + end +end