/db/calendar has a "show all" button

which brings to ?all=1. it will list all events, including highly
frequent ones
This commit is contained in:
boyska 2020-02-07 19:35:42 +01:00
parent 1f9f103876
commit b95eb96f12
4 changed files with 32 additions and 14 deletions

View file

@ -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

View file

@ -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")

View file

@ -19,6 +19,19 @@ li.alarm .alarm-actions { display: none; }
{% block content %}
<div class="container-fluid">
<div class="row">
{% if not show_all %}
<a href="{{url_for('db.events_calendar')}}?all=1"
class="btn btn-sm btn-default state-collapsed pull-right">
<span class="glyphicon glyphicon-resize-full"></span>
Mostra tutti gli eventi</a>
{% else %}
<a href="{{url_for('db.events_calendar')}}?all=0"
class="btn btn-sm btn-default state-collapsed pull-right">
<span class="glyphicon glyphicon-resize-small"></span>
Nascondi gli eventi troppo frequenti</a>
{% endif %}
</div>
{% for week, weekdays in weeks|dictsort %}
<div class="week row" id="week-{{week[0]}}-{{week[1]}}">
{% for day in weeks[week] %}
@ -45,5 +58,6 @@ li.alarm .alarm-actions { display: none; }
<hr/>
{%endfor %}
</div><!-- container -->
{% endblock content %}
{# vim: set ts=2 sw=2 noet: #}

View file

@ -1,4 +1,5 @@
/* global jQuery */
jQuery(function ($) {
$('.button').button({
icons: {