From b95eb96f12663e6b2052f6e5292ba3dfbbd9de21 Mon Sep 17 00:00:00 2001 From: boyska Date: Fri, 7 Feb 2020 19:35:42 +0100 Subject: [PATCH] /db/calendar has a "show all" button which brings to ?all=1. it will list all events, including highly frequent ones --- larigira/config.py | 3 +++ larigira/dbadmin/__init__.py | 28 ++++++++++++------------ larigira/dbadmin/templates/calendar.html | 14 ++++++++++++ larigira/static/calendar.js | 1 + 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/larigira/config.py b/larigira/config.py index d387945..8a698d2 100644 --- a/larigira/config.py +++ b/larigira/config.py @@ -32,7 +32,10 @@ def get_conf(prefix="LARIGIRA_"): conf["LOG_CONFIG"] = False conf["TMPDIR"] = os.getenv("TMPDIR", "/tmp/") conf["FILE_PATH_SUGGESTION"] = () # tuple of paths + # UI_CALENDAR_FREQUENCY_THRESHOLD"] has been removed + # use UI_CALENDAR_OCCURRENCIES_THRESHOLD instead conf["UI_CALENDAR_FREQUENCY_THRESHOLD"] = 4 * 60 * 60 # 4 hours + conf["UI_CALENDAR_OCCURRENCIES_THRESHOLD"] = 40 conf["UI_CALENDAR_DATE_FMT"] = "medium" conf["EVENT_FILTERS"] = [] conf["HTTP_PORT"] = 5000 diff --git a/larigira/dbadmin/__init__.py b/larigira/dbadmin/__init__.py index 3d846d6..5274d7f 100644 --- a/larigira/dbadmin/__init__.py +++ b/larigira/dbadmin/__init__.py @@ -67,26 +67,25 @@ def events_list(): def events_calendar(): model = current_app.larigira.controller.monitor.model today = datetime.now().date() - maxdays = 30 + max_days = 30 + max_occurrences = get_conf()["UI_CALENDAR_OCCURRENCIES_THRESHOLD"] # {date: {datetime: [(alarm1,actions1), (alarm2,actions2)]}} days = defaultdict(lambda: defaultdict(list)) - freq_threshold = get_conf()["UI_CALENDAR_FREQUENCY_THRESHOLD"] + show_all = (request.args.get('all', '0') == '1') for alarm in model.get_all_alarms(): - if ( - freq_threshold - and alarm["kind"] == "frequency" - and FrequencyAlarm(alarm).interval < freq_threshold - ): - continue actions = tuple(model.get_actions_by_alarm(alarm)) if not actions: continue t = datetime.fromtimestamp(int(today.strftime("%s"))) - for t in timegenerate(alarm, now=t, howmany=maxdays): - if t is None or t > datetime.combine( - today + timedelta(days=maxdays), time() - ): - break + occurrences = [ t for t in timegenerate(alarm, now=t, howmany=max_occurrences + + 1) if t is not None and t <= datetime.combine( + today + timedelta(days=max_days), time() + )] + if not occurrences: + continue + if not show_all and len(occurrences) > max_occurrences: + continue + for t in occurrences: days[t.date()][t].append((alarm, actions)) # { weeknum: [day1, day2, day3] } @@ -94,7 +93,8 @@ def events_calendar(): for d in sorted(days.keys()): weeks[d.isocalendar()[:2]].append(d) - return render_template("calendar.html", days=days, weeks=weeks) + return render_template("calendar.html", days=days, weeks=weeks, + show_all=show_all) @db.route("/add/time") diff --git a/larigira/dbadmin/templates/calendar.html b/larigira/dbadmin/templates/calendar.html index c61bd05..0b5f810 100644 --- a/larigira/dbadmin/templates/calendar.html +++ b/larigira/dbadmin/templates/calendar.html @@ -19,6 +19,19 @@ li.alarm .alarm-actions { display: none; } {% block content %}
+
+ {% if not show_all %} + + + Mostra tutti gli eventi + {% else %} + + + Nascondi gli eventi troppo frequenti + {% endif %} +
{% for week, weekdays in weeks|dictsort %}
{% for day in weeks[week] %} @@ -45,5 +58,6 @@ li.alarm .alarm-actions { display: none; }
{%endfor %}
+ {% endblock content %} {# vim: set ts=2 sw=2 noet: #} diff --git a/larigira/static/calendar.js b/larigira/static/calendar.js index b2bf9aa..35157cb 100644 --- a/larigira/static/calendar.js +++ b/larigira/static/calendar.js @@ -1,4 +1,5 @@ /* global jQuery */ + jQuery(function ($) { $('.button').button({ icons: {