Can create, edit, view, and delete assets

This commit is contained in:
2025-06-08 14:20:29 +02:00
parent 72f4a1cd28
commit afd36bcb0c
11 changed files with 223 additions and 34 deletions

View File

@@ -1,15 +1,19 @@
<body th:replace="~{fragments :: base(title='View '+${descriptor.pluralName}, content=~{::content})}">
<div th:fragment="content">
There are <span th:text="${assets.size()}"></span> <span th:text="${descriptor.pluralName}"></span> in the database.
<table border="1">
<table border="1" cellpadding="4">
<tr bgcolor="#d3d3d3">
<th th:each="p : ${properties}" th:text="${p.displayName}"></th>
<th>Actions</th>
</tr>
<tr th:each="a : ${assets}">
<td th:each="p : ${properties}"><a th:href="'/view/'+${a.getQr()}" th:text="${p.renderValue(a)}"></a></td>
<td th:each="p : ${properties}">
<a th:if="${p.name == 'qr'}" th:href="'/view/'+${a.getQr()}" th:text="${p.renderValue(a)}"></a>
<span th:if="${p.name != 'qr'}" th:text="${p.renderValue(a)}"></span>
</td>
<td>
<a href="/edit">Edit</a>
<a th:href="'/view/'+${a.getQr()}">View</a>
<a th:href="'/edit/'+${a.getQr()}">Edit</a>
</td>
</tr>
</table>

View File

@@ -1,30 +1,30 @@
<body th:replace="~{fragments :: base(title='Create '+${descriptor.displayName}, content=~{::content})}">
<div th:fragment="content">
Create a <span th:text="${descriptor.displayName}"></span>
<form th:action="'/create/'+${descriptor.getType()}" method="post">
<form th:action="'/'+${action}+'/'+${asset != null ? asset.getQr() : descriptor.getType()}" method="post">
<div th:each="d : ${descriptors}">
<h2 th:text="${d.displayName}"></h2>
<table border="1">
<table border="1" cellpadding="4">
<tr th:each="p : ${d.getProperties()}">
<td><label th:text="${p.displayName}" th:for="${d.asString(p)}"></label></td>
<td bgcolor="#d3d3d3"><b><label th:text="${p.displayName}" th:for="${d.asString(p)}"></label></b></td>
<td th:switch="${p.type.nameOrEnum()}">
<input th:case="STRING" type="text" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:placeholder="${p.displayName}" th:required="${p.required}"/>
<input th:case="INTEGER" type="number" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:required="${p.required}"/>
<input th:case="STRING" type="text" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:value="${p.getValue(asset)}" th:placeholder="${p.displayName}" th:required="${p.required}"/>
<input th:case="INTEGER" type="number" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:value="${p.getValue(asset)}" th:required="${p.required}"/>
<select th:case="enum" th:id="${d.asString(p)}" th:name="${d.asString(p)}">
<option th:each="o : ${p.options}" th:value="${o.value}" th:text="${o.displayName}" th:selected="${o.defaultValue}">Good</option>
<option th:each="o : ${p.options}" th:value="${o.value}" th:text="${o.displayName}" th:selected="${asset != null ? (p.getValue(asset) == o.enumConstant) : o.defaultValue}">Good</option>
</select>
<span th:case="CAPACITY">
<input type="number" th:id="${d.asString(p)+'-value'}" th:name="${d.asString(p)+'-value'}" th:required="${p.required}"/>
<select th:id="${d.asString(p)}+'-unit'" th:name="${d.asString(p)}+'-unit'">
<option value="1">Bytes</option>
<option th:if="${p.capacityAsSI}" value="1000">kB</option>
<option th:if="${p.capacityAsIEC}" value="1024">KiB</option>
<option th:if="${p.capacityAsSI}" value="1000000">MB</option>
<option th:if="${p.capacityAsIEC}" value="1048576">MiB</option>
<option th:if="${p.capacityAsSI}" value="1000000000">GB</option>
<option th:if="${p.capacityAsIEC}" value="1073741824">GiB</option>
<option th:if="${p.capacityAsSI}" value="1000000000000">TB</option>
<option th:if="${p.capacityAsIEC}" value="1099511627776">TiB</option>
<option th:if="${p.capacityAsSI}">kB</option>
<option th:if="${p.capacityAsIEC}">KiB</option>
<option th:if="${p.capacityAsSI}">MB</option>
<option th:if="${p.capacityAsIEC}">MiB</option>
<option th:if="${p.capacityAsSI}">GB</option>
<option th:if="${p.capacityAsIEC}">GiB</option>
<option th:if="${p.capacityAsSI}">TB</option>
<option th:if="${p.capacityAsIEC}">TiB</option>
</select>
</span>
<b th:case="*">Bad input type for <span th:text="${d.type}+'-'+${p.type}"></span></b>
@@ -33,7 +33,8 @@
</table>
</div>
<p>
<input type="submit" value="Create">
<input th:if="${action == 'create'}" type="submit" value="Create">
<input th:if="${action == 'edit'}" type="submit" value="Save Changes">
</p>
</form>
</div>

View File

@@ -13,5 +13,9 @@
<hr>
<div th:replace="${content}">
</div>
<hr>
<p>
<small>Rendered in <span th:text="${#execInfo.getNow().getTimeInMillis() - time}">25</span>ms on <span th:text="${#dates.format(#execInfo.getNow(), 'dd/MM/yyyy HH:mm')}"></span>.</small>
</p>
</body>
</html>

View File

@@ -1,5 +1,12 @@
<div th:replace="fragments :: base(title='Home', content=~{::content})">
<div th:fragment="content">
<p>This system holds <span th:text="${asset_count}">5</span> assets.</p>
<form action="/search" method="get">
<label>
Find an asset via QR code:
<input type="number" name="qr" placeholder="Find by QR..." />
</label>
<input type="submit" value="Search" />
</form>
</div>
</div>

View File

@@ -1,14 +1,26 @@
<body th:replace="~{fragments :: base(title='View asset information', content=~{::content})}">
<div th:fragment="content">
View device details
<h2 th:if="${action == 'view'}">Details of <span th:text="${descriptor.displayName}">Hard Disk Drive</span> <span th:text="${asset.getQr()}">21</span></h2>
<h2 th:if="${action == 'delete'}">Are you sure you want to delete <span th:text="${descriptor.displayName}">Hard Disk Drive</span> <span th:text="${asset.getQr()}">21</span></h2>
<div th:each="d : ${descriptors}">
<h2 th:text="${d.displayName}"></h2>
<table border="1">
<table border="1" cellpadding="4">
<tr th:each="p : ${d.properties}">
<td><b th:text="${p.displayName}"></b></td>
<td bgcolor="lightgray"><b th:text="${p.displayName}"></b></td>
<td th:text="${p.renderValue(asset)}"></td>
</tr>
</table>
</div>
<p>
<ul th:if="${action == 'view'}">
<li><a th:href="'/edit/'+${asset.getQr()}">Edit</a></li>
<li><a th:href="'/delete/'+${asset.getQr()}">Delete</a></li>
<li><a th:href="'/browse/'+${descriptor.type}">Browse all <span th:text="${descriptor.pluralName}">Hard Drives</span></a></li>
</ul>
<ul th:if="${action == 'delete'}">
<li><a th:href="'/view/'+${asset.getQr()}">No</a></li>
<li><a th:href="'/delete/'+${asset.getQr()}+'?confirm=true'">Yes, delete it</a></li>
</ul>
</p>
</div>
</body>