Add additional settings and customizations

This commit is contained in:
Angus McLeod 2018-09-28 17:33:27 +10:00
parent ae793ad247
commit e1eb585974
4 changed files with 59 additions and 22 deletions

View File

@ -1,4 +1,9 @@
{{#if siteSettings.discourse_donations_cause_category}} {{#if siteSettings.discourse_donations_cause_category}}
<section class='field'>
<label>{{i18n 'discourse_donations.cause.amounts.setting_label'}}</label>
{{input type="checkbox" checked=category.custom_fields.donations_show_amounts}}
</section>
<section class='field'> <section class='field'>
<label>{{i18n 'discourse_donations.cause.github.setting_label'}}</label> <label>{{i18n 'discourse_donations.cause.github.setting_label'}}</label>
{{text-field value=category.custom_fields.donations_github placeholderKey="discourse_donations.cause.github.setting_placeholder"}} {{text-field value=category.custom_fields.donations_github placeholderKey="discourse_donations.cause.github.setting_placeholder"}}
@ -13,4 +18,9 @@
<label>{{i18n 'discourse_donations.cause.maintainers.label'}}</label> <label>{{i18n 'discourse_donations.cause.maintainers.label'}}</label>
{{user-selector usernames=category.custom_fields.donations_maintainers}} {{user-selector usernames=category.custom_fields.donations_maintainers}}
</section> </section>
<section class='field'>
<label>{{i18n 'discourse_donations.cause.maintainers.setting_label'}}</label>
{{input value=category.custom_fields.donations_maintainers_label}}
</section>
{{/if}} {{/if}}

View File

@ -29,12 +29,14 @@ createWidget('category-header-widget', {
]) ])
]; ];
let metadata = [ let metadata = [];
donationDisplay(category.donations_total || 0, 'total')
];
if (Discourse.SiteSettings.discourse_donations_cause_month) { if (category.donations_show_amounts) {
metadata.push(donationDisplay(category.donations_month || 0, 'month')); metadata.push(donationDisplay(category.donations_total || 0, 'total'));
if (Discourse.SiteSettings.discourse_donations_cause_month) {
metadata.push(donationDisplay(category.donations_month || 0, 'month'));
}
} }
if (category.donations_github) { if (category.donations_github) {
@ -85,8 +87,11 @@ createWidget('category-header-widget', {
}; };
if (category.donations_maintainers.length) { if (category.donations_maintainers.length) {
let maintainersLabel = category.donations_maintainers_label ||
I18n.t('discourse_donations.cause.maintainers.label');
users.push(h('div.donations-maintainers', [ users.push(h('div.donations-maintainers', [
h('div.donations-maintainers-title', I18n.t('discourse_donations.cause.maintainers.label')), h('div.donations-maintainers-title', maintainersLabel),
category.donations_maintainers.map(user => { category.donations_maintainers.map(user => {
if (user) { if (user) {
return avatarFor('medium', { return avatarFor('medium', {

View File

@ -55,6 +55,9 @@ en:
setting_placeholder: "topic url" setting_placeholder: "topic url"
maintainers: maintainers:
label: "Maintainers" label: "Maintainers"
setting_label: "Maintainers label"
amounts:
setting_label: "Show donation amounts"
subscription: subscription:
cancel: cancel:
title: "Cancel Recurring Donation" title: "Cancel Recurring Donation"

View File

@ -35,6 +35,8 @@ after_initialize do
end end
end end
Category.register_custom_field_type('donations_show_amounts', :boolean)
class ::Category class ::Category
def donations_cause def donations_cause
SiteSetting.discourse_donations_causes_categories.split('|').include? self.id.to_s SiteSetting.discourse_donations_causes_categories.split('|').include? self.id.to_s
@ -48,6 +50,14 @@ after_initialize do
end end
end end
def donations_show_amounts
if custom_fields['donations_show_amounts'] != nil
custom_fields['donations_show_amounts']
else
true
end
end
def donations_month def donations_month
if custom_fields['donations_month'] if custom_fields['donations_month']
custom_fields['donations_month'] custom_fields['donations_month']
@ -76,11 +86,19 @@ after_initialize do
end end
end end
def donations_maintainers_label
if custom_fields['donations_maintainers_label']
custom_fields['donations_maintainers_label']
else
nil
end
end
def donations_github def donations_github
if custom_fields['donations_github'] if custom_fields['donations_github']
custom_fields['donations_github'] custom_fields['donations_github']
else else
'' nil
end end
end end
@ -88,25 +106,26 @@ after_initialize do
if custom_fields['donations_meta'] if custom_fields['donations_meta']
custom_fields['donations_meta'] custom_fields['donations_meta']
else else
'' nil
end end
end end
end end
if SiteSetting.discourse_donations_cause_category add_to_serializer(:basic_category, :donations_cause) { object.donations_cause }
add_to_serializer(:basic_category, :donations_cause) { object.donations_cause } add_to_serializer(:basic_category, :donations_total) { object.donations_total }
add_to_serializer(:basic_category, :donations_total) { object.donations_total } add_to_serializer(:basic_category, :include_donations_total?) { object.donations_show_amounts }
add_to_serializer(:basic_category, :donations_month) { object.donations_month } add_to_serializer(:basic_category, :donations_month) { object.donations_month }
add_to_serializer(:basic_category, :include_donations_month?) { SiteSetting.discourse_donations_cause_month } add_to_serializer(:basic_category, :include_donations_month?) { object.donations_show_amounts && SiteSetting.discourse_donations_cause_month }
add_to_serializer(:basic_category, :donations_backers) { add_to_serializer(:basic_category, :donations_backers) {
ActiveModel::ArraySerializer.new(object.donations_backers, each_serializer: BasicUserSerializer).as_json ActiveModel::ArraySerializer.new(object.donations_backers, each_serializer: BasicUserSerializer).as_json
} }
add_to_serializer(:basic_category, :donations_maintainers) { add_to_serializer(:basic_category, :donations_maintainers) {
ActiveModel::ArraySerializer.new(object.donations_maintainers, each_serializer: BasicUserSerializer).as_json ActiveModel::ArraySerializer.new(object.donations_maintainers, each_serializer: BasicUserSerializer).as_json
} }
add_to_serializer(:basic_category, :donations_github) { object.donations_github } add_to_serializer(:basic_category, :donations_maintainers_label) { object.donations_maintainers_label }
add_to_serializer(:basic_category, :donations_meta) { object.donations_meta } add_to_serializer(:basic_category, :include_donations_maintainers_label?) { object.donations_maintainers_label.present? }
end add_to_serializer(:basic_category, :donations_github) { object.donations_github }
add_to_serializer(:basic_category, :donations_meta) { object.donations_meta }
DiscourseEvent.trigger(:donations_ready) DiscourseEvent.trigger(:donations_ready)
end end