Skip to content

Commit

Permalink
Fix localization on Devices page (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
KraPete authored Aug 29, 2024
1 parent 2324030 commit f614f43
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
16 changes: 6 additions & 10 deletions app/scripts/controllers/devicesController.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
class DevicesCtrl {
constructor(
$injector,
$locale,
DeviceData,
rolesFactory,
) {
constructor($injector, $locale, DeviceData, rolesFactory, $scope) {
'ngInject';

this.haveRights = rolesFactory.checkRights(rolesFactory.ROLE_TWO);
Expand All @@ -13,6 +8,7 @@ class DevicesCtrl {
}

this.locale = $locale.id;
$scope.locale = this.locale;
this.deviceData = DeviceData;
this.stateParams = $injector.get('$stateParams');

Expand All @@ -29,8 +25,8 @@ class DevicesCtrl {

getColumns() {
const devicesIdsList = Array.from(Object.values(this.deviceData.devices))
.sort(((a, b) => a.getName(this.locale).localeCompare(b.getName(this.locale))))
.map((device) => device.id);
.sort((a, b) => a.getName(this.locale).localeCompare(b.getName(this.locale)))
.map(device => device.id);

// devices are loaded dynamically by sockets, their number may change
if (this.devicesIdsCount !== devicesIdsList.length) {
Expand All @@ -39,7 +35,7 @@ class DevicesCtrl {
this.deviceIdsIntoColumns = this.splitDevicesIdsIntoColumns(devicesIdsList);
const deviceIdFromUrl = this.stateParams.deviceId;

devicesIdsList.forEach((deviceId) => {
devicesIdsList.forEach(deviceId => {
// add new devices to localStorage
if (!devicesVisibility.devices[deviceId]) {
devicesVisibility.devices[deviceId] = { isOpen: true };
Expand Down Expand Up @@ -69,7 +65,7 @@ class DevicesCtrl {
const devicesIdsInColumns = Array.from({ length: columnCount }, () => []);

let index = 0;
devicesIdsList.forEach((deviceId) => {
devicesIdsList.forEach(deviceId => {
devicesIdsInColumns[index].push(deviceId);
index = (index + 1) % columnCount;
});
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/directives/textcell.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
ng-if="cell.readOnly"
class="cell cell-text"
>
{{ cell.getEnumName($locale.id, cell.value) }}
{{ cell.getEnumName(locale, cell.value) }}
</p>
<select ng-if="!cell.readOnly && cell.isEnum()"
ng-options="item.value as item.name for item in cell.getEnumValues($locale.id)"
ng-options="item.value as item.name for item in cell.getEnumValues(locale)"
ng-model="cell.value">
</select>
<input
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/directives/valuecell.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
min="{{ cell.min }}" max="{{ cell.max }}" step="{{ cell.step }}"
ng-model="cell.value" explicit-changes>
<select ng-if="cell.valueType == 'number' && !cell.readOnly && cell.isEnum()"
ng-options="item.value as item.name for item in cell.getEnumValues($locale.id)"
ng-options="item.value as item.name for item in cell.getEnumValues(locale)"
ng-model="cell.value">
</select>
<span ng-if="cell.readOnly" class="value">
<span ng-if="cell.isEnum()" class="cell cell-text">{{ cell.getEnumName($locale.id, cell.value) }}</span>
<span ng-if="cell.isEnum()" class="cell cell-text">{{ cell.getEnumName(locale, cell.value) }}</span>
<span ng-if="!cell.isEnum()" class="int">
<span>{{ vCtrl.getIntegerValue(cell) }}</span>
</span>
Expand Down
1 change: 0 additions & 1 deletion app/scripts/services/devicedata.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,6 @@ function deviceDataService(mqttClient, $window) {
}

getEnumValues(lang) {
console.log(lang);
if (!this._enumValues.hasOwnProperty(lang)) {
let values = Object.keys(this._enumTranslations).map(value => {
return {
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wb-mqtt-homeui (2.94.3) stable; urgency=medium

* Fix localization of widget on Devices page

-- Petr Krasnoshchekov <[email protected]> Thu, 29 Aug 2024 10:22:03 +0500

wb-mqtt-homeui (2.94.2) stable; urgency=medium

* Remove unnecessary libs
Expand Down

0 comments on commit f614f43

Please sign in to comment.