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}}
<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'>
<label>{{i18n 'discourse_donations.cause.github.setting_label'}}</label>
{{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>
{{user-selector usernames=category.custom_fields.donations_maintainers}}
</section>
<section class='field'>
<label>{{i18n 'discourse_donations.cause.maintainers.setting_label'}}</label>
{{input value=category.custom_fields.donations_maintainers_label}}
</section>
{{/if}}

View File

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

View File

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

View File

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