Skip to content

Firefly III: a personal finances manager

Switch things.

James Coleafd470075851
diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php
index 10190ce489..8aaa065c0f 100644
--- a/app/Http/Controllers/Transaction/LinkController.php
+++ b/app/Http/Controllers/Transaction/LinkController.php
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
+use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
use Log;
@@ -157,9 +158,10 @@ class LinkController extends Controller
*
* @return RedirectResponse|Redirector
*/
- public function switchLink(TransactionJournalLink $link)
+ public function switchLink(Request $request)
{
- $this->repository->switchLink($link);
+ $linkId = (int)$request->get('id');
+ $this->repository->switchLinkById($linkId);
return redirect(app('steam')->getSafePreviousUrl());
}
diff --git a/app/Repositories/LinkType/LinkTypeRepository.php b/app/Repositories/LinkType/LinkTypeRepository.php
index 1b43ef17af..89f9d4511c 100644
--- a/app/Repositories/LinkType/LinkTypeRepository.php
+++ b/app/Repositories/LinkType/LinkTypeRepository.php
@@ -389,4 +389,21 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
return TransactionJournalLink::whereDestinationId($two->id)->whereSourceId($one->id)->first();
}
+
+ /**
+ * @inheritDoc
+ */
+ public function switchLinkById(int $linkId): bool
+ {
+ /** @var TransactionJournalLink $link */
+ $link = TransactionJournalLink::find($linkId);
+ if (null !== $link) {
+
+ if ($link->source->user->id === $this->user->id) {
+ $this->switchLink($link);
+ }
+ }
+
+ return true;
+ }
}
diff --git a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
index 17ce2decea..2898350046 100644
--- a/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
+++ b/app/Repositories/LinkType/LinkTypeRepositoryInterface.php
@@ -154,6 +154,13 @@ interface LinkTypeRepositoryInterface
*/
public function switchLink(TransactionJournalLink $link): bool;
+ /**
+ * @param int $linkId
+ *
+ * @return bool
+ */
+ public function switchLinkById(int $linkId): bool;
+
/**
* @param LinkType $linkType
* @param array $data
diff --git a/resources/views/v1/admin/link/show.twig b/resources/views/v1/admin/link/show.twig
index 652c2b4ac6..72840d920c 100644
--- a/resources/views/v1/admin/link/show.twig
+++ b/resources/views/v1/admin/link/show.twig
@@ -27,8 +27,8 @@
<tr>
<td>
<div class="btn-group btn-group-xs">
- <a href="{{ route('transactions.link.delete', [link.id]) }}" class="btn btn-danger"><span class="fa fa-trash"></span></a>
- <a href="{{ route('transactions.link.switch', [link.id]) }}" class="btn btn-default"><span
+ <a href="{{ route('transactions.link.delete', [link.id]) }}" class="btn btn-danger delete-link" data-id="{{ link.id }}"><span class="fa fa-trash"></span></a>
+ <a href="#" class="btn btn-default switch-link" data-id="{{ link.id }}"><span
class="fa fa-fw fa-arrows-h"></span></a>
</div>
</td>
@@ -58,6 +58,28 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="v1/js/lib/bootstrap-sortable.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
+ <script nonce="{{ JS_NONCE }}">
+ $('.switch-link').on('click', switchLink);
+ var switchLinkUrl = '{{ route('transactions.link.switch') }}';
+ function switchLink(e) {
+ e.preventDefault();
+ var obj = $(e.currentTarget);
+
+ $.post(switchLinkUrl, {
+ _token: token,
+ id: obj.data('id')
+ }).done(function () {
+ location.reload();
+ }).fail(function () {
+ console.error('I failed :(');
+ });
+
+ //alert(obj.data('id'));
+
+ return false
+ }
+
+ </script>
{% endblock %}
{% block styles %}
diff --git a/resources/views/v1/profile/index.twig b/resources/views/v1/profile/index.twig
index bf01b5411b..3c7e7db198 100644
--- a/resources/views/v1/profile/index.twig
+++ b/resources/views/v1/profile/index.twig
@@ -126,13 +126,11 @@
<input class="btn btn-default" style="margin-top:20px;" type="submit" name="submit" value="{{ 'pref_two_factor_new_backup_codes'|_ }}" />
</form>
{% else %}
- <p>
<form action="{{ route('profile.enable2FA') }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<button type="submit" class="btn btn-info"><span
class="fa fa-lock"></span> {{ 'pref_enable_two_factor_auth'|_ }}</button>
</form>
- </p>
{% endif %}
</div>
</div>
diff --git a/resources/views/v1/transactions/show.twig b/resources/views/v1/transactions/show.twig
index f00d0303bd..ce50940d90 100644
--- a/resources/views/v1/transactions/show.twig
+++ b/resources/views/v1/transactions/show.twig
@@ -357,7 +357,7 @@
<tr>
<td style="width:120px;">
<div class="btn-group btn-group-xs">
- <a href="{{ route('transactions.link.switch', [link.id]) }}" class="btn btn-default"><span
+ <a href="#" class="btn btn-default switch-link" data-id="{{ link.id }}"><span
class="fa fa-fw fa-arrows-h"></span></a>
<a href="{{ route('transactions.link.delete', [link.id]) }}" class="btn btn-danger"><span class="fa fa-trash"></span></a>
</div>
@@ -423,6 +423,25 @@
var acURI = '{{ route('api.v1.autocomplete.transactions-with-id') }}';
var groupURI = '{{ route('transactions.show',['%GROUP%']) }}';
var cloneGroupUrl = '{{ route('transactions.clone') }}';
+
+ $('.switch-link').on('click', switchLink);
+ var switchLinkUrl = '{{ route('transactions.link.switch') }}';
+ function switchLink(e) {
+ e.preventDefault();
+ var obj = $(e.currentTarget);
+ $.post(switchLinkUrl, {
+ _token: token,
+ id: obj.data('id')
+ }).done(function () {
+ location.reload();
+ }).fail(function () {
+ console.error('I failed :(');
+ });
+
+ //alert(obj.data('id'));
+
+ return false
+ }
</script>
<script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
<script type="text/javascript" src="v1/js/ff/transactions/show.js?v={{ FF_VERSION }}" nonce="{{ JS_NONCE }}"></script>
diff --git a/routes/web.php b/routes/web.php
index 1c29386366..f01001d3a8 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -1079,8 +1079,7 @@ Route::group(
// See reference nr. 6
Route::post('store/{tj}', ['uses' => 'LinkController@store', 'as' => 'store']);
Route::get('delete/{journalLink}', ['uses' => 'LinkController@delete', 'as' => 'delete']);
- Route::post('switch/{journalLink}', ['uses' => 'LinkController@switchLink', 'as' => 'switch']);
-
+ Route::post('switch', ['uses' => 'LinkController@switchLink', 'as' => 'switch']);
Route::post('destroy/{journalLink}', ['uses' => 'LinkController@destroy', 'as' => 'destroy']);
}
);