Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sac points tracking system:tm: #1015

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finilised sac points system for now
stickyPiston committed Jun 8, 2022
commit cf98f5973f48d14d4308a4da62c3214f587a3feb
2 changes: 1 addition & 1 deletion app/controllers/admin/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ def update
@activity = Activity.find params[:id]
params = activity_post_params

p params
Rails.logger.debug params

# removing the images from disk
if params[:_destroy] == 'true'
26 changes: 14 additions & 12 deletions app/controllers/admin/members_controller.rb
Original file line number Diff line number Diff line change
@@ -40,18 +40,20 @@ def show
end

def sac
data = "name;category;points;date;activity\n"
rows = Member.all.map { |m| m.activities.map { |ac|
# {name => string, points => {date => string, activity => string, category => string, points => int}}
category = SAC_CATEGORIES.find { |c| c[:id] == ac.sac_category }
if ac.participants.where(:member => m).first.sac_points? then { activity: ac.name, date: ac.start_date, name: category[:name], points: ac.participants.where(:member => m).first.sac_points }
elsif ac.sac_category? then { activity: ac.name, date: ac.start_date, name: category[:name], points: category[:points] }
else 0 end }
.select { |points| points != 0 }
.map { |r| m.name + ";" + r[:name] + ";" + r[:points].to_s + ";" + r[:date].to_s + ";" + r[:activity] }
}.select{ |r| r.length > 0 }.map { |r| r.join "\n" }
rows.each { |row| data += row.to_s + "\n" }
send_data data, { :filename => "data.csv" }
data = "name;category;points;date;activity"
member = Member.find params[:member_id]

# Find all activities a members participated in with sac points
sac_eligible = member.activities.filter { |ac| (ac.sac_category? and ac.sac_category > 0) or ac.participants.where(member: member).first.sac_points? }

# Create csv rows for every activity
sac_eligible.each do |ac|
category = SAC_CATEGORIES.find { |c| c[:id] == ac.sac_category }
points = ac.participants.where(member: member).first.sac_points or category[:points]
data += "\n#{ member.name };#{ category[:name] };#{ points };#{ ac.start_date };#{ ac.name }"
end

send_data data, { filename: "data.csv" }
end

def new
1 change: 1 addition & 0 deletions app/controllers/admin/participants_controller.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ def update
@participant.update(price: params[:price])
elsif params[:sac_points].present?
raise 'negative sac points' unless params[:sac_points].to_i >= 0

@participant.update(sac_points: params[:sac_points])
end

66 changes: 35 additions & 31 deletions app/javascript/src/admin/activities.js
Original file line number Diff line number Diff line change
@@ -306,39 +306,43 @@ var participant = {
},
})
.done(function (data) {
$(row)
.find("button.unpaid")
.empty()
.addClass("paid btn-warning")
.removeClass("d-none unpaid btn-primary")
.append('<i class="fa fa-fw fa-times"></i>');
$(row).find("button.paid").removeClass("d-none");
$(row).removeClass("in-debt");

if (value > 0) {
$(row).addClass("in-debt");

$("#mail").trigger("recipient_unpayed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
if (field === "price") {
$(row)
.find("button.unpaid")
.empty()
.addClass("paid btn-warning")
.removeClass("d-none unpaid btn-primary")
.append('<i class="fa fa-fw fa-times"></i>');
$(row).find("button.paid").removeClass("d-none");
$(row).removeClass("in-debt");

if (value > 0) {
$(row).addClass("in-debt");

$("#mail").trigger("recipient_unpayed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
} else {
$(row).find("button.paid").addClass("d-none");

$("#mail").trigger("recipient_payed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
}

participant.update_debt_header(
data.activity.paid_sum,
data.activity.price_sum
);

toastr.success(I18n.t("admin.activities.info.price_changed"));
} else {
$(row).find("button.paid").addClass("d-none");

$("#mail").trigger("recipient_payed", [
$(row).attr("data-id"),
$(row).find("a").html(),
$(row).attr("data-email"),
]);
toastr.success(I18n.t("admin.activities.info.sac_changed"));
}

participant.update_debt_header(
data.activity.paid_sum,
data.activity.price_sum
);

toastr.success(I18n.t("admin.activities.info.price_changed"));
})
.fail(function () {
toastr.error(I18n.t("admin.activities.info.price_error"));
Original file line number Diff line number Diff line change
@@ -12,7 +12,8 @@
%td.price-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.price{ :type => 'text', :value => number_to_currency(participant.currency, :unit => ''), :autocomplete=>'off'}
%td.sac-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.sac{ :type => 'text', :value => (participant.sac_points or 0), :autocomplete=>'off'}
- category = SAC_CATEGORIES.find { |c| c[:id] == @activity.sac_category }
%input.sac{ :type => 'text', :value => (participant.sac_points or (category[:points] if category) or 0), :autocomplete=>'off'}
%td.notes-td
- if participant.notes
= participant.notes
2 changes: 1 addition & 1 deletion app/views/admin/activities/partials/_edit.html.haml
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@
= f.number_field :participant_limit, min: 0, data: {original: @activity.participant_limit}, id: "participant_limit"
.col-lg-6
= f.label :sac_category
= f.select :sac_category, choices: SAC_CATEGORIES.map { |c| [c[:name], c[:id]] }
= f.select :sac_category, choices: [["None", 0]] + SAC_CATEGORIES.map { |c| [c[:name], c[:id]] }
%hr.my-4
.row
.col-md-4
9 changes: 6 additions & 3 deletions app/views/admin/activities/show.html.haml
Original file line number Diff line number Diff line change
@@ -38,8 +38,7 @@
%td{ :style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
= I18n.t('activerecord.attributes.activity.price')
%td{ :style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
Sac points
-# TODO
= I18n.t('admin.sac.title')
- if !@is_summarized.nil?
%td
= I18n.t('activerecord.attributes.activity.notes')
@@ -64,7 +63,7 @@
%td.price-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.price{ :type => 'text', :value => number_to_currency(participant.currency, :unit => ''), :autocomplete=>'off'}
%td.sac-input-td{:style => 'padding: 0px; min-width: 10%; width: 10%; text-align:left;' }
%input.sac{ :type => 'text', :value => number_to_currency(participant.currency, :unit => ''), :autocomplete=>'off'}
%input.sac{ :type => 'text', :value => (participant.sac_points or @activity.sac_points or 0), :autocomplete=>'off'}
%td.notes-td
%td.buttons
.btn-group
@@ -84,6 +83,10 @@
%td{ :style => 'text-align: left;' }
- if !@activity.price.nil?
%span= number_to_currency(@activity.price, :unit => '€')
%td{ :style => 'text-align: left;' }
- if !@activity.sac_category.nil?
- category = SAC_CATEGORIES.find { |c| c[:id] == @activity.sac_category }
%span= (category[:points] if category) or 0
%td
%td

3 changes: 2 additions & 1 deletion app/views/admin/members/show.html.haml
Original file line number Diff line number Diff line change
@@ -256,6 +256,7 @@
.card
.card-header
= I18n.t('admin.sac.title')
= link_to I18n.t("admin.sac.download"), member_sac_path(@member.id)
%table.table.table-striped#sac
%thead
%tr
@@ -267,7 +268,7 @@
- @activities.select{ |ac| ac.sac_category? or ac.participants.where(:member => @member).first.sac_points?}.each do |activity|
stickyPiston marked this conversation as resolved.
Show resolved Hide resolved
%tr
- category = SAC_CATEGORIES.find {|c| c[:id] == activity.sac_category }
%td= activity.name
%td= link_to activity.name, activity
%td= category[:name] if activity.sac_category?
- user_points = activity.participants.where(:member => @member).first.sac_points
- points = [user_points, (activity.sac_category? and category[:points]), 0].find{ |n| n.present? }
1 change: 1 addition & 0 deletions config/initializers/sac.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SAC_CATEGORIES = [
stickyPiston marked this conversation as resolved.
Show resolved Hide resolved
{ id: 0, name: "None", points: 0 },
{ id: 1, name: "Category 1", points: 10 },
{ id: 2, name: "Category 2", points: 20 },
{ id: 3, name: "Category 3", points: 30 },
6 changes: 6 additions & 0 deletions config/locales/admin.en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
---
en:
admin:
sac:
title: Sac points
category: Category
total: Total
download: Download report
activities:
added_reservist: has been placed on the participants list
ended: Ended
@@ -10,6 +15,7 @@ en:
already_added: This participant was already added
price_changed: The participants fee has changed
price_error: No connection or not a number
sac_changed: The number of sac points has been changed
new: New activity
remove_participant: Do you want to remove %{user} as participant?
save: Save activity?
2 changes: 2 additions & 0 deletions config/locales/admin.nl.yml
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ nl:
title: Sac punten
category: Categorie
total: Totaal
download: Download rapport
activities:
added_reservist: is op de deelnemerslijst geplaatst
ended: Afgelopen
@@ -14,6 +15,7 @@ nl:
already_added: Deze persoon is al toegevoegd
price_changed: Het deelname bedrag is veranderd
price_error: Geen verbinding of geen nummer
sac_changed: Het aantal sac punten is veranderd
new: Nieuwe activiteit
remove_participant: Deelname van %{user} verwijderen?
save: Activiteit opslaan?