5 Commits

Author SHA1 Message Date
c57c429dae Fix 500 problem
All checks were successful
Build / build (push) Successful in 2m56s
Deploy / build (push) Successful in 2m59s
2025-06-09 15:10:31 +02:00
5d1c65a4c5 Better capacity support
All checks were successful
Build / build (push) Successful in 2m36s
Deploy / build (push) Successful in 2m40s
2025-06-09 15:03:16 +02:00
85de1c0c9f Add BigInteger support for capacity handling and enhance UI for capacity selection 2025-06-09 14:53:23 +02:00
a4b88f6dfd Ensure casing is ignored when sorting input list 2025-06-09 10:53:22 +02:00
b9bf2f1d38 Only login into docker once needed 2025-06-09 10:09:50 +02:00
8 changed files with 127 additions and 18 deletions

View File

@@ -17,16 +17,16 @@ jobs:
java-version: '21'
cache: 'gradle'
- name: Login
with: # Set the secret as an input
package_rw: ${{ secrets.PACKAGE_RW }}
run: docker login gitea.seeseepuff.be -u seeseemelk -p ${{ secrets.PACKAGE_RW }}
- name: Build Jar
run: ./gradlew bootJar
- name: Build Container
run: docker build --tag gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}} .
- name: Login
with: # Set the secret as an input
package_rw: ${{ secrets.PACKAGE_RW }}
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}}

View File

@@ -209,7 +209,7 @@ public class AssetProperty {
} else if (type == Type.INTEGER || type == Type.STRING) {
return value.toString();
} else if (type == Type.CAPACITY) {
return String.format("%s bytes", value);
return convertCapacity((Long) value).toString();
} else if (type.isEnum) {
if (value instanceof AssetEnum assetEnum) {
return assetEnum.getDisplayName();
@@ -220,6 +220,24 @@ public class AssetProperty {
}
}
public CapacityInfo convertCapacity(Long value) {
if (value == null) {
return null;
}
if (type != Type.CAPACITY) {
throw new IllegalStateException("Property '" + name + "' is not a capacity type.");
}
return CapacityInfo.of(value, capacityAsIEC, capacityAsSI);
}
public CapacityInfo asCapacity(@Nullable Object object) {
var value = getValue(object);
if (value == null) {
return null;
}
return convertCapacity((Long) value);
}
@Override
public String toString() {
var enumOptions = "";

View File

@@ -0,0 +1,62 @@
package be.seeseepuff.pcinv.meta;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
import java.util.Comparator;
/**
* Represents a capacity in bytes, with various units for display.
* This class is used to encapsulate the capacity information and provide
* a way to represent it in different units.
*/
@Getter
@RequiredArgsConstructor
public class CapacityInfo {
private final long capacity;
private final CapacityUnit idealUnit;
public static CapacityInfo of(long capacity, CapacityUnit idealUnit) {
return new CapacityInfo(capacity, idealUnit);
}
public static CapacityInfo of(long capacity) {
return of(capacity, idealUnitForCapacity(capacity, CapacityUnit.values()));
}
public static CapacityInfo ofSI(long capacity) {
return of(capacity, idealUnitForCapacity(capacity, CapacityUnit.SI_UNITS));
}
public static CapacityInfo ofIEC(long capacity) {
return of(capacity, idealUnitForCapacity(capacity, CapacityUnit.IEC_UNITS));
}
public static CapacityInfo of(long capacity, boolean iec, boolean si) {
if (iec && !si) {
return ofIEC(capacity);
} else if (si && !iec) {
return ofSI(capacity);
} else {
return of(capacity);
}
}
public static CapacityUnit idealUnitForCapacity(long capacity, CapacityUnit[] units) {
return Arrays.stream(units)
.sorted(Comparator.comparing(CapacityUnit::getBytes).reversed())
.filter(unit -> capacity % unit.getBytes() == 0)
.findFirst()
.orElse(CapacityUnit.BYTES);
}
public long getCapacityInUnit() {
return capacity / idealUnit.getBytes();
}
@Override
public String toString() {
return String.format("%d %s", capacity / idealUnit.getBytes(), idealUnit.getDisplayName());
}
}

View File

@@ -0,0 +1,28 @@
package be.seeseepuff.pcinv.meta;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* Represents a unit of capacity, either in binary (IEC) or decimal (SI) format.
*/
@Getter
@RequiredArgsConstructor
public enum CapacityUnit {
BYTES("Bytes", 1),
KIBIBYTES("KiB", 1024),
MEBIBYTES("MiB", 1024 * 1024),
GIBIBYTES("GiB", 1024 * 1024 * 1024),
TEBIBYTES("TiB", 1024L * 1024 * 1024 * 1024),
KILOBYTES("kB", 1000),
MEGABYTES("MB", 1000 * 1000),
GIGABYTES("GB", 1000 * 1000 * 1000),
TERABYTES("TB", 1000L * 1000 * 1000 * 1000),
;
public static final CapacityUnit[] SI_UNITS = {BYTES, KILOBYTES, MEGABYTES, GIGABYTES, TERABYTES};
public static final CapacityUnit[] IEC_UNITS = {BYTES, KIBIBYTES, MEBIBYTES, GIBIBYTES, TEBIBYTES};
private final String displayName;
private final long bytes;
}

View File

@@ -37,5 +37,5 @@ public class RamAsset implements Asset
@Description("The speed of the memory in MHz.")
@Property("Speed")
private Long speed;
private Integer speed;
}

View File

@@ -291,7 +291,7 @@ public class AssetService {
entries = repository.findAll();
}
Set<String> inputList = new TreeSet<>();
var inputList = new TreeSet<String>(Comparator.comparing(String::toLowerCase));
for (var entry : entries) {
String entryType;
if (entry instanceof Asset asset) {

View File

@@ -31,17 +31,17 @@
<option th:each="o : ${p.options}" th:value="${o.value}" th:text="${o.displayName}" th:selected="${asset != null ? (p.getValue(asset) == o.enumConstant) : o.defaultValue}">Good</option>
</select>
<span th:case="CAPACITY">
<input type="number" th:id="${d.asString(p)+'-value'}" th:name="${d.asString(p)+'-value'}" th:required="${p.required}"/>
<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'">
<option value="1">Bytes</option>
<option th:if="${p.capacityAsSI}">kB</option>
<option th:if="${p.capacityAsIEC}">KiB</option>
<option th:if="${p.capacityAsSI}">MB</option>
<option th:if="${p.capacityAsIEC}">MiB</option>
<option th:if="${p.capacityAsSI}">GB</option>
<option th:if="${p.capacityAsIEC}">GiB</option>
<option th:if="${p.capacityAsSI}">TB</option>
<option th:if="${p.capacityAsIEC}">TiB</option>
<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="${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="${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="${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="1099511627776" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset)?.getIdealUnit()?.name() == 'TEBIBYTES'}">TiB</option>
</select>
</span>
<b th:case="*">Bad input type for <span th:text="${d.type}+'-'+${p.type}"></span></b>

View File

@@ -15,6 +15,7 @@
<ul th:if="${action == 'view'}">
<li><a th:href="'/edit/'+${asset.getQr()}">Edit</a></li>
<li><a th:href="'/delete/'+${asset.getQr()}">Delete</a></li>
<li><a th:href="'/create/'+${asset.getAsset().type}">Create another <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>
</ul>
<ul th:if="${action == 'delete'}">