clean code for boats ui

This commit is contained in:
philipp 2023-07-26 12:24:22 +02:00
parent 692d77d302
commit 97703403a8
2 changed files with 72 additions and 81 deletions

View File

@ -0,0 +1,65 @@
{% macro new() %}
<form
action="/admin/boat/new"
method="post"
class="mt-4 bg-primary-900 rounded-md text-white px-3 pb-3 pt-2 sm:flex items-end justify-between"
>
<div class="w-full">
<h2 class="text-md font-bold mb-2 uppercase tracking-wide">
Neues Boot hinzufügen
</h2>
{{ macros::input(label="Name", name="name", type="text", required=true) }}
{{ macros::input(label="Anzahl Sitze", name="amount_seats", type="number", required=true, min=1) }}
{{ macros::input(label="Baujahr", name="year_built", type="number", min=1950, max, 2050) }}
{{ macros::input(label="Bootsbauer", name="boatbuilder", type="text") }}
{{ macros::select(data=locations, label='location', select_name='location_id', selected_id=1) }}
{{ macros::select(data=users, label='users', select_name='owner', default="Vereinsboot") }}
{{ macros::checkbox(label="Steuerperson steuert nur", name="default_shipmaster_only_steering")}}
{{ macros::checkbox(label="Skull", name="skull", checked=true)}}
{{ macros::checkbox(label="Externes Boot (anderer Verein)", name="external")}}
</div>
<div class="text-right">
<input
value="Hinzufügen"
type="submit"
class="w-28 mt-2 sm:mt-0 rounded-md bg-primary-500 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"
/>
</div>
</form>
{% endmacro checkbox %}
{% macro edit(boat, uuid) %}
<form
action="/admin/boat"
data-filterable="true"
method="post"
class="bg-white p-3 rounded-md flex items-end md:items-center justify-between"
>
<div class="w-full">
<input type="hidden" name="id" value="{{ boat.id }}" />
<div class="font-bold mb-1">{{ boat.name }}<br /></div>
<div class="grid md:grid-cols-3">
{{ macros::input(label='Name', name='name', type='text', value=boat.name) }}
{{ macros::input(label='Amount Seats', name='amount_seats', type='number', min=0, value=boat.amount_seats) }}
{{ macros::select(data=locations, label='location', select_name='location_id', selected_id=boat.location_id) }}
{{ macros::select(data=users, label='users', select_name='owner', selected_id=boat.owner, default="Vereinsboot") }}
{{ macros::input(label='Baujahr', name='year_built', type='number', min=1950, value=boat.year_built) }}
{{ macros::input(label='Bootsbauer', name='boatbuilder', type='text', value=boat.boatbuilder) }}
{{ macros::checkbox(label='default_shipmaster_only_steering', name='default_shipmaster_only_steering', id=uuid , checked=boat.default_shipmaster_only_steering) }}
{{ macros::checkbox(label='skull', name='skull', id=uuid , checked=boat.skull) }}
{{ macros::checkbox(label='external', name='external', id=uuid , checked=boat.external) }}
</div>
</div>
<div class="grid gap-3">
<a
href="/admin/boat/{{ boat.id }}/delete"
class="inline-block btn btn-alert"
onclick="return confirm('Wirklich löschen?');"
>
{% include "includes/delete-icon" %} Löschen
</a>
<input value="Ändern" type="submit" class="w-28 btn btn-primary" />
</div>
</form>
{% endmacro checkbox %}

View File

@ -1,93 +1,19 @@
{% import "includes/macros" as macros %} {% import "includes/macros" as macros %}
{% import "admin/boat/boat" as boat %}
{% extends "base" %} {% extends "base" %}
{% block content %} {% block content %}
<div class="max-w-screen-lg w-full"> <div class="max-w-screen-lg w-full">
{% if flash %}
{{ macros::alert(message=flash.1, type=flash.0, class="sm:col-span-2 lg:col-span-3") }}
{% endif %}
<h1 class="h1">Boats</h1> <h1 class="h1">Boats</h1>
{{ boat::new() }}
<form action="/admin/boat/new" method="post" class="mt-4 bg-primary-900 rounded-md text-white px-3 pb-3 pt-2 sm:flex items-end justify-between"> <div class="bg-primary-100 p-3 rounded-b-md grid gap-4">
<div class="w-full"> {% for boat in boats %}
<h2 class="text-md font-bold mb-2 uppercase tracking-wide">Neues Boot hinzufügen</h2> {{ boat::edit(boat=boat, uuid=loop.index) }}
<div class="grid md:grid-cols-3"> {% endfor %}
<div>
<label for="name" class="sr-only">Name</label>
<input type="text" name="name" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" placeholder="Name"/>
</div>
<div>
<label for="amount_seats" class="sr-only">Anzahl Sitze</label>
<input type="number" min=0 name="amount_seats" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" placeholder="Anzahl Sitze"/>
</div>
<div>
<label for="year_built" class="sr-only">Baujahr</label>
<input type="number" min="1950" name="year_built" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" placeholder="Baujahr"/>
</div>
<div>
<label for="boatbuilder" class="sr-only">Boatbuilder</label>
<input type="text" name="boatbuilder" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" placeholder="Boatbuilder"/>
</div>
{{ macros::select(data=locations, label='location', select_name='location_id', selected_id=1) }}
{{ macros::select(data=users, label='users', select_name='owner', default="Vereinsboot") }}
<div>
default_shipmaster_only_steering:
<label for="default_shipmaster_only_steering" class="sr-only">default_shipmaster_only_steering</label>
<input type="checkbox" name="default_shipmaster_only_steering" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0"/>
</div>
<div>
skull:
<label for="skull" class="sr-only">skull</label>
<input type="checkbox" name="skull" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" checked="checked"/>
</div>
<div>
external:
<label for="external" class="sr-only">external</label>
<input type="checkbox" name="external" class="relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:z-10 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0"/>
</div>
</div>
</div> </div>
<div class="text-right">
<input value="Hinzufügen" type="submit" class="w-28 mt-2 sm:mt-0 rounded-md bg-primary-500 px-3 py-2 text-sm font-semibold text-white hover:bg-primary-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"/>
</div>
</form>
<div class="bg-primary-100 p-3 rounded-b-md grid gap-4">
<div id="filter-result-js" class="text-primary-950"></div>
{% for boat in boats %}
<form action="/admin/boat" data-filterable="true" method="post" class="bg-white p-3 rounded-md flex items-end md:items-center justify-between">
<div class="w-full">
<input type="hidden" name="id" value="{{ boat.id }}" />
<div class="font-bold mb-1">{{ boat.name }}<br />
</div>
<div class="grid md:grid-cols-3">
{{ macros::input(label='Name', name='name', type='text', value=boat.name) }}
{{ macros::input(label='Amount Seats', name='amount_seats', type='number', min=0, value=boat.amount_seats) }}
{{ macros::select(data=locations, label='location', select_name='location_id', selected_id=boat.location_id) }}
{{ macros::select(data=users, label='users', select_name='owner', selected_id=boat.owner, default="Vereinsboot") }}
{{ macros::input(label='Baujahr', name='year_built', type='number', min=1950, value=boat.year_built) }}
{{ macros::input(label='Bootsbauer', name='boatbuilder', type='text', value=boat.boatbuilder) }}
{{ macros::checkbox(label='default_shipmaster_only_steering', name='default_shipmaster_only_steering', id=loop.index , checked=boat.default_shipmaster_only_steering) }}
{{ macros::checkbox(label='skull', name='skull', id=loop.index , checked=boat.skull) }}
{{ macros::checkbox(label='external', name='external', id=loop.index , checked=boat.external) }}
</div>
</div>
<div class="grid gap-3">
<a href="/admin/boat/{{ boat.id }}/delete" class="inline-block btn btn-alert" onclick="return confirm('Wirklich löschen?');">
{% include "includes/delete-icon" %}
Löschen
</a>
<input value="Ändern" type="submit" class="w-28 btn btn-primary"/>
</div>
</form>
{% endfor %}
</div>
</div> </div>
{% endblock content %} {% endblock content %}