Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b4c493c27b | |||
| 8e26a73243 | |||
| 8cbededc79 | |||
| 13617eed6d | |||
| 698f6a3903 | |||
| d702544f2c | |||
| 7fca7c4ff0 | |||
| 3789fee73b | |||
| 18baf239e8 | |||
| c57c429dae |
@@ -28,6 +28,8 @@ dependencies {
|
|||||||
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
implementation("org.springframework.boot:spring-boot-starter-actuator")
|
||||||
|
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8")
|
||||||
|
implementation("org.modelmapper:modelmapper:3.2.3")
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly("org.projectlombok:lombok")
|
||||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
runtimeOnly("org.postgresql:postgresql")
|
runtimeOnly("org.postgresql:postgresql")
|
||||||
|
|||||||
15
src/main/java/be/seeseepuff/pcinv/PcinvConfig.java
Normal file
15
src/main/java/be/seeseepuff/pcinv/PcinvConfig.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package be.seeseepuff.pcinv;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableWebMvc
|
||||||
|
public class PcinvConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
|
registry.addMapping("/**");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package be.seeseepuff.pcinv.controllers;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.meta.AssetDescriptor;
|
||||||
|
import be.seeseepuff.pcinv.models.Asset;
|
||||||
|
import be.seeseepuff.pcinv.services.AssetService;
|
||||||
|
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.info.Info;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api")
|
||||||
|
@RestController
|
||||||
|
@OpenAPIDefinition(
|
||||||
|
info = @Info(
|
||||||
|
title = "PC Inventory API",
|
||||||
|
version = "1.0",
|
||||||
|
description = "API for managing PC inventory assets. Assets are identified by QR or ID codes."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
public class ApiController {
|
||||||
|
private final AssetService assetService;
|
||||||
|
|
||||||
|
@Operation(summary = "Lists all types of assets available in the system.")
|
||||||
|
@GetMapping("/assetTypes")
|
||||||
|
public List<String> assets() {
|
||||||
|
return assetService.getAssetDescriptors().getAssets().stream()
|
||||||
|
.map(AssetDescriptor::getType)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Lists all information of a specific asset.")
|
||||||
|
@GetMapping("/asset/{qr}")
|
||||||
|
public Asset getAsset(
|
||||||
|
@PathVariable @Parameter(name = "qr", description = "The QR number of the asset") long qr
|
||||||
|
) {
|
||||||
|
return assetService.getAssetByQr(qr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Adds a work log entry to an asset.")
|
||||||
|
@PostMapping("/asset/worklog")
|
||||||
|
public String addWorkLogEntry(
|
||||||
|
@RequestBody Entry entry
|
||||||
|
) {
|
||||||
|
var qr = entry.qr;
|
||||||
|
var asset = assetService.getAssetByQr(qr);
|
||||||
|
if (asset == null) {
|
||||||
|
throw new IllegalArgumentException("Asset with QR code " + qr + " not found.");
|
||||||
|
}
|
||||||
|
if (entry.entry == null || entry.entry.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Work log entry comment cannot be empty.");
|
||||||
|
}
|
||||||
|
assetService.addWorkLogEntry(asset, entry.entry);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Entry {
|
||||||
|
@Parameter(name = "qr", description = "The QR number of the asset")
|
||||||
|
public long qr;
|
||||||
|
@Parameter(name = "entry", description = "The work log entry text")
|
||||||
|
public String entry;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package be.seeseepuff.pcinv.controllers;
|
|||||||
|
|
||||||
import be.seeseepuff.pcinv.models.WorkLogEntry;
|
import be.seeseepuff.pcinv.models.WorkLogEntry;
|
||||||
import be.seeseepuff.pcinv.services.AssetService;
|
import be.seeseepuff.pcinv.services.AssetService;
|
||||||
|
import be.seeseepuff.pcinv.services.BuildService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
@@ -42,6 +43,12 @@ public class WebController {
|
|||||||
private static final String INPUT_LIST = "inputLists";
|
private static final String INPUT_LIST = "inputLists";
|
||||||
/// The name of the model attribute that holds the current work log entries.
|
/// The name of the model attribute that holds the current work log entries.
|
||||||
private static final String WORKLOG = "worklog";
|
private static final String WORKLOG = "worklog";
|
||||||
|
/// The name of the model attribute that holds the current build being viewed or edited.
|
||||||
|
private static final String BUILD = "build";
|
||||||
|
/// The name of the model attribute that holds the build information.
|
||||||
|
private static final String BUILD_INFO = "buildInfo";
|
||||||
|
/// The name of the model attribute that holds the builds available for selection.
|
||||||
|
private static final String BUILDS = "builds";
|
||||||
|
|
||||||
/// The name of the input field for the current size of the work log.
|
/// The name of the input field for the current size of the work log.
|
||||||
private static final String WORKLOG_SIZE = "worklog_size";
|
private static final String WORKLOG_SIZE = "worklog_size";
|
||||||
@@ -49,6 +56,7 @@ public class WebController {
|
|||||||
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd MMM yyyy 'at' HH:mm");
|
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd MMM yyyy 'at' HH:mm");
|
||||||
|
|
||||||
private final AssetService assetService;
|
private final AssetService assetService;
|
||||||
|
private final BuildService buildService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the root URL and returns the index page with asset descriptors and asset count.
|
* Handles the root URL and returns the index page with asset descriptors and asset count.
|
||||||
@@ -90,6 +98,54 @@ public class WebController {
|
|||||||
return "browse_type";
|
return "browse_type";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the browsing of all builds.
|
||||||
|
* Displays a list of all builds available in the system.
|
||||||
|
*/
|
||||||
|
@GetMapping("/builds")
|
||||||
|
public String browseBuilds(Model model) {
|
||||||
|
model.addAttribute(TIME, System.currentTimeMillis());
|
||||||
|
model.addAttribute(BUILDS, buildService.getAllBuilds());
|
||||||
|
return "builds";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the viewing of a specific build by its ID.
|
||||||
|
* If the build does not exist, it redirects to the builds page.
|
||||||
|
*/
|
||||||
|
@GetMapping("/build/{id}")
|
||||||
|
public String viewBuild(Model model, @PathVariable long id) {
|
||||||
|
model.addAttribute(TIME, System.currentTimeMillis());
|
||||||
|
var build = buildService.getBuildById(id);
|
||||||
|
if (build == null) {
|
||||||
|
return "redirect:/builds";
|
||||||
|
}
|
||||||
|
model.addAttribute(BUILD, build);
|
||||||
|
model.addAttribute(BUILD_INFO, buildService.getBuildInfo(build));
|
||||||
|
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptors());
|
||||||
|
return "build_view";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the creation of a new build.
|
||||||
|
*/
|
||||||
|
@PostMapping("/create_build")
|
||||||
|
public String createBuild(Model model, @RequestBody MultiValueMap<String, String> formData) {
|
||||||
|
model.addAttribute(TIME, System.currentTimeMillis());
|
||||||
|
var build = buildService.createBuild(formData.getFirst("name"), formData.getFirst("description"));
|
||||||
|
return "redirect:/build/" + build.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a build by its ID.
|
||||||
|
*/
|
||||||
|
@GetMapping("/delete_build/{id}")
|
||||||
|
public String deleteBuild(Model model, @PathVariable long id) {
|
||||||
|
model.addAttribute(TIME, System.currentTimeMillis());
|
||||||
|
buildService.deleteBuild(id);
|
||||||
|
return "redirect:/builds";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the view of an asset by its QR code.
|
* Handles the view of an asset by its QR code.
|
||||||
* If the asset does not exist, it redirects to the index page.
|
* If the asset does not exist, it redirects to the index page.
|
||||||
@@ -202,6 +258,7 @@ public class WebController {
|
|||||||
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(type));
|
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(type));
|
||||||
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
|
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
|
||||||
model.addAttribute(INPUT_LIST, assetService.getInputList(type));
|
model.addAttribute(INPUT_LIST, assetService.getInputList(type));
|
||||||
|
model.addAttribute(BUILDS, buildService.getAllBuilds());
|
||||||
return "create_asset";
|
return "create_asset";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,6 +280,28 @@ public class WebController {
|
|||||||
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(assetType));
|
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(assetType));
|
||||||
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(assetType));
|
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(assetType));
|
||||||
model.addAttribute(INPUT_LIST, assetService.getInputList(assetType));
|
model.addAttribute(INPUT_LIST, assetService.getInputList(assetType));
|
||||||
|
model.addAttribute(BUILDS, buildService.getAllBuilds());
|
||||||
|
return "create_asset";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a view where the user can edit an existing asset.
|
||||||
|
*
|
||||||
|
* @param qr The QR code of the asset to edit.
|
||||||
|
*/
|
||||||
|
@GetMapping("/duplicate/{qr}")
|
||||||
|
public String duplicate(Model model, @PathVariable long qr) {
|
||||||
|
model.addAttribute(TIME, System.currentTimeMillis());
|
||||||
|
var asset = assetService.getAssetByQr(qr);
|
||||||
|
if (asset == null) {
|
||||||
|
throw new RuntimeException("Asset not found");
|
||||||
|
}
|
||||||
|
String assetType = asset.getAsset().getType();
|
||||||
|
model.addAttribute(ACTION, "duplicate");
|
||||||
|
model.addAttribute(ASSET, asset);
|
||||||
|
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(assetType));
|
||||||
|
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(assetType));
|
||||||
|
model.addAttribute(INPUT_LIST, assetService.getInputList(assetType));
|
||||||
return "create_asset";
|
return "create_asset";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,6 +99,19 @@ public class AssetDescriptor {
|
|||||||
return String.format("%s-%s", type, property.getName());
|
return String.format("%s-%s", type, property.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the property with the specified name.
|
||||||
|
*
|
||||||
|
* @param name The name of the property to retrieve.
|
||||||
|
* @return The AssetProperty with the given name.
|
||||||
|
*/
|
||||||
|
public AssetProperty getProperty(String name) {
|
||||||
|
return properties.stream()
|
||||||
|
.filter(property -> property.getName().equals(name))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("No property found with name: " + name));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the asset type described by this descriptor.
|
* Creates a new instance of the asset type described by this descriptor.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,6 +24,37 @@ public class AssetDescriptors {
|
|||||||
assets.add(property);
|
assets.add(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the descriptor for a specific asset type.
|
||||||
|
*
|
||||||
|
* @param type The type of the asset to retrieve the descriptor for.
|
||||||
|
*/
|
||||||
|
public AssetDescriptor getDescriptorForType(String type) {
|
||||||
|
return assets.stream()
|
||||||
|
.filter(assetDescriptor -> assetDescriptor.getType().equals(type))
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("No asset descriptor found for type: " + type));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the property for a specific asset type and property name.
|
||||||
|
*
|
||||||
|
* @param type The type of the asset to retrieve the property for.
|
||||||
|
* @param propertyName The name of the property to retrieve.
|
||||||
|
*/
|
||||||
|
public AssetProperty getPropertyForType(String type, String propertyName) {
|
||||||
|
return getDescriptorForType(type).getProperty(propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the generic property for a specific property name.
|
||||||
|
*
|
||||||
|
* @param propertyName The name of the property to retrieve.
|
||||||
|
*/
|
||||||
|
public AssetProperty getGenericProperty(String propertyName) {
|
||||||
|
return getPropertyForType("asset", propertyName);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
|||||||
@@ -1,12 +1,8 @@
|
|||||||
package be.seeseepuff.pcinv.meta;
|
package be.seeseepuff.pcinv.meta;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.models.Asset;
|
import be.seeseepuff.pcinv.models.*;
|
||||||
import be.seeseepuff.pcinv.models.AssetCondition;
|
|
||||||
import be.seeseepuff.pcinv.models.GenericAsset;
|
|
||||||
import be.seeseepuff.pcinv.models.ReadWrite;
|
|
||||||
import jakarta.annotation.Nonnull;
|
import jakarta.annotation.Nonnull;
|
||||||
import jakarta.annotation.Nullable;
|
import jakarta.annotation.Nullable;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Singular;
|
import lombok.Singular;
|
||||||
@@ -28,7 +24,7 @@ public class AssetProperty {
|
|||||||
/// The name of the property as it should be displayed, e.g., "Brand", "Model", etc.
|
/// The name of the property as it should be displayed, e.g., "Brand", "Model", etc.
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
/// The type of the property, which can be a string or an integer.
|
/// The type of the property, which can be a string or an integer.
|
||||||
private final Type type;
|
private final PropertyType type;
|
||||||
/// Whether the property is required for the asset.
|
/// Whether the property is required for the asset.
|
||||||
private final boolean required;
|
private final boolean required;
|
||||||
/// A set of options for the property, used for enum types.
|
/// A set of options for the property, used for enum types.
|
||||||
@@ -49,31 +45,6 @@ public class AssetProperty {
|
|||||||
/// A description of the property, if any.
|
/// A description of the property, if any.
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
/**
|
|
||||||
* Enum representing the possible types of asset properties.
|
|
||||||
*/
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum Type {
|
|
||||||
STRING(false),
|
|
||||||
INTEGER(false),
|
|
||||||
BOOLEAN(false),
|
|
||||||
CAPACITY(false),
|
|
||||||
CONDITION(true),
|
|
||||||
READWRITE(true),
|
|
||||||
;
|
|
||||||
/// Set to `true` if the type is an enum, `false` otherwise.
|
|
||||||
public final boolean isEnum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the name of the type, or "enum" if it is an enum type.
|
|
||||||
*
|
|
||||||
* @return The name of the type or "enum" if it is an enum.
|
|
||||||
*/
|
|
||||||
public String nameOrEnum() {
|
|
||||||
return isEnum ? "enum" : name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an AssetProperty from a given field.
|
* Loads an AssetProperty from a given field.
|
||||||
*
|
*
|
||||||
@@ -99,7 +70,7 @@ public class AssetProperty {
|
|||||||
.setter((obj, value) -> {
|
.setter((obj, value) -> {
|
||||||
try {
|
try {
|
||||||
property.setAccessible(true);
|
property.setAccessible(true);
|
||||||
property.set(obj, value);
|
property.set(obj, Converters.convert(value, property.getType()));
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -131,7 +102,7 @@ public class AssetProperty {
|
|||||||
builder.option(option);
|
builder.option(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type == Type.CAPACITY) {
|
if (type == PropertyType.CAPACITY) {
|
||||||
var capacityAnnotation = property.getAnnotation(Capacity.class);
|
var capacityAnnotation = property.getAnnotation(Capacity.class);
|
||||||
builder.capacityAsSI(capacityAnnotation.si());
|
builder.capacityAsSI(capacityAnnotation.si());
|
||||||
builder.capacityAsIEC(capacityAnnotation.iec());
|
builder.capacityAsIEC(capacityAnnotation.iec());
|
||||||
@@ -146,19 +117,21 @@ public class AssetProperty {
|
|||||||
* @return The type of the property.
|
* @return The type of the property.
|
||||||
* @throws IllegalArgumentException if the property type is unsupported.
|
* @throws IllegalArgumentException if the property type is unsupported.
|
||||||
*/
|
*/
|
||||||
private static Type determineType(Field property) {
|
private static PropertyType determineType(Field property) {
|
||||||
if (property.getType() == String.class) {
|
if (property.getType() == String.class) {
|
||||||
return Type.STRING;
|
return PropertyType.STRING;
|
||||||
} else if (property.isAnnotationPresent(Capacity.class)) {
|
} else if (property.isAnnotationPresent(Capacity.class)) {
|
||||||
return Type.CAPACITY;
|
return PropertyType.CAPACITY;
|
||||||
} else if (property.getType() == Integer.class || property.getType() == int.class || property.getType() == Long.class || property.getType() == long.class) {
|
} else if (property.getType() == Integer.class || property.getType() == int.class || property.getType() == Long.class || property.getType() == long.class) {
|
||||||
return Type.INTEGER;
|
return PropertyType.INTEGER;
|
||||||
} else if (property.getType() == Boolean.class || property.getType() == boolean.class) {
|
} else if (property.getType() == Boolean.class || property.getType() == boolean.class) {
|
||||||
return Type.BOOLEAN;
|
return PropertyType.BOOLEAN;
|
||||||
} else if (property.getType() == AssetCondition.class) {
|
} else if (property.getType() == AssetCondition.class) {
|
||||||
return Type.CONDITION;
|
return PropertyType.CONDITION;
|
||||||
} else if (property.getType() == ReadWrite.class) {
|
} else if (property.getType() == ReadWrite.class) {
|
||||||
return Type.READWRITE;
|
return PropertyType.READWRITE;
|
||||||
|
} else if (property.getType() == Build.class) {
|
||||||
|
return PropertyType.BUILD;
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Unsupported property type: " + property.getType());
|
throw new IllegalArgumentException("Unsupported property type: " + property.getType());
|
||||||
}
|
}
|
||||||
@@ -204,12 +177,15 @@ public class AssetProperty {
|
|||||||
var value = getValue(asset);
|
var value = getValue(asset);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return "?";
|
return "?";
|
||||||
} else if (type == Type.BOOLEAN) {
|
} else if (type == PropertyType.BOOLEAN) {
|
||||||
return (boolean) value ? "Yes" : "No";
|
return (boolean) value ? "Yes" : "No";
|
||||||
} else if (type == Type.INTEGER || type == Type.STRING) {
|
} else if (type == PropertyType.INTEGER || type == PropertyType.STRING) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
} else if (type == Type.CAPACITY) {
|
} else if (type == PropertyType.CAPACITY) {
|
||||||
return convertCapacity((Long) value).toString();
|
return convertCapacity((Long) value).toString();
|
||||||
|
} else if (type == PropertyType.BUILD) {
|
||||||
|
var build = (Build) value;
|
||||||
|
return build.getName();
|
||||||
} else if (type.isEnum) {
|
} else if (type.isEnum) {
|
||||||
if (value instanceof AssetEnum assetEnum) {
|
if (value instanceof AssetEnum assetEnum) {
|
||||||
return assetEnum.getDisplayName();
|
return assetEnum.getDisplayName();
|
||||||
@@ -224,7 +200,7 @@ public class AssetProperty {
|
|||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (type != Type.CAPACITY) {
|
if (type != PropertyType.CAPACITY) {
|
||||||
throw new IllegalStateException("Property '" + name + "' is not a capacity type.");
|
throw new IllegalStateException("Property '" + name + "' is not a capacity type.");
|
||||||
}
|
}
|
||||||
return CapacityInfo.of(value, capacityAsIEC, capacityAsSI);
|
return CapacityInfo.of(value, capacityAsIEC, capacityAsSI);
|
||||||
|
|||||||
66
src/main/java/be/seeseepuff/pcinv/meta/Converters.java
Normal file
66
src/main/java/be/seeseepuff/pcinv/meta/Converters.java
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package be.seeseepuff.pcinv.meta;
|
||||||
|
|
||||||
|
import lombok.experimental.UtilityClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for converting values to different types.
|
||||||
|
*/
|
||||||
|
@UtilityClass
|
||||||
|
public class Converters {
|
||||||
|
/**
|
||||||
|
* Converts a value to the specified target type.
|
||||||
|
*
|
||||||
|
* @param value The value to convert.
|
||||||
|
* @param target The target class to convert the value to.
|
||||||
|
* @return The converted value, or null if conversion is not possible.
|
||||||
|
*/
|
||||||
|
public static Object convert(Object value, Class<?> target) {
|
||||||
|
if (value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (target.isInstance(value)) {
|
||||||
|
return value; // No conversion needed
|
||||||
|
}
|
||||||
|
if (value instanceof Long longValue) {
|
||||||
|
return convertLong(longValue, target);
|
||||||
|
}
|
||||||
|
if (value instanceof Integer intValue) {
|
||||||
|
return convertInteger(intValue, target);
|
||||||
|
}
|
||||||
|
throw new ClassCastException("Cannot convert " + value.getClass().getName() + " to " + target.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Long value to the specified target type.
|
||||||
|
*
|
||||||
|
* @param value The Long value to convert.
|
||||||
|
* @param target The target class to convert the value to.
|
||||||
|
* @return The converted value, or throws ClassCastException if conversion is not possible.
|
||||||
|
*/
|
||||||
|
private static Object convertLong(Long value, Class<?> target) {
|
||||||
|
if (target == Long.class || target == long.class) {
|
||||||
|
return value; // No conversion needed
|
||||||
|
}
|
||||||
|
if (target == Integer.class || target == int.class) {
|
||||||
|
return value.intValue();
|
||||||
|
}
|
||||||
|
throw new ClassCastException("Cannot convert " + value.getClass().getName() + " to " + target.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an Integer value to the specified target type.
|
||||||
|
*
|
||||||
|
* @param value The Integer value to convert.
|
||||||
|
* @param target The target class to convert the value to.
|
||||||
|
* @return The converted value, or throws ClassCastException if conversion is not possible.
|
||||||
|
*/
|
||||||
|
private static Object convertInteger(Integer value, Class<?> target) {
|
||||||
|
if (target == Integer.class || target == int.class) {
|
||||||
|
return value; // No conversion needed
|
||||||
|
}
|
||||||
|
if (target == Long.class || target == long.class) {
|
||||||
|
return value.longValue();
|
||||||
|
}
|
||||||
|
throw new ClassCastException("Cannot convert " + value.getClass().getName() + " to " + target.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
31
src/main/java/be/seeseepuff/pcinv/meta/PropertyType.java
Normal file
31
src/main/java/be/seeseepuff/pcinv/meta/PropertyType.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package be.seeseepuff.pcinv.meta;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum representing the possible types of asset properties.
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum PropertyType
|
||||||
|
{
|
||||||
|
STRING(false),
|
||||||
|
INTEGER(false),
|
||||||
|
BOOLEAN(false),
|
||||||
|
CAPACITY(false),
|
||||||
|
CONDITION(true),
|
||||||
|
READWRITE(true),
|
||||||
|
BUILD(false),
|
||||||
|
;
|
||||||
|
/// Set to `true` if the type is an enum, `false` otherwise.
|
||||||
|
public final boolean isEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name of the type, or "enum" if it is an enum type.
|
||||||
|
*
|
||||||
|
* @return The name of the type or "enum" if it is an enum.
|
||||||
|
*/
|
||||||
|
public String nameOrEnum()
|
||||||
|
{
|
||||||
|
return isEnum ? "enum" : name();
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/main/java/be/seeseepuff/pcinv/models/Build.java
Normal file
50
src/main/java/be/seeseepuff/pcinv/models/Build.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Table(
|
||||||
|
name = "builds",
|
||||||
|
uniqueConstraints = @UniqueConstraint(columnNames = "name")
|
||||||
|
)
|
||||||
|
public class Build
|
||||||
|
{
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether this build is a meta build.
|
||||||
|
* A meta build is a build that does not represent a physical computer,
|
||||||
|
* but rather a collection of parts that can be used in other builds.
|
||||||
|
*
|
||||||
|
* It is used internally to represents parts that are explicitly not part of a build.
|
||||||
|
*/
|
||||||
|
private boolean meta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the build.
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A description of the build.
|
||||||
|
* This can be used to provide additional information about the build.
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of parts that are included in the build.
|
||||||
|
*/
|
||||||
|
@OneToMany(mappedBy = "build")
|
||||||
|
@OrderBy("type, brand, model, qr")
|
||||||
|
private List<GenericAsset> parts;
|
||||||
|
}
|
||||||
20
src/main/java/be/seeseepuff/pcinv/models/BuildInfo.java
Normal file
20
src/main/java/be/seeseepuff/pcinv/models/BuildInfo.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.meta.CapacityInfo;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class BuildInfo {
|
||||||
|
private long totalRam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the total RAM capacity of the build.
|
||||||
|
*
|
||||||
|
* @return A CapacityInfo object representing the total RAM capacity.
|
||||||
|
*/
|
||||||
|
public CapacityInfo getTotalRamCapacity() {
|
||||||
|
return CapacityInfo.of(totalRam);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import be.seeseepuff.pcinv.meta.AssetInfo;
|
|||||||
import be.seeseepuff.pcinv.meta.Description;
|
import be.seeseepuff.pcinv.meta.Description;
|
||||||
import be.seeseepuff.pcinv.meta.HideInOverview;
|
import be.seeseepuff.pcinv.meta.HideInOverview;
|
||||||
import be.seeseepuff.pcinv.meta.Property;
|
import be.seeseepuff.pcinv.meta.Property;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -21,6 +22,7 @@ public class ChassisAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -21,6 +22,7 @@ public class CpuAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@OneToOne(orphanRemoval = true)
|
@OneToOne(orphanRemoval = true)
|
||||||
|
|||||||
30
src/main/java/be/seeseepuff/pcinv/models/CustomAsset.java
Normal file
30
src/main/java/be/seeseepuff/pcinv/models/CustomAsset.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a CPU or similar device.
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Entity
|
||||||
|
@AssetInfo(
|
||||||
|
displayName = "Custom Device",
|
||||||
|
pluralName = "Custom Devices",
|
||||||
|
type = "custom"
|
||||||
|
)
|
||||||
|
@Table(name = "custom_assets")
|
||||||
|
public class CustomAsset implements Asset
|
||||||
|
{
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
|
private long id;
|
||||||
|
|
||||||
|
@OneToOne(orphanRemoval = true)
|
||||||
|
private GenericAsset asset;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class DisplayAdapterAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class FloppyDriveAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -27,7 +28,9 @@ public class GenericAsset
|
|||||||
{
|
{
|
||||||
public static final String TYPE = "asset";
|
public static final String TYPE = "asset";
|
||||||
|
|
||||||
@Id @GeneratedValue
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The QR code attached to the asset, used for identification.
|
/// The QR code attached to the asset, used for identification.
|
||||||
@@ -70,4 +73,9 @@ public class GenericAsset
|
|||||||
|
|
||||||
@OneToMany(mappedBy = "asset", cascade = CascadeType.ALL, orphanRemoval = true)
|
@OneToMany(mappedBy = "asset", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
private List<WorkLogEntry> workLog;
|
private List<WorkLogEntry> workLog;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@Property("Part of build")
|
||||||
|
@Description("Select which build this asset is placed in.")
|
||||||
|
private Build build;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -21,6 +22,7 @@ public class HddAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@OneToOne(orphanRemoval = true)
|
@OneToOne(orphanRemoval = true)
|
||||||
@@ -40,12 +42,12 @@ public class HddAsset implements Asset
|
|||||||
@InputList
|
@InputList
|
||||||
private String formFactor;
|
private String formFactor;
|
||||||
|
|
||||||
@Description("The drive's RPM (Revolutions Per Minute) speed, if applicable.")
|
@Description("The drive's RPM (Revolutions Per Minute) speed.")
|
||||||
@Property("RPM Speed")
|
@Property("RPM Speed")
|
||||||
@HideInOverview
|
@HideInOverview
|
||||||
private Long rpmSpeed;
|
private Long rpmSpeed;
|
||||||
|
|
||||||
@Description("The drive's cache size, if applicable.")
|
@Description("The drive's cache size.")
|
||||||
@Property("Cache Size")
|
@Property("Cache Size")
|
||||||
@HideInOverview
|
@HideInOverview
|
||||||
private Long cacheSize;
|
private Long cacheSize;
|
||||||
@@ -54,4 +56,19 @@ public class HddAsset implements Asset
|
|||||||
@Property("Drive Type")
|
@Property("Drive Type")
|
||||||
@InputList
|
@InputList
|
||||||
private String driveType;
|
private String driveType;
|
||||||
|
|
||||||
|
@Description("Number of heads in the drive.")
|
||||||
|
@Property("Heads")
|
||||||
|
@HideInOverview
|
||||||
|
private Integer heads;
|
||||||
|
|
||||||
|
@Description("Number of cylinders in the drive.")
|
||||||
|
@Property("Cylinders")
|
||||||
|
@HideInOverview
|
||||||
|
private Integer cylinders;
|
||||||
|
|
||||||
|
@Description("Number of sectors in the drive.")
|
||||||
|
@Property("Sectors")
|
||||||
|
@HideInOverview
|
||||||
|
private Integer sectors;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class MotherboardAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class NICAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class OpticalDriveAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class PowerSupplyAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -21,6 +22,7 @@ public class RamAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
@OneToOne(orphanRemoval = true)
|
@OneToOne(orphanRemoval = true)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.*;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -18,6 +19,7 @@ public class SoundAdapterAsset implements Asset
|
|||||||
{
|
{
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
/// The generic asset associated with this RAM.
|
/// The generic asset associated with this RAM.
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package be.seeseepuff.pcinv.models;
|
package be.seeseepuff.pcinv.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
@@ -18,8 +20,10 @@ import java.time.ZonedDateTime;
|
|||||||
public class WorkLogEntry {
|
public class WorkLogEntry {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
|
@JsonIgnore
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
@ManyToOne(optional = false)
|
@ManyToOne(optional = false)
|
||||||
private GenericAsset asset;
|
private GenericAsset asset;
|
||||||
|
|
||||||
@@ -27,5 +31,6 @@ public class WorkLogEntry {
|
|||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
/// The date and time when the work log entry was created.
|
/// The date and time when the work log entry was created.
|
||||||
|
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||||
private ZonedDateTime date;
|
private ZonedDateTime date;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package be.seeseepuff.pcinv.repositories;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.models.Build;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface BuildRepository extends JpaRepository<Build, Long>
|
||||||
|
{
|
||||||
|
Build getBuildByNameAndMeta(String name, boolean meta);
|
||||||
|
|
||||||
|
Build getBuildById(long id);
|
||||||
|
|
||||||
|
List<Build> findAllByMeta(boolean meta);
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package be.seeseepuff.pcinv.repositories;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.models.CustomAsset;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public interface CustomRepository extends JpaRepository<CustomAsset, Long>, AssetRepository<CustomAsset> {
|
||||||
|
@Override
|
||||||
|
default Class<CustomAsset> getAssetType() {
|
||||||
|
return CustomAsset.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
package be.seeseepuff.pcinv.services;
|
package be.seeseepuff.pcinv.services;
|
||||||
|
|
||||||
import be.seeseepuff.pcinv.meta.AssetDescriptor;
|
import be.seeseepuff.pcinv.meta.*;
|
||||||
import be.seeseepuff.pcinv.meta.AssetDescriptors;
|
|
||||||
import be.seeseepuff.pcinv.meta.AssetInfo;
|
|
||||||
import be.seeseepuff.pcinv.meta.AssetProperty;
|
|
||||||
import be.seeseepuff.pcinv.models.Asset;
|
import be.seeseepuff.pcinv.models.Asset;
|
||||||
import be.seeseepuff.pcinv.models.GenericAsset;
|
import be.seeseepuff.pcinv.models.GenericAsset;
|
||||||
import be.seeseepuff.pcinv.models.WorkLogEntry;
|
import be.seeseepuff.pcinv.models.WorkLogEntry;
|
||||||
@@ -12,6 +9,8 @@ import be.seeseepuff.pcinv.repositories.GenericAssetRepository;
|
|||||||
import be.seeseepuff.pcinv.repositories.WorkLogRepository;
|
import be.seeseepuff.pcinv.repositories.WorkLogRepository;
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.modelmapper.ModelMapper;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -29,6 +28,7 @@ public class AssetService {
|
|||||||
private final WorkLogRepository workLogRepository;
|
private final WorkLogRepository workLogRepository;
|
||||||
private final Collection<AssetRepository<?>> repositories;
|
private final Collection<AssetRepository<?>> repositories;
|
||||||
private final EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
private final BuildService buildService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the count of all assets in the repository.
|
* Returns the count of all assets in the repository.
|
||||||
@@ -54,6 +54,30 @@ public class AssetService {
|
|||||||
return getRepositoryFor(genericAsset.getType()).findByAsset(genericAsset);
|
return getRepositoryFor(genericAsset.getType()).findByAsset(genericAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an asset by its QR code and duplicates the object.
|
||||||
|
*
|
||||||
|
* @param qr the QR code of the asset to retrieve
|
||||||
|
* @return the Asset associated with the given QR code, or null if no duplicate is found
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
public Asset getAssetDuplicateByQr(long qr) {
|
||||||
|
var mapper = new ModelMapper();
|
||||||
|
var originalGenericAsset = genericRepository.findByQr(qr);
|
||||||
|
if (originalGenericAsset == null) {
|
||||||
|
throw new IllegalArgumentException("No asset found with QR code: " + qr);
|
||||||
|
}
|
||||||
|
var originalAsset = getRepositoryFor(originalGenericAsset.getType()).findByAsset(originalGenericAsset);
|
||||||
|
|
||||||
|
var genericAsset = mapper.map(originalGenericAsset, GenericAsset.class);
|
||||||
|
genericAsset.setId(0); // Reset ID to create a new instance
|
||||||
|
genericAsset.setQr(0);
|
||||||
|
var asset = mapper.map(originalAsset, originalAsset.getClass());
|
||||||
|
asset.setAsset(genericAsset);
|
||||||
|
|
||||||
|
return asset;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all assets of a specific type.
|
* Retrieves all assets of a specific type.
|
||||||
*
|
*
|
||||||
@@ -199,7 +223,7 @@ public class AssetService {
|
|||||||
* @return The parsed value as an Object.
|
* @return The parsed value as an Object.
|
||||||
*/
|
*/
|
||||||
private Object parseValue(AssetDescriptor descriptor, AssetProperty property, Map<String, String> values) {
|
private Object parseValue(AssetDescriptor descriptor, AssetProperty property, Map<String, String> values) {
|
||||||
if (property.getType() == AssetProperty.Type.CAPACITY) {
|
if (property.getType() == PropertyType.CAPACITY) {
|
||||||
var value = values.get(descriptor.asString(property) + "-value");
|
var value = values.get(descriptor.asString(property) + "-value");
|
||||||
var unit = values.get(descriptor.asString(property) + "-unit");
|
var unit = values.get(descriptor.asString(property) + "-unit");
|
||||||
if (value == null || value.isBlank() || unit == null || unit.isBlank()) {
|
if (value == null || value.isBlank() || unit == null || unit.isBlank()) {
|
||||||
@@ -218,16 +242,22 @@ public class AssetService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (property.getType() == AssetProperty.Type.INTEGER) {
|
if (property.getType() == PropertyType.INTEGER) {
|
||||||
return Integer.parseInt(stringValue);
|
return Integer.parseInt(stringValue);
|
||||||
} else if (property.getType() == AssetProperty.Type.STRING) {
|
} else if (property.getType() == PropertyType.STRING) {
|
||||||
return stringValue;
|
return stringValue;
|
||||||
} else if (property.getType() == AssetProperty.Type.BOOLEAN) {
|
} else if (property.getType() == PropertyType.BOOLEAN) {
|
||||||
return switch (stringValue.toLowerCase()) {
|
return switch (stringValue.toLowerCase()) {
|
||||||
case "true" -> true;
|
case "true" -> true;
|
||||||
case "false" -> false;
|
case "false" -> false;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
} else if (property.getType() == PropertyType.BUILD) {
|
||||||
|
var build = buildService.getBuildById(Integer.parseInt(stringValue));
|
||||||
|
if (build == null) {
|
||||||
|
throw new IllegalArgumentException("Invalid build ID for property '" + property.getName() + "': " + stringValue);
|
||||||
|
}
|
||||||
|
return build;
|
||||||
} else if (property.getType().isEnum) {
|
} else if (property.getType().isEnum) {
|
||||||
for (var option : property.getOptions()) {
|
for (var option : property.getOptions()) {
|
||||||
if (option.getValue().equals(stringValue)) {
|
if (option.getValue().equals(stringValue)) {
|
||||||
|
|||||||
113
src/main/java/be/seeseepuff/pcinv/services/BuildService.java
Normal file
113
src/main/java/be/seeseepuff/pcinv/services/BuildService.java
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
package be.seeseepuff.pcinv.services;
|
||||||
|
|
||||||
|
import be.seeseepuff.pcinv.models.Build;
|
||||||
|
import be.seeseepuff.pcinv.models.BuildInfo;
|
||||||
|
import be.seeseepuff.pcinv.repositories.BuildRepository;
|
||||||
|
import be.seeseepuff.pcinv.repositories.RamRepository;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A service that manages computer builds.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BuildService {
|
||||||
|
private final BuildRepository buildRepository;
|
||||||
|
private final RamRepository ramRepository;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
Build empty = buildRepository.getBuildByNameAndMeta("None", true);
|
||||||
|
if (empty == null) {
|
||||||
|
empty = Build.builder()
|
||||||
|
.name("None")
|
||||||
|
.meta(true)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
empty.setDescription("A meta build to hold unused parts.");
|
||||||
|
empty = buildRepository.save(empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of all computer builds, including meta builds.
|
||||||
|
*
|
||||||
|
* @return A list of all builds.
|
||||||
|
*/
|
||||||
|
public List<Build> getAllBuilds() {
|
||||||
|
return buildRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a list of all computer builds, excluding meta builds.
|
||||||
|
*
|
||||||
|
* @return A list of all builds.
|
||||||
|
*/
|
||||||
|
public List<Build> getAllRealBuilds() {
|
||||||
|
return buildRepository.findAllByMeta(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a build by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the build to retrieve.
|
||||||
|
* @return The build with the given ID, or null if not found.
|
||||||
|
*/
|
||||||
|
public Build getBuildById(long id) {
|
||||||
|
return buildRepository.getBuildById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new build with the given name and description.
|
||||||
|
*
|
||||||
|
* @param name The name of the build.
|
||||||
|
* @param description The description of the build.
|
||||||
|
* @return The created build.
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public Build createBuild(String name, String description) {
|
||||||
|
Build build = Build.builder()
|
||||||
|
.name(name)
|
||||||
|
.description(description)
|
||||||
|
.build();
|
||||||
|
return buildRepository.saveAndFlush(build);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a build by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the build to delete.
|
||||||
|
*/
|
||||||
|
@Transactional
|
||||||
|
public void deleteBuild(long id) {
|
||||||
|
Build build = buildRepository.getBuildById(id);
|
||||||
|
for (var part : build.getParts()) {
|
||||||
|
part.setBuild(null);
|
||||||
|
}
|
||||||
|
buildRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the build information for a given build ID.
|
||||||
|
*
|
||||||
|
* @param build The build object for which to retrieve the information.
|
||||||
|
* @return The BuildInfo object containing the build information.
|
||||||
|
* @throws IllegalArgumentException if the build with the given ID does not exist.
|
||||||
|
*/
|
||||||
|
public BuildInfo getBuildInfo(Build build) {
|
||||||
|
var buildInfo = new BuildInfo();
|
||||||
|
for (var part : build.getParts()) {
|
||||||
|
if (part.getType().equals("ram")) {
|
||||||
|
var asset = ramRepository.findByAsset(part);
|
||||||
|
if (asset.getCapacity() != null) {
|
||||||
|
buildInfo.setTotalRam(buildInfo.getTotalRam() + asset.getCapacity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buildInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<a th:href="'/view/'+${a.getQr()}">View</a>
|
<a th:href="'/view/'+${a.getQr()}">View</a>
|
||||||
<a th:href="'/edit/'+${a.getQr()}">Edit</a>
|
<a th:href="'/edit/'+${a.getQr()}">Edit</a>
|
||||||
|
<a th:href="'/duplicate/'+${a.getQr()}">Duplicate</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
24
src/main/resources/templates/build_view.html
Normal file
24
src/main/resources/templates/build_view.html
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<body th:replace="~{fragments :: base(title=${'Build ' + build.getName()}, content=~{::content})}">
|
||||||
|
<div th:fragment="content">
|
||||||
|
<ul>
|
||||||
|
<li><b>Name: </b><span th:text="${build.name}"></span></li>
|
||||||
|
<li><b>Description: </b><span th:text="${build.description}"></span></li>
|
||||||
|
<li><b>Part Count: </b><span th:text="${build.getParts()?.size() ?: 0}"></span></li>
|
||||||
|
<li><b>Total RAM: </b><span th:text="${buildInfo.getTotalRamCapacity().getCapacityInUnit()} + ' ' + ${buildInfo.getTotalRamCapacity().getIdealUnit().displayName}"></span></li>
|
||||||
|
</ul>
|
||||||
|
<table border="1" cellpadding="4">
|
||||||
|
<tr bgcolor="#d3d3d3">
|
||||||
|
<th>QR</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Brand</th>
|
||||||
|
<th>Model</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="p : ${build.getParts()}">
|
||||||
|
<td><a th:href="'/view/' + ${p.qr}" th:text="${p.qr}"></a></td>
|
||||||
|
<td th:text="${descriptors.getDescriptorForType(p.type).displayName}"></td>
|
||||||
|
<td th:text="${descriptors.getGenericProperty('brand').renderValue(p)}"></td>
|
||||||
|
<td th:text="${descriptors.getGenericProperty('model').renderValue(p)}"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
28
src/main/resources/templates/builds.html
Normal file
28
src/main/resources/templates/builds.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<body th:replace="~{fragments :: base(title='Builds', content=~{::content})}">
|
||||||
|
<div th:fragment="content">
|
||||||
|
<table border="1" cellpadding="4">
|
||||||
|
<tr bgcolor="#d3d3d3">
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Part Count</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
<tr th:each="b : ${builds}">
|
||||||
|
<td><a th:href="'/build/' + ${b.id}" th:text="${b.getName()}"></a></td>
|
||||||
|
<td th:text="${b.getDescription()}"></td>
|
||||||
|
<td th:text="${b.getParts()?.size() ?: 0}"></td>
|
||||||
|
<td>
|
||||||
|
<a th:if="${!b.isMeta()}" th:href="${'/delete_build/' + b.id}">Delete</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<form action="/create_build" method="post">
|
||||||
|
<tr>
|
||||||
|
<td><label><input type="text" name="name" placeholder="Name"></label></td>
|
||||||
|
<td><label><input type="text" name="description" placeholder="Description"></label></td>
|
||||||
|
<td></td>
|
||||||
|
<td><input type="submit" value="Create"></td>
|
||||||
|
</tr>
|
||||||
|
</form>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
<body th:replace="~{fragments :: base(title='Create '+${descriptor.displayName}, content=~{::content})}">
|
<body th:replace="~{fragments :: base(title='Create '+${descriptor.displayName}, content=~{::content})}">
|
||||||
<div th:fragment="content">
|
<div th:fragment="content">
|
||||||
<h2>Create a <span th:text="${descriptor.displayName}"></span></h2>
|
<h2>Create a <span th:text="${descriptor.displayName}"></span></h2>
|
||||||
<form th:action="'/'+${action}+'/'+${asset != null ? asset.getQr() : descriptor.getType()}" method="post">
|
<form th:action="'/'+${(action == 'duplicate') ? 'create' : action}+'/'+${(asset != null && action != 'duplicate') ? asset.getQr() : descriptor.getType()}" method="post">
|
||||||
<div th:each="d : ${descriptors}">
|
<div th:each="d : ${descriptors}">
|
||||||
<h2 th:text="${d.displayName}"></h2>
|
<h2 th:text="${d.displayName}"></h2>
|
||||||
<table border="1" cellpadding="4">
|
<table border="1" cellpadding="4">
|
||||||
<tr th:each="p : ${d.getProperties()}">
|
<tr th:each="p : ${d.getProperties()}">
|
||||||
<td bgcolor="#d3d3d3"><b><label th:text="${p.displayName}" th:for="${d.asString(p)}" th:title="${p.description}"></label></b></td>
|
<td bgcolor="#d3d3d3"><b><label th:text="${p.displayName}" th:for="${d.asString(p)}" th:title="${p.description}"></label></b></td>
|
||||||
<td th:switch="${p.type.nameOrEnum()}">
|
<td th:switch="${p.type.nameOrEnum()}">
|
||||||
|
<!-- Property Type: String List -->
|
||||||
<span th:case="STRING">
|
<span th:case="STRING">
|
||||||
<select th:if="${p.inputList}" th:id="${d.asString(p)+'-list'}" th:name="${d.asString(p)+'-list'}">
|
<select th:if="${p.inputList}" th:id="${d.asString(p)+'-list'}" th:name="${d.asString(p)+'-list'}">
|
||||||
<option value="__new__">New...</option>
|
<option value="__new__">New...</option>
|
||||||
@@ -17,8 +18,9 @@
|
|||||||
<input 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 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}"/>
|
||||||
</span>
|
</span>
|
||||||
<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="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}"/>
|
<!-- Property Type: Integer -->
|
||||||
<!-- <input th:case="BOOLEAN" type="checkbox" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:value="true" th:checked="${asset != null ? p.getValue(asset) : p.defaultValue}"/>-->
|
<input th:case="INTEGER" type="number" th:id="${d.asString(p)}" th:name="${d.asString(p)}" th:value="${(p.name == 'qr' && action == 'duplicate') ? null : p.getValue(asset)}" th:required="${p.required}"/>
|
||||||
|
<!-- Property Type: Boolean -->
|
||||||
<span th:case="BOOLEAN">
|
<span th:case="BOOLEAN">
|
||||||
<input th:name="${d.asString(p)}" th:id="${d.asString(p)}+'-null'" type="radio" value="null" th:checked="${asset == null || (p.getValue(asset) == null)}">
|
<input th:name="${d.asString(p)}" th:id="${d.asString(p)}+'-null'" type="radio" value="null" th:checked="${asset == null || (p.getValue(asset) == null)}">
|
||||||
<label th:for="${d.asString(p)}+'-null'">Not known</label>
|
<label th:for="${d.asString(p)}+'-null'">Not known</label>
|
||||||
@@ -27,21 +29,30 @@
|
|||||||
<input th:name="${d.asString(p)}" th:id="${d.asString(p)}+'-false'" type="radio" value="false" th:checked="${asset != null && (p.getValue(asset) == false)}">
|
<input th:name="${d.asString(p)}" th:id="${d.asString(p)}+'-false'" type="radio" value="false" th:checked="${asset != null && (p.getValue(asset) == false)}">
|
||||||
<label th:for="${d.asString(p)}+'-false'">No</label>
|
<label th:for="${d.asString(p)}+'-false'">No</label>
|
||||||
</span>
|
</span>
|
||||||
|
<!-- Property Type: Enum -->
|
||||||
<select th:case="enum" th:id="${d.asString(p)}" th:name="${d.asString(p)}">
|
<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="${asset != null ? (p.getValue(asset) == o.enumConstant) : 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>
|
</select>
|
||||||
|
<!-- Property Type: Capacity -->
|
||||||
<span th:case="CAPACITY">
|
<span th:case="CAPACITY">
|
||||||
<input type="number" th:id="${d.asString(p)+'-value'}" th:name="${d.asString(p)+'-value'}" th:required="${p.required}" th:value="${p.asCapacity(asset).getCapacityInUnit()}"/>
|
<input type="number" th:id="${d.asString(p)+'-value'}" th:name="${d.asString(p)+'-value'}" th:required="${p.required}" th:value="${p.asCapacity(asset)?.getCapacityInUnit() ?: ''}"/>
|
||||||
<select th:id="${d.asString(p)}+'-unit'" th:name="${d.asString(p)}+'-unit'">
|
<select th:id="${d.asString(p)}+'-unit'" th:name="${d.asString(p)}+'-unit'">
|
||||||
<option value="1" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'BYTES'}">Bytes</option>
|
<option value="1" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'BYTES'}">Bytes</option>
|
||||||
<option th:value="${1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'KILOBYTES'}">kB</option>
|
<option th:value="${1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'KILOBYTES'}">kB</option>
|
||||||
<option th:value="${1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'KIBIBYTES'}">KiB</option>
|
<option th:value="${1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'KIBIBYTES'}">KiB</option>
|
||||||
<option th:value="${1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'MEGABYTES'}">MB</option>
|
<option th:value="${1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'MEGABYTES'}">MB</option>
|
||||||
<option th:value="${1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'MEBIBYTES'}">MiB</option>
|
<option th:value="${1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'MEBIBYTES'}">MiB</option>
|
||||||
<option th:value="${1000*1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'GIGABYTES'}">GB</option>
|
<option th:value="${1000*1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'GIGABYTES'}">GB</option>
|
||||||
<option th:value="${1024*1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'GIBIBYTES'}">GiB</option>
|
<option th:value="${1024*1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'GIBIBYTES'}">GiB</option>
|
||||||
<option value="1000000000000" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'TERABYTES'}">TB</option>
|
<option value="1000000000000" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'TERABYTES'}">TB</option>
|
||||||
<option value="1099511627776" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'TEBIBYTES'}">TiB</option>
|
<option value="1099511627776" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'TEBIBYTES'}">TiB</option>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
|
<!-- Property Type: Build-->
|
||||||
|
<span th:case="BUILD">
|
||||||
|
<select th:id="${d.asString(p)}" th:name="${d.asString(p)}">
|
||||||
|
<option value="" th:selected="${p.getValue(asset) == null}">(Unknown)</option>
|
||||||
|
<option th:each="b : ${builds}" th:value="${b.getId()}" th:selected="${p.getValue(asset) == b}" th:text="${b.getName()}">My PC Build</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
<b th:case="*">Bad input type for <span th:text="${d.type}+'-'+${p.type}"></span></b>
|
<b th:case="*">Bad input type for <span th:text="${d.type}+'-'+${p.type}"></span></b>
|
||||||
@@ -50,7 +61,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<p>
|
<p>
|
||||||
<input th:if="${action == 'create'}" type="submit" value="Create">
|
<input th:if="${action == 'create' || action == 'duplicate'}" type="submit" value="Create">
|
||||||
<input th:if="${action == 'edit'}" type="submit" value="Save Changes">
|
<input th:if="${action == 'edit'}" type="submit" value="Save Changes">
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<a href="/">Home</a>
|
<a href="/">Home</a>
|
||||||
<a href="/browse">Browse</a>
|
<a href="/browse">Browse</a>
|
||||||
<a href="/create">Create</a>
|
<a href="/create">Create</a>
|
||||||
|
<a href="/builds">Builds</a>
|
||||||
<hr>
|
<hr>
|
||||||
<div th:replace="${content}">
|
<div th:replace="${content}">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
<table border="1" cellpadding="4">
|
<table border="1" cellpadding="4">
|
||||||
<tr th:each="p : ${d.properties}">
|
<tr th:each="p : ${d.properties}">
|
||||||
<th bgcolor="lightgray"><b th:text="${p.displayName}"></b></th>
|
<th bgcolor="lightgray"><b th:text="${p.displayName}"></b></th>
|
||||||
<td th:text="${p.renderValue(asset)}"></td>
|
<td th:if="${p.name == 'build'}"><a th:href="'/build/' + ${asset.getAsset().getBuild().id}" th:text="${p.renderValue(asset)}"></a></td>
|
||||||
|
<td th:if="${p.name != 'build'}" th:text="${p.renderValue(asset)}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
@@ -15,7 +16,8 @@
|
|||||||
<ul th:if="${action == 'view'}">
|
<ul th:if="${action == 'view'}">
|
||||||
<li><a th:href="'/edit/'+${asset.getQr()}">Edit</a></li>
|
<li><a th:href="'/edit/'+${asset.getQr()}">Edit</a></li>
|
||||||
<li><a th:href="'/delete/'+${asset.getQr()}">Delete</a></li>
|
<li><a th:href="'/delete/'+${asset.getQr()}">Delete</a></li>
|
||||||
<li><a th:href="'/create/'+${asset.getAsset().type}">Create another <span th:text="${descriptor.displayName}">Hard Drive</span> </a></li>
|
<li><a th:href="'/create/'+${asset.getAsset().type}">Create another <span th:text="${descriptor.displayName}">Hard Drive</span></a></li>
|
||||||
|
<li><a th:href="'/duplicate/'+${asset.getQr()}">Duplicate this <span th:text="${descriptor.displayName}">Hard Drive</span></a></li>
|
||||||
<li><a th:href="'/browse/'+${descriptor.type}">Browse all <span th:text="${descriptor.pluralName}">Hard Drives</span></a></li>
|
<li><a th:href="'/browse/'+${descriptor.type}">Browse all <span th:text="${descriptor.pluralName}">Hard Drives</span></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<ul th:if="${action == 'delete'}">
|
<ul th:if="${action == 'delete'}">
|
||||||
|
|||||||
Reference in New Issue
Block a user