Skip to content

Commit

Permalink
Merge pull request #25 from deanblackborough/main
Browse files Browse the repository at this point in the history
Pagination and minor tweaks
  • Loading branch information
deanblackborough authored Jul 31, 2022
2 parents 9fa6149 + 55122b5 commit f882f13
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

The complete changelog for the Costs to Expect REST API, our changelog follows the format defined at https://keepachangelog.com/en/1.0.0/

## [0.13.0] - [2022-07-31]
### Added
- Added pagination to the games list, we can now see all games and how many we have played.
- Added additional toast messages options.
### Changed
- Minor change to the layout of open games ready for more buttons.

## [0.12.0] - [2022-07-30]
### Added
- Added a "Complete & Play Again" button, sets up a new game with the same players.
Expand Down
3 changes: 2 additions & 1 deletion app/Api/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function get(string $uri): array
return match ($response->status()) {
200 => [
'status' => $response->status(),
'content' => $response->json()
'content' => $response->json(),
'headers' => $response->headers()
],
404 => [
'status' => 404,
Expand Down
2 changes: 1 addition & 1 deletion app/Api/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function getAssignedGamePlayers(
return $this->http->get($uri['uri']);
}

#[ArrayShape(['status' => "integer", 'content' => "array"])]
#[ArrayShape(['status' => "integer", 'content' => "array", 'headers' => "array"])]
public function getGames(
string $resource_type_id,
string $resource_id,
Expand Down
19 changes: 18 additions & 1 deletion app/Http/Controllers/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,28 @@ public function index(Request $request)
{
$this->boostrap($request);

$offset = (int) $request->query('offset', 0);
$limit = (int) $request->query('limit', 10);

$games_response = $this->api->getGames(
$this->resource_type_id,
$this->resource_id,
['complete' => 1, 'include-players' => 1]
[
'complete' => 1,
'include-players' => 1,
'offset' => $offset,
'limit' => $limit
]
);

$pagination = [
'previous' => ($games_response['headers']['X-Link-Previous'][0] !== ''),
'next' => ($games_response['headers']['X-Link-Next'][0] !== ''),
'offset' => $games_response['headers']['X-Offset'][0],
'limit' => $games_response['headers']['X-Limit'][0],
'total' => $games_response['headers']['X-Total-Count'][0],
];

$games = [];
if ($games_response['status'] === 200 && count($games_response['content']) > 0) {
$games = $games_response['content'];
Expand All @@ -35,6 +51,7 @@ public function index(Request $request)
return view(
'games',
[
'pagination' => $pagination,
'games' => $games,
]
);
Expand Down
34 changes: 33 additions & 1 deletion app/View/Components/Toast.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function __construct()
[
'heading' => '50 points in the bag!',
'message' => 'Are you going to try for a Yahtzee bonus?',
],
[
'heading' => '50 points!',
'message' => 'Well done, this should help, now go score a Yahtzee bonus!',
],
[
'heading' => 'Fifty points!',
'message' => 'Look at everyone, they can\'t believe it',
]
],
'toast_yahtzee_scratch' => [
Expand All @@ -34,7 +42,7 @@ public function __construct()
'message' => 'I\'m guessing the game isn\'t going too well.',
],
[
'heading' => 'Bye-bye 50 points!',
'heading' => 'Oops!',
'message' => 'Did you click the wrong button?',
],
[
Expand All @@ -46,24 +54,48 @@ public function __construct()
[
'heading' => 'Oh dear!',
'message' => 'Why are you scratching chance, what is going on?',
],
[
'heading' => 'Really!',
'message' => 'What is wrong with you, do you know how to play?',
]
],
'toast_yahtzee_bonus_one' => [
[
'heading' => 'Yahtzee X 2',
'message' => 'Have you considered giving the other players a chance?',
],
[
'heading' => 'Yahtzee X 2',
'message' => 'Yes, the other players suck!',
]
],
'toast_yahtzee_bonus_two' => [
[
'heading' => 'Yahtzee X 3',
'message' => 'Do the other players hate you?',
],
[
'heading' => 'Bonus X 2',
'message' => 'Was one bonus not enough?',
],
[
'heading' => 'Bonus X 2',
'message' => 'OMG!, are you going for three?',
]
],
'toast_yahtzee_bonus_three' => [
[
'heading' => 'Yahtzee X 4',
'message' => 'GAME OVER!',
],
[
'heading' => 'Yahtzee X 4',
'message' => 'Score another bonus, I dare you!',
],
[
'heading' => 'Bonus X 3',
'message' => 'Please don\'t score another bonus, we will need another checkbox!',
]
],
];
Expand Down
4 changes: 2 additions & 2 deletions config/app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
'item_subtype_id' => env('ITEM_SUBTYPE_ID'),
'cookie_user' => env('SESSION_NAME_USER'),
'cookie_bearer' => env('SESSION_NAME_BEARER'),
'version' => '0.12.0',
'release_date' => '30th July 2022'
'version' => '0.13.0',
'release_date' => '31st July 2022'
];
4 changes: 2 additions & 2 deletions public/css/theme.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/theme.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/scss/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $theme-colors: (
$link-color: rgba(137, 43, 124, 1);
$input-focus-border-color: rgba(137, 43, 124, 1);
$form-check-input-checked-bg-color: rgba(137, 43, 124, 1);
$pagination-border-radius: 0;
$pagination-border-radius-sm: 0;

@import "../../public/node_modules/bootstrap/scss/bootstrap";

Expand Down
34 changes: 34 additions & 0 deletions resources/views/games.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,41 @@

<p class="lead">Start a new <a href="{{ route('game.create.view') }}">game</a>.</p>

<hr />

@if (count($games) > 0)

<nav aria-label="Page pagination">
<ul class="pagination pagination-sm justify-content-center">
@if ($pagination['previous'])
<li class="page-item">
<a class="page-link" href="{{ route('games', ['offset' => max($pagination['offset'] - $pagination['limit'], 0), 'limit' => $pagination['limit']]) }}">Previous</a>
</li>
@else
<li class="page-item disabled">
<a class="page-link">Previous</a>
</li>
@endif
<li class="page-item">
<span class="page-link">
{{ $pagination['offset'] + 1 }} -
{{ min($pagination['offset'] + $pagination['limit'], $pagination['total']) }}
of
{{ $pagination['total'] }}
</span>
</li>
@if ($pagination['next'])
<li class="page-item">
<a class="page-link" href="{{ route('games', ['offset' => $pagination['offset'] + $pagination['limit'], 'limit' => $pagination['limit']]) }}">Next</a>
</li>
@else
<li class="page-item disabled">
<a class="page-link">Next</a>
</li>
@endif
</ul>
</nav>

<ul class="list-unstyled">
@foreach ($games as $__game)
<li class="mb-3">
Expand Down
13 changes: 7 additions & 6 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ul class="list-unstyled mb-2">

@foreach ($__open_game['players']['collection'] as $__player)
<li>
<li class="pb-2">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-person-fill" viewBox="0 0 16 16">
<path d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
</svg>
Expand All @@ -58,11 +58,12 @@
(0 pts)
@endif

<a href="{{ route('game.score-sheet', ['game_id' => $__open_game['id'], 'player_id' => $__player['id']]) }}">[Score sheet]</a>

@if (array_key_exists($__open_game['id'], $share_tokens) && array_key_exists($__player['id'], $share_tokens[$__open_game['id']]))
<a href="{{ route('public.score-sheet', ['token' => $share_tokens[$__open_game['id']][$__player['id']]]) }}">[Share]</a>
@endif
<ul class="list-inline ps-4">
<li class="list-inline-item"><a href="{{ route('game.score-sheet', ['game_id' => $__open_game['id'], 'player_id' => $__player['id']]) }}">[Score sheet]</a></li>
@if (array_key_exists($__open_game['id'], $share_tokens) && array_key_exists($__player['id'], $share_tokens[$__open_game['id']]))
<li class="list-inline-item"><a href="{{ route('public.score-sheet', ['token' => $share_tokens[$__open_game['id']][$__player['id']]]) }}">[Share]</a></li>
@endif
</ul>
</li>
@endforeach
</ul>
Expand Down

0 comments on commit f882f13

Please sign in to comment.