31 Commits

Author SHA1 Message Date
9b6202e123 Update Gradle to v9
All checks were successful
Build / build (pull_request) Successful in 1m30s
2026-05-03 12:00:36 +00:00
2c21af81c4 Merge pull request 'Update all minor and patch updates' (#19) from renovate/all-minor-patch into master
All checks were successful
Deploy / build (push) Successful in 1m8s
2026-05-03 13:16:08 +02:00
c10ff0de3b Update all minor and patch updates
All checks were successful
Build / build (pull_request) Successful in 1m33s
2026-05-03 11:08:07 +00:00
9f31be7c04 Merge pull request 'Update renovate.json' (#17) from seeseemelk-patch-1 into master
All checks were successful
Deploy / build (push) Successful in 1m46s
Reviewed-on: #17
2026-05-03 13:04:08 +02:00
6c9f2346d1 Update renovate.json
All checks were successful
Build / build (pull_request) Successful in 1m14s
2026-05-03 13:02:49 +02:00
76008065bf Merge pull request 'Update dependency org.springdoc:springdoc-openapi-starter-webmvc-ui to v3' (#13) from renovate/org.springdoc-springdoc-openapi-starter-webmvc-ui-3.x into master
All checks were successful
Deploy / build (push) Successful in 1m36s
Reviewed-on: #13
2026-05-03 12:41:22 +02:00
be9aeeae33 Merge branch 'master' into renovate/org.springdoc-springdoc-openapi-starter-webmvc-ui-3.x
All checks were successful
Build / build (pull_request) Successful in 2m0s
2026-05-03 12:39:20 +02:00
93976751ca Merge pull request 'Update plugin org.springframework.boot to v4' (#16) from renovate/major-spring-boot into master
All checks were successful
Deploy / build (push) Successful in 1m8s
Reviewed-on: #16
2026-05-03 10:04:58 +02:00
dd9bef7855 Update plugin org.springframework.boot to v4
All checks were successful
Build / build (pull_request) Successful in 52s
2026-05-03 10:04:02 +02:00
aa7785472b Merge pull request 'Update actions/setup-java action to v5' (#12) from renovate/actions-setup-java-5.x into master
All checks were successful
Deploy / build (push) Successful in 1m27s
Reviewed-on: #12
2026-05-02 23:10:44 +02:00
9f642a65dd Update dependency org.springdoc:springdoc-openapi-starter-webmvc-ui to v3
All checks were successful
Build / build (pull_request) Successful in 1m54s
2026-05-02 21:00:57 +00:00
d002f4655e Update actions/setup-java action to v5
All checks were successful
Build / build (pull_request) Successful in 1m24s
2026-05-02 21:00:54 +00:00
e006f01b8e Merge pull request 'Update renovate.json' (#7) from seeseemelk-patch-1 into master
All checks were successful
Deploy / build (push) Successful in 1m37s
Reviewed-on: #7
2026-05-02 22:58:40 +02:00
4c89789601 Update renovate.json
All checks were successful
Build / build (pull_request) Successful in 1m23s
2026-05-02 22:54:52 +02:00
5359209956 Merge pull request 'Update .gitea/workflows/build.yml' (#6) from seeseemelk-patch-1 into master
Some checks failed
Deploy / build (push) Has been cancelled
Reviewed-on: #6
2026-05-02 22:53:13 +02:00
6b63f75070 Update .gitea/workflows/build.yml
All checks were successful
Build / build (pull_request) Successful in 2m10s
2026-05-02 22:52:58 +02:00
164f7fe3a6 Merge pull request 'Configure Renovate' (#3) from renovate/configure into master
Some checks failed
Deploy / build (push) Has been cancelled
Build / build (push) Successful in 3m23s
Reviewed-on: #3
2026-05-02 22:51:39 +02:00
312ab74ead Add renovate.json 2026-05-02 20:51:01 +00:00
ad1cb70cdc Update .gitea/workflows/deploy.yml
All checks were successful
Build / build (push) Successful in 1m35s
Deploy / build (push) Successful in 2m7s
2026-02-14 19:08:58 +01:00
ce01b7ad14 Update .gitea/workflows/deploy.yml
Some checks failed
Build / build (push) Has been cancelled
2026-02-14 19:08:32 +01:00
02c7b966eb Update .gitea/workflows/build.yml
Some checks failed
Build / build (push) Has been cancelled
2026-02-14 19:08:22 +01:00
a3d9e1ebb9 Update .gitea/workflows/deploy.yml
Some checks failed
Build / build (push) Has been cancelled
2026-02-14 19:08:14 +01:00
40e13ec585 Enhance asset display by linking builds and handling null builds in overview
All checks were successful
Build / build (push) Successful in 1m23s
2025-06-15 17:29:50 +02:00
bb15c55e46 Improve asset sorting by brand, model, and QR code with null handling
All checks were successful
Build / build (push) Successful in 2m27s
Deploy / build (push) Successful in 3m1s
2025-06-15 09:48:07 +02:00
35c2e07c05 Update build view to link part types for better navigation
All checks were successful
Build / build (push) Successful in 2m2s
Deploy / build (push) Successful in 2m43s
2025-06-15 09:27:32 +02:00
92187fd345 Handle non-positive capacities in idealUnitForCapacity method 2025-06-15 09:27:29 +02:00
0dbab45651 Enhance asset display by handling null builds and sorting assets by QR code 2025-06-15 09:26:08 +02:00
14ac78982f Reorder fields in HddAsset for clarity
All checks were successful
Build / build (push) Successful in 1m20s
2025-06-15 09:14:13 +02:00
b4c493c27b Merge pull request 'Add support for builds' (#2) from builds into master
All checks were successful
Build / build (push) Successful in 1m51s
Deploy / build (push) Successful in 2m23s
Reviewed-on: #2
2025-06-15 09:06:19 +02:00
8e26a73243 Add build management features and views
All checks were successful
Build / build (push) Successful in 2m10s
2025-06-15 09:03:47 +02:00
8cbededc79 Initial support for builds
All checks were successful
Build / build (push) Successful in 2m16s
2025-06-15 07:47:30 +02:00
27 changed files with 494 additions and 102 deletions

View File

@@ -1,17 +1,18 @@
name: Build
on:
push:
pull_request:
branches:
- '*'
- master
jobs:
build:
runs-on: standard-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '21'

View File

@@ -1,27 +1,28 @@
name: Deploy
on:
push:
tags:
- 'v*'
branches:
- master
jobs:
build:
runs-on: standard-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '21'
cache: 'gradle'
- name: Build Jar
run: ./gradlew bootJar
run: ./gradlew bootJar --no-daemon
- name: Build Container
run: docker build --tag gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}} .
run: docker build --tag gitea.seeseepuff.be/seeseemelk/pcinv:latest .
- name: Login
with: # Set the secret as an input
@@ -29,4 +30,4 @@ jobs:
run: docker login gitea.seeseepuff.be -u seeseemelk -p ${{ secrets.PACKAGE_RW }}
- name: Push Container
run: docker push gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}}
run: docker push gitea.seeseepuff.be/seeseemelk/pcinv:latest

View File

@@ -1,6 +1,6 @@
plugins {
java
id("org.springframework.boot") version "3.5.0"
id("org.springframework.boot") version "4.0.6"
id("io.spring.dependency-management") version "1.1.7"
}
@@ -28,8 +28,8 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-web")
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")
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3")
implementation("org.modelmapper:modelmapper:3.2.6")
compileOnly("org.projectlombok:lombok")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("org.postgresql:postgresql")

Binary file not shown.

View File

@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

7
gradlew vendored
View File

@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -114,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH="\\\"\\\""
# Determine the Java command to use to start the JVM.
@@ -172,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

32
gradlew.bat vendored
View File

@@ -23,8 +23,8 @@
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@@ -51,7 +51,7 @@ echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
@@ -65,30 +65,18 @@ echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%

6
renovate.json Normal file
View File

@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>seeseemelk/renovate"
]
}

View File

@@ -1,7 +1,9 @@
package be.seeseepuff.pcinv.controllers;
import be.seeseepuff.pcinv.models.Asset;
import be.seeseepuff.pcinv.models.WorkLogEntry;
import be.seeseepuff.pcinv.services.AssetService;
import be.seeseepuff.pcinv.services.BuildService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.repository.query.Param;
import org.springframework.http.MediaType;
@@ -42,6 +44,12 @@ public class WebController {
private static final String INPUT_LIST = "inputLists";
/// The name of the model attribute that holds the current work log entries.
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.
private static final String WORKLOG_SIZE = "worklog_size";
@@ -49,6 +57,7 @@ public class WebController {
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd MMM yyyy 'at' HH:mm");
private final AssetService assetService;
private final BuildService buildService;
/**
* Handles the root URL and returns the index page with asset descriptors and asset count.
@@ -86,10 +95,63 @@ public class WebController {
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
model.addAttribute(DESCRIPTORS, tree);
model.addAttribute(PROPERTIES, tree.stream().flatMap(d -> d.getProperties().stream()).toList());
model.addAttribute(ASSETS, assetService.getAssetsByType(type));
var assets = assetService.getAssetsByType(type);
assets.sort(Comparator
.comparing((Asset a) -> a.getAsset().getBrand(), Comparator.nullsFirst(Comparator.naturalOrder()))
.thenComparing((Asset a) -> a.getAsset().getModel(), Comparator.nullsFirst(Comparator.naturalOrder()))
.thenComparing(Asset::getQr));
model.addAttribute(ASSETS, assets);
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.
* If the asset does not exist, it redirects to the index page.
@@ -202,6 +264,7 @@ public class WebController {
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(type));
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(type));
model.addAttribute(INPUT_LIST, assetService.getInputList(type));
model.addAttribute(BUILDS, buildService.getAllBuilds());
return "create_asset";
}
@@ -223,6 +286,7 @@ public class WebController {
model.addAttribute(DESCRIPTORS, assetService.getAssetDescriptorTree(assetType));
model.addAttribute(DESCRIPTOR, assetService.getAssetDescriptor(assetType));
model.addAttribute(INPUT_LIST, assetService.getInputList(assetType));
model.addAttribute(BUILDS, buildService.getAllBuilds());
return "create_asset";
}

View File

@@ -99,6 +99,19 @@ public class AssetDescriptor {
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.
*

View File

@@ -24,6 +24,37 @@ public class AssetDescriptors {
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
public String toString() {
var builder = new StringBuilder();

View File

@@ -1,12 +1,8 @@
package be.seeseepuff.pcinv.meta;
import be.seeseepuff.pcinv.models.Asset;
import be.seeseepuff.pcinv.models.AssetCondition;
import be.seeseepuff.pcinv.models.GenericAsset;
import be.seeseepuff.pcinv.models.ReadWrite;
import be.seeseepuff.pcinv.models.*;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
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.
private final String displayName;
/// 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.
private final boolean required;
/// 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.
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.
*
@@ -131,7 +102,7 @@ public class AssetProperty {
builder.option(option);
}
}
if (type == Type.CAPACITY) {
if (type == PropertyType.CAPACITY) {
var capacityAnnotation = property.getAnnotation(Capacity.class);
builder.capacityAsSI(capacityAnnotation.si());
builder.capacityAsIEC(capacityAnnotation.iec());
@@ -146,19 +117,21 @@ public class AssetProperty {
* @return The type of the property.
* @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) {
return Type.STRING;
return PropertyType.STRING;
} 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) {
return Type.INTEGER;
return PropertyType.INTEGER;
} else if (property.getType() == Boolean.class || property.getType() == boolean.class) {
return Type.BOOLEAN;
return PropertyType.BOOLEAN;
} else if (property.getType() == AssetCondition.class) {
return Type.CONDITION;
return PropertyType.CONDITION;
} else if (property.getType() == ReadWrite.class) {
return Type.READWRITE;
return PropertyType.READWRITE;
} else if (property.getType() == Build.class) {
return PropertyType.BUILD;
} else {
throw new IllegalArgumentException("Unsupported property type: " + property.getType());
}
@@ -204,12 +177,15 @@ public class AssetProperty {
var value = getValue(asset);
if (value == null) {
return "?";
} else if (type == Type.BOOLEAN) {
} else if (type == PropertyType.BOOLEAN) {
return (boolean) value ? "Yes" : "No";
} else if (type == Type.INTEGER || type == Type.STRING) {
} else if (type == PropertyType.INTEGER || type == PropertyType.STRING) {
return value.toString();
} else if (type == Type.CAPACITY) {
} else if (type == PropertyType.CAPACITY) {
return convertCapacity((Long) value).toString();
} else if (type == PropertyType.BUILD) {
var build = (Build) value;
return build.getName();
} else if (type.isEnum) {
if (value instanceof AssetEnum assetEnum) {
return assetEnum.getDisplayName();
@@ -224,7 +200,7 @@ public class AssetProperty {
if (value == null) {
return null;
}
if (type != Type.CAPACITY) {
if (type != PropertyType.CAPACITY) {
throw new IllegalStateException("Property '" + name + "' is not a capacity type.");
}
return CapacityInfo.of(value, capacityAsIEC, capacityAsSI);

View File

@@ -44,6 +44,10 @@ public class CapacityInfo {
}
public static CapacityUnit idealUnitForCapacity(long capacity, CapacityUnit[] units) {
if (capacity <= 0) {
return CapacityUnit.BYTES; // Default to bytes for non-positive capacities
}
return Arrays.stream(units)
.sorted(Comparator.comparing(CapacityUnit::getBytes).reversed())
.filter(unit -> capacity % unit.getBytes() == 0)

View 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();
}
}

View 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;
}

View 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);
}
}

View File

@@ -73,4 +73,9 @@ public class GenericAsset
@OneToMany(mappedBy = "asset", cascade = CascadeType.ALL, orphanRemoval = true)
private List<WorkLogEntry> workLog;
@ManyToOne
@Property("Part of build")
@Description("Select which build this asset is placed in.")
private Build build;
}

View File

@@ -57,16 +57,16 @@ public class HddAsset implements Asset
@InputList
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 heads in the drive.")
@Property("Heads")
@HideInOverview
private Integer heads;
@Description("Number of sectors in the drive.")
@Property("Sectors")
@HideInOverview

View File

@@ -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);
}

View File

@@ -1,9 +1,6 @@
package be.seeseepuff.pcinv.services;
import be.seeseepuff.pcinv.meta.AssetDescriptor;
import be.seeseepuff.pcinv.meta.AssetDescriptors;
import be.seeseepuff.pcinv.meta.AssetInfo;
import be.seeseepuff.pcinv.meta.AssetProperty;
import be.seeseepuff.pcinv.meta.*;
import be.seeseepuff.pcinv.models.Asset;
import be.seeseepuff.pcinv.models.GenericAsset;
import be.seeseepuff.pcinv.models.WorkLogEntry;
@@ -31,6 +28,7 @@ public class AssetService {
private final WorkLogRepository workLogRepository;
private final Collection<AssetRepository<?>> repositories;
private final EntityManager entityManager;
private final BuildService buildService;
/**
* Returns the count of all assets in the repository.
@@ -225,7 +223,7 @@ public class AssetService {
* @return The parsed value as an Object.
*/
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 unit = values.get(descriptor.asString(property) + "-unit");
if (value == null || value.isBlank() || unit == null || unit.isBlank()) {
@@ -244,16 +242,22 @@ public class AssetService {
return null;
}
if (property.getType() == AssetProperty.Type.INTEGER) {
if (property.getType() == PropertyType.INTEGER) {
return Integer.parseInt(stringValue);
} else if (property.getType() == AssetProperty.Type.STRING) {
} else if (property.getType() == PropertyType.STRING) {
return stringValue;
} else if (property.getType() == AssetProperty.Type.BOOLEAN) {
} else if (property.getType() == PropertyType.BOOLEAN) {
return switch (stringValue.toLowerCase()) {
case "true" -> true;
case "false" -> false;
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) {
for (var option : property.getOptions()) {
if (option.getValue().equals(stringValue)) {

View 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;
}
}

View File

@@ -9,7 +9,8 @@
<tr th:each="a : ${assets}">
<td th:each="p : ${properties}" th:if="${!p.hideInOverview}">
<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>
<a th:if="${p.name == 'build' && a.getAsset().getBuild() != null}" th:href="'/build/'+${a.getAsset().getBuild().getId()}" th:text="${p.renderValue(a)}"></a>
<span th:if="${p.name != 'qr' && (p.name != 'build' || a.getAsset().getBuild() == null)}" th:text="${p.renderValue(a)}"></span>
</td>
<td>
<a th:href="'/view/'+${a.getQr()}">View</a>

View 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><a th:href="'/browse/' + ${p.type}" th:text="${descriptors.getDescriptorForType(p.type).displayName}"></a></td>
<td th:text="${descriptors.getGenericProperty('brand').renderValue(p)}"></td>
<td th:text="${descriptors.getGenericProperty('model').renderValue(p)}"></td>
</tr>
</table>
</div>
</body>

View 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>

View File

@@ -8,6 +8,7 @@
<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 th:switch="${p.type.nameOrEnum()}">
<!-- Property Type: String List -->
<span th:case="STRING">
<select th:if="${p.inputList}" th:id="${d.asString(p)+'-list'}" th:name="${d.asString(p)+'-list'}">
<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}"/>
</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}"/>
<!-- Property Type: Integer -->
<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}"/>
<!-- <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}"/>-->
<!-- Property Type: 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)}">
<label th:for="${d.asString(p)}+'-null'">Not known</label>
@@ -27,9 +29,11 @@
<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>
</span>
<!-- Property Type: Enum -->
<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>
</select>
<!-- Property Type: 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() ?: ''}"/>
<select th:id="${d.asString(p)}+'-unit'" th:name="${d.asString(p)}+'-unit'">
@@ -44,6 +48,13 @@
<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>
</span>
<b th:case="*">Bad input type for <span th:text="${d.type}+'-'+${p.type}"></span></b>
</td>
</tr>

View File

@@ -10,6 +10,7 @@
<a href="/">Home</a>
<a href="/browse">Browse</a>
<a href="/create">Create</a>
<a href="/builds">Builds</a>
<hr>
<div th:replace="${content}">
</div>

View File

@@ -7,7 +7,11 @@
<table border="1" cellpadding="4">
<tr th:each="p : ${d.properties}">
<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:if="${asset.getAsset().getBuild() != null}" th:href="'/build/' + ${asset.getAsset().getBuild().id}" th:text="${p.renderValue(asset)}"></a>
<span th:if="${asset.getAsset().getBuild() == null}" th:text="${p.renderValue(asset)}"></span>
</td>
<td th:if="${p.name != 'build'}" th:text="${p.renderValue(asset)}"></td>
</tr>
</table>
</div>