Skip to content

Firefly III: a personal finances manager

Add link edit buttons and working search.

James Coleffba77eb99dc
diff --git a/app/Http/Controllers/Transaction/ShowController.php b/app/Http/Controllers/Transaction/ShowController.php
index d7b3b18ffd..7ac3b27a31 100644
--- a/app/Http/Controllers/Transaction/ShowController.php
+++ b/app/Http/Controllers/Transaction/ShowController.php
@@ -36,6 +36,7 @@ use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
+use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -66,6 +67,10 @@ final class ShowController extends Controller
});
}
+ public function redirectToGroup(TransactionJournal $journal): RedirectResponse {
+ return redirect(route('transactions.show', [$journal->transaction_group_id]));
+ }
+
/**
* @return JsonResponse
*/
diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js
index 499942fb98..2ff02cca15 100644
--- a/resources/assets/v3/js/pages/transactions/create.js
+++ b/resources/assets/v3/js/pages/transactions/create.js
@@ -247,7 +247,33 @@ let create = function () {
}, 500);
},
saveNewLink(e) {
- // add entry to temporary table.
+ let index = parseInt(e.currentTarget.dataset.index);
+
+ let linkSelect = document.getElementById('link_type_id_' + index);
+ let linkType = linkSelect.value;
+ let linkLabel = linkSelect.options[linkSelect.selectedIndex].innerHTML;
+ let searchBox = document.getElementById('links_modal_search_' + index);
+ let hiddenField = searchBox.parentNode.querySelector('input[name="search"]');
+ if('' === linkType || '' === hiddenField.value || '' === searchBox.value) {
+ return;
+ }
+
+ // add entry to temporary table.
+ console.log('Link ' + linkType+ ' ("'+linkLabel+'") to transaction #' + hiddenField.value + '("'+searchBox.value+'")');
+
+ this.links[index].push(
+ {
+ id: 0,
+ type: linkType,
+ label: linkLabel,
+ journal_id: hiddenField.value,
+ group_id: hiddenField.value,
+ description: searchBox.value,
+ editMode: false,
+ }
+ );
+ searchBox.value = '';
+ hiddenField.value = '';
},
createAutocomplete(fieldIdentifier, url) {
let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
@@ -259,6 +285,7 @@ let create = function () {
server: url + '?_token=' + token,
labelField: 'name',
+ hiddenInput: true,
valueField: 'id',
liveServer: true,
onRenderItem: renderJournal.bind(this),
@@ -310,7 +337,7 @@ let create = function () {
//console.log(data);
this.formData.linkTypes = data;
this.formStates.loadingLinks = false;
- this.createAutocomplete('linksModal_search_0','api/v1/autocomplete/transactions-with-meta');
+ this.createAutocomplete('links_modal_search_0','api/v1/autocomplete/transactions-with-meta');
});
}
diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.php
index 1fc9a47b00..6c989c8558 100644
--- a/resources/lang/en_US/firefly.php
+++ b/resources/lang/en_US/firefly.php
@@ -2858,6 +2858,8 @@ return [
'overview_for_recurrence' => 'Overview for recurring transaction ":title"',
'warning_duplicates_repetitions' => 'In rare instances, dates appear twice in this list. This can happen when multiple repetitions collide. Firefly III will always generate one transaction per day.',
'created_transactions' => 'Related transactions',
+ 'manage_related_transactions' => 'Manage related transactions',
+ 'switch' => 'Switch',
'expected_withdrawals' => 'Expected withdrawals',
'expected_deposits' => 'Expected deposits',
'expected_transfers' => 'Expected transfers',
diff --git a/resources/views/components/transaction/split.blade.php b/resources/views/components/transaction/split.blade.php
index b23d351bd3..d846e24c4f 100644
--- a/resources/views/components/transaction/split.blade.php
+++ b/resources/views/components/transaction/split.blade.php
@@ -137,12 +137,12 @@
</div>
</div>
<!-- Modal for links -->
- <div class="modal modal-xl fade" :id="'linksModal_' + index" data-bs-backdrop="static" tabindex="-1"
- :aria-labelledby="'linksModal_' + index" aria-hidden="true">
+ <div class="modal modal-xl fade" :id="'links_modal_' + index" data-bs-backdrop="static" tabindex="-1"
+ :aria-labelledby="'links_modal_' + index" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
- <h1 class="modal-title fs-5" :id="'linksModal_' + index">Transaction relations</h1>
+ <h1 class="modal-title fs-5">Transaction relations</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
@@ -165,12 +165,21 @@
<tr>
<th colspan="2">Transaction relations</th>
</tr>
- <tr>
- <td>Pays for / is paid by <a href="#">#123: something else</a></td>
- <td class="w-20">
- switch,change, del
- </td>
- </tr>
+ <template x-for="link, key in links[index]" key="link.id">
+ <tr>
+ <td>
+ <span x-text="link.label"></span> <a :href="'transactions/show-by-journal/' + link.journal_id" target="_blank"><span x-text="link.description"></span></a>
+ </td>
+ <td class="w-20">
+ <div class="btn-group btn-group-sm">
+ <button :data-row-index="key" @click.prevent="switchLink" class="btn btn-outline-secondary" title="{{ __('firefly.switch') }}"><em class="bi bi-arrow-left-right"></em></button>
+ <button :data-row-index="key" @click.prevent="editLink" class="btn btn-outline-secondary" title="{{ __('firefly.edit') }}"><em class="bi bi-pencil"></em></button>
+ <button :data-row-index="key" @click.prevent="removeLink" class="btn btn-outline-danger" title="{{ __('firefly.delete') }}"><em class="bi bi-trash"></em></button>
+ </div>
+ </td>
+ </tr>
+ </template>
+
</table>
</div>
</div>
@@ -193,7 +202,7 @@
</select>
</div>
<div class="col">
- <input type="text" name="search" :id="'linksModal_search_' + index" class="form-control linked-transactions-search" placeholder="TODO Search here..." aria-label="TODO Search here...">
+ <input type="text" name="search" :id="'links_modal_search_' + index" class="form-control linked-transactions-search" placeholder="TODO Search here..." aria-label="TODO Search here...">
</div>
<div class="col w-15 text-end">
<input type="submit" name="submit" :data-index="index" @click.prevent="saveNewLink" value="TODO Save" class="btn btn-primary">
diff --git a/resources/views/partials/form/transaction/links.blade.php b/resources/views/partials/form/transaction/links.blade.php
index 72ca5a7999..e9c38ada12 100644
--- a/resources/views/partials/form/transaction/links.blade.php
+++ b/resources/views/partials/form/transaction/links.blade.php
@@ -8,15 +8,16 @@
<div class="form-control-plaintext">
<template x-if="formStates.loadingLinks">
- <button disabled="disabled" class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" :data-bs-target="'#linksModal_' + index" type="button">
+ <button disabled="disabled" class="btn btn-sm btn-outline-primary" type="button">
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">{{ __('firefly.thinking') }}</span>
</div>
</button>
</template>
<template x-if="!formStates.loadingLinks">
- <button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" :data-bs-target="'#linksModal_' + index" type="button">
- TODO Manage related transactions</button>
+ <button class="btn btn-sm btn-outline-primary" data-bs-toggle="modal" :data-bs-target="'#links_modal_' + index" type="button">
+ {{ __('firefly.manage_related_transactions') }}
+ </button>
</template>
</div>
</div>
diff --git a/routes/web.php b/routes/web.php
index f63bac52c6..8e00913ff1 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1327,6 +1327,7 @@ Route::group(
Route::post('unreconcile/{tj}', ['uses' => 'Transaction\EditController@unreconcile', 'as' => 'unreconcile']);
Route::get('show/{transactionGroup?}', ['uses' => 'Transaction\ShowController@show', 'as' => 'show']);
+ Route::get('show-by-journal/{tj}', ['uses' => 'Transaction\ShowController@redirectToGroup', 'as' => 'show-by-journal']);
Route::get('debug/{transactionGroup}', ['uses' => 'Transaction\ShowController@debugShow', 'as' => 'debug']);
}
);