Skip to content

Commit e510b80

Browse files
authored
Refresh UI on contract acceptance (#87)
* Fix #60: Refresh the UI when a user accepts a contract to show the changed state.
1 parent ac843a1 commit e510b80

37 files changed

+223
-199
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
}
7272
},
7373
"scripts": {
74-
"check-code": ["@phpcs", "@phpstan", "@phparkitect"],
74+
"check-code": ["@phpcs", "@phpstan", "@phparkitect", "@twig-lint"],
75+
"fix-code": ["@phpcbf", "@twig-lint-fix"],
7576
"phpmd": "vendor/bin/phpmd --ignore-violations-on-exit --ignore-errors-on-exit src text phpmd.xml" ,
7677
"phpstan": "vendor/bin/phpstan --memory-limit=1G",
7778
"phpcs": "vendor/bin/phpcs -s",

src/Controller/ContractsController.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ public function __construct(
2222
}
2323

2424
/**
25-
* @return array<mixed>
2625
* @throws BadRequestException
2726
*/
28-
#[Route(name: 'accept_contract', path: '/contract/accept', methods: ['POST'])]
29-
public function accceptContract(): array
27+
#[Route(
28+
name: 'accept_contract',
29+
path: '/contract/accept',
30+
methods: ['POST'],
31+
strategy: 'application'
32+
)]
33+
public function accceptContract(): ResponseInterface
3034
{
3135
/**
3236
* @var array{
@@ -38,9 +42,13 @@ public function accceptContract(): array
3842
throw new BadRequestException("Contract ID is required");
3943
}
4044

41-
$id = $post['id'];
45+
$contract = $this->client->accept($post['id']);
46+
$contracts = $this->client->myContracts();
4247

43-
return (array) $this->client->accept($id);
48+
return $this->render('contracts/accept.html.twig', [
49+
'contract' => $contract,
50+
'contracts' => $contracts->contracts,
51+
]);
4452
}
4553

4654
#[Route(

templates/base.html.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% import "macros/helpers.html.twig" as helpers %}
1+
{% import 'macros/helpers.html.twig' as helpers %}
22

33
<!DOCTYPE html>
44
<html>
@@ -27,7 +27,7 @@
2727
</nav>
2828

2929
{% block breadcrumb %}
30-
{% include 'partials/breadcrumb.html.twig' %}
30+
{{ include('partials/breadcrumb.html.twig') }}
3131
{% endblock %}
3232

3333
{% block errors %}
@@ -36,7 +36,6 @@
3636

3737
<div id="content" class="content">{% block content %}{% endblock %}</div>
3838

39-
4039
{% block footerScripts %}
4140
{% endblock %}
4241
</body>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% import 'macros/helpers.html.twig' as helpers %}
2+
{% extends 'base.html.twig' %}
3+
{% set breadcrumbs = [
4+
{label: 'Contracts', url: '/contracts/'},
5+
{label: contract.id},
6+
] %}
7+
8+
{% block content %}
9+
<aside class="contract-list">
10+
{{ include('partials/contracts-list-brief.html.twig'
11+
, {contracts: contracts}) }}
12+
</aside>
13+
<main class="contract-detail">
14+
{{ include('partials/contract-card.html.twig'
15+
, {contract: contract}) }}
16+
</main>
17+
{% endblock %}
Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,13 @@
1-
{% import "macros/helpers.html.twig" as helpers %}
1+
{% import 'macros/helpers.html.twig' as helpers %}
22
{% extends 'base.html.twig' %}
33
{% set breadcrumbs = [
4-
{ label: 'Contracts', url: '/contracts/' },
5-
{ label: contract.id}
4+
{label: 'Contracts', url: '/contracts/'},
5+
{label: contract.id},
66
] %}
77

88
{% block content %}
99

10-
{% if contract.fulfilled %}
11-
{% set state="Fulfilled" %}
12-
{% elseif contract.accepted %}
13-
{% set state="Accepted" %}
14-
{% else %}
15-
{% set state="Pending" %}
16-
{% endif %}
10+
{{ include('partials/contract-card.html.twig'
11+
, {contract: contract}) }}
1712

18-
<div class="card card-one-third contract-card">
19-
<h1 class="title">Contract {{ contract.id }}</h1>
20-
<div class="info">
21-
<p>{{ contract.type.value }} | <b><span class="state">{{ state }}</b></p>
22-
<p><b>Faction:</b> {{ contract.factionSymbol.faction }}</p>
23-
<p><b>Deadline:</b> {{ contract.terms.deadline.date|date }}</p>
24-
<p><b>Expires:</b> {{ contract.expiration|date }}</span></p>
25-
{% if not contract.accepted %}
26-
<p>
27-
<b>Deadline to Accept:</b>
28-
{{ contract.deadlineToAccept|date }}
29-
</p>
30-
<form method="post" action="/contract/accept">
31-
<input type="hidden" name="id" value="{{ contract.id }}">
32-
<button value="accept">Accept</button>
33-
</form>
34-
{% endif %}
35-
36-
<h3>Terms</h3>
37-
<div>
38-
<div>
39-
<p>Payment</p>
40-
<ul>
41-
<li>
42-
On Acceptance: <span>{{ contract.terms.payment.onAccepted|number_format }}</span> credits
43-
</li>
44-
<li>
45-
On Fulfillment: <span>{{ contract.terms.payment.onFulfilled|number_format }}</span> credits
46-
</li>
47-
</ul>
48-
</div>
49-
{% if contract.terms.deliver is defined and contract.terms.deliver is not empty %}
50-
<div>
51-
<p>Deliver Items</p>
52-
<ul>
53-
{% for item in contract.terms.deliver %}
54-
<li>
55-
{{ item.unitsRequired }} units of {{ item.tradeSymbol }} to
56-
{{ helpers.drawer_link_grow(viewWaypointPath(item.destinationSymbol), item.destinationSymbol) }}
57-
<span>(Progress: {{ item.unitsFulfilled }} / {{ item.unitsRequired }})</span>
58-
</li>
59-
{% endfor %}
60-
</ul>
61-
</div>
62-
{% endif %}
63-
</div>
64-
</div>
65-
</div>
6613
{% endblock %}

templates/contracts/list.html.twig

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{% import "macros/helpers.html.twig" as helpers %}
1+
{% import 'macros/helpers.html.twig' as helpers %}
22
{% extends 'base.html.twig' %}
33
{% set breadcrumbs = [
4-
{ label: 'Contracts', url: '.' },
4+
{label: 'Contracts', url: '.'},
55
]
66
%}
77

@@ -10,21 +10,19 @@
1010

1111
{% if contracts %}
1212
<div class="game-container">
13-
<aside>
14-
{% include 'partials/contracts-list-brief.html.twig'
15-
with {'contracts': contracts} %}
13+
<aside class="contract-list">
14+
{{ include('partials/contracts-list-brief.html.twig'
15+
, {contracts: contracts}) }}
1616
</aside>
17-
<main>
17+
<main class="contract-detail">
1818
<div class="contract-card">
1919
<p>Select a contract to view details.</p>
2020
</div>
2121
</main>
2222
</div>
2323

24-
2524
{% else %}
2625
<p>No contracts available.</p>
2726
{% endif %}
2827

2928
{% endblock %}
30-

templates/error-message.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{% import "macros/helpers.html.twig" as helpers %}
1+
{% import 'macros/helpers.html.twig' as helpers %}
22
{% extends minimalTemplate ? 'minimal.html.twig' : 'base.html.twig' %}
33

44
{% block errors %}
55
<div class="errors">
66
{{ message }}
77
</div>
8-
{% endblock %}
8+
{% endblock %}

templates/forms/unpoly-form.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
>
66
{% block form_body %}
77
{% endblock %}
8-
</form>
8+
</form>

templates/index.html.twig

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
{% import "macros/helpers.html.twig" as helpers %}
1+
{% import 'macros/helpers.html.twig' as helpers %}
22
{% extends 'base.html.twig' %}
33

44
{% block content %}
55
<div class="game-container">
66
<aside>
77
<h1>Welcome, Captain</h1>
88
<h2>Your Agent</h2>
9-
{% include 'partials/agent-table.html.twig'
10-
with {'agent': agent} %}
9+
{{ include('partials/agent-table.html.twig'
10+
, {agent: agent}) }}
1111

1212
<h2>Ships</h2>
13-
{% include 'partials/ships-table.html.twig'
14-
with {'ships': ships} %}
13+
{{ include('partials/ships-table.html.twig'
14+
, {ships: ships}) }}
1515
</aside>
1616
<main>
1717
<div class="well">
@@ -27,7 +27,6 @@
2727
</main>
2828
</div>
2929

30-
3130
<h2>Waypoints</h2>
3231
<p>Quickstart suggests viewing your starting location</p>
3332
<h3>View a Waypoint</h3>
@@ -52,10 +51,9 @@
5251
<input type="submit" value="Search">
5352
</form>
5453

55-
5654
{% endblock %}
5755

5856
{% block footerScripts %}
5957
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
6058
<script src="/js/system-map.js"></script>
61-
{% endblock %}
59+
{% endblock %}

templates/macros/helpers.html.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<a href="{{ path|e('html_attr') }}"
88
up-target="{{ target ?: '.content' }}"
99
up-animation="move-from-top"
10-
up-cache="{{ cache ? 'true': 'false' }}"
10+
up-cache="{{ cache ? 'true' : 'false' }}"
1111
up-layer="swap modal">{{ text ?: path }}</a>
1212
{% endmacro %}
1313

@@ -16,7 +16,7 @@
1616
up-target="{{ target ?: '.content' }}"
1717
up-size="grow"
1818
up-animation="move-from-top"
19-
up-cache="{{ cache ? 'true': 'false' }}"
19+
up-cache="{{ cache ? 'true' : 'false' }}"
2020
up-layer="swap modal">{{ text ?: path }}</a>
2121
{% endmacro %}
2222

@@ -25,30 +25,30 @@
2525
up-target="{{ target ?: '.content' }}"
2626
up-size="large"
2727
up-animation="move-from-top"
28-
up-cache="{{ cache ? 'true': 'false' }}"
28+
up-cache="{{ cache ? 'true' : 'false' }}"
2929
up-layer="swap modal">{{ text ?: path }}</a>
3030
{% endmacro %}
3131

3232
{% macro drawer_link(path, text, cache, target) %}
3333
<a href="{{ path|e('html_attr') }}"
3434
up-target="{{ target ?: '.content' }}"
35-
up-cache="{{ cache ? 'true': 'false' }}"
35+
up-cache="{{ cache ? 'true' : 'false' }}"
3636
up-layer="new drawer">{{ text ?: path }}</a>
3737
{% endmacro %}
3838

3939
{% macro drawer_link_grow(path, text, cache, target) %}
4040
<a href="{{ path|e('html_attr') }}"
4141
up-target="{{ target ?: '.content' }}"
4242
up-size="grow"
43-
up-cache="{{ cache ? 'true': 'false' }}"
43+
up-cache="{{ cache ? 'true' : 'false' }}"
4444
up-layer="new drawer">{{ text ?: path }}</a>
4545
{% endmacro %}
4646

4747
{% macro drawer_link_large(path, text, cache, target) %}
4848
<a href="{{ path|e('html_attr') }}"
4949
up-target="{{ target ?: '.content' }}"
5050
up-size="large"
51-
up-cache="{{ cache ? 'true': 'false' }}"
51+
up-cache="{{ cache ? 'true' : 'false' }}"
5252
up-layer="new drawer">{{ text ?: path }}</a>
5353
{% endmacro %}
5454

@@ -60,4 +60,4 @@
6060
{% for opt in options %}
6161
<option value="{{ opt.value|e('html_attr') }}">{{ opt.name }}</option>
6262
{% endfor %}
63-
{% endmacro %}
63+
{% endmacro %}

0 commit comments

Comments
 (0)