From 64eeaddf2a4d8106175379245c1740ef7b3bc37d Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Thu, 19 Dec 2024 13:58:25 +0100 Subject: [PATCH] uzsu: improve web interface --- uzsu/__init__.py | 8 ++-- uzsu/webif/templates/index.html | 66 ++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/uzsu/__init__.py b/uzsu/__init__.py index 1ac214b7f..2686f00b7 100755 --- a/uzsu/__init__.py +++ b/uzsu/__init__.py @@ -629,6 +629,8 @@ def _update_item(self, item, caller="", comment=""): self.logger.debug(f'Issues with updating sunset/rise calculations for item {item} caller: {caller} comment: {comment}, issue: {success}') #item(self._items[item], caller, comment) self._webdata['items'][item.property.path].update({'interpolation': self._items[item].get('interpolation')}) + if self._webdata['items'][item.property.path].get('interpolationrunning') is None: + self._webdata['items'][item.property.path].update({'interpolationrunning': 'False'}) self._webdata['items'][item.property.path].update({'active': str(self._items[item].get('active'))}) _suncalc = self._items[item].get('SunCalculated') self._webdata['items'][item.property.path].update({'sun': _suncalc}) @@ -838,9 +840,10 @@ def _schedule(self, item, caller=None): self._update_item(item, 'UZSU Plugin', 'reset_interpolation') if _caller != "dry_run": self.logger.debug(f'will add scheduler named uzsu_{item.property.path} with datetime {_next} and tzinfo {_next.tzinfo} and value {_value} based on list index {_entryindex}') - self._planned.update({item: {'value': _value, 'next': _next.strftime('%Y-%m-%d %H:%M:%S')}}) - self._webdata['items'][item.property.path].update({'planned': {'value': _value, 'time': _next.strftime('%d.%m.%Y %H:%M')}}) + self._planned.update({item: {'value': _value, 'next': _next.strftime('%d.%m.%Y %H:%M:%S')}}) + self._webdata['items'][item.property.path].update({'planned': {'value': _value, 'time': _next.strftime('%d.%m.%Y %H:%M:%S')}}) self._webdata['items'][item.property.path].update({'seriesrunning': 'True' if self._series[item].get(_entryindex) == "running" else 'False'}) + self._webdata['items'][item.property.path].update({'interpolationrunning': str(_interpolated)}) self._update_count['done'] = self._update_count.get('done', 0) + 1 update = 'init' if update == 'init' else 'add_scheduler' self._update_item(item, 'UZSU Plugin', 'add_scheduler') @@ -1495,7 +1498,6 @@ def get_itemdict(self, item): :item: uzsu item :return: sanitized dict from uzsu item """ - return html.escape(json.dumps(self._items[item])) def get_items(self): diff --git a/uzsu/webif/templates/index.html b/uzsu/webif/templates/index.html index 42e6351fd..f202066e3 100755 --- a/uzsu/webif/templates/index.html +++ b/uzsu/webif/templates/index.html @@ -39,30 +39,32 @@ planned = objResponse['items'][item]['planned']['value']; lastvalue = objResponse['items'][item]['lastvalue']; seriesrunning = objResponse['items'][item]['seriesrunning']; - if (objResponse['items'][item]['active'] == 'True' && planned == '-') {color = 'red';} - else if (planned == '-' || objResponse['items'][item]['active'] == 'False' ){color = 'gray';} - else if (seriesrunning == 'True'){color = '#FEC34D';} - else {color = 'green'} - + if (objResponse['items'][item]['active'] === 'True' && planned === '-') {color = 'red';} + else if (planned === '-' || objResponse['items'][item]['active'] === 'False' ){color = 'gray';} + else if (seriesrunning === 'True'){color = '#FEC34D';} + else {color = 'green';} + {intpl_color = color;} if (objResponse['items'][item]['depend']['item'] == null) { depend_text = '{{ _('Item existiert nicht!') }}'; color = 'red'; + intpl_color = 'red'; } else { depend_text = objResponse['items'][item]['depend']['item'] + ' (' + objResponse['items'][item]['interpolation']['itemtype'] + ')'; } - if (objResponse['items'][item]['interpolation'] == undefined) { + if (objResponse['items'][item]['interpolation'] === undefined) { intpl_text = "{{ _('fehlt!') }}"; bit_text = "{{ _('fehlt!') }}"; color = 'red'; + intpl_color = 'red'; } else { - if (objResponse['items'][item]['interpolation']['itemtype'] == 'bool') { - if (planned == 1) {planned = 'True';} - else if (planned == 0) {planned = 'False';} - if (lastvalue == 1) {lastvalue = 'True';} - else if (lastvalue == 0) {lastvalue = 'False';} + if (objResponse['items'][item]['interpolation']['itemtype'] === 'bool') { + if (planned === 1) {planned = 'True';} + else if (planned === 0) {planned = 'False';} + if (lastvalue === 1) {lastvalue = 'True';} + else if (lastvalue === 0) {lastvalue = 'False';} } if (objResponse['items'][item]['interpolation']['initage'] === '') { bit_text = '0'; @@ -70,8 +72,10 @@ else { bit_text = objResponse['items'][item]['interpolation']['initage']; } - if (objResponse['items'][item]['interpolation']['interval'] == '' || objResponse['items'][item]['interpolation']['interval'] == undefined) { - if (objResponse['items'][item]['interpolation']['type'] == 'none') { + if (objResponse['items'][item]['interpolationrunning'] !== 'True') + intpl_color = 'gray'; + if (objResponse['items'][item]['interpolation']['interval'] === '' || objResponse['items'][item]['interpolation']['interval'] === undefined) { + if (objResponse['items'][item]['interpolation']['type'] === 'none') { interval = ''; } else { @@ -79,15 +83,21 @@ } } else { - if (objResponse['items'][item]['interpolation']['type'] == 'none') { + if (objResponse['items'][item]['interpolation']['type'] === 'none') { interval = ''; } else { - interval = ' (' + objResponse['items'][item]['interpolation']['interval'] + ')'; + if (objResponse['items'][item]['interpolation']['perday'] === true) { + perday = ', per day'; + } + else { + perday = ''; + } + interval = ' (' + objResponse['items'][item]['interpolation']['interval'] + perday + ')'; } } intpl_text = objResponse['items'][item]['interpolation']['type'] + interval; - if (objResponse['items'][item]['sun'] == undefined) { + if (objResponse['items'][item]['sun'] === undefined) { sunrise_text = ''; sunset_text = ''; } @@ -112,15 +122,16 @@ } } $('#' + $.escapeSelector(item)).css({'color': color}); + $('#' + $.escapeSelector(item + '_interpolation')).css({'color': intpl_color}); shngInsertText (item+'_interpolation', intpl_text, 'maintable', 10); shngInsertText (item+'_backintime', bit_text, 'maintable', 10); shngInsertText (item+'_dict', objResponse['items'][item]['dict'], 'maintable'); shngInsertText (item+'_dependvalue', objResponse['items'][item]['depend']['value'], 'maintable', 10); shngInsertText (item+'_nextvalue', planned, 'maintable', 10); - if (objResponse['items'][item]['planned']['time'] == '-') + if (objResponse['items'][item]['planned']['time'] === '-') shngInsertText (item+'_nexttime', '-', 'maintable', 10); else - shngInsertText (item+'_nexttime', '‪'+objResponse['items'][item]['planned']['time']+'‬', 'maintable', 10); + shngInsertText (item+'_nexttime', '‪'+objResponse['items'][item]['planned']['time']+'‬', 'maintable', 10); shngInsertText (item+'_dependitem', depend_text, 'maintable'); shngInsertText (item+'_lastvalue', lastvalue, 'maintable', 10); shngInsertText ('sunrise', sunrise_text, null, 2); @@ -204,6 +215,7 @@ {% else %} {% set color = 'green' %} {% endif %} + {% set intpl_color = color %} {{ item }} @@ -221,25 +233,35 @@ {% endif %} - {{ p._webdata['items'][item]['planned']['value'] }} + {{ p._webdata['items'][item]['planned']['value'] | replace('.0', '') }} {% if p._webdata['items'][item]['planned']['time'] == '-' %} - {% else %} - ‪{{ p._webdata['items'][item]['planned']['time'] }}‬ + ‪{{ p._webdata['items'][item]['planned']['time'] }}‬ {% endif %} {{ p._webdata['items'][item]['lastvalue'] }} - + {% if p._webdata['items'][item]['interpolation'] is not defined %} + {% set intpl_color = 'red' %} + {% elif p._webdata['items'][item]['interpolationrunning'] != 'True' %} + {% set intpl_color = 'gray' %} + {% endif %} + {% if p._webdata['items'][item]['interpolation'] is not defined %} {{ _('fehlt!') }} {% elif p._webdata['items'][item]['interpolation']['type'] %} {{ p._webdata['items'][item]['interpolation']['type'] }} {% if p._webdata['items'][item]['interpolation']['type'] != 'none' and p._webdata['items'][item]['interpolation']['interval'] %} - ({{ p._webdata['items'][item]['interpolation']['interval'] }}) + {% if p._webdata['items'][item]['interpolation']['perday'] == true %} + {% set perday = ', per day' %} + {% else %} + {% set perday = '' %} + {% endif %} + ({{ p._webdata['items'][item]['interpolation']['interval'] }}{{ perday }}) {% endif %} {% else %}- {% endif %}