Skip to content

Commit

Permalink
uzsu: improve web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Dec 19, 2024
1 parent 119f935 commit 64eeadd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 25 deletions.
8 changes: 5 additions & 3 deletions uzsu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down
66 changes: 44 additions & 22 deletions uzsu/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,65 @@
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';
}
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 {
interval = ' (<span style="color: gray;">5</span>)';
}
}
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 = '';
}
Expand All @@ -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', '&#x202a;'+objResponse['items'][item]['planned']['time']+'&#x202c;', 'maintable', 10);
shngInsertText (item+'_nexttime', '&#8234;'+objResponse['items'][item]['planned']['time']+'&#8236;', 'maintable', 10);
shngInsertText (item+'_dependitem', depend_text, 'maintable');
shngInsertText (item+'_lastvalue', lastvalue, 'maintable', 10);
shngInsertText ('sunrise', sunrise_text, null, 2);
Expand Down Expand Up @@ -204,6 +215,7 @@
{% else %}
{% set color = 'green' %}
{% endif %}
{% set intpl_color = color %}
<tr id="{{ item }}" style="color: {{ color }}">
<td></td>
<td class="py-1" id="{{ item }}_path">{{ item }}</td>
Expand All @@ -221,25 +233,35 @@
{% endif %}
</td>
<td class="py-1" id="{{ item }}_nextvalue">
{{ p._webdata['items'][item]['planned']['value'] }}
{{ p._webdata['items'][item]['planned']['value'] | replace('.0', '') }}
</td>
<td class="py-1" id="{{ item }}_nexttime">
{% if p._webdata['items'][item]['planned']['time'] == '-' %}
-
{% else %}
&#x202a;{{ p._webdata['items'][item]['planned']['time'] }}&#x202c;
&#8234;{{ p._webdata['items'][item]['planned']['time'] }}&#8236;
{% endif %}
</td>
<td class="py-1" id="{{ item }}_lastvalue">
{{ p._webdata['items'][item]['lastvalue'] }}
</td>
<td class="py-1" id="{{ item }}_interpolation">
{% 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 %}
<td class="py-1" id="{{ item }}_interpolation" style="color: {{ intpl_color }}">
{% 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 %}
Expand Down

0 comments on commit 64eeadd

Please sign in to comment.