Add setting for monthly total and other minor improvements

This commit is contained in:
Angus McLeod 2018-09-24 10:17:53 +10:00
parent a3636a5038
commit ae793ad247
6 changed files with 15 additions and 3 deletions

View File

@ -105,6 +105,10 @@ module DiscourseDonations
args = user_params.to_h.slice(:email, :username, :password, :name).merge(rewards: output['rewards'])
Jobs.enqueue(:donation_user, args)
end
if SiteSetting.discourse_donations_cause_category
Jobs.enqueue(:update_category_donation_statistics)
end
end
render json: output

View File

@ -1,6 +1,6 @@
module Jobs
class UpdateCategoryDonationStatistics < ::Jobs::Scheduled
every 1.hour
every 1.day
def execute(args)
return unless SiteSetting.discourse_donations_cause_category

View File

@ -30,10 +30,13 @@ createWidget('category-header-widget', {
];
let metadata = [
donationDisplay(category.donations_total || 0, 'total'),
donationDisplay(category.donations_month || 0, 'month')
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) {
metadata.push(
h('div.donations-github', this.attach('link', {

View File

@ -22,6 +22,7 @@ en:
discourse_donations_causes_categories: "Categories of cause a user can donate do."
discourse_donations_cause_category: "Category causes enabled."
discourse_donations_cause_required: "Require user to select a cause when donating."
discourse_donations_cause_month: "Show monthly total of donations to each cause."
errors:
discourse_donations_amount_must_be_number: "Amounts must be numbers"

View File

@ -73,3 +73,6 @@ plugins:
discourse_donations_cause_required:
client: true
default: false
discourse_donations_cause_month:
client: true
default: false

View File

@ -97,6 +97,7 @@ after_initialize do
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
}