Add API routes and expand v2 frontend

This commit is contained in:
James Cole 2023-09-20 06:18:25 +02:00
parent 0e3ebb9f1a
commit 6b5774a66d
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
8 changed files with 69 additions and 48 deletions

View File

@ -201,14 +201,16 @@ export default () => ({
for (let iii = 0; iii < current.attributes.transactions.length; iii++) { for (let iii = 0; iii < current.attributes.transactions.length; iii++) {
let currentTransaction = current.attributes.transactions[iii]; let currentTransaction = current.attributes.transactions[iii];
//console.log(currentTransaction); //console.log(currentTransaction);
const nativeAmountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.native_amount) * -1 : parseFloat(currentTransaction.native_amount);
const amountRaw = 'withdrawal' === currentTransaction.type ? parseFloat(currentTransaction.amount) * -1 : parseFloat(currentTransaction.amount);
group.transactions.push({ group.transactions.push({
description: currentTransaction.description, description: currentTransaction.description,
id: current.id, id: current.id,
type: currentTransaction.type, type: currentTransaction.type,
amount_raw: parseFloat(currentTransaction.amount), amount_raw: amountRaw,
amount: formatMoney(currentTransaction.amount, currentTransaction.currency_code), amount: formatMoney(amountRaw, currentTransaction.currency_code),
native_amount_raw: parseFloat(currentTransaction.native_amount), native_amount_raw: nativeAmountRaw,
native_amount: formatMoney(currentTransaction.native_amount, currentTransaction.native_currency_code), native_amount: formatMoney(nativeAmountRaw, currentTransaction.native_currency_code),
}); });
} }
groups.push(group); groups.push(group);

View File

@ -30,6 +30,8 @@ let transactions = function () {
return { return {
count: 0, count: 0,
totalAmount: 0, totalAmount: 0,
showSuccessMessage: false,
showErrorMessage: false,
entries: [], entries: [],
// error and success messages: // error and success messages:
@ -37,38 +39,15 @@ let transactions = function () {
showSuccess: false, showSuccess: false,
init() { init() {
const opts = { console.log('init()');
onSelectItem: console.log,
};
let src = [];
for (let i = 0; i < 50; i++) {
src.push({
title: "Option " + i,
id: "opt" + i,
data: {
key: i,
},
});
}
// for each thing, make autocomplete?
this.addSplit(); this.addSplit();
console.log('Ik ben init hoera');
// let element = document.getElementById('source_0');
// new Autocomplete(element, {
// items: src,
// valueField: "id",
// labelField: "title",
// highlightTyped: true,
// onSelectItem: console.log,
// });
}, },
submitTransaction() { submitTransaction() {
// todo disable buttons
let transactions = parseFromEntries(this.entries); let transactions = parseFromEntries(this.entries);
let submission = { let submission = {
// todo process all options
group_title: null, group_title: null,
fire_webhooks: false, fire_webhooks: false,
apply_rules: false, apply_rules: false,
@ -77,8 +56,15 @@ let transactions = function () {
let poster = new Post(); let poster = new Post();
console.log(submission); console.log(submission);
poster.post(submission).then((response) => { poster.post(submission).then((response) => {
// todo create success banner
this.showSuccessMessage = true;
// todo or redirect to transaction.
// todo release form
console.log(response); console.log(response);
}).catch((error) => { }).catch((error) => {
this.showErrorMessage = true;
// todo create error banner.
// todo release form
console.error(error); console.error(error);
}); });
}, },
@ -90,7 +76,6 @@ let transactions = function () {
// fall back to index 0 // fall back to index 0
const triggerFirstTabEl = document.querySelector('#split-0-tab') const triggerFirstTabEl = document.querySelector('#split-0-tab')
triggerFirstTabEl.click(); triggerFirstTabEl.click();
//bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
}, },
formattedTotalAmount() { formattedTotalAmount() {
return formatMoney(this.totalAmount, 'EUR'); return formatMoney(this.totalAmount, 'EUR');
@ -109,7 +94,6 @@ function loadPage() {
Alpine.start(); Alpine.start();
} }
// wait for load until bootstrapped event is received. // wait for load until bootstrapped event is received.
document.addEventListener('firefly-iii-bootstrapped', () => { document.addEventListener('firefly-iii-bootstrapped', () => {
console.log('Loaded through event listener.'); console.log('Loaded through event listener.');

View File

@ -27,6 +27,7 @@ function getDefaultChartSettings(type) {
data: { data: {
datasets: [], datasets: [],
}, },
options: {animations: false}
} }
} }
if ('pie' === type) { if ('pie' === type) {

View File

@ -1681,6 +1681,7 @@ return [
'remove_budgeted_amount' => 'Remove budgeted amount in :currency', 'remove_budgeted_amount' => 'Remove budgeted amount in :currency',
// bills: // bills:
'subscription' => 'Subscription',
'not_expected_period' => 'Not expected this period', 'not_expected_period' => 'Not expected this period',
'subscriptions_in_group' => 'Subscriptions in group "%{title}"', 'subscriptions_in_group' => 'Subscriptions in group "%{title}"',
'subscr_expected_x_times' => 'Expect to pay %{amount} %{times} times this period', 'subscr_expected_x_times' => 'Expect to pay %{amount} %{times} times this period',
@ -1720,6 +1721,7 @@ return [
'bill_edit_rules' => 'Firefly III will attempt to edit the rule related to this bill as well. If you\'ve edited this rule yourself however, Firefly III won\'t change anything.|Firefly III will attempt to edit the :count rules related to this bill as well. If you\'ve edited these rules yourself however, Firefly III won\'t change anything.', 'bill_edit_rules' => 'Firefly III will attempt to edit the rule related to this bill as well. If you\'ve edited this rule yourself however, Firefly III won\'t change anything.|Firefly III will attempt to edit the :count rules related to this bill as well. If you\'ve edited these rules yourself however, Firefly III won\'t change anything.',
'bill_expected_date' => 'Expected :date', 'bill_expected_date' => 'Expected :date',
'bill_expected_date_js' => 'Expected {date}', 'bill_expected_date_js' => 'Expected {date}',
'expected_amount' => '(Expected) amount',
'bill_paid_on' => 'Paid on {date}', 'bill_paid_on' => 'Paid on {date}',
'bill_repeats_weekly' => 'Repeats weekly', 'bill_repeats_weekly' => 'Repeats weekly',
'bill_repeats_monthly' => 'Repeats monthly', 'bill_repeats_monthly' => 'Repeats monthly',

View File

@ -13,7 +13,7 @@
x-text="account.name"></a> x-text="account.name"></a>
<span class="small"> <span class="small">
@include('partials.elements.amount', ['autoConversion' => true,'amount' => 'account.balance','native' => 'account.native_balance']) @include('partials.elements.amount', ['autoConversion' => true,'type' => 'null','amount' => 'account.balance','native' => 'account.native_balance'])
</span> </span>
</h3> </h3>
</div> </div>
@ -71,7 +71,7 @@
</template> </template>
<template x-for="transaction in group.transactions"> <template x-for="transaction in group.transactions">
<span> <span>
@include('partials.elements.amount', ['autoConversion' => true,'amount' => 'transaction.amount','native' => 'transaction.native_amount']) @include('partials.elements.amount', ['autoConversion' => true,'type' => 'transaction.type','amount' => 'transaction.amount','native' => 'transaction.native_amount'])
</span> </span>
</template> </template>
</td> </td>

View File

@ -8,7 +8,7 @@
</a> </a>
</h3> </h3>
</div> </div>
<div class="card-body p-0"> <div class="card-body">
<div class="row mb-2"> <div class="row mb-2">
<template x-for="pie in group.payment_info"> <template x-for="pie in group.payment_info">
<div :class='group.col_size'> <div :class='group.col_size'>
@ -22,15 +22,15 @@
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>
<th>TODO Subscription</th> <th>{{ __('firefly.subscription') }}</th>
<th>(Expected) amount</th> <th>{{ __('firefly.expected_amount') }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<template x-for="bill in group.bills"> <template x-for="bill in group.bills">
<tr> <tr>
<td> <td>
<a href="#" :title="bill.name"> <a :href="'{{ route('subscriptions.show',['']) }}/' + bill.id" :title="bill.name">
<span x-text="bill.name"></span> <span x-text="bill.name"></span>
</a> </a>
<template x-if="bill.paid"> <template x-if="bill.paid">

View File

@ -7,9 +7,16 @@
</span> </span>
</template> </template>
<template x-if="{{ $native }}_raw >= 0"> <template x-if="{{ $native }}_raw >= 0">
<span class="text-success"> <template x-if="'transfer' === {{ $type }}">
<span x-text="{{ $native }}"></span> <span class="text-primary">
</span> <span x-text="{{ $native }}"></span>
</span>
</template>
<template x-if="'transfer' !== {{ $type }}">
<span class="text-success">
<span x-text="{{ $native }}"></span>
</span>
</template>
</template> </template>
</span> </span>
</template> </template>
@ -29,13 +36,20 @@
</template> </template>
@else @else
<template x-if="{{ $amount }}_raw < 0"> <template x-if="{{ $amount }}_raw < 0">
<span class="text-danger"> <span class="text-danger">
<span x-text="{{ $amount }}"></span> <span x-text="{{ $amount }}"></span>
</span> </span>
</template> </template>
<template x-if="{{ $amount }}_raw >= 0"> <template x-if="{{ $amount }}_raw >= 0">
<span class="text-success"> <template x-if="'transfer' === {{ $type }}">
<span x-text="{{ $amount }}"></span> <span class="text-primary">
</span> <span x-text="{{ $amount }}"></span>
</span>
</template>
<template x-if="'transfer' !== {{ $type }}">
<span class="text-success">
<span x-text="{{ $amount }}"></span>
</span>
</template>
</template> </template>
@endif @endif

View File

@ -202,6 +202,24 @@ Route::group(
} }
); );
/**
* V2 API route for user groups (administrations).
*/
Route::group(
[
'namespace' => 'FireflyIII\Api\V2\Controllers\UserGroup',
'prefix' => 'v2/user-groups',
'as' => 'api.v2.user-groups.',
],
static function () {
Route::get('', ['uses' => 'ShowController@index', 'as' => 'index']);
Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']);
Route::get('{userGroup}', ['uses' => 'ShowController@show', 'as' => 'show']);
}
);
// down here is v1
/** /**
* Autocomplete controllers * Autocomplete controllers
*/ */