feat(transactions:action-bar): add more math options in a dropdown

This commit is contained in:
Herculino Trotta
2025-01-05 14:35:23 -03:00
parent 10a0ac42a2
commit 881fed1895
@@ -56,12 +56,45 @@
<i class="fa-solid fa-trash text-danger"></i> <i class="fa-solid fa-trash text-danger"></i>
</button> </button>
<div class="vr mx-3 tw-align-middle"></div> <div class="vr mx-3 tw-align-middle"></div>
<span _="on selected_transactions_updated from #actions-bar {# <span _="on selected_transactions_updated from #actions-bar#}
{# set realTotal to 0.0#}
{# set flatTotal to 0.0#}
{# for transaction in <.transaction:has(input[name='transactions']:checked)/>#}
{# set amt to first <.main-amount .amount/> in transaction#}
{# set amountValue to parseFloat(amt.getAttribute('data-amount'))#}
{# if not isNaN(amountValue)#}
{# set flatTotal to flatTotal + (amountValue * 100)#}
{##}
{# if transaction match .income#}
{# set realTotal to realTotal + (amountValue * 100)#}
{# else#}
{# set realTotal to realTotal - (amountValue * 100)#}
{# end#}
{# end#}
{# end#}
{# set realTotal to realTotal / 100#}
{# put realTotal.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 40}) into me#}
{# end#}
{# on click#}
{# set original_value to my innerText#}
{# writeText(my innerText) on navigator.clipboard#}
{# put '{% translate "copied!" %}' into me#}
{# wait 1s#}
{# put original_value into me#}
{# end"#}
{# class="" role="button"></span>#}
<div class="btn-group"
_="on selected_transactions_updated from #actions-bar
set realTotal to 0.0 set realTotal to 0.0
set flatTotal to 0.0 set flatTotal to 0.0
for transaction in <.transaction:has(input[name='transactions']:checked)/> set transactions to <.transaction:has(input[name='transactions']:checked)/>
set amountValues to []
for transaction in transactions
set amt to first <.main-amount .amount/> in transaction set amt to first <.main-amount .amount/> in transaction
set amountValue to parseFloat(amt.getAttribute('data-amount')) set amountValue to parseFloat(amt.getAttribute('data-amount'))
append amountValue to amountValues
if not isNaN(amountValue) if not isNaN(amountValue)
set flatTotal to flatTotal + (amountValue * 100) set flatTotal to flatTotal + (amountValue * 100)
@@ -72,17 +105,158 @@
end end
end end
end end
set realTotal to realTotal / 100 set realTotal to realTotal / 100
put realTotal.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 40}) into me put realTotal.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 40}) into #real-total-front's innerText
end put realTotal.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 40}) into #calc-menu-real-total's innerText
on click set flatTotal to flatTotal / 100
put flatTotal.toLocaleString(undefined, {minimumFractionDigits: 0, maximumFractionDigits: 40}) into #calc-menu-flat-total's innerText
log amountValues
put Math.max.apply(Math, amountValues) into #calc-menu-max's innerText
put Math.min.apply(Math, amountValues) into #calc-menu-min's innerText
put flatTotal / amountValues.length into #calc-menu-mean's innerText
put amountValues.length into #calc-menu-count's innerText
end"
>
<button class="btn btn-secondary btn-sm">
<i class="fa-solid fa-plus fa-fw me-2 text-primary"></i>
<span id="real-total-front"
_="on click
set original_value to my innerText set original_value to my innerText
writeText(my innerText) on navigator.clipboard writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me put '{% translate "copied!" %}' into me
wait 1s wait 1s
put original_value into me put original_value into me
end" end">0</span>
class="" role="button"></span> </button>
<button type="button" class="btn btn-sm btn-secondary dropdown-toggle dropdown-toggle-split"
data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
<span class="visually-hidden">{% trans "Toggle Dropdown" %}</span>
</button>
<ul class="dropdown-menu">
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Flat Total" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-flat-total"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Real Total" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-real-total"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Mean" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-mean"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Max" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-max"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Min" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-min"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
<li>
<div class="dropdown-item-text p-0">
<div>
<div class="text-body-secondary tw-text-xs tw-font-medium px-3">
{% trans "Count" %}
</div>
<div class="dropdown-item px-3 tw-cursor-pointer"
id="calc-menu-count"
_="on click
set original_value to my innerText
writeText(my innerText) on navigator.clipboard
put '{% translate "copied!" %}' into me
wait 1s
put original_value into me
end">
0
</div>
</div>
</div>
</li>
</ul>
</div>
{% endspaceless %} {% endspaceless %}
</div> </div>
</div> </div>