mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: add user custom fields to user card
The user's custom fields are now displayed on the user card. This has to be enabled for each custom field in the custom field settings. See https://meta.discourse.org/t/custom-user-fields-on-usercard/22662/
This commit is contained in:
parent
95155cda64
commit
cf8b3fbd56
11 changed files with 63 additions and 13 deletions
|
@ -43,9 +43,12 @@ export default Ember.Component.extend(bufferedProperty('userField'), {
|
|||
if (this.get('userField.show_on_profile')) {
|
||||
ret.push(I18n.t('admin.user_fields.show_on_profile.enabled'));
|
||||
}
|
||||
if (this.get('userField.show_on_user_card')) {
|
||||
ret.push(I18n.t('admin.user_fields.show_on_user_card.enabled'));
|
||||
}
|
||||
|
||||
return ret.join(', ');
|
||||
}.property('userField.editable', 'userField.required', 'userField.show_on_profile'),
|
||||
}.property('userField.editable', 'userField.required', 'userField.show_on_profile', 'userField.show_on_user_card'),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
|
@ -57,6 +60,7 @@ export default Ember.Component.extend(bufferedProperty('userField'), {
|
|||
'editable',
|
||||
'required',
|
||||
'show_on_profile',
|
||||
'show_on_user_card',
|
||||
'options');
|
||||
|
||||
this.get('userField').save(attrs).then(function() {
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
{{input type="checkbox" checked=buffered.show_on_profile}} {{i18n 'admin.user_fields.show_on_profile.title'}}
|
||||
{{/admin-form-row}}
|
||||
|
||||
{{#admin-form-row wrapLabel="true"}}
|
||||
{{input type="checkbox" checked=buffered.show_on_user_card}} {{i18n 'admin.user_fields.show_on_user_card.title'}}
|
||||
{{/admin-form-row}}
|
||||
|
||||
{{#admin-form-row}}
|
||||
{{d-button action="save" class="btn-primary" icon="check" label="admin.user_fields.save"}}
|
||||
{{d-button action="cancel" class="btn-danger" icon="times" label="admin.user_fields.cancel"}}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import DiscourseURL from 'discourse/lib/url';
|
||||
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
||||
import computed from 'ember-addons/ember-computed-decorators';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
needs: ['topic', 'application'],
|
||||
|
@ -26,6 +27,19 @@ export default Ember.Controller.extend({
|
|||
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
|
||||
showDelete: Em.computed.and("viewingAdmin", "showName", "user.canBeDeleted"),
|
||||
|
||||
@computed('model.user_fields.@each.value')
|
||||
publicUserFields() {
|
||||
const siteUserFields = this.site.get('user_fields');
|
||||
if (!Ember.isEmpty(siteUserFields)) {
|
||||
const userFields = this.get('user.user_fields');
|
||||
return siteUserFields.filterProperty('show_on_user_card', true).sortBy('position').map(field => {
|
||||
Ember.set(field, 'dasherized_name', field.get('name').dasherize());
|
||||
const value = userFields ? userFields[field.get('id')] : null;
|
||||
return Ember.isEmpty(value) ? null : Ember.Object.create({ value, field });
|
||||
}).compact();
|
||||
}
|
||||
},
|
||||
|
||||
moreBadgesCount: function() {
|
||||
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
||||
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
||||
|
|
|
@ -65,6 +65,19 @@
|
|||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if publicUserFields}}
|
||||
<div class="public-user-fields">
|
||||
{{#each uf in publicUserFields}}
|
||||
{{#if uf.value}}
|
||||
<div class="public-user-field {{uf.field.dasherized_name}}">
|
||||
<span class="user-field-name">{{uf.field.name}}:</span>
|
||||
<span class="user-field-value">{{uf.value}}</span>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if showBadges}}
|
||||
<div class="badge-section">
|
||||
{{#each ub in user.featured_user_badges}}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Admin::UserFieldsController < Admin::AdminController
|
||||
|
||||
def self.columns
|
||||
[:name, :field_type, :editable, :description, :required, :show_on_profile, :position]
|
||||
[:name, :field_type, :editable, :description, :required, :show_on_profile, :show_on_user_card, :position]
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -12,14 +12,15 @@ end
|
|||
#
|
||||
# Table name: user_fields
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# field_type :string not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# editable :boolean default(FALSE), not null
|
||||
# description :string not null
|
||||
# required :boolean default(TRUE), not null
|
||||
# show_on_profile :boolean default(FALSE), not null
|
||||
# position :integer default(0)
|
||||
# id :integer not null, primary key
|
||||
# name :string not null
|
||||
# field_type :string not null
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
# editable :boolean default(FALSE), not null
|
||||
# description :string not null
|
||||
# required :boolean default(TRUE), not null
|
||||
# show_on_profile :boolean default(FALSE), not null
|
||||
# show_on_user_card :boolean default(FALSE), not null
|
||||
# position :integer default(0)
|
||||
#
|
||||
|
|
|
@ -6,6 +6,7 @@ class UserFieldSerializer < ApplicationSerializer
|
|||
:editable,
|
||||
:required,
|
||||
:show_on_profile,
|
||||
:show_on_user_card,
|
||||
:position,
|
||||
:options
|
||||
|
||||
|
|
|
@ -2443,6 +2443,10 @@ de:
|
|||
title: "Im öffentlichen Profil anzeigen?"
|
||||
enabled: "wird im Profil angezeigt"
|
||||
disabled: "wird im Profil nicht angezeigt"
|
||||
show_on_user_card:
|
||||
title: "Auf Benutzerkarte anzeigen?"
|
||||
enabled: "wird auf Benutzerkarte angezeigt"
|
||||
disabled: "wird auf Benutzerkarte nicht angezeigt"
|
||||
field_types:
|
||||
text: 'Textfeld'
|
||||
confirm: 'Bestätigung'
|
||||
|
|
|
@ -2640,6 +2640,10 @@ en:
|
|||
title: "Show on public profile?"
|
||||
enabled: "shown on profile"
|
||||
disabled: "not shown on profile"
|
||||
show_on_user_card:
|
||||
title: "Show on user card?"
|
||||
enabled: "shown on user card"
|
||||
disabled: "not shown on user card"
|
||||
|
||||
field_types:
|
||||
text: 'Text Field'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddShowOnUserCardToUserFields < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :user_fields, :show_on_user_card, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
|
@ -26,7 +26,7 @@ class ImportScripts::Ning < ImportScripts::Base
|
|||
# Example of importing a custom profile field:
|
||||
# @interests_field = UserField.find_by_name("My interests")
|
||||
# unless @interests_field
|
||||
# @interests_field = UserField.create(name: "My interests", description: "Do you like stuff?", field_type: "text", editable: true, required: false, show_on_profile: true)
|
||||
# @interests_field = UserField.create(name: "My interests", description: "Do you like stuff?", field_type: "text", editable: true, required: false, show_on_profile: true, show_on_user_card: true)
|
||||
# end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue