Fix view issues when user has multiple pages of budgets #1111

This commit is contained in:
James Cole
2018-02-01 17:55:18 +01:00
parent 0d9a221b00
commit d8664096f9
4 changed files with 18 additions and 15 deletions

View File

@@ -198,13 +198,13 @@ class BudgetController extends Controller
$prev->subDay(); $prev->subDay();
$prev = app('navigation')->startOfPeriod($prev, $range); $prev = app('navigation')->startOfPeriod($prev, $range);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets(); $allBudgets = $this->repository->getActiveBudgets();
$total = $budgets->count(); $total = $allBudgets->count();
$budgets = $budgets->slice(($page - 1) * $pageSize, $pageSize); $budgets = $allBudgets->slice(($page - 1) * $pageSize, $pageSize);
$inactive = $this->repository->getInactiveBudgets(); $inactive = $this->repository->getInactiveBudgets();
$periodStart = $start->formatLocalized($this->monthAndDayFormat); $periodStart = $start->formatLocalized($this->monthAndDayFormat);
$periodEnd = $end->formatLocalized($this->monthAndDayFormat); $periodEnd = $end->formatLocalized($this->monthAndDayFormat);
$budgetInformation = $this->repository->collectBudgetInformation($budgets, $start, $end); $budgetInformation = $this->repository->collectBudgetInformation($allBudgets, $start, $end);
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
$available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end); $available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end);
$spent = array_sum(array_column($budgetInformation, 'spent')); $spent = array_sum(array_column($budgetInformation, 'spent'));
@@ -252,7 +252,7 @@ class BudgetController extends Controller
'currentMonth', 'currentMonth',
'next', 'next',
'nextText', 'nextText',
'prev', 'prev', 'allBudgets',
'prevText', 'prevText',
'periodStart', 'periodStart',
'periodEnd', 'periodEnd',
@@ -420,11 +420,12 @@ class BudgetController extends Controller
$end = Carbon::createFromFormat('Y-m-d', $request->string('end')); $end = Carbon::createFromFormat('Y-m-d', $request->string('end'));
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
$amount = $request->get('amount'); $amount = $request->get('amount');
$page = $request->integer('page') === 0 ? 1 : $request->integer('page');
$this->repository->setAvailableBudget($defaultCurrency, $start, $end, $amount); $this->repository->setAvailableBudget($defaultCurrency, $start, $end, $amount);
Preferences::mark(); Preferences::mark();
return redirect(route('budgets.index', [$start->format('Y-m-d')])); return redirect(route('budgets.index', [$start->format('Y-m-d')]) . '?page=' . $page);
} }
/** /**
@@ -549,13 +550,14 @@ class BudgetController extends Controller
* *
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/ */
public function updateIncome(Carbon $start, Carbon $end) public function updateIncome(Request $request, Carbon $start, Carbon $end)
{ {
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
$available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end); $available = $this->repository->getAvailableBudget($defaultCurrency, $start, $end);
$available = round($available, $defaultCurrency->decimal_places); $available = round($available, $defaultCurrency->decimal_places);
$page = intval($request->get('page'));
return view('budgets.income', compact('available', 'start', 'end')); return view('budgets.income', compact('available', 'start', 'end', 'page'));
} }
/** /**

View File

@@ -18,7 +18,7 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>. * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/ */
/** global: infoIncomeUri, token, spent, budgeted, available, currencySymbol, budgetIndexUri, updateIncomeUri, periodStart, periodEnd, budgetAmountUri, accounting */ /** global: infoIncomeUri, page, token, spent, budgeted, available, currencySymbol, budgetIndexUri, updateIncomeUri, periodStart, periodEnd, budgetAmountUri, accounting */
/** /**
* *
*/ */
@@ -44,7 +44,7 @@ $(function () {
var sel = $(e.target).val(); var sel = $(e.target).val();
if (sel !== "x") { if (sel !== "x") {
var newUri = budgetIndexUri.replace("REPLACE", sel); var newUri = budgetIndexUri.replace("REPLACE", sel);
window.location.assign(newUri); window.location.assign(newUri + "?page=" + page);
} }
}); });

View File

@@ -14,6 +14,7 @@
<input type="hidden" name="_token" value="{{ csrf_token() }}"/> <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="start" value="{{ start.format('Y-m-d') }}"/> <input type="hidden" name="start" value="{{ start.format('Y-m-d') }}"/>
<input type="hidden" name="end" value="{{ end.format('Y-m-d') }}"/> <input type="hidden" name="end" value="{{ end.format('Y-m-d') }}"/>
<input type="hidden" name="page" value="{{ page }}" />
<div class="input-group"> <div class="input-group">
<div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div> <div class="input-group-addon">{{ getCurrencySymbol()|raw }}</div>

View File

@@ -108,9 +108,9 @@
</div> </div>
<div class="col-lg-8 col-md-4 col-sm-12 col-xs-12 text-center"> <div class="col-lg-8 col-md-4 col-sm-12 col-xs-12 text-center">
<div class="btn btn-group btn-group-lg" style="padding-top:0;"> <div class="btn btn-group btn-group-lg" style="padding-top:0;">
<a href="{{ route('budgets.index', [prev.format('Y-m-d')]) }}" class="btn btn-default" title="{{ prevText }}">&larr;</a> <a href="{{ route('budgets.index', [prev.format('Y-m-d')]) }}?page={{ page }}" class="btn btn-default" title="{{ prevText }}">&larr;</a>
<a href="{{ route('budgets.index', [start.format('Y-m-d')]) }}" class="btn btn-default">{{ currentMonth }}</a> <a href="{{ route('budgets.index', [start.format('Y-m-d')]) }}?page={{ page }}" class="btn btn-default">{{ currentMonth }}</a>
<a href="{{ route('budgets.index', [next.format('Y-m-d')]) }}" class="btn btn-default" title="{{ nextText }}">&rarr;</a> <a href="{{ route('budgets.index', [next.format('Y-m-d')]) }}?page={{ page }}" class="btn btn-default" title="{{ nextText }}">&rarr;</a>
</div> </div>
</div> </div>
<div class="col-lg-2 col-md-4 col-sm-12 col-xs-12 text-right"> <div class="col-lg-2 col-md-4 col-sm-12 col-xs-12 text-right">
@@ -237,13 +237,13 @@
<script type="text/javascript"> <script type="text/javascript">
// actually spent bar data: // actually spent bar data:
var spent = {{ spent * -1 }}; // must be positive for the calculation to work. var spent = {{ spent * -1 }}; // must be positive for the calculation to work.
var page = {{ page }};
// budgeted data: // budgeted data:
var budgeted = {{ budgeted }}; var budgeted = {{ budgeted }};
var available = {{ available }}; var available = {{ available }};
var budgetIndexUri = "{{ route('budgets.index','REPLACE') }}"; var budgetIndexUri = "{{ route('budgets.index','REPLACE') }}";
var budgetAmountUri = "{{ route('budgets.amount','REPLACE') }}"; var budgetAmountUri = "{{ route('budgets.amount','REPLACE') }}";
var updateIncomeUri = "{{ route('budgets.income',[start.format('Y-m-d'),end.format('Y-m-d')]) }}"; var updateIncomeUri = "{{ route('budgets.income',[start.format('Y-m-d'),end.format('Y-m-d')]) }}?page={{ page }}";
var infoIncomeUri = "{{ route('budgets.income.info',[start.format('Y-m-d'),end.format('Y-m-d')]) }}"; var infoIncomeUri = "{{ route('budgets.income.info',[start.format('Y-m-d'),end.format('Y-m-d')]) }}";
var periodStart = "{{ start.format('Y-m-d') }}"; var periodStart = "{{ start.format('Y-m-d') }}";
var periodEnd = "{{ end.format('Y-m-d') }}"; var periodEnd = "{{ end.format('Y-m-d') }}";