Mercurial > lbo > hg > analyrics
changeset 53:f81d2fdcbe63
Split index template
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 22 Jul 2022 18:11:28 -0700 |
parents | ce8e102ee2e0 |
children | d1f8cccac7b2 |
files | assets/index.html.hbs assets/index_dashboard.html.hbs src/main.rs |
diffstat | 3 files changed, 129 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/assets/index.html.hbs Thu Jul 21 19:09:52 2022 -0700 +++ b/assets/index.html.hbs Fri Jul 22 18:11:28 2022 -0700 @@ -49,87 +49,9 @@ <!-- Header --> <div id="header"> <span id="logo">AnaLyrics</span> -{{#if loggedin}} - <form id="logout" action="/logout" method="POST"> - <input type="submit" value="Log out" /> - </form> - <div class="useraction"><b>{{username}}</b>.</div> - <div class="userdomain">{{#if domain}}Domain: <b>{{domain}}</b>{{else}}<i>(all domains)</i>{{/if}}</div> -{{else}} <a class="useraction" href="login">Log in</a> -{{/if}} </div> {{#if flash}}<div id="flash"><span id="flashtext">{{flash}}<span></div>{{/if}} {{#if error}}<div id="error"><span id="errortext">{{error}}</span></div>{{/if}} - - {{#if loggedin}} - - <!-- Time navigation --> - <div id="timebox"> - <div id="timeindicator"> - from {{ date.today }} ({{date.duration}} days) - </div> - <div id="timenav"> - <button onclick="adjustURLDateParams(-30, 1)">-30d</button> - <button onclick="adjustURLDateParams(-7, 1)">-7d</button> - <button onclick="adjustURLDateParams(-1, 1)">-1d</button> - - <button onclick="adjustURLDateParams(1, 1)">+1d</button> - <button onclick="adjustURLDateParams(7, 1)">+7d</button> - <button onclick="adjustURLDateParams(30, 1)">+30d</button> - </div> - <div id="topconfig"> - <label for="botbox" id="botboxlabel">Include bots</label> - <input type="checkbox" id="botbox" name="botbox" onclick="toggleBots('botbox')"></input> - </div> - </div> - - - <!-- Plots -- only shown when logged in. --> - <div class="plotrow row1"> - <div class="plotframe fullwidth"> - <div class="plottitle">Visits and Sessions</div> - <div class="chartcontainer1"><canvas id="visitsAndSessions" height="100"></canvas></div> - </div> - </div> - <div class="plotrow row2"> - <div class="plotframe halfwidth">Top paths - <div class="chartcontainer2"><canvas id="topPaths"></canvas></div> </div> - <div class="plotframe halfwidth">Requests per Session - <div class="chartcontainer2"><canvas id="requestsBySession"></canvas></div> </div> - </div> - <div class="plotrow row3"> - <div class="plotframe halfwidth">Sessions by country - <div class="chartcontainer2"><canvas id="sessionsByCountry"></canvas></div> </div> - <div class="plotframe halfwidth">Top External Referers - <div class="chartcontainer2"><canvas id="topRefer"></canvas></div> </div> - </div> - - <script> - let plots = {"visitsAndSessions": {{{ chartconfig.visitsAndSessions }}}, - "topPaths": {{{ chartconfig.topPaths }}}, - "requestsBySession": {{{ chartconfig.requestsBySession }}}, - "sessionsByCountry": {{{ chartconfig.sessionsByCountry }}}, - "topRefer": {{{ chartconfig.topRefer }}} }; - - Object.keys(plots).forEach((cv) => { - if (plots[cv] == undefined) { - return; - } - const ctx = document.getElementById(cv).getContext('2d'); - const myChart = new Chart(ctx, plots[cv]); - }); - </script> - {{/if}} - - <script> - // Set up page after load. - (function() { - let box = document.getElementById("botbox"); - let usp = new URLSearchParams(window.location.search); - box.checked = usp.get("includebots") == "true"; - })(); - </script> - </body> </html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/assets/index_dashboard.html.hbs Fri Jul 22 18:11:28 2022 -0700 @@ -0,0 +1,128 @@ +<!DOCTYPE html> +<html> + <head> + <title>Analyrics</title> + + <meta name="robots" content="noindex"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + + <link rel="stylesheet" href="static/style.css" type="text/css" /> + <link rel="icon" type="image/png" href="static/favicon.ico"> + + <script src="static/chart.min.js" type="application/javascript"></script> + + <script type="application/javascript"> + let from = "{{ date.today }}"; + let duration = {{ date.duration }}; // in days + + function formatDate(d) { + let m = d.getUTCMonth()+1; m = m < 10 ? "0"+m : m; + let day = d.getUTCDate(); day = day < 10 ? "0"+day : day; + + return `${d.getUTCFullYear()}-${m}-${day}`; + } + function adjustURLDateParams(dateOffsetDays, durationMultiplier) { + let usp = new URLSearchParams(window.location.search); + let from_date = new Date(usp.get("from") || from); + console.log("from date", from_date, " ", dateOffsetDays); + let gduration = +usp.get("duration") || duration; + + let new_from_date = formatDate(new Date(from_date.getTime() + dateOffsetDays * 86400 * 1000)); + console.log(from_date, new_from_date); + let new_duration = gduration * durationMultiplier; + + usp.set("from", new_from_date); + usp.set("duration", new_duration.toFixed()); + window.location.search = usp.toString(); + }; + function toggleBots(checkboxid) { + let box = document.getElementById(checkboxid); + let usp = new URLSearchParams(window.location.search); + usp.set("includebots", box.checked); + window.location.search = usp.toString(); + }; + </script> + + </head> + <body> + + <!-- Header --> + <div id="header"> + <span id="logo">AnaLyrics</span> + <form id="logout" action="/logout" method="POST"> + <input type="submit" value="Log out" /> + </form> + <div class="useraction"><b>{{username}}</b>.</div> + <div class="userdomain">{{#if domain}}Domain: <b>{{domain}}</b>{{else}}<i>(all domains)</i>{{/if}}</div> + </div> + {{#if flash}}<div id="flash"><span id="flashtext">{{flash}}<span></div>{{/if}} + {{#if error}}<div id="error"><span id="errortext">{{error}}</span></div>{{/if}} + + <!-- Time navigation --> + <div id="timebox"> + <div id="timeindicator"> + from {{ date.today }} ({{date.duration}} days) + </div> + <div id="timenav"> + <button onclick="adjustURLDateParams(-30, 1)">-30d</button> + <button onclick="adjustURLDateParams(-7, 1)">-7d</button> + <button onclick="adjustURLDateParams(-1, 1)">-1d</button> + + <button onclick="adjustURLDateParams(1, 1)">+1d</button> + <button onclick="adjustURLDateParams(7, 1)">+7d</button> + <button onclick="adjustURLDateParams(30, 1)">+30d</button> + </div> + <div id="topconfig"> + <label for="botbox" id="botboxlabel">Include bots</label> + <input type="checkbox" id="botbox" name="botbox" onclick="toggleBots('botbox')"></input> + </div> + </div> + + + <!-- Plots -- only shown when logged in. --> + <div class="plotrow row1"> + <div class="plotframe fullwidth"> + <div class="plottitle">Visits and Sessions</div> + <div class="chartcontainer1"><canvas id="visitsAndSessions" height="100"></canvas></div> + </div> + </div> + <div class="plotrow row2"> + <div class="plotframe halfwidth">Top paths + <div class="chartcontainer2"><canvas id="topPaths"></canvas></div> </div> + <div class="plotframe halfwidth">Requests per Session + <div class="chartcontainer2"><canvas id="requestsBySession"></canvas></div> </div> + </div> + <div class="plotrow row3"> + <div class="plotframe halfwidth">Sessions by country + <div class="chartcontainer2"><canvas id="sessionsByCountry"></canvas></div> </div> + <div class="plotframe halfwidth">Top External Referers + <div class="chartcontainer2"><canvas id="topRefer"></canvas></div> </div> + </div> + + <script> + let plots = {"visitsAndSessions": {{{ chartconfig.visitsAndSessions }}}, + "topPaths": {{{ chartconfig.topPaths }}}, + "requestsBySession": {{{ chartconfig.requestsBySession }}}, + "sessionsByCountry": {{{ chartconfig.sessionsByCountry }}}, + "topRefer": {{{ chartconfig.topRefer }}} }; + + Object.keys(plots).forEach((cv) => { + if (plots[cv] == undefined) { + return; + } + const ctx = document.getElementById(cv).getContext('2d'); + const myChart = new Chart(ctx, plots[cv]); + }); + </script> + + <script> + // Set up page after load. + (function() { + let box = document.getElementById("botbox"); + let usp = new URLSearchParams(window.location.search); + box.checked = usp.get("includebots") == "true"; + })(); + </script> + + </body> +</html>