<%include file="/pageheader.html"/>
<%!
from kaithem.src import messagelogging
import time,itertools,math
from kaithem.src.unitsofmeasure import format_time_interval,strftime
from kaithem.src.util import url,saferepr
from kaithem.src.config import config
def dump(j):
    return saferepr(j)
def getEntries(p,page = 1):
    global entries
    start =len(p)- ((page) * 200)
    stop = max(0,start + 200)
    x = list(itertools.islice(p,max(0,start),stop) )
    return reversed(x), len(x)
%>

<%
e,entries = getEntries(messagelogging.log[topicname], page)
%>

<h2>Recent messages on topic ${topicname|h} (${len(messagelogging.log[topicname])} Messages total, ${entries} shown)</h2>
<div class="window paper">
<details class="help"><summary><i class="mdi mdi-help-circle-outline"></i></summary>
Only messages posted since the most recent periodic dump are shown
</details>
<p class="menubar">
Page:
%for i in range(1,(int(math.ceil(len(messagelogging.log[topicname])/200))+1)):
    <a href= "?page=${str(i)}"> ${i} </a>
%endfor
<p>
%for i in e:
    <h3>${strftime(i[0])}(about ${format_time_interval(time.time()-i[0],2)} ago)</h3>
    <p><pre>${dump(i[1])|h}</pre></p>
%endfor
</div>

<%include file="/pagefooter.html"/>
