Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d1c65a4c5 | |||
| 85de1c0c9f | |||
| a4b88f6dfd | |||
| b9bf2f1d38 |
@@ -17,16 +17,16 @@ jobs:
|
|||||||
java-version: '21'
|
java-version: '21'
|
||||||
cache: 'gradle'
|
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
|
- name: Build Jar
|
||||||
run: ./gradlew bootJar
|
run: ./gradlew bootJar
|
||||||
|
|
||||||
- name: Build Container
|
- name: Build Container
|
||||||
run: docker build --tag gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}} .
|
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
|
- name: Push Container
|
||||||
run: docker push gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}}
|
run: docker push gitea.seeseepuff.be/seeseemelk/pcinv:${{github.ref_name}}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ public class AssetProperty {
|
|||||||
} else if (type == Type.INTEGER || type == Type.STRING) {
|
} else if (type == Type.INTEGER || type == Type.STRING) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
} else if (type == Type.CAPACITY) {
|
} else if (type == Type.CAPACITY) {
|
||||||
return String.format("%s bytes", value);
|
return convertCapacity((Long) value).toString();
|
||||||
} else if (type.isEnum) {
|
} else if (type.isEnum) {
|
||||||
if (value instanceof AssetEnum assetEnum) {
|
if (value instanceof AssetEnum assetEnum) {
|
||||||
return assetEnum.getDisplayName();
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
var enumOptions = "";
|
var enumOptions = "";
|
||||||
|
|||||||
62
src/main/java/be/seeseepuff/pcinv/meta/CapacityInfo.java
Normal file
62
src/main/java/be/seeseepuff/pcinv/meta/CapacityInfo.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/main/java/be/seeseepuff/pcinv/meta/CapacityUnit.java
Normal file
28
src/main/java/be/seeseepuff/pcinv/meta/CapacityUnit.java
Normal 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;
|
||||||
|
}
|
||||||
@@ -37,5 +37,5 @@ public class RamAsset implements Asset
|
|||||||
|
|
||||||
@Description("The speed of the memory in MHz.")
|
@Description("The speed of the memory in MHz.")
|
||||||
@Property("Speed")
|
@Property("Speed")
|
||||||
private Long speed;
|
private Integer speed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ public class AssetService {
|
|||||||
entries = repository.findAll();
|
entries = repository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<String> inputList = new TreeSet<>();
|
var inputList = new TreeSet<String>(Comparator.comparing(String::toLowerCase));
|
||||||
for (var entry : entries) {
|
for (var entry : entries) {
|
||||||
String entryType;
|
String entryType;
|
||||||
if (entry instanceof Asset asset) {
|
if (entry instanceof Asset asset) {
|
||||||
|
|||||||
@@ -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>
|
<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>
|
||||||
<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}"/>
|
<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">Bytes</option>
|
<option value="1" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'BYTES'}">Bytes</option>
|
||||||
<option th:if="${p.capacityAsSI}">kB</option>
|
<option th:value="${1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'KILOBYTES'}">kB</option>
|
||||||
<option th:if="${p.capacityAsIEC}">KiB</option>
|
<option th:value="${1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'KIBIBYTES'}">KiB</option>
|
||||||
<option th:if="${p.capacityAsSI}">MB</option>
|
<option th:value="${1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'MEGABYTES'}">MB</option>
|
||||||
<option th:if="${p.capacityAsIEC}">MiB</option>
|
<option th:value="${1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'MEBIBYTES'}">MiB</option>
|
||||||
<option th:if="${p.capacityAsSI}">GB</option>
|
<option th:value="${1000*1000*1000}" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'GIGABYTES'}">GB</option>
|
||||||
<option th:if="${p.capacityAsIEC}">GiB</option>
|
<option th:value="${1024*1024*1024}" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'GIBIBYTES'}">GiB</option>
|
||||||
<option th:if="${p.capacityAsSI}">TB</option>
|
<option value="1000000000000" th:if="${p.capacityAsSI}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'TERABYTES'}">TB</option>
|
||||||
<option th:if="${p.capacityAsIEC}">TiB</option>
|
<option value="1099511627776" th:if="${p.capacityAsIEC}" th:selected="${p.asCapacity(asset).getIdealUnit().name() == 'TEBIBYTES'}">TiB</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>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<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="'/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