diff --git a/bin/lib/chats_viewer.py b/bin/lib/chats_viewer.py index 49916d4e..076f81da 100755 --- a/bin/lib/chats_viewer.py +++ b/bin/lib/chats_viewer.py @@ -762,7 +762,7 @@ def api_get_chats_selector(): selector.append({'id': chat.get_global_id(), 'name': f'{chat.get_chat_instance()}: {chat.get_label()}'}) return selector -def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True): +def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, page=-1, messages=True, heatmap=False): chat = Chats.Chat(chat_id, chat_instance_uuid) if not chat.exists(): return {"status": "error", "reason": "Unknown chat"}, 404 @@ -778,6 +778,8 @@ def api_get_chat(chat_id, chat_instance_uuid, translation_target=None, nb=-1, pa if messages: meta['messages'], meta['pagination'], meta['tags_messages'] = chat.get_messages(translation_target=translation_target, nb=nb, page=page) meta['messages'] = get_chat_object_messages_meta(meta['messages']) + if heatmap: + meta['years'] = chat.get_message_years() return meta, 200 def api_get_nb_message_by_week(chat_type, chat_instance_uuid, chat_id): @@ -805,7 +807,7 @@ def api_get_nb_year_messages(chat_type, chat_instance_uuid, chat_id, year): year = datetime.now().year nb_max, nb = chat.get_nb_year_messages(year) nb = [[date, value] for date, value in nb.items()] - return {'max': nb_max, 'nb': nb}, 200 + return {'max': nb_max, 'nb': nb, 'year': year}, 200 def api_get_chat_participants(chat_type, chat_subtype, chat_id): diff --git a/var/www/blueprints/chats_explorer.py b/var/www/blueprints/chats_explorer.py index bb4d0cbd..aead6ff6 100644 --- a/var/www/blueprints/chats_explorer.py +++ b/var/www/blueprints/chats_explorer.py @@ -93,7 +93,7 @@ def chats_explorer_chat(): target = None nb_messages = request.args.get('nb') page = request.args.get('page') - chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target, nb=nb_messages, page=page) + chat = chats_viewer.api_get_chat(chat_id, instance_uuid, translation_target=target, nb=nb_messages, page=page, heatmap=True) if chat[1] != 200: return create_json_response(chat[0], chat[1]) else: diff --git a/var/www/templates/chats_explorer/chat_viewer.html b/var/www/templates/chats_explorer/chat_viewer.html index 0d43fef8..c0df4ef2 100644 --- a/var/www/templates/chats_explorer/chat_viewer.html +++ b/var/www/templates/chats_explorer/chat_viewer.html @@ -114,7 +114,18 @@ {% endif %}
Messages by year:
-
+
+
+
+
+
+
+ {% for year in chat['years'] %} +
+ {% endfor %} +
+
+
{% with translate_url=url_for('chats_explorer.chats_explorer_chat', subtype=chat['subtype']), obj_id=chat['id'], pagination=chat['pagination'] %} {% include 'chats_explorer/block_translation.html' %} @@ -248,8 +259,7 @@ optionheatmap = { calendar: [ { orient: 'horizontal', - //range: new Date().getFullYear(), - range: '2024', + range: new Date().getFullYear(), }, ], series: [ @@ -263,14 +273,18 @@ optionheatmap = { }; heatyearChart.setOption(optionheatmap); -$.getJSON("{{ url_for('chats_explorer.chats_explorer_messages_stats_year') }}?type=chat&subtype={{ chat['subtype'] }}&id={{ chat['id'] }}") - .done(function(data) { - optionheatmap['visualMap']['max'] = data['max'] - optionheatmap['series'][0]['data'] = data['nb'] - heatyearChart.setOption(optionheatmap) +update_heatmap_year(null); +function update_heatmap_year(year) { + $.getJSON("{{ url_for('chats_explorer.chats_explorer_messages_stats_year') }}?type=chat&subtype={{ chat['subtype'] }}&id={{ chat['id'] }}&year=" + year) + .done(function(data) { + optionheatmap['visualMap']['max'] = data['max'] + optionheatmap['calendar'][0]['range'] = data['year'] + optionheatmap['series'][0]['data'] = data['nb'] + heatyearChart.setOption(optionheatmap) - } -); + } + ); +}