1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Refactored macros into includes and removed remaining htmlmodules

This commit is contained in:
Krateng 2020-08-30 23:51:24 +02:00
parent 22ee6bf751
commit e55975514f
16 changed files with 149 additions and 104 deletions

View File

@ -70,9 +70,8 @@
</tr>
</table>
<h2><a href='/charts_tracks?{{ encodedartist }}'>Top Tracks</a></h2>
<h2><a href='{{ mlj_uri.create_uri("/charts_tracks",filterkeys) }}'>Top Tracks</a></h2>
{# htmlmodules.module_trackcharts(**filterkeys,max_=15)[0] #}
{% import 'partials/charts_tracks.jinja' as charts_tracks %}
{{ charts_tracks.charts_tracks(filterkeys,limitkeys,{"perpage":15,"page":0},compare=false) }}
@ -83,62 +82,63 @@
<tr>
<td>
<h2 class="headerwithextra"><a href='/pulse?{{ encodedartist }}&amp;step=year&amp;trail=1'>Pulse</a></h2>
<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/pulse",filterkeys) }}'>Pulse</a></h2>
<br/>
{% for range in xranges %}
{% for r in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
onclick="showRangeManual('pulse','{{ r.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
{{ r.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/pulse.jinja' as pulse %}
{% for range in xranges %}
{% for r in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
class="stat_module_pulse pulse_{{ r.identifier }}"
style="{{ 'display:none;' if initialrange==r.identifier else '' }}"
>
{{ pulse.pulse(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
{% include 'partials/pulse.jinja' %}
{% endwith %}
</span>
{% endfor %}
</td>
<td>
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
<h2 class="headerwithextra"><a href='/performance?{{ encodedcredited }}&amp;step=year&amp;trail=1'>Performance</a></h2>
<h2 class="headerwithextra"><a href='{{ mlj_uri.create_uri("/performance",filterkeys) }}'>Performance</a></h2>
{% if not competes %}<span class="afterheader">of {{ htmlgenerators.artistLink(credited) }}</span>
{% endif %}
<br/>
{% for range in xranges %}
{% for r in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
onclick="showRangeManual('pulse','{{ r.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
{{ r.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/performance.jinja' as performance %}
{% for range in xranges %}
{% for r in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
class="stat_module_pulse pulse_{{ r.identifier }}"
style="{{ 'display:none;' if initialrange==r.identifier else '' }}"
>
{{ performance.performance({'artist':credited},{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
{% include 'partials/performance.jinja' %}
{% endwith %}
</span>
{% endfor %}
@ -148,10 +148,10 @@
</table>
<h2><a href='/scrobbles?{{ encodedartist }}'>Last Scrobbles</a></h2>
{% import 'partials/scrobbles.jinja' as scrobbles %}
{{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }}
<h2><a href='{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}'>Last Scrobbles</a></h2>
{% with amountkeys = {"perpage":15,"page":0} %}
{% include 'partials/scrobbles.jinja' %}
{% endwith %}
{% endblock %}

View File

@ -27,7 +27,8 @@
<h1>Artist Charts</h1><a href="/top_artists"><span>View #1 Artists</span></a><br/>
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys) }}
</td>
</tr>

View File

@ -27,7 +27,8 @@
{% if filterkeys.get('artist') is not none %}by {{ htmlgenerators.artistLink(filterkeys.get('artist')) }}{% endif %}
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys) }}
</td>
</tr>

View File

@ -1,5 +1,3 @@
{% macro performance(filterkeys,limitkeys,delimitkeys,amountkeys) %}
{% set ranges = dbp.get_performance(filterkeys,limitkeys,delimitkeys) %}
{% set minrank = ranges|map(attribute="rank")|reject("none")|max|default(60) %}
@ -25,6 +23,3 @@
</tr>
{% endfor %}
</table>
{%- endmacro %}

View File

@ -1,5 +1,3 @@
{% macro pulse(filterkeys,limitkeys,delimitkeys,amountkeys) %}
{% set ranges = dbp.get_pulse(filterkeys,limitkeys,delimitkeys) %}
{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %}
@ -20,6 +18,3 @@
</tr>
{% endfor %}
</table>
{%- endmacro %}

View File

@ -1,5 +1,3 @@
{% macro scrobbles(filterkeys,limitkeys,amountkeys,shortTimeDesc=False) %}
{% set scrobbles = dbp.get_scrobbles(filterkeys,limitkeys,amountkeys) %}
{% set firstindex = amountkeys.page * amountkeys.perpage %}
@ -18,5 +16,3 @@
{% endif %}
{% endfor %}
</table>
{%- endmacro %}

View File

@ -1,5 +1,3 @@
{% macro top_artists(limitkeys,delimitkeys,amountkeys) %}
{% set ranges = dbp.get_top_artists(limitkeys,delimitkeys) %}
{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %}
@ -27,6 +25,3 @@
</tr>
{% endfor %}
</table>
{%- endmacro %}

View File

@ -1,5 +1,3 @@
{% macro top_tracks(filterkeys,limitkeys,delimitkeys,amountkeys) %}
{% set ranges = dbp.get_top_tracks(filterkeys,limitkeys,delimitkeys) %}
{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %}
@ -27,6 +25,3 @@
</tr>
{% endfor %}
</table>
{%- endmacro %}

View File

@ -2,7 +2,6 @@
{% block title %}Maloja - {{ malojatime.delimit_desc_p(delimitkeys) }} Performance{% endblock %}
{% import 'snippets/filterdescription.jinja' as filterdesc %}
{% import 'partials/performance.jinja' as performance %}
{% if filterkeys.get('track') is not none %}
{% set img = utilities.getTrackImage(artists=filterkeys.track.artists,title=filterkeys.track.title,fast=True) %}
@ -21,18 +20,19 @@
<td class="text">
<h1>{{ malojatime.delimit_desc_p(delimitkeys) }} Performance</h1>
{% if limitkeys != {} %}
<a href="/pulse?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys) }}"><span>View Pulse</span></a>
<a href="{{ mlj_uri.create_uri("/pulse",filterkeys,limitkeys,delimitkeys) }}"><span>View Pulse</span></a>
{% endif %}
<br/>
{{ filterdesc.desc(filterkeys,limitkeys,prefix='of') }}
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys,delimit=True) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys,delimit=True) }}
</td>
</tr>
</table>
{{ performance.performance(filterkeys,limitkeys,delimitkeys,amountkeys) }}
{% include 'partials/performance.jinja' %}
{% endblock %}

View File

@ -2,7 +2,6 @@
{% block title %}Maloja - {{ malojatime.delimit_desc_p(delimitkeys) }} Pulse{% endblock %}
{% import 'snippets/filterdescription.jinja' as filterdesc %}
{% import 'partials/pulse.jinja' as pulse %}
{% if filterkeys.get('track') is not none %}
{% set img = utilities.getTrackImage(artists=filterkeys.track.artists,title=filterkeys.track.title,fast=True) %}
@ -21,18 +20,19 @@
<td class="text">
<h1>{{ malojatime.delimit_desc_p(delimitkeys) }} Pulse</h1>
{% if filterkeys != {} %}
<a href="/performance?{{ urihandler.compose_from_dicts(filterkeys,limitkeys,delimitkeys) }}"><span>View Rankings</span></a>
<a href="{{ mlj_uri.create_uri("/performance",filterkeys,limitkeys,delimitkeys) }}"><span>View Rankings</span></a>
{% endif %}
<br/>
{{ filterdesc.desc(filterkeys,limitkeys,prefix='of') }}
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys,delimit=True) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys,delimit=True) }}
</td>
</tr>
</table>
{{ pulse.pulse(filterkeys,limitkeys,delimitkeys,amountkeys) }}
{% include 'partials/pulse.jinja' %}
{% endblock %}

View File

@ -2,7 +2,6 @@
{% block title %}Maloja - Scrobbles{% endblock %}
{% import 'snippets/filterdescription.jinja' as filterdesc %}
{% import 'partials/scrobbles.jinja' as scrobblemodule %}
{% import 'snippets/pagination.jinja' as pagination %}
{% set scrobbles = dbp.get_scrobbles(filterkeys,limitkeys,amountkeys) %}
@ -32,14 +31,15 @@
<br/>
<p class="stats">{{ scrobbles.__len__() }} Scrobbles</p>
<br/>
{{ htmlmodules.module_filterselection(_urikeys) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys) }}
</td>
</tr>
</table>
{{ scrobblemodule.scrobbles(filterkeys,limitkeys,amountkeys) }}
{% include 'partials/scrobbles.jinja' %}
{{ pagination.pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages) }}

View File

@ -0,0 +1,64 @@
{% macro selector(filterkeys,limitkeys,delimitkeys,amountkeys,limit=True,delimit=False) %}
<!-- drop keys that are not relevant so they don't clutter the URI -->
{% if not limit %}{% set limitkeys = {} %}{% endif %}
{% if not delimit %}{% set delimitkeys = {} %}{% endif %}
{% set allkeys = [filterkeys,limitkeys,delimitkeys,amountkeys] | combine_dicts %}
{% if limit %}
<div>
{% set thisrange = limitkeys.timerange %}
{% set prevrange = thisrange.next(-1) %}
{% set nextrange = thisrange.next(1) %}
{% if prevrange is not none %}
<a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,{'timerange':prevrange}) }}'><span class='stat_selector'>{{ prevrange.desc() }}</span></a>
«
{% endif %}
{% if prevrange is not none or nextrange is not none %}
<span class='stat_selector' style='opacity:0.5;'>{{ thisrange.desc() }}</span>
{% endif %}
{% if nextrange is not none %}
»
<a href='{{ mlj_uri.create_uri("",filterkeys,limitkeys,delimitkeys,{'timerange':nextrange}) }}'><span class='stat_selector'>{{ nextrange.desc() }}</span></a>
{% endif %}
</div>
<div>
{% for r in xcurrent %}
{% if r.range == limitkeys.timerange %}
<span class='stat_selector' style='opacity:0.5;'>{{ r.localisation }}</span>
{% else %}
<a href='{{ mlj_uri.create_uri("",allkeys,{"timerange":r.range}) }}'><span class='stat_selector'>{{ r.localisation }}</span></a>
{% endif %}
{{ "|" if not loop.last }}
{% endfor %}
</div>
{% endif %}
{% if delimit %}
<div>
{% for cat in [xdelimiters,xtrails] %}
{% for r in cat %}
{# {% if all(r.keys[k] == allkeys[k] for k in r.keys) %} #}
{% if r.replacekeys | map('compare_key_in_dicts',r.replacekeys,allkeys) | alltrue %}
<span class='stat_selector' style='opacity:0.5;'>{{ r.localisation }}</span>
{% else %}
<a href='{{ mlj_uri.create_uri("",allkeys,r.replacekeys) }}'><span class='stat_selector'>{{ r.localisation }}</span></a>
{% endif %}
{{ "|" if not loop.last }}
{% endfor %}
<br/>
{% endfor %}
</div>
{% endif %}
{% endmacro %}

View File

@ -61,7 +61,6 @@
<div class="sidelist">
<!-- SCROBBLES -->
{% import 'partials/scrobbles.jinja' as scr %}
<h1><a href="/scrobbles">Last Scrobbles</a></h1>
@ -74,7 +73,9 @@
<span class="stat_module">
{{ scr.scrobbles({},{},{"perpage":15,"page":0},shortTimeDesc=True) }}
{% with amountkeys = {"perpage":15,"page":0}, shortTimeDesc=True %}
{% include 'partials/scrobbles.jinja' %}
{% endwith %}
</span>
@ -84,7 +85,6 @@
<!-- PULSE -->
{% import 'partials/pulse.jinja' as pls %}
<h1><a class="stat_link_pulse" href="/pulse?trail=1&step=month">Pulse</a></h1>
{% for range in xranges %}
@ -95,7 +95,9 @@
{% for range in xranges %}
<span class="stat_module_pulse pulse_{{ range.identifier }}" style="display:none;">
{{ pls.pulse({},{"since":range.firstrange},{"step":range.identifier},{}) }}
{% with limitkeys={"since":range.firstrange},delimitkeys={"step":range.identifier} %}
{% include 'partials/pulse.jinja' %}
{% endwith %}
</span>
{% endfor %}

View File

@ -20,13 +20,13 @@
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys,delimit=True) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys,delimit=True) }}
</td>
</tr>
</table>
{% import 'partials/top_artists.jinja' as top_artists %}
{{ top_artists.top_artists(limitkeys,delimitkeys,amountkeys) }}
{% include 'partials/top_artists.jinja' %}
{% endblock %}

View File

@ -20,13 +20,12 @@
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/><br/>
{{ htmlmodules.module_filterselection(_urikeys,delimit=True) }}
{% import 'snippets/timeselection.jinja' as timeselection %}
{{ timeselection.selector(filterkeys,limitkeys,delimitkeys,delimit=True) }}
</td>
</tr>
</table>
{% import 'partials/top_tracks.jinja' as top_tracks %}
{{ top_tracks.top_tracks(filterkeys,limitkeys,delimitkeys,amountkeys) }}
{% include 'partials/top_tracks.jinja' %}
{% endblock %}

View File

@ -47,7 +47,7 @@
<p class="stats">
{% if adminmode %}<span onclick="scrobble('{{ encodedtrack }}')" class="button">Scrobble now</span>{% endif %}
<a href="/scrobbles?{{ encodedtrack }}">{{ info['scrobbles'] }} Scrobbles</a>
<a href="{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}">{{ info['scrobbles'] }} Scrobbles</a>
</p>
@ -67,59 +67,60 @@
<tr>
<td>
<h2><a href='/pulse?{{ encodedtrack }}&amp;step=year&amp;trail=1'>Pulse</a></h2>
<h2><a href='{{ mlj_uri.create_uri("/pulse",filterkeys) }}'>Pulse</a></h2>
<br/>
{% for range in xranges %}
{% for r in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
onclick="showRangeManual('pulse','{{ r.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
{{ r.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/pulse.jinja' as pulse %}
{% for range in xranges %}
{% for r in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
class="stat_module_pulse pulse_{{ r.identifier }}"
style="{{ 'display:none;' if initialrange==r.identifier else '' }}"
>
{{ pulse.pulse(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
{% include 'partials/pulse.jinja' %}
{% endwith %}
</span>
{% endfor %}
</td>
<td>
<!-- We use the same classes / function calls here because we want it to switch together with pulse -->
<h2><a href='/performance?{{ encodedtrack }}&amp;step=year&amp;trail=1'>Performance</a></h2>
<h2><a href='{{ mlj_uri.create_uri("/performance",filterkeys) }}'>Performance</a></h2>
<br/>
{% for range in xranges %}
{% for r in xranges %}
<span
onclick="showRangeManual('pulse','{{ range.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ range.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==range.identifier else '' }}">
{{ range.localisation }}
onclick="showRangeManual('pulse','{{ r.identifier }}')"
class="stat_selector_pulse selector_pulse_{{ r.identifier }}"
style="{{ 'opacity:0.5;' if initialrange==r.identifier else '' }}">
{{ r.localisation }}
</span>
{% if not loop.last %}|{% endif %}
{% endfor %}
<br/><br/>
{% import 'partials/performance.jinja' as performance %}
{% for range in xranges %}
{% for r in xranges %}
<span
class="stat_module_pulse pulse_{{ range.identifier }}"
style="{{ 'display:none;' if initialrange==range.identifier else '' }}"
class="stat_module_pulse pulse_{{ r.identifier }}"
style="{{ 'display:none;' if initialrange==r.identifier else '' }}"
>
{{ performance.performance(filterkeys,{'since':range.firstrange},{'step':range.identifier,'trail':1},amountkeys) }}
{% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %}
{% include 'partials/performance.jinja' %}
{% endwith %}
</span>
{% endfor %}
@ -129,10 +130,11 @@
</table>
<h2><a href='/scrobbles?{{ encodedtrack }}'>Last Scrobbles</a></h2>
<h2><a href='{{ mlj_uri.create_uri("/scrobbles",filterkeys) }}'>Last Scrobbles</a></h2>
{% import 'partials/scrobbles.jinja' as scrobbles %}
{{ scrobbles.scrobbles(filterkeys,limitkeys,{"perpage":15,"page":0}) }}
{% with amountkeys = {"perpage":15,"page":0} %}
{% include 'partials/scrobbles.jinja' %}
{% endwith %}
{% endblock %}