Add composite asset creation functionality with new views and asset descriptor handling
All checks were successful
Build / build (push) Successful in 1m22s
All checks were successful
Build / build (push) Successful in 1m22s
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package be.seeseepuff.pcinv.controllers;
|
||||
|
||||
import be.seeseepuff.pcinv.meta.AssetDescriptor;
|
||||
import be.seeseepuff.pcinv.models.Asset;
|
||||
import be.seeseepuff.pcinv.models.GenericAsset;
|
||||
import be.seeseepuff.pcinv.models.WorkLogEntry;
|
||||
import be.seeseepuff.pcinv.services.AssetService;
|
||||
import be.seeseepuff.pcinv.services.BuildService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -16,8 +19,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Controller for handling web requests related to assets.
|
||||
@@ -132,6 +137,40 @@ public class WebController {
|
||||
return "build_view";
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a view where the user can create a specific type of composite asset.
|
||||
*
|
||||
* @param type The type of composite asset to create.
|
||||
*/
|
||||
@GetMapping("/create_composite")
|
||||
public String createCompositeType(Model model, HttpServletRequest request) {
|
||||
var parameters = request.getParameterMap();
|
||||
if (parameters == null || parameters.isEmpty()) {
|
||||
model.addAttribute(TIME, System.currentTimeMillis());
|
||||
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptors());
|
||||
return "create_composite";
|
||||
} else {
|
||||
model.addAttribute(TIME, System.currentTimeMillis());
|
||||
model.addAttribute(ACTION, "create");
|
||||
var descriptors = new ArrayList<AssetDescriptor>();
|
||||
var inputLists = new HashMap<String, Set<String>>();
|
||||
descriptors.add(assetService.getAssetDescriptor(GenericAsset.TYPE));
|
||||
for (String assetType : parameters.keySet()) {
|
||||
descriptors.add(assetService.getAssetDescriptor(assetType));
|
||||
inputLists.putAll(assetService.getInputList(assetType));
|
||||
}
|
||||
model.addAttribute(DESCRIPTORS, descriptors);
|
||||
model.addAttribute(DESCRIPTOR, AssetDescriptor.builder()
|
||||
.type("composite")
|
||||
.displayName("Composite Asset")
|
||||
.pluralName("Composite Assets")
|
||||
.build());
|
||||
model.addAttribute(INPUT_LIST, inputLists);
|
||||
model.addAttribute(BUILDS, buildService.getAllBuilds());
|
||||
return "create_asset";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the creation of a new build.
|
||||
*/
|
||||
|
||||
@@ -20,8 +20,16 @@ public class AssetDescriptors {
|
||||
* @param assetType The type of the asset to load properties for.
|
||||
*/
|
||||
public void loadFrom(Class<?> assetType) {
|
||||
var property = AssetDescriptor.loadFrom(assetType);
|
||||
assets.add(property);
|
||||
add(AssetDescriptor.loadFrom(assetType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new asset descriptor to the collection.
|
||||
*
|
||||
* @param assetDescriptor The asset descriptor to add.
|
||||
*/
|
||||
public void add(AssetDescriptor assetDescriptor) {
|
||||
assets.add(assetDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
11
src/main/resources/templates/create_composite.html
Normal file
11
src/main/resources/templates/create_composite.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<body th:replace="~{fragments :: base(title='Select type to create', content=~{::content})}">
|
||||
<div th:fragment="content">
|
||||
<h2>Create a new composite device</h2>
|
||||
<form method="get" action="/create_composite">
|
||||
<div th:each="d : ${descriptors.getAssets()}" th:if="${d.visible}"><label><input type="checkbox" value="on" th:name="${d.type}"><span th:text="${d.displayName}"></span></label></div>
|
||||
<p>
|
||||
<input type="submit" value="Create Composite">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
@@ -2,6 +2,7 @@
|
||||
<div th:fragment="content">
|
||||
<h2>Create a new device</h2>
|
||||
<ul>
|
||||
<li><a href="/create_composite"><i>Composite</i></a></li>
|
||||
<li th:each="d : ${descriptors.getAssets()}" th:if="${d.visible}"><a th:href="'/create/'+${d.getType()}" th:text="${d.displayName}"></a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user