Improve navigation bar;

Fix an error upon aggregation of PubSub item entries.
This commit is contained in:
Schimon Jehudah, Adv. 2024-10-13 21:24:14 +03:00
parent aa90d922b0
commit 928f5272e0
4 changed files with 47 additions and 22 deletions

View file

@ -118,7 +118,8 @@ label,
#action > a, #action > a,
#action-bar > a, #action-bar > a,
#number-of-pages > a { #number-of-pages > a,
#number-of-pages .inactive {
display: inline-block; display: inline-block;
font-size: 1.2em; font-size: 1.2em;
min-width: 90px; min-width: 90px;
@ -178,7 +179,8 @@ label,
#action-bar > a, #action-bar > a,
#download, #download,
#input, #input,
#number-of-pages > a { #number-of-pages > a,
#number-of-pages .inactive {
color: #f5f5f5; color: #f5f5f5;
font-weight: bold; font-weight: bold;
padding-left: 2em; padding-left: 2em;
@ -187,6 +189,10 @@ label,
text-transform: uppercase; text-transform: uppercase;
} }
#number-of-pages .inactive {
background: #7a7a7a;
}
#download { #download {
background: #d9541e; /* #e96d1f */ background: #d9541e; /* #e96d1f */
} }

17
fasi.py
View file

@ -186,6 +186,7 @@ class HttpInstance:
# Group chat messages # Group chat messages
action = 'Join' action = 'Join'
messages = [] messages = []
# TODO Create configurations for group chat preview
room_info_muc = await XmppXep0045.get_room_information(xmpp_instance, jid_bare, alias, maxstanzas=50) room_info_muc = await XmppXep0045.get_room_information(xmpp_instance, jid_bare, alias, maxstanzas=50)
messages = room_info_muc['iq'][3] messages = room_info_muc['iq'][3]
messages.reverse() messages.reverse()
@ -196,9 +197,11 @@ class HttpInstance:
page_number = int(page_number) page_number = int(page_number)
ix = (page_number -1) * 10 ix = (page_number -1) * 10
except: except:
ix = page_number = 0 ix = 0
page_number = 1
else: else:
ix = page_number = 0 ix = 0
page_number = 1
messages_10 = messages[ix:][:10] messages_10 = messages[ix:][:10]
number_of_pages = int(len(messages) / 10) number_of_pages = int(len(messages) / 10)
if number_of_pages < len(messages) / 10: number_of_pages += 1 if number_of_pages < len(messages) / 10: number_of_pages += 1
@ -293,6 +296,7 @@ class HttpInstance:
'previous' : previous, 'previous' : previous,
'request' : request, 'request' : request,
'subject' : subject, 'subject' : subject,
'title' : jid_detail['name'],
'url' : request.url._url, 'url' : request.url._url,
'xmpp_uri' : xmpp_uri} 'xmpp_uri' : xmpp_uri}
response = templates.TemplateResponse(template_file, template_dict) response = templates.TemplateResponse(template_file, template_dict)
@ -438,9 +442,11 @@ class HttpInstance:
page_number = int(page_number) page_number = int(page_number)
ix = (page_number -1) * 10 ix = (page_number -1) * 10
except: except:
ix = page_number = 0 ix = 0
page_number = 1
else: else:
ix = page_number = 0 ix = 0
page_number = 1
item_ids_10 = item_ids[ix:][:10] item_ids_10 = item_ids[ix:][:10]
node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=item_ids_10) node_items = await XmppXep0060.get_node_items(xmpp_instance, jid_bare, node_name, item_ids=item_ids_10)
number_of_pages = int(len(item_ids) / 10) number_of_pages = int(len(item_ids) / 10)
@ -468,7 +474,7 @@ class HttpInstance:
for item in node_items['pubsub']['items']: for item in node_items['pubsub']['items']:
item_payload = item['payload'] item_payload = item['payload']
entry = Syndication.extract_items(item_payload) entry = Syndication.extract_items(item_payload)
entry['id'] = item['id'] if entry: entry['id'] = item['id']
entries.append(entry) entries.append(entry)
#if len(entries) > 10: break #if len(entries) > 10: break
if entries: entries.reverse() if entries: entries.reverse()
@ -542,6 +548,7 @@ class HttpInstance:
'page_number' : page_number, 'page_number' : page_number,
'previous' : previous, 'previous' : previous,
'request' : request, 'request' : request,
'title' : node_title,
'url' : request.url._url, 'url' : request.url._url,
'xmpp_uri' : xmpp_uri} 'xmpp_uri' : xmpp_uri}
response = templates.TemplateResponse(template_file, template_dict) response = templates.TemplateResponse(template_file, template_dict)

View file

@ -49,7 +49,7 @@
<span> <span>
<h1>{% if jid_title %}{{jid_title}}{% else %}Group Chat{% endif %}</h1> <h1>{% if jid_title %}{{jid_title}}{% else %}Group Chat{% endif %}</h1>
<a href="/{{jid_bare}}"> <a href="/{{jid_bare}}">
<h2>{% if jid_title %}{{jid_title}}{% else %}{{jid_bare}}{% endif %}</h2> <h2>{% if jid_note %}{{jid_note}}{% else %}{{jid_bare}}{% endif %}</h2>
</a> </a>
</span> </span>
<img id="qrcode" src="/qr/{{jid_bare}}.png" /> <img id="qrcode" src="/qr/{{jid_bare}}.png" />
@ -90,15 +90,21 @@
{% if number_of_pages %} {% if number_of_pages %}
<div id="number-of-pages"> <div id="number-of-pages">
{% if number_of_pages > 5 %} {% if number_of_pages > 5 %}
<a href="?page=1">First</a> {% if page_number < 2 %}
<a href="?page={{page_number-1}}">{{page_number-1}}</a> <span class="inactive">First</span>
{% if number_of_pages > page_number %} <span class="inactive">Back</span>
<a href="?page={{page_number}}">{{page_number}}</a> {% else %}
<a href="?page=1">First</a>
<a href="?page={{page_number-1}}">Back</a>
{% endif %} {% endif %}
{% if number_of_pages > page_number+1 %} <a href="?page={{page_number}}">{{page_number}}</a>
<a href="?page={{page_number+1}}">{{page_number+1}}</a> {% if page_number == number_of_pages %}
<span class="inactive">Proceed</span>
<span class="inactive">Last</span>
{% else %}
<a href="?page={{page_number+1}}">Proceed</a>
<a href="?page={{number_of_pages}}">Last</a>
{% endif %} {% endif %}
<a href="?page={{number_of_pages}}">Last</a>
{% else %} {% else %}
{% for number in range(number_of_pages) %} {% for number in range(number_of_pages) %}
<a href="?page={{number+1}}">{{number+1}}</a> <a href="?page={{number+1}}">{{number+1}}</a>

View file

@ -97,15 +97,21 @@
{% if number_of_pages %} {% if number_of_pages %}
<div id="number-of-pages"> <div id="number-of-pages">
{% if number_of_pages > 5 %} {% if number_of_pages > 5 %}
<a href="?page=1">First</a> {% if page_number < 2 %}
<a href="?page={{page_number-1}}">{{page_number-1}}</a> <span class="inactive">First</span>
{% if number_of_pages > page_number %} <span class="inactive">Back</span>
<a href="?page={{page_number}}">{{page_number}}</a> {% else %}
<a href="?page=1">First</a>
<a href="?page={{page_number-1}}">Back</a>
{% endif %} {% endif %}
{% if number_of_pages > page_number+1 %} <a href="?page={{page_number}}">{{page_number}}</a>
<a href="?page={{page_number+1}}">{{page_number+1}}</a> {% if page_number == number_of_pages %}
<span class="inactive">Proceed</span>
<span class="inactive">Last</span>
{% else %}
<a href="?page={{page_number+1}}">Proceed</a>
<a href="?page={{number_of_pages}}">Last</a>
{% endif %} {% endif %}
<a href="?page={{number_of_pages}}">Last</a>
{% else %} {% else %}
{% for number in range(number_of_pages) %} {% for number in range(number_of_pages) %}
<a href="?page={{number+1}}">{{number+1}}</a> <a href="?page={{number+1}}">{{number+1}}</a>