Skip to content

Commit

Permalink
fix: fix this PR to use localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
miettal committed Nov 2, 2024
1 parent 501207f commit 6862f8f
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class ChartComponent extends AbstractHistoryChart {
this.chartType = "line";
this.chartObject = this.getChartData();

const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, this.locale, dataResponse);
const displayValues = AbstractHistoryChart.fillChart(this.chartType, this.chartObject, dataResponse);
this.datasets = displayValues.datasets;
this.legendOptions = displayValues.legendOptions;
this.labels = displayValues.labels;
Expand All @@ -155,7 +155,7 @@ export class ChartComponent extends AbstractHistoryChart {
const label = item.dataset.label;
const value = item.dataset.data[item.dataIndex];

return TimeOfUseTariffUtils.getLabel(value, label, this.translate, this.locale, this.currencyLabel);
return TimeOfUseTariffUtils.getLabel(value, label, this.translate, this.currencyLabel);
};

this.options.scales[ChartAxis.LEFT]["title"].text = this.currencyLabel;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/edge/history/abstracthistorychart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export abstract class AbstractHistoryChart {
const value = tooltipItem.dataset.data[tooltipItem.dataIndex];

const customUnit = tooltipItem.dataset.unit ?? null;
return label.split(":")[0] + ": " + NewAbstractHistoryChart.getToolTipsSuffix("", value, formatNumber, customUnit ?? unit, "line", locale, translate, locale, conf);
return label.split(":")[0] + ": " + NewAbstractHistoryChart.getToolTipsSuffix("", value, formatNumber, customUnit ?? unit, "line", translate, conf);
};

options.plugins.tooltip.callbacks.labelColor = (item: Chart.TooltipItem<any>) => {
Expand Down Expand Up @@ -242,7 +242,7 @@ export abstract class AbstractHistoryChart {
});

// Only one yAxis defined
options = NewAbstractHistoryChart.getYAxisOptions(options, yAxis, this.translate, "line", locale, this.datasets, true);
options = NewAbstractHistoryChart.getYAxisOptions(options, yAxis, this.translate, "line", this.datasets, true);
options = NewAbstractHistoryChart.applyChartTypeSpecificOptionsChanges("line", options, this.service, chartObject);
options.scales[ChartAxis.LEFT]["stacked"] = false;
options.scales.x["stacked"] = true;
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/edge/history/storage/singlechart.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @ts-strict-ignore
import { formatNumber } from "@angular/common";
import { Component, Input, OnChanges, OnDestroy, OnInit, LOCALE_ID, Inject } from "@angular/core";
import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import * as Chart from "chart.js";
import { DefaultTypes } from "src/app/shared/service/defaulttypes";
import { ChartAxis, YAxisType } from "src/app/shared/service/utils";
import { Language } from "src/app/shared/type/language"

Check failure on line 9 in ui/src/app/edge/history/storage/singlechart.component.ts

View workflow job for this annotation

GitHub Actions / build-ui

Missing semicolon

import { ChannelAddress, Edge, EdgeConfig, Service, Utils } from "../../../shared/shared";
import { AbstractHistoryChart } from "../abstracthistorychart";
Expand All @@ -23,7 +24,6 @@ export class StorageSingleChartComponent extends AbstractHistoryChart implements
protected override service: Service,
protected override translate: TranslateService,
private route: ActivatedRoute,
@Inject(LOCALE_ID) private locale: string,
) {
super("storage-single-chart", service, translate);
}
Expand Down Expand Up @@ -209,7 +209,7 @@ export class StorageSingleChartComponent extends AbstractHistoryChart implements

private applyControllerSpecificChartOptions(options: Chart.ChartOptions) {
const translate = this.translate;
const locale = this.locale;
const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey;

options.scales[ChartAxis.LEFT].min = null;
options.plugins.tooltip.callbacks.label = function (tooltipItem: Chart.TooltipItem<any>) {
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/edge/history/storage/totalchart.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @ts-strict-ignore
import { formatNumber } from "@angular/common";
import { Component, Input, OnChanges, OnDestroy, OnInit, LOCALE_ID, Inject } from "@angular/core";
import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import * as Chart from "chart.js";
import { DefaultTypes } from "src/app/shared/service/defaulttypes";
import { ChartAxis, Utils, YAxisType } from "src/app/shared/service/utils";
import { ChannelAddress, Edge, EdgeConfig, Service } from "src/app/shared/shared";
import { Language } from "src/app/shared/type/language"

Check failure on line 10 in ui/src/app/edge/history/storage/totalchart.component.ts

View workflow job for this annotation

GitHub Actions / build-ui

Missing semicolon

import { AbstractHistoryChart } from "../abstracthistorychart";

Expand All @@ -23,7 +24,6 @@ export class StorageTotalChartComponent extends AbstractHistoryChart implements
protected override service: Service,
protected override translate: TranslateService,
private route: ActivatedRoute,
@Inject(LOCALE_ID) private locale: string,
) {
super("storage-total-chart", service, translate);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ export class StorageTotalChartComponent extends AbstractHistoryChart implements

private applyControllerSpecificChartOptions(options: Chart.ChartOptions) {
const translate = this.translate;
const locale = this.locale;
const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey;

options.scales[ChartAxis.LEFT].min = null;
options.plugins.tooltip.callbacks.label = function (tooltipItem: Chart.TooltipItem<any>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-strict-ignore
import { Component, Input, OnChanges, OnDestroy, OnInit, Inject, LOCALE_ID } from "@angular/core";
import { Component, Input, OnChanges, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import * as Chart from "chart.js";
Expand Down Expand Up @@ -28,7 +28,6 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl
protected override translate: TranslateService,
private route: ActivatedRoute,
private websocket: Websocket,
@Inject(LOCALE_ID) protected locale: string,
) {
super("powerSoc-chart", service, translate);
}
Expand All @@ -52,7 +51,6 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl
protected setLabel() {
this.options = this.createDefaultChartOptions();
const translate = this.translate;
const locale = this.locale;
this.options.plugins = {
tooltip: {
callbacks: {
Expand All @@ -61,7 +59,7 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl
const label = item.dataset.label;
const value = item.dataset.data[item.dataIndex];

return TimeOfUseTariffUtils.getLabel(value, label, translate, locale);
return TimeOfUseTariffUtils.getLabel(value, label, translate);
},
},
},
Expand Down Expand Up @@ -206,10 +204,9 @@ export class SchedulePowerAndSocChartComponent extends AbstractHistoryChart impl
private applyControllerSpecificOptions() {
const rightYAxis: HistoryUtils.yAxes = { position: "right", unit: YAxisType.PERCENTAGE, yAxisId: ChartAxis.RIGHT };
const leftYAxis: HistoryUtils.yAxes = { position: "left", unit: YAxisType.POWER, yAxisId: ChartAxis.LEFT };
const locale = this.service.translate.currentLang;

this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxis, this.translate, "line", locale, ChartConstants.EMPTY_DATASETS, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, leftYAxis, this.translate, "line", locale, ChartConstants.EMPTY_DATASETS, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxis, this.translate, "line", ChartConstants.EMPTY_DATASETS, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, leftYAxis, this.translate, "line", ChartConstants.EMPTY_DATASETS, true);

this.datasets = this.datasets.map((el: Chart.ChartDataset) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,11 @@ export class ScheduleStateAndPriceChartComponent extends AbstractHistoryChart im
}

private applyControllerSpecificOptions() {
const locale = this.service.translate.currentLang;
const rightYaxisSoc: HistoryUtils.yAxes = { position: "right", unit: YAxisType.PERCENTAGE, yAxisId: ChartAxis.RIGHT, displayGrid: true };
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYaxisSoc, this.translate, "line", locale, this.datasets, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYaxisSoc, this.translate, "line", this.datasets, true);

const rightYAxisPower: HistoryUtils.yAxes = { position: "right", unit: YAxisType.POWER, yAxisId: ChartAxis.RIGHT_2 };
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxisPower, this.translate, "line", locale, this.datasets, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, rightYAxisPower, this.translate, "line", this.datasets, true);

this.options.scales.x["time"].unit = calculateResolution(this.service, this.service.historyPeriod.value.from, this.service.historyPeriod.value.to).timeFormat;
this.options.scales.x["ticks"] = { source: "auto", autoSkip: false };
Expand Down Expand Up @@ -167,7 +166,7 @@ export class ScheduleStateAndPriceChartComponent extends AbstractHistoryChart im
});
const leftYAxis: HistoryUtils.yAxes = { position: "left", unit: this.unit, yAxisId: ChartAxis.LEFT, customTitle: this.currencyLabel };
[rightYaxisSoc, rightYAxisPower].forEach((element) => {
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, element, this.translate, "line", locale, this.datasets, true);
this.options = NewAbstractHistoryChart.getYAxisOptions(this.options, element, this.translate, "line", this.datasets, true);
});

this.options.scales[ChartAxis.LEFT] = {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/edge/live/Controller/Evcs/flat/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ export class FlatComponent extends AbstractFlatWidget {
this.phases = currentData.allComponents[this.componentId + "/Phases"];

this.chargeDischargePower = Utils.convertChargeDischargePower(this.translate, currentData.allComponents[this.component.id + "/ChargePower"]);
this.chargeTarget = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]), this.locale);
this.energySession = Utils.CONVERT_TO_WATT(currentData.allComponents[this.component.id + "/EnergySession"], this.locale);
this.chargeTarget = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]));
this.energySession = Utils.CONVERT_TO_WATT(currentData.allComponents[this.component.id + "/EnergySession"]);

this.minChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MinimumHardwarePower"]);
this.maxChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MaximumHardwarePower"]);
Expand Down
9 changes: 4 additions & 5 deletions ui/src/app/edge/live/Controller/Evcs/modal/modal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-strict-ignore
import { ChangeDetectorRef, Component, Inject, LOCALE_ID } from "@angular/core";
import { ChangeDetectorRef, Component, Inject } from "@angular/core";
import { FormBuilder, FormControl, FormGroup } from "@angular/forms";
import { ActivatedRoute } from "@angular/router";
import { ModalController, PopoverController } from "@ionic/angular";
Expand Down Expand Up @@ -48,11 +48,10 @@ export class ModalComponent extends AbstractModal {
@Inject(PopoverController) public popoverctrl: PopoverController,
@Inject(TranslateService) protected override translate: TranslateService,
@Inject(FormBuilder) public override formBuilder: FormBuilder,
@Inject(LOCALE_ID) protected override locale: string,
public override ref: ChangeDetectorRef) {
super(
websocket, route, service, modalController, translate,
formBuilder, locale, ref);
formBuilder, ref);
ref.detach();
setInterval(() => {
this.ref.detectChanges(); // manually trigger change detection
Expand Down Expand Up @@ -129,9 +128,9 @@ export class ModalComponent extends AbstractModal {
if (this.formGroup?.pristine) {
this.status = this.getState(this.controller ? currentData.allComponents[this.controller.id + "/_PropertyEnabledCharging"] === 1 : null, currentData.allComponents[this.component.id + "/Status"], currentData.allComponents[this.component.id + "/Plug"]);
this.chargePower = Utils.convertChargeDischargePower(this.translate, currentData.allComponents[this.component.id + "/ChargePower"]);
this.chargePowerLimit = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]), this.locale);
this.chargePowerLimit = Utils.CONVERT_TO_WATT(this.formatNumber(currentData.allComponents[this.component.id + "/SetChargePowerLimit"]));
this.state = currentData.allComponents[this.component.id + "/Status"];
this.energySession = Utils.CONVERT_TO_WATTHOURS(currentData.allComponents[this.component.id + "/EnergySession"], this.locale);
this.energySession = Utils.CONVERT_TO_WATTHOURS(currentData.allComponents[this.component.id + "/EnergySession"]);
this.minChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MinimumHardwarePower"]);
this.maxChargePower = this.formatNumber(currentData.allComponents[this.component.id + "/MaximumHardwarePower"]);
this.numberOfPhases = currentData.allComponents[this.component.id + "/Phases"] ? currentData.allComponents[this.component.id + "/Phases"] : 3;
Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/edge/live/common/autarchy/modal/modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject, LOCALE_ID } from "@angular/core";
import { Component } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { AbstractFormlyComponent, OeFormlyView } from "src/app/shared/components/shared/oe-formly-component";
import { EdgeConfig } from "src/app/shared/shared";
Expand All @@ -8,7 +8,6 @@ import { Role } from "src/app/shared/type/role";
templateUrl: "../../../../../shared/components/formly/formly-field-modal/template.html",
})
export class ModalComponent extends AbstractFormlyComponent {
constructor(@Inject(LOCALE_ID) protected locale: string){ super(); }

public static generateView(translate: TranslateService): OeFormlyView {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ModalComponent } from "./modal";

export function expectView(config: EdgeConfig, viewContext: OeFormlyViewTester.Context, testContext: TestContext, view: OeFormlyViewTester.View): void {

const generatedView = OeFormlyViewTester.apply(ModalComponent.generateView(DummyConfig.convertDummyEdgeConfigToRealEdgeConfig(config), testContext.translate, "de"), viewContext);
const generatedView = OeFormlyViewTester.apply(ModalComponent.generateView(DummyConfig.convertDummyEdgeConfigToRealEdgeConfig(config), testContext.translate), viewContext);

expect(generatedView).toEqual(view);
}
7 changes: 3 additions & 4 deletions ui/src/app/edge/live/common/consumption/modal/modal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Inject, LOCALE_ID } from "@angular/core";
import { Component } from "@angular/core";
import { TranslateService } from "@ngx-translate/core";
import { TextIndentation } from "src/app/shared/components/modal/modal-line/modal-line";
import { Converter } from "src/app/shared/components/shared/converter";
Expand All @@ -12,9 +12,8 @@ import { ChannelAddress, CurrentData, EdgeConfig } from "../../../../../shared/s
templateUrl: "../../../../../shared/components/formly/formly-field-modal/template.html",
})
export class ModalComponent extends AbstractFormlyComponent {
constructor(@Inject(LOCALE_ID) protected locale: string){ super(); }

public static generateView(config: EdgeConfig, translate: TranslateService, locale: string): OeFormlyView {
public static generateView(config: EdgeConfig, translate: TranslateService): OeFormlyView {

const evcss: EdgeConfig.Component[] | null = config.getComponentsImplementingNature("io.openems.edge.evcs.api.Evcs")
.filter(component =>
Expand Down Expand Up @@ -124,7 +123,7 @@ export class ModalComponent extends AbstractFormlyComponent {
}

protected override generateView(config: EdgeConfig): OeFormlyView {
return ModalComponent.generateView(config, this.translate, this.locale);
return ModalComponent.generateView(config, this.translate);
}

}
4 changes: 3 additions & 1 deletion ui/src/app/edge/live/common/storage/storage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Component } from "@angular/core";
import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget";
import { CurrentData , ChannelAddress, EdgeConfig, Utils } from "src/app/shared/shared";
import { DateUtils } from "src/app/shared/utils/date/dateutils";
import { Language, MyTranslateLoader } from "src/app/shared/type/language";

Check failure on line 7 in ui/src/app/edge/live/common/storage/storage.component.ts

View workflow job for this annotation

GitHub Actions / build-ui

`src/app/shared/type/language` import should occur before import of `src/app/shared/utils/date/dateutils`

Check failure on line 7 in ui/src/app/edge/live/common/storage/storage.component.ts

View workflow job for this annotation

GitHub Actions / build-ui

'MyTranslateLoader' is defined but never used

Check failure on line 7 in ui/src/app/edge/live/common/storage/storage.component.ts

View workflow job for this annotation

GitHub Actions / build-ui

'MyTranslateLoader' is defined but never used

import { StorageModalComponent } from "./modal/modal.component";

Expand Down Expand Up @@ -50,6 +51,7 @@ export class StorageComponent extends AbstractFlatWidget {
* @returns only positive and 0
*/
public convertPower(value: number, isCharge?: boolean) {
const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey;
if (value == null) {
return "-";
}
Expand All @@ -58,7 +60,7 @@ export class StorageComponent extends AbstractFlatWidget {

// Round thisValue to Integer when decimal place equals 0
if (thisValue > 0) {
return formatNumber(thisValue, this.locale, "1.0-1") + " kW";
return formatNumber(thisValue, locale, "1.0-1") + " kW";

} else if (thisValue == 0 && isCharge) {
// if thisValue is 0, then show only when charge and not discharge
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/edge/settings/powerassistant/powerassistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { formatNumber } from "@angular/common";
import { Component } from "@angular/core";
import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget";
import { DataService } from "src/app/shared/components/shared/dataservice";
import { Language } from "src/app/shared/type/language"

Check failure on line 6 in ui/src/app/edge/settings/powerassistant/powerassistant.ts

View workflow job for this annotation

GitHub Actions / build-ui

Missing semicolon
import { ChannelAddress, CurrentData, EdgeConfig, Utils } from "../../../shared/shared";
import { LiveDataService } from "../../live/livedataservice";

Expand Down Expand Up @@ -221,10 +222,11 @@ export class PowerAssistantComponent extends AbstractFlatWidget {
export namespace Converter {
export function unit(unit: string): (value: any) => string {
return function (value: any): string {
const locale: string = (Language.getByKey(localStorage.LANGUAGE) ?? Language.DEFAULT).i18nLocaleKey;
if (value == null) {
return "-";
} else if (value >= 0) {
return formatNumber(value, this.locale, "1.0-0") + " " + unit;
return formatNumber(value, locale, "1.0-0") + " " + unit;
}
};
}
Expand Down
Loading

0 comments on commit 6862f8f

Please sign in to comment.