Compare commits

..

3 Commits

Author SHA1 Message Date
2da0ccb09b
Merge pull request 'feature/layout-improvements' (!38) from feature/layout-improvements into master
All checks were successful
rvr-nextgen/pipeline/head This commit looks good
Reviewed-on: #38
2023-05-01 23:42:30 +02:00
584fcaba39
make community layout clearer
All checks were successful
rvr-nextgen/pipeline/pr-master This commit looks good
2023-05-01 23:37:30 +02:00
b5dc96f98b
fix stupid variable names 2023-05-01 23:02:57 +02:00
10 changed files with 135 additions and 91 deletions

View File

@ -53,36 +53,48 @@ class CommunityController implements IAuthenticationRequired
$balanceCalculator = new BalanceCalculator($community); $balanceCalculator = new BalanceCalculator($community);
$debts = $balanceCalculator->calculate(); $debts = $balanceCalculator->calculate();
$debtUsers = []; $debtItems = [];
$debtBalance = 0.0; $debtBalance = 0.0;
$outstandingUsers = []; $outstandingItems = [];
$outstandingBalance = 0.0; $outstandingBalance = 0.0;
foreach ($debts as $debt) { foreach ($debts as $debt) {
if ($debt['payer']->getId() === \Container::$request->user()->getUniqueId()) { if ($debt['payer']->getId() === \Container::$request->user()->getUniqueId()) {
$debtBalance += $debt['amount']; $debtBalance += $debt['amount'];
$debtUsers[] = $debt; $debtItems[] = $debt;
} }
if ($debt['payee']->getId() === \Container::$request->user()->getUniqueId()) { if ($debt['payee']->getId() === \Container::$request->user()->getUniqueId()) {
$outstandingBalance += $debt['amount']; $outstandingBalance += $debt['amount'];
$outstandingUsers[] = $debt; $outstandingItems[] = $debt;
} }
} }
$balance = $outstandingBalance - $debtBalance; $balance = $outstandingBalance - $debtBalance;
return new HtmlContent('communities/community', [ return new HtmlContent('communities/community', [
'community' => $community, 'community' => $community,
'members' => $this->getMembers($community),
'currencies' => $this->getCurrencies($community),
'upcomingEvents' => [], 'upcomingEvents' => [],
'debtUsers' => $debtUsers, 'debtItems' => $debtItems,
'debtBalance' => $debtBalance, 'debtBalance' => $debtBalance,
'outstandingUsers' => $outstandingUsers, 'outstandingItems' => $outstandingItems,
'outstandingBalance' => $outstandingBalance, 'outstandingBalance' => $outstandingBalance,
'balance' => $balance, 'balance' => $balance,
'editPermission' => $ownCommunityMember->getOwner() 'editPermission' => $ownCommunityMember->getOwner()
]); ]);
} }
public function getCommunitySettings(): ?IContent
{
if (!$this->checkPermission(\Container::$request->query('communityId'), false, $community, $ownCommunityMember)) {
return null;
}
return new HtmlContent('communities/community_settings', [
'community' => $community,
'members' => $this->getMembers($community),
'currencies' => $this->getCurrencies($community),
'editPermission' => $ownCommunityMember->getOwner()
]);
}
public function getCommunityNew(): IContent public function getCommunityNew(): IContent
{ {
return new HtmlContent('communities/community_edit'); return new HtmlContent('communities/community_edit');

View File

@ -86,6 +86,7 @@ class TransactionController implements IAuthenticationRequired, ISecured
'exchangeRateCalculator' => $exchangeRateCalculator, 'exchangeRateCalculator' => $exchangeRateCalculator,
'pages' => $pages, 'pages' => $pages,
'currentPage' => $currentPage, 'currentPage' => $currentPage,
'numberOfTransactions' => $numberOfTransactions,
'transactions' => $transactions 'transactions' => $transactions
]); ]);
} }

View File

@ -1,35 +1,16 @@
@extends(templates/layout_normal) @extends(templates/layout_normal)
@section(main) @section(main)
<h2><?= $community->getName() ?> <span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-edit')->generateLink(['communityId' => $community->getId()]) ?>">edit</a>]</span></h2> <h2>
<?= $community->getName() ?>
<?php if ($editPermission): ?>
<span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-edit')->generateLink(['communityId' => $community->getId()]) ?>">edit</a>]</span>
<?php endif; ?>
</h2>
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.settings')->generateLink(['communityId' => $community->getId()]) ?>">Settings</a></p>
<div class="gridContainer marginTop"> <div class="gridContainer marginTop">
<div>
<h3 class="marginBottom">Members</h3>
<?php foreach ($members as $member): ?>
<p><?= $member->getUser()->getDisplayName() ?></p>
<?php endforeach; ?>
<?php if ($editPermission): ?>
<hr>
<p><a href="<?= Container::$routeCollection->getRoute('community-members')->generateLink(['communityId' => $community->getId()]) ?>">Edit members</a></p>
<?php endif; ?>
</div>
<div>
<h3 class="marginBottom">Currencies</h3>
<?php foreach ($currencies as $currency): ?>
<p>
<?php if ($currency->getId() === $community->getMainCurrencyId()): ?>
<b><?= $currency->getCode() ?></b>
<?php else: ?>
<a href="<?= Container::$routeCollection->getRoute('community-currency-exchange-rates')->generateLink(['communityId' => $community->getId(), 'code' => $currency->getCode()]) ?>"><?= $currency->getCode() ?></a>
<?php endif; ?>
</p>
<?php endforeach; ?>
<?php if ($editPermission): ?>
<hr>
<p><a href="<?= Container::$routeCollection->getRoute('community-currencies')->generateLink(['communityId' => $community->getId()]) ?>">Edit currencies</a></p>
<?php endif; ?>
</div>
<div> <div>
<h3 class="marginBottom">Upcoming events</h3> <h3 class="marginBottom">Upcoming events</h3>
<?php if (count($upcomingEvents) > 0): ?> <?php if (count($upcomingEvents) > 0): ?>
@ -52,20 +33,20 @@
<td class="bold">You owe</td> <td class="bold">You owe</td>
<td class="mono red" style="text-align: right;"><?= number_format($debtBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td> <td class="mono red" style="text-align: right;"><?= number_format($debtBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr> </tr>
<?php foreach ($debtUsers as $owe): ?> <?php foreach ($debtItems as $item): ?>
<tr> <tr>
<td class="small"><?= $owe['payee']->getUser()->getDisplayName() ?></td> <td class="small"><?= $item['payee']->getUser()->getDisplayName() ?></td>
<td class="small mono red" style="text-align: right;"><?= number_format($owe['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td> <td class="small mono red" style="text-align: right;"><?= number_format($item['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr> <tr>
<td class="bold">You're owed</td> <td class="bold">You're owed</td>
<td class="mono green" style="text-align: right;"><?= number_format($outstandingBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td> <td class="mono green" style="text-align: right;"><?= number_format($outstandingBalance, $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr> </tr>
<?php foreach ($outstandingUsers as $owe): ?> <?php foreach ($outstandingItems as $item): ?>
<tr> <tr>
<td class="small"><?= $owe['payer']->getUser()->getDisplayName() ?></td> <td class="small"><?= $item['payer']->getUser()->getDisplayName() ?></td>
<td class="small mono green" style="text-align: right;"><?= number_format($owe['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td> <td class="small mono green" style="text-align: right;"><?= number_format($item['amount'], $mainCurrencyRoundDigits) ?> <?= $mainCurrencyCode ?></td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
<tr> <tr>

View File

@ -3,6 +3,7 @@
@section(main) @section(main)
<h2> <h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> » <a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
<a href="<?= Container::$routeCollection->getRoute('community.settings')->generateLink(['communityId' => $community->getId()]) ?>">Settings</a> »
Edit currencies Edit currencies
</h2> </h2>
<div class="box compactBox"> <div class="box compactBox">

View File

@ -7,6 +7,7 @@
@section(main) @section(main)
<h2> <h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> » <a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
<a href="<?= Container::$routeCollection->getRoute('community.settings')->generateLink(['communityId' => $community->getId()]) ?>">Settings</a> »
Edit members Edit members
</h2> </h2>
<div class="box compactBox"> <div class="box compactBox">

View File

@ -0,0 +1,39 @@
@extends(templates/layout_normal)
@section(main)
<h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
Settings
</h2>
<div class="gridContainer marginTop">
<div>
<h3 class="marginBottom">
Members
<?php if ($editPermission): ?>
<span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-members')->generateLink(['communityId' => $community->getId()]) ?>">edit</a>]</span>
<?php endif; ?>
</h3>
<?php foreach ($members as $member): ?>
<p><?= $member->getUser()->getDisplayName() ?></p>
<?php endforeach; ?>
</div>
<div>
<h3 class="marginBottom">
Currencies
<?php if ($editPermission): ?>
<span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-currencies')->generateLink(['communityId' => $community->getId()]) ?>">edit</a>]</span>
<?php endif; ?>
</h3>
<?php foreach ($currencies as $currency): ?>
<p>
<?php if ($currency->getId() === $community->getMainCurrencyId()): ?>
<b><?= $currency->getCode() ?></b>
<?php else: ?>
<a href="<?= Container::$routeCollection->getRoute('community-currency-exchange-rates')->generateLink(['communityId' => $community->getId(), 'code' => $currency->getCode()]) ?>"><?= $currency->getCode() ?></a>
<?php endif; ?>
</p>
<?php endforeach; ?>
</div>
</div>
@endsection

View File

@ -3,6 +3,7 @@
@section(main) @section(main)
<h2> <h2>
<a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> » <a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a> »
<a href="<?= Container::$routeCollection->getRoute('community.settings')->generateLink(['communityId' => $community->getId()]) ?>">Settings</a> »
Exchange rates for <?= $currency->getCode() ?> Exchange rates for <?= $currency->getCode() ?>
</h2> </h2>
<div class="box compactBox"> <div class="box compactBox">

View File

@ -8,55 +8,61 @@
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p> <p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p>
<?php if ($pages > 1): ?> <?php if ($numberOfTransactions > 0): ?>
<p class="paginateContainer marginTop"> <?php if ($pages > 1): ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a> <p class="paginateContainer marginTop">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => max(0, $currentPage - 1)]) ?>"></a> <a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a>
<?php for ($i = 0; $i < $pages; $i++): ?> <a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => max(0, $currentPage - 1)]) ?>"></a>
<?php if ($currentPage == $i): ?> <?php for ($i = 0; $i < $pages; $i++): ?>
<span class="selected"><?= $i + 1 ?></span> <?php if ($currentPage == $i): ?>
<?php else: ?> <span class="selected"><?= $i + 1 ?></span>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a> <?php else: ?>
<?php endif; ?> <a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
<?php endfor; ?> <?php endif; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>"></a> <?php endfor; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a> <a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>"></a>
</p> <a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a>
<?php endif; ?> </p>
<?php endif; ?>
<?php foreach ($transactions as $transaction): ?> <?php foreach ($transactions as $transaction): ?>
<a class="block" href="<?= Container::$routeCollection->getRoute('community.transactions.edit')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) ?>"> <a class="block" href="<?= Container::$routeCollection->getRoute('community.transactions.edit')->generateLink(['communityId' => $community->getId(), 'transactionId' => $transaction->getId()]) ?>">
<div class="box transaction"> <div class="box transaction">
<div> <div>
<p style="font-weight: bold;"><?= $transaction->getDescription() ?></p> <p style="font-weight: bold;"><?= $transaction->getDescription() ?></p>
<p class="small"><?= $transaction->getPayerUser()->getDisplayName() ?> ► <?= $transaction->getPayeeUser() ? $transaction->getPayeeUser()->getDisplayName() : '[common]' ?></p> <p class="small"><?= $transaction->getPayerUser()->getDisplayName() ?> ► <?= $transaction->getPayeeUser() ? $transaction->getPayeeUser()->getDisplayName() : '[common]' ?></p>
<p class="small"><?= $transaction->getTimeDate()->format('Y-m-d H:i') ?></p> <p class="small"><?= $transaction->getTimeDate()->format('Y-m-d H:i') ?></p>
</div> </div>
<div style="text-align: right;"> <div style="text-align: right;">
<h3><?= number_format($exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate()), $community->getMainCurrency()->getRoundDigits()) ?> <?= $community->getMainCurrency()->getCode() ?></h3> <h3><?= number_format($exchangeRateCalculator->calculate($transaction->getSum(), $transaction->getCurrency(), $transaction->getTimeDate()), $community->getMainCurrency()->getRoundDigits()) ?> <?= $community->getMainCurrency()->getCode() ?></h3>
<?php if ($community->getMainCurrencyId() !== $transaction->getCurrencyId()): ?> <?php if ($community->getMainCurrencyId() !== $transaction->getCurrencyId()): ?>
<p style="color: #8e8e8e; font-weight: bold;"><?= number_format($transaction->getSum(), $transaction->getCurrency()->getRoundDigits()) ?> <?= $transaction->getCurrency()->getCode() ?></p> <p style="color: #8e8e8e; font-weight: bold;"><?= number_format($transaction->getSum(), $transaction->getCurrency()->getRoundDigits()) ?> <?= $transaction->getCurrency()->getCode() ?></p>
<?php endif; ?> <?php endif; ?>
</div>
</div> </div>
</a>
<?php endforeach; ?>
<?php if ($pages > 1): ?>
<p class="paginateContainer marginTop">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => max(0, $currentPage - 1)]) ?>"></a>
<?php for ($i = 0; $i < $pages; $i++): ?>
<?php if ($currentPage == $i): ?>
<span class="selected"><?= $i + 1 ?></span>
<?php else: ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
<?php endif; ?>
<?php endfor; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>"></a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a>
</p>
<?php endif; ?>
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p>
<?php else: ?>
<div class="box">
<p>There are no transactions yet.</p>
</div> </div>
</a>
<?php endforeach; ?>
<?php if ($pages > 1): ?>
<p class="paginateContainer marginTop">
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => 0]) ?>">«</a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => max(0, $currentPage - 1)]) ?>"></a>
<?php for ($i = 0; $i < $pages; $i++): ?>
<?php if ($currentPage == $i): ?>
<span class="selected"><?= $i + 1 ?></span>
<?php else: ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $i]) ?>"><?= $i + 1 ?></a>
<?php endif; ?>
<?php endfor; ?>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => min($pages - 1, $currentPage + 1)]) ?>"></a>
<a href="<?= Container::$routeCollection->getRoute('community.transactions')->generateLink(['communityId' => $community->getId(), 'page' => $pages - 1]) ?>">»</a>
</p>
<?php endif; ?> <?php endif; ?>
<p class="marginTop"><a href="<?= Container::$routeCollection->getRoute('community.transactions.new')->generateLink(['communityId' => $community->getId()]) ?>">New transaction</a></p>
@endsection @endsection

View File

@ -3,7 +3,10 @@
@section(main) @section(main)
<div class="gridContainer"> <div class="gridContainer">
<div> <div>
<h3 class="marginBottom">Communities</h3> <h3 class="marginBottom">
Communities
<span class="small">[<a href="<?= Container::$routeCollection->getRoute('community-new')->generateLink() ?>">new</a>]</span>
</h3>
<?php if (count($communities) > 0): ?> <?php if (count($communities) > 0): ?>
<?php foreach ($communities as $community): ?> <?php foreach ($communities as $community): ?>
<p><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a></p> <p><a href="<?= Container::$routeCollection->getRoute('community')->generateLink(['communityId' => $community->getId()]) ?>"><?= $community->getName() ?></a></p>
@ -11,8 +14,6 @@
<?php else: ?> <?php else: ?>
<p>You have no community.</p> <p>You have no community.</p>
<?php endif; ?> <?php endif; ?>
<hr>
<p><a href="<?= Container::$routeCollection->getRoute('community-new')->generateLink() ?>">New community</a></p>
</div> </div>
<div> <div>
<h3 class="marginBottom">Upcoming events</h3> <h3 class="marginBottom">Upcoming events</h3>

View File

@ -61,6 +61,7 @@ Container::$routeCollection->group('communities', function (RouteCollection $rou
$routeCollection->post('community-new-action', 'new', [CommunityController::class, 'saveCommunity']); $routeCollection->post('community-new-action', 'new', [CommunityController::class, 'saveCommunity']);
$routeCollection->group('{communityId}', function (RouteCollection $routeCollection) { $routeCollection->group('{communityId}', function (RouteCollection $routeCollection) {
$routeCollection->get('community', '', [CommunityController::class, 'getCommunityHome']); $routeCollection->get('community', '', [CommunityController::class, 'getCommunityHome']);
$routeCollection->get('community.settings', 'settings', [CommunityController::class, 'getCommunitySettings']);
$routeCollection->get('community-edit', 'edit', [CommunityController::class, 'getCommunityEdit']); $routeCollection->get('community-edit', 'edit', [CommunityController::class, 'getCommunityEdit']);
$routeCollection->post('community-edit-action', 'edit', [CommunityController::class, 'saveCommunity']); $routeCollection->post('community-edit-action', 'edit', [CommunityController::class, 'saveCommunity']);
$routeCollection->get('community-members', 'members', [CommunityController::class, 'getMembersEdit']); $routeCollection->get('community-members', 'members', [CommunityController::class, 'getMembersEdit']);