From 27a2bc705a6fa78dbd52b5f1e2258074c48710b4 Mon Sep 17 00:00:00 2001 From: krateng Date: Tue, 28 Mar 2023 20:26:46 +0200 Subject: [PATCH] Added web pages for albums --- maloja/web/jinja/album.jinja | 154 ++++++++++++++++++ maloja/web/jinja/charts_albums.jinja | 52 ++++++ maloja/web/jinja/partials/awards_album.jinja | 42 +++++ maloja/web/jinja/partials/charts_albums.jinja | 56 +++++++ .../jinja/partials/charts_albums_tiles.jinja | 45 +++++ maloja/web/jinja/partials/top_albums.jinja | 30 ++++ maloja/web/jinja/snippets/entityrow.jinja | 8 +- .../jinja/snippets/filterdescription.jinja | 3 + maloja/web/jinja/snippets/links.jinja | 8 +- maloja/web/jinja/top_albums.jinja | 30 ++++ 10 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 maloja/web/jinja/album.jinja create mode 100644 maloja/web/jinja/charts_albums.jinja create mode 100644 maloja/web/jinja/partials/awards_album.jinja create mode 100644 maloja/web/jinja/partials/charts_albums.jinja create mode 100644 maloja/web/jinja/partials/charts_albums_tiles.jinja create mode 100644 maloja/web/jinja/partials/top_albums.jinja create mode 100644 maloja/web/jinja/top_albums.jinja diff --git a/maloja/web/jinja/album.jinja b/maloja/web/jinja/album.jinja new file mode 100644 index 0000000..4a6f855 --- /dev/null +++ b/maloja/web/jinja/album.jinja @@ -0,0 +1,154 @@ +{% extends "abstracts/base.jinja" %} +{% block title %}Maloja - {{ info.album.albumtitle }}{% endblock %} + +{% import 'snippets/links.jinja' as links %} + +{% block scripts %} + + +{% endblock %} + +{% set album = filterkeys.album %} +{% set info = dbc.album_info({'album':album}) %} + +{% set initialrange ='month' %} + + +{% set encodedalbum = mlj_uri.uriencode({'album':album}) %} + + +{% block icon_bar %} + {% if adminmode %} + {% include 'icons/edit.jinja' %} + {% include 'icons/merge.jinja' %} + {% include 'icons/merge_mark.jinja' %} + {% include 'icons/merge_cancel.jinja' %} + + {% endif %} +{% endblock %} + +{% block content %} + + + + +{% import 'partials/awards_album.jinja' as awards %} + + + + + + + +
+ {% if adminmode %} +
+ {% else %} +
+
+ {% endif %} +
+ {{ links.links(album.artists) }}
+

{{ info.album.albumtitle | e }}

+ {# awards.certs(album) #} + #{{ info.position }} +
+ +

+ {{ info['scrobbles'] }} Scrobbles +

+ + + + + + {{ awards.medals(info) }} + {{ awards.topweeks(info) }} + + +
+ + + + + + + + +
+

Pulse

+
+ {% for r in xranges %} + + {{ r.localisation }} + + {% if not loop.last %}|{% endif %} + {% endfor %} + +

+ + {% for r in xranges %} + + + + {% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %} + {% include 'partials/pulse.jinja' %} + {% endwith %} + + + {% endfor %} +
+ +

Performance

+
+ {% for r in xranges %} + + {{ r.localisation }} + + {% if not loop.last %}|{% endif %} + {% endfor %} + +

+ + {% for r in xranges %} + + + + {% with limitkeys={"since":r.firstrange},delimitkeys={'step':r.identifier,'trail':1} %} + {% include 'partials/performance.jinja' %} + {% endwith %} + + + {% endfor %} + +
+ + +

Last Scrobbles

+ +{% with amountkeys = {"perpage":15,"page":0} %} +{% include 'partials/scrobbles.jinja' %} +{% endwith %} + + +{% endblock %} diff --git a/maloja/web/jinja/charts_albums.jinja b/maloja/web/jinja/charts_albums.jinja new file mode 100644 index 0000000..7d2667a --- /dev/null +++ b/maloja/web/jinja/charts_albums.jinja @@ -0,0 +1,52 @@ +{% extends "abstracts/base.jinja" %} +{% block title %}Maloja - Album Charts{% endblock %} + +{% import 'snippets/links.jinja' as links %} + +{% block scripts %} + +{% endblock %} + +{% set charts = dbc.get_charts_albums(filterkeys,limitkeys) %} +{% set pages = math.ceil(charts.__len__() / amountkeys.perpage) %} +{% if charts[0] is defined %} + {% set topalbum = charts[0].album %} + {% set img = images.get_album_image(topalbum) %} +{% else %} + {% set img = "/favicon.png" %} +{% endif %} + + +{% block content %} + + + + + + +
+
+
+

Album Charts

View #1 Albums
+ {% if filterkeys.get('artist') is not none %}by {{ links.link(filterkeys.get('artist')) }}{% endif %} + {{ limitkeys.timerange.desc(prefix=True) }} +

+ {% with delimitkeys = {} %} + {% include 'snippets/timeselection.jinja' %} + {% endwith %} + +
+ +{% if settings['CHARTS_DISPLAY_TILES'] %} + {% include 'partials/charts_albums_tiles.jinja' %} +

+{% endif %} + +{% with compare=true %} +{% include 'partials/charts_albums.jinja' %} +{% endwith %} + +{% import 'snippets/pagination.jinja' as pagination %} +{{ pagination.pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages) }} + +{% endblock %} diff --git a/maloja/web/jinja/partials/awards_album.jinja b/maloja/web/jinja/partials/awards_album.jinja new file mode 100644 index 0000000..5ded047 --- /dev/null +++ b/maloja/web/jinja/partials/awards_album.jinja @@ -0,0 +1,42 @@ +{% macro medals(info) %} + + +{% for year in info.medals.gold -%} + + {{ year }} + +{%- endfor %} +{% for year in info.medals.silver -%} + + {{ year }} + +{%- endfor %} +{% for year in info.medals.bronze -%} + + {{ year }} + +{%- endfor %} + +{%- endmacro %} + + + + + + + + +{% macro topweeks(info) %} + +{% set encodedtrack = mlj_uri.uriencode({'album':info.album}) %} + + + + {% if info.topweeks > 0 %} + + {{ info.topweeks }} + + {% endif %} + + +{%- endmacro %} diff --git a/maloja/web/jinja/partials/charts_albums.jinja b/maloja/web/jinja/partials/charts_albums.jinja new file mode 100644 index 0000000..b6bcc0f --- /dev/null +++ b/maloja/web/jinja/partials/charts_albums.jinja @@ -0,0 +1,56 @@ +{% import 'snippets/links.jinja' as links %} +{% import 'snippets/entityrow.jinja' as entityrow %} + +{% if charts is undefined %} + {% set charts = dbc.get_charts_albums(filterkeys,limitkeys) %} +{% endif %} +{% if compare %} + {% if compare is true %} + {% set compare = limitkeys.timerange.next(step=-1) %} + {% if compare is none %}{% set compare = False %}{% endif %} + {% endif %} + {% if compare %} + {% set prevalbums = dbc.get_charts_albums(filterkeys,{'timerange':compare}) %} + + {% set lastranks = {} %} + {% for t in prevalbums %} + {% if lastranks.update({"|".join(t.album.artists)+"||"+t.album.albumtitle:t.rank}) %}{% endif %} + {% endfor %} + + {% for t in charts %} + {% if "|".join(t.album.artists)+"||"+t.album.albumtitle in lastranks %} + {% if t.update({'last_rank':lastranks["|".join(t.album.artists)+"||"+t.album.albumtitle]}) %}{% endif %} + {% endif %} + {% endfor %} + {% endif %} +{% endif %} + +{% set firstindex = amountkeys.page * amountkeys.perpage %} +{% set lastindex = firstindex + amountkeys.perpage %} + +{% set maxbar = charts[0]['scrobbles'] if charts != [] else 0 %} + + {% for e in charts %} + {% if loop.index0 >= firstindex and loop.index0 < lastindex %} + + + + + {% if compare %} + {% if e.last_rank is undefined %} + {% elif e.last_rank < e.rank %} + {% elif e.last_rank > e.rank %} + {% elif e.last_rank == e.rank %} + {% endif %} + {% endif %} + + + {{ entityrow.row(e['album']) }} + + + + + + {% endif %} + {% endfor %} +
{%if loop.changed(e.scrobbles) %}#{{ e.rank }}{% endif %}🆕↘↗➡{{ links.link_scrobbles([{'album':e.album,'timerange':limitkeys.timerange}],amount=e['scrobbles']) }}{{ links.link_scrobbles([{'album':e.album,'timerange':limitkeys.timerange}],percent=e['scrobbles']*100/maxbar) }}
diff --git a/maloja/web/jinja/partials/charts_albums_tiles.jinja b/maloja/web/jinja/partials/charts_albums_tiles.jinja new file mode 100644 index 0000000..56e3c4e --- /dev/null +++ b/maloja/web/jinja/partials/charts_albums_tiles.jinja @@ -0,0 +1,45 @@ +{% import 'snippets/links.jinja' as links %} + + +{% if charts is undefined %} + {% set charts = dbc.get_charts_albums(limitkeys) %} +{% endif %} + +{% set charts_14 = charts | fixlength(14) %} +{% set charts_cycler = cycler(*charts_14) %} + + + + +{% for segment in range(3) %} + {% if charts_14[0] is none and loop.first %} + {% include 'icons/nodata.jinja' %} + {% else %} + + {% endif %} +{% endfor %} +
+ {% set segmentsize = segment+1 %} + + {% for row in range(segmentsize) -%} + + {% for col in range(segmentsize) %} + {% set entry = charts_cycler.next() %} + {% if entry is not none %} + {% set album = entry.album %} + {% set rank = entry.rank %} + + {% else -%} + + {%- endif -%} + {%- endfor -%} + + {%- endfor -%} +
+ +
+ #{{ rank }} {{ album.title }} +
+
+
+
diff --git a/maloja/web/jinja/partials/top_albums.jinja b/maloja/web/jinja/partials/top_albums.jinja new file mode 100644 index 0000000..cdedd6a --- /dev/null +++ b/maloja/web/jinja/partials/top_albums.jinja @@ -0,0 +1,30 @@ +{% import 'snippets/links.jinja' as links %} +{% import 'snippets/entityrow.jinja' as entityrow %} + +{% set ranges = dbc.get_top_albums(filterkeys,limitkeys,delimitkeys) %} + +{% set maxbar = ranges|map(attribute="scrobbles")|max|default(1) %} +{% if maxbar < 1 %}{% set maxbar = 1 %}{% endif %} + + + {% for e in ranges %} + + {% set thisrange = e.range %} + {% set album = e.album %} + + + + {% if album is none %} + + + + + {% else %} + {{ entityrow.row(album) }} + + + {% endif %} + + + {% endfor %} +
{{ thisrange.desc() }}
n/a0{{ links.link_scrobbles([{'album':album,'timerange':thisrange}],amount=e.scrobbles) }} {{ links.link_scrobbles([{'album':album,'timerange':thisrange}],percent=e.scrobbles*100/maxbar) }}
diff --git a/maloja/web/jinja/snippets/entityrow.jinja b/maloja/web/jinja/snippets/entityrow.jinja index 7601fea..2721f0c 100644 --- a/maloja/web/jinja/snippets/entityrow.jinja +++ b/maloja/web/jinja/snippets/entityrow.jinja @@ -2,8 +2,10 @@ {% import 'snippets/links.jinja' as links %} -{% if entity is mapping and 'artists' in entity %} +{% if entity is mapping and 'title' in entity %} {% set img = images.get_track_image(entity) %} +{% elif entity is mapping and 'albumtitle' in entity %} + {% set img = images.get_album_image(entity) %} {% else %} {% set img = images.get_artist_image(entity) %} {% endif %} @@ -20,6 +22,10 @@ {{ links.links(entity.artists) }} – {{ links.link(entity) }} +{% elif entity is mapping and 'albumtitle' in entity %} + + {{ links.links(entity.artists) }} – {{ links.link(entity) }} + {% else %} {{ links.link(entity) }} {% if counting != [] %} diff --git a/maloja/web/jinja/snippets/filterdescription.jinja b/maloja/web/jinja/snippets/filterdescription.jinja index 820d501..4a5135f 100644 --- a/maloja/web/jinja/snippets/filterdescription.jinja +++ b/maloja/web/jinja/snippets/filterdescription.jinja @@ -7,6 +7,9 @@ {% elif filterkeys.get('track') is not none %} of {{ links.link(filterkeys.get('track')) }} by {{ links.links(filterkeys["track"]["artists"]) }} + {% elif filterkeys.get('album') is not none %} + of {{ links.link(filterkeys.get('album')) }} + by {{ links.links(filterkeys["album"]["artists"]) }} {% endif %} {{ limitkeys.timerange.desc(prefix=True) }} diff --git a/maloja/web/jinja/snippets/links.jinja b/maloja/web/jinja/snippets/links.jinja index e53a39f..e49b2c3 100644 --- a/maloja/web/jinja/snippets/links.jinja +++ b/maloja/web/jinja/snippets/links.jinja @@ -1,6 +1,6 @@ {% macro link(entity) -%} {% if entity is mapping and 'artists' in entity %} - {% set name = entity.title %} + {% set name = entity.title or entity.albumtitle %} {% else %} {% set name = entity %} {% endif %} @@ -17,7 +17,9 @@ {% macro url(entity) %} - {% if entity is mapping and 'artists' in entity -%} + {% if entity is mapping and 'albumtitle' in entity -%} + {{ mlj_uri.create_uri("/album",{'album':entity}) }} + {% elif entity is mapping and 'artists' in entity -%} {{ mlj_uri.create_uri("/track",{'track':entity}) }} {%- else -%} {{ mlj_uri.create_uri("/artist",{'artist':entity}) }} @@ -43,6 +45,8 @@ {% if 'track' in filterkeys %} {% set url = mlj_uri.create_uri("/charts_tracks",{'timerange':timerange}) %} + {% elif 'album' in filterkeys %} + {% set url = mlj_uri.create_uri("/charts_albums",{'timerange':timerange}) %} {% elif 'artist' in filterkeys %} {% set url = mlj_uri.create_uri("/charts_artists",{'timerange':timerange}) %} {% endif %} diff --git a/maloja/web/jinja/top_albums.jinja b/maloja/web/jinja/top_albums.jinja new file mode 100644 index 0000000..c7a0782 --- /dev/null +++ b/maloja/web/jinja/top_albums.jinja @@ -0,0 +1,30 @@ +{% extends "abstracts/base.jinja" %} +{% block title %}Maloja - #1 Albums{% endblock %} + + + + +{% set entries = dbc.get_top_albums(filterkeys,limitkeys,delimitkeys) %} +{% set repr = entries | find_representative('album','scrobbles') %} +{% set img = "/favicon.png" if repr is none else images.get_album_image(repr.album) %} + + +{% block content %} + + + + + +
+
+
+

#1 Albums


+ {{ limitkeys.timerange.desc(prefix=True) }} + +

+ {% include 'snippets/timeselection.jinja' %} +
+ + {% include 'partials/top_albums.jinja' %} + +{% endblock %}