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
|
@ -43,9 +43,12 @@ export default Ember.Component.extend(bufferedProperty('userField'), {
|
||||||
if (this.get('userField.show_on_profile')) {
|
if (this.get('userField.show_on_profile')) {
|
||||||
ret.push(I18n.t('admin.user_fields.show_on_profile.enabled'));
|
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(', ');
|
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: {
|
actions: {
|
||||||
save() {
|
save() {
|
||||||
|
@ -57,6 +60,7 @@ export default Ember.Component.extend(bufferedProperty('userField'), {
|
||||||
'editable',
|
'editable',
|
||||||
'required',
|
'required',
|
||||||
'show_on_profile',
|
'show_on_profile',
|
||||||
|
'show_on_user_card',
|
||||||
'options');
|
'options');
|
||||||
|
|
||||||
this.get('userField').save(attrs).then(function() {
|
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'}}
|
{{input type="checkbox" checked=buffered.show_on_profile}} {{i18n 'admin.user_fields.show_on_profile.title'}}
|
||||||
{{/admin-form-row}}
|
{{/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}}
|
{{#admin-form-row}}
|
||||||
{{d-button action="save" class="btn-primary" icon="check" label="admin.user_fields.save"}}
|
{{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"}}
|
{{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 DiscourseURL from 'discourse/lib/url';
|
||||||
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
import { propertyNotEqual, setting } from 'discourse/lib/computed';
|
||||||
|
import computed from 'ember-addons/ember-computed-decorators';
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
needs: ['topic', 'application'],
|
needs: ['topic', 'application'],
|
||||||
|
@ -26,6 +27,19 @@ export default Ember.Controller.extend({
|
||||||
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
|
showMoreBadges: Em.computed.gt('moreBadgesCount', 0),
|
||||||
showDelete: Em.computed.and("viewingAdmin", "showName", "user.canBeDeleted"),
|
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() {
|
moreBadgesCount: function() {
|
||||||
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
return this.get('user.badge_count') - this.get('user.featured_user_badges.length');
|
||||||
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
}.property('user.badge_count', 'user.featured_user_badges.@each'),
|
||||||
|
|
|
@ -65,6 +65,19 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/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}}
|
{{#if showBadges}}
|
||||||
<div class="badge-section">
|
<div class="badge-section">
|
||||||
{{#each ub in user.featured_user_badges}}
|
{{#each ub in user.featured_user_badges}}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class Admin::UserFieldsController < Admin::AdminController
|
class Admin::UserFieldsController < Admin::AdminController
|
||||||
|
|
||||||
def self.columns
|
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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
@ -12,14 +12,15 @@ end
|
||||||
#
|
#
|
||||||
# Table name: user_fields
|
# Table name: user_fields
|
||||||
#
|
#
|
||||||
# id :integer not null, primary key
|
# id :integer not null, primary key
|
||||||
# name :string not null
|
# name :string not null
|
||||||
# field_type :string not null
|
# field_type :string not null
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# editable :boolean default(FALSE), not null
|
# editable :boolean default(FALSE), not null
|
||||||
# description :string not null
|
# description :string not null
|
||||||
# required :boolean default(TRUE), not null
|
# required :boolean default(TRUE), not null
|
||||||
# show_on_profile :boolean default(FALSE), not null
|
# show_on_profile :boolean default(FALSE), not null
|
||||||
# position :integer default(0)
|
# show_on_user_card :boolean default(FALSE), not null
|
||||||
|
# position :integer default(0)
|
||||||
#
|
#
|
||||||
|
|
|
@ -6,6 +6,7 @@ class UserFieldSerializer < ApplicationSerializer
|
||||||
:editable,
|
:editable,
|
||||||
:required,
|
:required,
|
||||||
:show_on_profile,
|
:show_on_profile,
|
||||||
|
:show_on_user_card,
|
||||||
:position,
|
:position,
|
||||||
:options
|
:options
|
||||||
|
|
||||||
|
|
|
@ -2443,6 +2443,10 @@ de:
|
||||||
title: "Im öffentlichen Profil anzeigen?"
|
title: "Im öffentlichen Profil anzeigen?"
|
||||||
enabled: "wird im Profil angezeigt"
|
enabled: "wird im Profil angezeigt"
|
||||||
disabled: "wird im Profil nicht 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:
|
field_types:
|
||||||
text: 'Textfeld'
|
text: 'Textfeld'
|
||||||
confirm: 'Bestätigung'
|
confirm: 'Bestätigung'
|
||||||
|
|
|
@ -2640,6 +2640,10 @@ en:
|
||||||
title: "Show on public profile?"
|
title: "Show on public profile?"
|
||||||
enabled: "shown on profile"
|
enabled: "shown on profile"
|
||||||
disabled: "not 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:
|
field_types:
|
||||||
text: 'Text Field'
|
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:
|
# Example of importing a custom profile field:
|
||||||
# @interests_field = UserField.find_by_name("My interests")
|
# @interests_field = UserField.find_by_name("My interests")
|
||||||
# unless @interests_field
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue