diff --git a/io.openems.backend.common/src/io/openems/backend/common/metadata/MetadataUtils.java b/io.openems.backend.common/src/io/openems/backend/common/metadata/MetadataUtils.java new file mode 100644 index 00000000000..c298e8b98e5 --- /dev/null +++ b/io.openems.backend.common/src/io/openems/backend/common/metadata/MetadataUtils.java @@ -0,0 +1,71 @@ +package io.openems.backend.common.metadata; + +import static io.openems.common.utils.StringUtils.containsWithNullCheck; + +import java.util.Collection; +import java.util.List; + +import io.openems.common.channel.Level; +import io.openems.common.exceptions.OpenemsError.OpenemsNamedException; +import io.openems.common.jsonrpc.request.GetEdgesRequest.PaginationOptions; +import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata; +import io.openems.common.session.Role; + +public class MetadataUtils { + + private MetadataUtils() { + } + + /** + * Common implementation for + * {@link Metadata#getPageDevice(User, PaginationOptions)}. + * + * @param the type of the {@link Edge} + * @param user the {@link User} + * @param edges a Collection of {@link Edge}s + * @param paginationOptions the {@link PaginationOptions} + * @return the result, a list of {@link EdgeMetadata} + * @throws OpenemsNamedException on error + */ + public static List getPageDevice(User user, Collection edges, + PaginationOptions paginationOptions) throws OpenemsNamedException { + var pagesStream = edges.stream(); + final var query = paginationOptions.getQuery(); + if (query != null) { + pagesStream = pagesStream.filter(// + edge -> containsWithNullCheck(edge.getId(), query) // + || containsWithNullCheck(edge.getComment(), query) // + || containsWithNullCheck(edge.getProducttype(), query) // + ); + } + final var searchParams = paginationOptions.getSearchParams(); + if (searchParams != null) { + if (searchParams.searchIsOnline()) { + pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline()); + } + if (searchParams.productTypes() != null && !searchParams.productTypes().isEmpty()) { + pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype())); + } + // TODO sum state filter + } + + return pagesStream // + .sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) // + .skip(paginationOptions.getPage() * paginationOptions.getLimit()) // + .limit(paginationOptions.getLimit()) // + .peek(t -> user.setRole(t.getId(), Role.ADMIN)) // + .map(myEdge -> { + return new EdgeMetadata(// + myEdge.getId(), // + myEdge.getComment(), // + myEdge.getProducttype(), // + myEdge.getVersion(), // + Role.ADMIN, // + myEdge.isOnline(), // + myEdge.getLastmessage(), // + null, // firstSetupProtocol + Level.OK); + }).toList(); + } + +} diff --git a/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java b/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java index c2f7e9bc9ce..584835bae5d 100644 --- a/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java +++ b/io.openems.backend.metadata.dummy/src/io/openems/backend/metadata/dummy/MetadataDummy.java @@ -37,6 +37,7 @@ import io.openems.backend.common.metadata.Edge; import io.openems.backend.common.metadata.EdgeHandler; import io.openems.backend.common.metadata.Metadata; +import io.openems.backend.common.metadata.MetadataUtils; import io.openems.backend.common.metadata.SimpleEdgeHandler; import io.openems.backend.common.metadata.User; import io.openems.common.channel.Level; @@ -48,7 +49,6 @@ import io.openems.common.jsonrpc.response.GetEdgesResponse.EdgeMetadata; import io.openems.common.session.Language; import io.openems.common.session.Role; -import io.openems.common.utils.StringUtils; import io.openems.common.utils.ThreadPoolUtils; @Designate(ocd = Config.class, factory = false) @@ -330,43 +330,7 @@ public void setUserAlertingSettings(User user, String edgeId, List getPageDevice(User user, PaginationOptions paginationOptions) throws OpenemsNamedException { - var pagesStream = this.edges.values().stream(); - final var query = paginationOptions.getQuery(); - if (query != null) { - pagesStream = pagesStream.filter(// - edge -> StringUtils.containsWithNullCheck(edge.getId(), query) // - || StringUtils.containsWithNullCheck(edge.getComment(), query) // - || StringUtils.containsWithNullCheck(edge.getProducttype(), query) // - ); - } - final var searchParams = paginationOptions.getSearchParams(); - if (searchParams != null) { - if (searchParams.searchIsOnline()) { - pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline()); - } - if (searchParams.productTypes() != null && !searchParams.productTypes().isEmpty()) { - pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype())); - } - // TODO sum state filter - } - - return pagesStream // - .sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) // - .skip(paginationOptions.getPage() * paginationOptions.getLimit()) // - .limit(paginationOptions.getLimit()) // - .peek(t -> user.setRole(t.getId(), Role.ADMIN)) // - .map(myEdge -> { - return new EdgeMetadata(// - myEdge.getId(), // - myEdge.getComment(), // - myEdge.getProducttype(), // - myEdge.getVersion(), // - Role.ADMIN, // - myEdge.isOnline(), // - myEdge.getLastmessage(), // - null, // firstSetupProtocol - Level.OK); - }).toList(); + return MetadataUtils.getPageDevice(user, this.edges.values(), paginationOptions); } @Override diff --git a/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java b/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java index 014d47bca20..9ac20615469 100644 --- a/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java +++ b/io.openems.backend.metadata.file/src/io/openems/backend/metadata/file/MetadataFile.java @@ -39,6 +39,7 @@ import io.openems.backend.common.metadata.Edge; import io.openems.backend.common.metadata.EdgeHandler; import io.openems.backend.common.metadata.Metadata; +import io.openems.backend.common.metadata.MetadataUtils; import io.openems.backend.common.metadata.SimpleEdgeHandler; import io.openems.backend.common.metadata.User; import io.openems.common.channel.Level; @@ -51,7 +52,6 @@ import io.openems.common.session.Language; import io.openems.common.session.Role; import io.openems.common.utils.JsonUtils; -import io.openems.common.utils.StringUtils; /** * This implementation of MetadataService reads Edges configuration from a file. @@ -339,42 +339,7 @@ public void setUserAlertingSettings(User user, String edgeId, List getPageDevice(User user, PaginationOptions paginationOptions) throws OpenemsNamedException { - var pagesStream = this.edges.values().stream(); - final var query = paginationOptions.getQuery(); - if (query != null) { - pagesStream = pagesStream.filter(// - edge -> StringUtils.containsWithNullCheck(edge.getId(), query) // - || StringUtils.containsWithNullCheck(edge.getComment(), query) // - || StringUtils.containsWithNullCheck(edge.getProducttype(), query) // - ); - } - final var searchParams = paginationOptions.getSearchParams(); - if (searchParams != null) { - if (searchParams.searchIsOnline()) { - pagesStream = pagesStream.filter(edge -> edge.isOnline() == searchParams.isOnline()); - } - if (searchParams.productTypes() != null) { - pagesStream = pagesStream.filter(edge -> searchParams.productTypes().contains(edge.getProducttype())); - } - // TODO sum state filter - } - return pagesStream // - .sorted((s1, s2) -> s1.getId().compareTo(s2.getId())) // - .skip(paginationOptions.getPage() * paginationOptions.getLimit()) // - .limit(paginationOptions.getLimit()) // - .peek(t -> user.setRole(t.getId(), Role.ADMIN)) // - .map(myEdge -> { - return new EdgeMetadata(// - myEdge.getId(), // - myEdge.getComment(), // - myEdge.getProducttype(), // - myEdge.getVersion(), // - Role.ADMIN, // - myEdge.isOnline(), // - myEdge.getLastmessage(), // - null, // firstSetupProtocol - Level.OK); - }).toList(); + return MetadataUtils.getPageDevice(user, this.edges.values(), paginationOptions); } @Override diff --git a/ui/src/app/edge/history/common/consumption/details/details.overview.ts b/ui/src/app/edge/history/common/consumption/details/details.overview.ts index e742c69555a..10c26d168f3 100644 --- a/ui/src/app/edge/history/common/consumption/details/details.overview.ts +++ b/ui/src/app/edge/history/common/consumption/details/details.overview.ts @@ -26,7 +26,7 @@ export class DetailsOverviewComponent extends AbstractHistoryChartOverview { protected override afterIsInitialized() { this.service.getCurrentEdge().then(edge => { - if (this.config?.hasComponentNature("io.openems.edge.evcs.api.Evcs", this.component?.id)) { + if (this.component && this.config?.hasComponentNature("io.openems.edge.evcs.api.Evcs", this.component.id)) { return; } diff --git a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/flat/flat.ts b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/flat/flat.ts index 72cccc4ce15..fc6f09c6b4b 100644 --- a/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/flat/flat.ts +++ b/ui/src/app/edge/live/Controller/Ess/TimeOfUseTariff/flat/flat.ts @@ -12,7 +12,8 @@ export class FlatComponent extends AbstractFlatWidget implements OnInit { protected readonly CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC = Utils.CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC(this.translate); protected readonly CONVERT_TIME_OF_USE_TARIFF_STATE = Utils.CONVERT_TIME_OF_USE_TARIFF_STATE(this.translate); - protected priceWithCurrency: string; + + protected priceWithCurrency: string = "-"; async presentModal() { const modal = await this.modalController.create({