Skip to content

Commit

Permalink
feat: Display vehicle measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
mthmulders committed Jan 7, 2025
1 parent 8d94b47 commit fa9cec3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package it.mulders.traqqr.web.faces;

import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;
import jakarta.faces.convert.Converter;
import jakarta.faces.convert.FacesConverter;

import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.Locale;

@FacesConverter("traqqr.MeasurementTimestampConverter")
public class MeasurementTimestampConverter implements Converter<OffsetDateTime> {
private static final DateTimeFormatter FORMAT = new DateTimeFormatterBuilder()
.appendPattern("dd MMM uuuu, HH:mm.ss")
.toFormatter(Locale.ROOT);

@Override
public OffsetDateTime getAsObject(FacesContext context, UIComponent component, String value) {
if (context == null || component == null) {
throw new NullPointerException();
}
if (value == null) {
return null;
}

return OffsetDateTime.parse(value, FORMAT);
}

@Override
public String getAsString(FacesContext context, UIComponent component, OffsetDateTime value) {
return value.format(FORMAT);
}
}
22 changes: 17 additions & 5 deletions app/adapters/web/src/main/webapp/secure/measurements/index.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,23 @@

<p:divider />

<h:outputText id="measurements"
rendered="#{not empty manageMeasurementsView.measurementsForSelectedVehicle}">
There are #{manageMeasurementsView.measurementsForSelectedVehicle.size()} measurement(s)
for #{manageMeasurementsView.selectedVehicle.description}.
</h:outputText>
<p:dataTable id="measurements"
var="measurement" value="${manageMeasurementsView.measurementsForSelectedVehicle}"
editable="false" stripedRows="true">
<p:column headerText="Timestamp">
<h:outputText value="#{measurement.timestamp()}" converter="traqqr.MeasurementTimestampConverter" /> (UTC)
</p:column>
<p:column headerText="Odometer">
<h:outputText value="#{measurement.odometer()}" />
</p:column>
<p:column headerText="Battery SoC">
<h:outputText value="#{measurement.battery().soc()}" />%
</p:column>
<p:column headerText="GPS Location">
<h:outputText value="#{measurement.location().lat()}" />,
<h:outputText value="#{measurement.location().lon()}" />
</p:column>
</p:dataTable>
</p:card>
</h:form>
</ui:define>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package it.mulders.traqqr.web.faces;

import jakarta.faces.context.FacesContext;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;

import java.time.*;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class MeasurementTimestampConverterTest implements WithAssertions {
private final MeasurementTimestampConverter converter = new MeasurementTimestampConverter();

private static final OffsetDateTime INPUT = OffsetDateTime.of(
LocalDate.of(2025, Month.JANUARY, 7),
LocalTime.of(22, 14, 13, 0),
ZoneOffset.UTC
);

@Test
void should_format_measurement_timestamp() {
assertThat(converter.getAsString(null, null, INPUT)).isEqualTo("07 Jan 2025, 22:14.13");
}
}

0 comments on commit fa9cec3

Please sign in to comment.