Various small changes.

This commit is contained in:
James Cole
2017-03-03 18:19:25 +01:00
parent 978e3e615c
commit 8fb6c1a0c8
10 changed files with 83 additions and 26 deletions

View File

@@ -13,6 +13,10 @@ namespace FireflyIII\Http\Controllers;
use Amount; use Amount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Navigation; use Navigation;
use Preferences; use Preferences;
@@ -26,6 +30,33 @@ use Session;
class JavascriptController extends Controller class JavascriptController extends Controller
{ {
/**
*
*/
public function accounts(AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository)
{
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$preference = Preferences::get('currencyPreference', config('firefly.default_currency', 'EUR'));
$default = $currencyRepository->findByCode($preference->data);
$data = ['accounts' => [],];
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$currency = intval($account->getMeta('currency_id'));
$currency = $currency === 0 ? $default->id : $currency;
$entry = ['preferredCurrency' => $currency];
$data['accounts'][$accountId] = $entry;
}
return response()
->view('javascript.accounts', $data, 200)
->header('Content-Type', 'text/javascript');
}
/** /**
* @param Request $request * @param Request $request
* *

View File

@@ -162,9 +162,12 @@ class SingleController extends Controller
*/ */
public function delete(TransactionJournal $journal) public function delete(TransactionJournal $journal)
{ {
// Covered by another controller's tests
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) { if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); return $this->redirectToAccount($journal);
} }
// @codeCoverageIgnoreEnd
$what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type); $what = strtolower($journal->transaction_type_type ?? $journal->transactionType->type);
$subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]); $subTitle = trans('firefly.delete_' . $what, ['description' => $journal->description]);
@@ -187,9 +190,11 @@ class SingleController extends Controller
*/ */
public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal) public function destroy(JournalRepositoryInterface $repository, TransactionJournal $transactionJournal)
{ {
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($transactionJournal)) { if ($this->isOpeningBalance($transactionJournal)) {
return $this->redirectToAccount($transactionJournal); return $this->redirectToAccount($transactionJournal);
} }
// @codeCoverageIgnoreEnd
$type = TransactionJournal::transactionTypeStr($transactionJournal); $type = TransactionJournal::transactionTypeStr($transactionJournal);
Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)]))); Session::flash('success', strval(trans('firefly.deleted_' . strtolower($type), ['description' => e($transactionJournal->description)])));
@@ -207,9 +212,11 @@ class SingleController extends Controller
*/ */
public function edit(TransactionJournal $journal) public function edit(TransactionJournal $journal)
{ {
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) { if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); return $this->redirectToAccount($journal);
} }
// @codeCoverageIgnoreEnd
$count = $journal->transactions()->count(); $count = $journal->transactions()->count();
@@ -313,22 +320,20 @@ class SingleController extends Controller
Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)]))); Session::flash('success', strval(trans('firefly.stored_journal', ['description' => e($journal->description)])));
Preferences::mark(); Preferences::mark();
// @codeCoverageIgnoreStart
if ($createAnother === true) { if ($createAnother === true) {
// set value so create routine will not overwrite URL:
Session::put('transactions.create.fromStore', true); Session::put('transactions.create.fromStore', true);
return redirect(route('transactions.create', [$request->input('what')]))->withInput(); return redirect(route('transactions.create', [$request->input('what')]))->withInput();
} }
if ($doSplit === true) { if ($doSplit === true) {
// redirect to edit screen:
return redirect(route('transactions.split.edit', [$journal->id])); return redirect(route('transactions.split.edit', [$journal->id]));
} }
// @codeCoverageIgnoreEnd
// redirect to previous URL.
return redirect($this->getPreviousUri('transactions.create.uri')); return redirect($this->getPreviousUri('transactions.create.uri'));
} }
/** /**
@@ -340,9 +345,11 @@ class SingleController extends Controller
*/ */
public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal) public function update(JournalFormRequest $request, JournalRepositoryInterface $repository, TransactionJournal $journal)
{ {
// @codeCoverageIgnoreStart
if ($this->isOpeningBalance($journal)) { if ($this->isOpeningBalance($journal)) {
return $this->redirectToAccount($journal); return $this->redirectToAccount($journal);
} }
// @codeCoverageIgnoreEnd
$data = $request->getJournalData(); $data = $request->getJournalData();
$journal = $repository->update($journal, $data); $journal = $repository->update($journal, $data);
@@ -350,14 +357,14 @@ class SingleController extends Controller
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$this->attachments->saveAttachmentsForModel($journal, $files); $this->attachments->saveAttachmentsForModel($journal, $files);
// flash errors // @codeCoverageIgnoreStart
if (count($this->attachments->getErrors()->get('attachments')) > 0) { if (count($this->attachments->getErrors()->get('attachments')) > 0) {
Session::flash('error', $this->attachments->getErrors()->get('attachments')); Session::flash('error', $this->attachments->getErrors()->get('attachments'));
} }
// flash messages
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
Session::flash('info', $this->attachments->getMessages()->get('attachments')); Session::flash('info', $this->attachments->getMessages()->get('attachments'));
} }
// @codeCoverageIgnoreEnd
event(new UpdatedTransactionJournal($journal)); event(new UpdatedTransactionJournal($journal));
// update, get events by date and sort DESC // update, get events by date and sort DESC
@@ -366,15 +373,13 @@ class SingleController extends Controller
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['description'])]))); Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['description'])])));
Preferences::mark(); Preferences::mark();
// if wishes to split: // @codeCoverageIgnoreStart
if (intval($request->get('return_to_edit')) === 1) { if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL:
Session::put('transactions.edit.fromUpdate', true); Session::put('transactions.edit.fromUpdate', true);
return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]); return redirect(route('transactions.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
} }
// @codeCoverageIgnoreEnd
// redirect to previous URL. // redirect to previous URL.
return redirect($this->getPreviousUri('transactions.edit.uri')); return redirect($this->getPreviousUri('transactions.edit.uri'));

View File

@@ -141,25 +141,27 @@ class SplitController extends Controller
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
// save attachments: // save attachments:
$this->attachments->saveAttachmentsForModel($journal, $files); $this->attachments->saveAttachmentsForModel($journal, $files);
event(new UpdatedTransactionJournal($journal)); event(new UpdatedTransactionJournal($journal));
// update, get events by date and sort DESC
// flash messages // flash messages
// @codeCoverageIgnoreStart
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
Session::flash('info', $this->attachments->getMessages()->get('attachments')); Session::flash('info', $this->attachments->getMessages()->get('attachments'));
} }
// @codeCoverageIgnoreEnd
$type = strtolower(TransactionJournal::transactionTypeStr($journal)); $type = strtolower(TransactionJournal::transactionTypeStr($journal));
Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])]))); Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => e($data['journal_description'])])));
Preferences::mark(); Preferences::mark();
// @codeCoverageIgnoreStart
if (intval($request->get('return_to_edit')) === 1) { if (intval($request->get('return_to_edit')) === 1) {
// set value so edit routine will not overwrite URL: // set value so edit routine will not overwrite URL:
Session::put('transactions.edit-split.fromUpdate', true); Session::put('transactions.edit-split.fromUpdate', true);
return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]); return redirect(route('transactions.split.edit', [$journal->id]))->withInput(['return_to_edit' => 1]);
} }
// @codeCoverageIgnoreEnd
// redirect to previous URL. // redirect to previous URL.
return redirect($this->getPreviousUri('transactions.edit-split.uri')); return redirect($this->getPreviousUri('transactions.edit-split.uri'));

View File

@@ -102,7 +102,7 @@ function currencySelect(e) {
$('#' + spanId).text(symbol); $('#' + spanId).text(symbol);
// close the menu (hack hack) // close the menu (hack hack)
$('#' + menuID).click(); $('#' + menuID).dropdown('toggle');
return false; return false;

View File

@@ -6,19 +6,16 @@
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
/** global: what,Modernizr, title, breadcrumbs, middleCrumbName, button, piggiesLength, txt, doSwitch, middleCrumbUrl */ /** global: what,Modernizr, title, breadcrumbs, middleCrumbName, button, piggiesLength, txt, middleCrumbUrl */
$(document).ready(function () { $(document).ready(function () {
"use strict"; "use strict";
// respond to switch buttons when // respond to switch buttons
// creating stuff:
if (doSwitch == true) {
updateButtons(); updateButtons();
updateForm(); updateForm();
updateLayout(); updateLayout();
updateDescription(); updateDescription();
}
if (!Modernizr.inputtypes.date) { if (!Modernizr.inputtypes.date) {
$('input[type="date"]').datepicker( $('input[type="date"]').datepicker(
@@ -28,11 +25,27 @@ $(document).ready(function () {
); );
} }
// update currency
$('select[name="source_account_id"]').on('change', updateCurrency)
// get JSON things: // get JSON things:
getJSONautocomplete(); getJSONautocomplete();
}); });
function updateCurrency() {
// get value:
var accountId = $('select[name="source_account_id"]').val();
console.log('account id is ' + accountId);
var currencyPreference = accountInfo[accountId].preferredCurrency;
console.log('currency pref is ' + currencyPreference);
$('.currency-option[data-id="' + currencyPreference + '"]').click();
$('[data-toggle="dropdown"]').parent().removeClass('open');
$('select[name="source_account_id"]').focus();
}
function updateDescription() { function updateDescription() {
$.getJSON('json/transaction-journals/' + what).done(function (data) { $.getJSON('json/transaction-journals/' + what).done(function (data) {
$('input[name="description"]').typeahead('destroy').typeahead({source: data}); $('input[name="description"]').typeahead('destroy').typeahead({source: data});

View File

@@ -559,6 +559,7 @@ return [
'select_more_than_one_tag' => 'Please select more than one tag', 'select_more_than_one_tag' => 'Please select more than one tag',
'from_to' => 'From :start to :end', 'from_to' => 'From :start to :end',
'from_to_breadcrumb' => 'from :start to :end', 'from_to_breadcrumb' => 'from :start to :end',
'account_default_currency' => 'If you select another currency, new transactions from this account will have this currency pre-selected.',
// categories: // categories:
'new_category' => 'New category', 'new_category' => 'New category',

View File

@@ -19,7 +19,7 @@
{{ ExpandedForm.text('name') }} {{ ExpandedForm.text('name') }}
{% if what == 'asset' %} {% if what == 'asset' %}
{# Not really mandatory but OK #} {# Not really mandatory but OK #}
{{ ExpandedForm.select('currency_id', currencies) }} {{ ExpandedForm.select('currency_id', currencies, null, {helpText:'account_default_currency'|_}) }}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@@ -12,7 +12,7 @@
<div class="row"> <div class="row">
<div class="col-lg-8 col-md-12 col-sm-12"> <div class="col-lg-8 col-md-12 col-sm-12">
<!-- ACCOUNTS --> {# ACCOUNTS #}
<div class="box box-primary"> <div class="box box-primary">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'yourAccounts'|_ }}</h3> <h3 class="box-title">{{ 'yourAccounts'|_ }}</h3>
@@ -22,7 +22,7 @@
</div> </div>
</div> </div>
<!-- BUDGETS --> {# BUDGETS #}
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'budgetsAndSpending'|_ }}</h3> <h3 class="box-title">{{ 'budgetsAndSpending'|_ }}</h3>

View File

@@ -0,0 +1,4 @@
var accountInfo = [];
{% for id, account in accounts %}
accountInfo[{{ id }}] = {preferredCurrency: {{ account.preferredCurrency}}};
{% endfor %}

View File

@@ -414,6 +414,7 @@ Route::group(
Route::group( Route::group(
['middleware' => 'user-full-auth', 'prefix' => 'javascript', 'as' => 'javascript.'], function () { ['middleware' => 'user-full-auth', 'prefix' => 'javascript', 'as' => 'javascript.'], function () {
Route::get('variables', ['uses' => 'JavascriptController@variables', 'as' => 'variables']); Route::get('variables', ['uses' => 'JavascriptController@variables', 'as' => 'variables']);
Route::get('accounts', ['uses' => 'JavascriptController@accounts', 'as' => 'accounts']);
} }
); );