jens-maus / RaspberryMatic

:house: A feature-rich but lightweight, buildroot-based Linux operating system alternative for your CloudFree CCU3/ELV-Charly 'homematicIP CCU' IoT smarthome central. Running as a pure virtual appliance (ProxmoxVE, Home Assistant, LXC, Docker/OCI, Kubernetes/K8s, etc.) on a dedicated embedded device (RaspberryPi, etc.) or generic x86/ARM hardware.
https://raspberrymatic.de
Apache License 2.0
1.52k stars 186 forks source link

system variables in descending order (Z-A) in selection popup #1519

Closed MichaelN0815 closed 2 years ago

MichaelN0815 commented 2 years ago

Describe the issue you are experiencing

In the popup for selecting a system variable (called in programming or favorites) the system variables are sorted in descending order (Z first)

Describe the behavior you expected

ascending order (A first) is expected.

Steps to reproduce the issue

  1. Programme / Zentralenprogramme
  2. NEU
  3. Bedingung - WENN - Systemzustand - Systemvariablen Unbenannt

What is the version this bug report is based on?

3.61.5.20211113

Which base platform are you running?

rpi3 (RaspberryPi3)

Which HomeMatic/homematicIP radio module are you using?

RPI-RF-MOD

Anything in the logs that might be useful for us?

n/a

Additional information

bug is already in nightly build 3.61.4.20211109

perhaps @ptweety has an idea to solve this issue. It could not be a side effect of https://github.com/jens-maus/RaspberryMatic/pull/1492 ?

jp112sdl commented 2 years ago

https://github.com/jens-maus/RaspberryMatic/blob/cf0ce242099fa804de4385c8bf21d7d765b8c8fa/buildroot-external/patches/occu/0145-WebUI-NaturalSorting.patch#L65

Da muss eine 1 hin.

mbhomie007 commented 2 years ago

Vielleicht auch mit #1508 zu tun?

MichaelN0815 commented 2 years ago

Da muss eine 1 hin.

OK, ich kann bestätigen das es damit wieder richtig sortiert wird und anscheinend keinen negativen Einfluss auf andere Sortierungen hat. Das sollte aber nochmal jemand anderes austesten.

Anbei das DIFF webui.js.diff.txt

jens-maus commented 2 years ago

Ok, hab das nun integriert. Bitte wenn möglich mit dem nächsten nightly build testen.

MichaelN0815 commented 2 years ago

Mit der 3.61.5.20211116 getestet und für gut befunden.

ptweety commented 2 years ago

Ich glaube nicht, dass dieser Fix schon hinreichend ist. Nachdem ich nochmal drauf geschaut habe, braucht es wohl noch eine Anpassung an anderer Stelle.

Ich teste gerade dieses Fragment in WebUI.js:

/**
 * Vergleicht zwei Zeichenketten (case-insensitiv)
 **/
String.prototype.ex_compareTo = function(other)
{
  if (typeof(other) == "string")
  {
    var strA = this.toLowerCase();
    var strB = other.toLowerCase();

    return strA.localeCompare(strB, undefined, {numeric: true, sensitivity: 'base'});
  }

  return 0;
};

Um diesen Teil des patches zu ersetzen:

--- occu/WebUI/www/webui/webui.js.orig
+++ occu/WebUI/www/webui/webui.js
@@ -6078,7 +6078,8 @@
  **/
 Array.prototype.ex_sortBy = function(name, sortReverse)
 {
-  this.sort(function(a,b) { return Object.ex_compare(a[name], b[name]); });
+  const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'});
+  this.sort( (x, y) => { return collator.compare(x[name], y[name]); } );
   if (sortReverse) { this.reverse(); }

   return this;
MichaelN0815 commented 2 years ago

Was funktioniert denn nicht korrekt?

ptweety commented 2 years ago

Es gibt (mindest) zwei Stellen, an welchen der Sortier-Algorythmus in WebUI.js implementiert ist.

Letzteres hat nicht korrekt funktioniert.

ptweety commented 2 years ago

Argh: Unter Programme und Verknüpfungen > Direkte Verknüpfungen > Neue Verknüpfung anlegen - Schritt 1/3 ist noch das alte Sortierverhalten.