Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
}
},
"scripts": {
"check-code": ["@phpcs", "@phpstan", "@phparkitect"],
"check-code": ["@phpcs", "@phpstan", "@phparkitect", "@twig-lint"],
"fix-code": ["@phpcbf", "@twig-lint-fix"],
"phpmd": "vendor/bin/phpmd --ignore-violations-on-exit --ignore-errors-on-exit src text phpmd.xml" ,
"phpstan": "vendor/bin/phpstan --memory-limit=1G",
"phpcs": "vendor/bin/phpcs -s",
Expand Down
18 changes: 13 additions & 5 deletions src/Controller/ContractsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ public function __construct(
}

/**
* @return array<mixed>
* @throws BadRequestException
*/
#[Route(name: 'accept_contract', path: '/contract/accept', methods: ['POST'])]
public function accceptContract(): array
#[Route(
name: 'accept_contract',
path: '/contract/accept',
methods: ['POST'],
strategy: 'application'
)]
public function accceptContract(): ResponseInterface
{
/**
* @var array{
Expand All @@ -38,9 +42,13 @@ public function accceptContract(): array
throw new BadRequestException("Contract ID is required");
}

$id = $post['id'];
$contract = $this->client->accept($post['id']);
$contracts = $this->client->myContracts();

return (array) $this->client->accept($id);
return $this->render('contracts/accept.html.twig', [
'contract' => $contract,
'contracts' => $contracts->contracts,
]);
}

#[Route(
Expand Down
5 changes: 2 additions & 3 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}

<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -27,7 +27,7 @@
</nav>

{% block breadcrumb %}
{% include 'partials/breadcrumb.html.twig' %}
{{ include('partials/breadcrumb.html.twig') }}
{% endblock %}

{% block errors %}
Expand All @@ -36,7 +36,6 @@

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


{% block footerScripts %}
{% endblock %}
</body>
Expand Down
17 changes: 17 additions & 0 deletions templates/contracts/accept.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% import 'macros/helpers.html.twig' as helpers %}
{% extends 'base.html.twig' %}
{% set breadcrumbs = [
{label: 'Contracts', url: '/contracts/'},
{label: contract.id},
] %}

{% block content %}
<aside class="contract-list">
{{ include('partials/contracts-list-brief.html.twig'
, {contracts: contracts}) }}
</aside>
<main class="contract-detail">
{{ include('partials/contract-card.html.twig'
, {contract: contract}) }}
</main>
{% endblock %}
63 changes: 5 additions & 58 deletions templates/contracts/details.html.twig
Original file line number Diff line number Diff line change
@@ -1,66 +1,13 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}
{% extends 'base.html.twig' %}
{% set breadcrumbs = [
{ label: 'Contracts', url: '/contracts/' },
{ label: contract.id}
{label: 'Contracts', url: '/contracts/'},
{label: contract.id},
] %}

{% block content %}

{% if contract.fulfilled %}
{% set state="Fulfilled" %}
{% elseif contract.accepted %}
{% set state="Accepted" %}
{% else %}
{% set state="Pending" %}
{% endif %}
{{ include('partials/contract-card.html.twig'
, {contract: contract}) }}

<div class="card card-one-third contract-card">
<h1 class="title">Contract {{ contract.id }}</h1>
<div class="info">
<p>{{ contract.type.value }} | <b><span class="state">{{ state }}</b></p>
<p><b>Faction:</b> {{ contract.factionSymbol.faction }}</p>
<p><b>Deadline:</b> {{ contract.terms.deadline.date|date }}</p>
<p><b>Expires:</b> {{ contract.expiration|date }}</span></p>
{% if not contract.accepted %}
<p>
<b>Deadline to Accept:</b>
{{ contract.deadlineToAccept|date }}
</p>
<form method="post" action="/contract/accept">
<input type="hidden" name="id" value="{{ contract.id }}">
<button value="accept">Accept</button>
</form>
{% endif %}

<h3>Terms</h3>
<div>
<div>
<p>Payment</p>
<ul>
<li>
On Acceptance: <span>{{ contract.terms.payment.onAccepted|number_format }}</span> credits
</li>
<li>
On Fulfillment: <span>{{ contract.terms.payment.onFulfilled|number_format }}</span> credits
</li>
</ul>
</div>
{% if contract.terms.deliver is defined and contract.terms.deliver is not empty %}
<div>
<p>Deliver Items</p>
<ul>
{% for item in contract.terms.deliver %}
<li>
{{ item.unitsRequired }} units of {{ item.tradeSymbol }} to
{{ helpers.drawer_link_grow(viewWaypointPath(item.destinationSymbol), item.destinationSymbol) }}
<span>(Progress: {{ item.unitsFulfilled }} / {{ item.unitsRequired }})</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
{% endblock %}
14 changes: 6 additions & 8 deletions templates/contracts/list.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}
{% extends 'base.html.twig' %}
{% set breadcrumbs = [
{ label: 'Contracts', url: '.' },
{label: 'Contracts', url: '.'},
]
%}

Expand All @@ -10,21 +10,19 @@

{% if contracts %}
<div class="game-container">
<aside>
{% include 'partials/contracts-list-brief.html.twig'
with {'contracts': contracts} %}
<aside class="contract-list">
{{ include('partials/contracts-list-brief.html.twig'
, {contracts: contracts}) }}
</aside>
<main>
<main class="contract-detail">
<div class="contract-card">
<p>Select a contract to view details.</p>
</div>
</main>
</div>


{% else %}
<p>No contracts available.</p>
{% endif %}

{% endblock %}

4 changes: 2 additions & 2 deletions templates/error-message.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}
{% extends minimalTemplate ? 'minimal.html.twig' : 'base.html.twig' %}

{% block errors %}
<div class="errors">
{{ message }}
</div>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion templates/forms/unpoly-form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
>
{% block form_body %}
{% endblock %}
</form>
</form>
14 changes: 6 additions & 8 deletions templates/index.html.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}
{% extends 'base.html.twig' %}

{% block content %}
<div class="game-container">
<aside>
<h1>Welcome, Captain</h1>
<h2>Your Agent</h2>
{% include 'partials/agent-table.html.twig'
with {'agent': agent} %}
{{ include('partials/agent-table.html.twig'
, {agent: agent}) }}

<h2>Ships</h2>
{% include 'partials/ships-table.html.twig'
with {'ships': ships} %}
{{ include('partials/ships-table.html.twig'
, {ships: ships}) }}
</aside>
<main>
<div class="well">
Expand All @@ -27,7 +27,6 @@
</main>
</div>


<h2>Waypoints</h2>
<p>Quickstart suggests viewing your starting location</p>
<h3>View a Waypoint</h3>
Expand All @@ -52,10 +51,9 @@
<input type="submit" value="Search">
</form>


{% endblock %}

{% block footerScripts %}
<script src="https://unpkg.com/konva@9/konva.min.js"></script>
<script src="/js/system-map.js"></script>
{% endblock %}
{% endblock %}
14 changes: 7 additions & 7 deletions templates/macros/helpers.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a href="{{ path|e('html_attr') }}"
up-target="{{ target ?: '.content' }}"
up-animation="move-from-top"
up-cache="{{ cache ? 'true': 'false' }}"
up-cache="{{ cache ? 'true' : 'false' }}"
up-layer="swap modal">{{ text ?: path }}</a>
{% endmacro %}

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

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

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

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

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

Expand All @@ -60,4 +60,4 @@
{% for opt in options %}
<option value="{{ opt.value|e('html_attr') }}">{{ opt.name }}</option>
{% endfor %}
{% endmacro %}
{% endmacro %}
4 changes: 2 additions & 2 deletions templates/partials/agent-table.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% import "macros/helpers.html.twig" as helpers %}
{% import 'macros/helpers.html.twig' as helpers %}

<table>
<tr>
Expand All @@ -17,4 +17,4 @@
<td>{{ agent.startingFaction }}</td>
<td>{{ agent.shipCount }}</td>
</tr>
</table>
</table>
2 changes: 1 addition & 1 deletion templates/partials/breadcrumb.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ has a `label` and an `url`. The last item can omit the `url`
{% endif %}
{% endfor %}
</ol>
</nav>
</nav>
61 changes: 61 additions & 0 deletions templates/partials/contract-card.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% if contract.fulfilled %}
{% set state = 'Fulfilled' %}
{% elseif contract.accepted %}
{% set state = 'Accepted' %}
{% else %}
{% set state = 'Pending' %}
{% endif %}

<div class="card card-one-third contract-card">
<h1 class="title">Contract {{ contract.id }}</h1>
<div class="info">
<p>{{ contract.type.value }} | <b><span class="state">{{ state }}</b></p>
<p><b>Faction:</b> {{ contract.factionSymbol.faction }}</p>
<p><b>Deadline:</b> {{ contract.terms.deadline.date|date }}</p>
<p><b>Expires:</b> {{ contract.expiration|date }}</span></p>
{% if not contract.accepted %}
<p>
<b>Deadline to Accept:</b>
{{ contract.deadlineToAccept|date }}
</p>
{% embed 'forms/unpoly-form.html.twig' with {
action: '/contract/accept',
up_target: '.contract-list, .contract-card',
} %}
{% block form_body %}
<input type="hidden" name="id" value="{{ contract.id }}">
<button value="accept">Accept</button>
{% endblock %}
{% endembed %}
{% endif %}

<h3>Terms</h3>
<div>
<div>
<p>Payment</p>
<ul>
<li>
On Acceptance: <span>{{ contract.terms.payment.onAccepted|number_format }}</span> credits
</li>
<li>
On Fulfillment: <span>{{ contract.terms.payment.onFulfilled|number_format }}</span> credits
</li>
</ul>
</div>
{% if contract.terms.deliver is defined and contract.terms.deliver is not empty %}
<div>
<p>Deliver Items</p>
<ul>
{% for item in contract.terms.deliver %}
<li>
{{ item.unitsRequired }} units of {{ item.tradeSymbol }} to
{{ helpers.drawer_link_grow(viewWaypointPath(item.destinationSymbol), item.destinationSymbol) }}
<span>(Progress: {{ item.unitsFulfilled }} / {{ item.unitsRequired }})</span>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
Loading