From 25ba050d3097db40b271195aff9cc86e4457a7f2 Mon Sep 17 00:00:00 2001 From: krateng Date: Tue, 17 Oct 2023 12:55:25 +0200 Subject: [PATCH] Added quick associate functionality to web UI --- maloja/database/sqldb.py | 14 ++-- .../web/jinja/icons/association_cancel.jinja | 4 +- maloja/web/jinja/icons/association_mark.jinja | 4 +- maloja/web/jinja/partials/list_tracks.jinja | 19 ++++- maloja/web/static/css/maloja.css | 19 +++++ maloja/web/static/js/edit.js | 79 +++++++++++++++++-- 6 files changed, 120 insertions(+), 19 deletions(-) diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index a53dbf3..508fc4c 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -941,7 +941,7 @@ def count_scrobbles_by_artist(since,to,resolve_ids=True,dbconn=None): if resolve_ids: artists = get_artists_map([row.artist_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'artist':artists[row.artist_id]} for row in result] + result = [{'scrobbles':row.count,'artist':artists[row.artist_id],'artist_id':row.artist_id} for row in result] else: result = [{'scrobbles':row.count,'artist_id':row.artist_id} for row in result] result = rank(result,key='scrobbles') @@ -963,7 +963,7 @@ def count_scrobbles_by_track(since,to,resolve_ids=True,dbconn=None): if resolve_ids: tracks = get_tracks_map([row.track_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'track':tracks[row.track_id]} for row in result] + result = [{'scrobbles':row.count,'track':tracks[row.track_id],'track_id':row.track_id} for row in result] else: result = [{'scrobbles':row.count,'track_id':row.track_id} for row in result] result = rank(result,key='scrobbles') @@ -991,7 +991,7 @@ def count_scrobbles_by_album(since,to,resolve_ids=True,dbconn=None): if resolve_ids: albums = get_albums_map([row.album_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'album':albums[row.album_id]} for row in result] + result = [{'scrobbles':row.count,'album':albums[row.album_id],'album_id':row.album_id} for row in result] else: result = [{'scrobbles':row.count,'album_id':row.album_id} for row in result] result = rank(result,key='scrobbles') @@ -1028,7 +1028,7 @@ def count_scrobbles_by_album_of_artist(since,to,artist,resolve_ids=True,dbconn=N if resolve_ids: albums = get_albums_map([row.album_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'album':albums[row.album_id]} for row in result] + result = [{'scrobbles':row.count,'album':albums[row.album_id],'album_id':row.album_id} for row in result] else: result = [{'scrobbles':row.count,'album_id':row.album_id} for row in result] result = rank(result,key='scrobbles') @@ -1065,7 +1065,7 @@ def count_scrobbles_of_artist_by_album(since,to,artist,resolve_ids=True,dbconn=N if resolve_ids: albums = get_albums_map([row.album_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'album':albums[row.album_id]} for row in result] + result = [{'scrobbles':row.count,'album':albums[row.album_id],'album_id':row.album_id} for row in result] else: result = [{'scrobbles':row.count,'album_id':row.album_id} for row in result] result = rank(result,key='scrobbles') @@ -1097,7 +1097,7 @@ def count_scrobbles_by_track_of_artist(since,to,artist,resolve_ids=True,dbconn=N if resolve_ids: tracks = get_tracks_map([row.track_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'track':tracks[row.track_id]} for row in result] + result = [{'scrobbles':row.count,'track':tracks[row.track_id],'track_id':row.track_id} for row in result] else: result = [{'scrobbles':row.count,'track_id':row.track_id} for row in result] result = rank(result,key='scrobbles') @@ -1129,7 +1129,7 @@ def count_scrobbles_by_track_of_album(since,to,album,resolve_ids=True,dbconn=Non if resolve_ids: tracks = get_tracks_map([row.track_id for row in result],dbconn=dbconn) - result = [{'scrobbles':row.count,'track':tracks[row.track_id]} for row in result] + result = [{'scrobbles':row.count,'track':tracks[row.track_id],'track_id':row.track_id} for row in result] else: result = [{'scrobbles':row.count,'track_id':row.track_id} for row in result] result = rank(result,key='scrobbles') diff --git a/maloja/web/jinja/icons/association_cancel.jinja b/maloja/web/jinja/icons/association_cancel.jinja index a8d9615..9729378 100644 --- a/maloja/web/jinja/icons/association_cancel.jinja +++ b/maloja/web/jinja/icons/association_cancel.jinja @@ -1,5 +1,5 @@ -
- +
+ diff --git a/maloja/web/jinja/icons/association_mark.jinja b/maloja/web/jinja/icons/association_mark.jinja index 6b68dae..7e27ca5 100644 --- a/maloja/web/jinja/icons/association_mark.jinja +++ b/maloja/web/jinja/icons/association_mark.jinja @@ -1,5 +1,5 @@ -
- +
+
diff --git a/maloja/web/jinja/partials/list_tracks.jinja b/maloja/web/jinja/partials/list_tracks.jinja index bfef6de..0150bc8 100644 --- a/maloja/web/jinja/partials/list_tracks.jinja +++ b/maloja/web/jinja/partials/list_tracks.jinja @@ -6,16 +6,33 @@ {% set firstindex = amountkeys.page * amountkeys.perpage %} {% set lastindex = firstindex + amountkeys.perpage %} + {% for e in list %} {% if loop.index0 >= firstindex and loop.index0 < lastindex %} - + {{ entityrow.row(e['track']) }} + {% with inlineicons = True %} + + {% endwith %} + {% endif %} {% endfor %}
+ {% include 'icons/association_mark.jinja' %} + {% include 'icons/association_cancel.jinja' %} +
+ + diff --git a/maloja/web/static/css/maloja.css b/maloja/web/static/css/maloja.css index bd25e80..9d1ac30 100644 --- a/maloja/web/static/css/maloja.css +++ b/maloja/web/static/css/maloja.css @@ -83,7 +83,26 @@ div.clickable_icon.danger:hover svg { fill: red; } +#icon_bar svg { + width:24px; + height:24px; +} +.list svg { + height:16px; +} +.list div.clickable_icon { + display: inline-block; +} +.list tr.marked { + background-color: rgba(50,20,0,0.5); +} +.list tr.marked #associationmarkicon { + display:none; +} +.list tr:not(.marked) #associationcancelicon { + display:none; +} /** Footer diff --git a/maloja/web/static/js/edit.js b/maloja/web/static/js/edit.js index 2859708..2fb6d9c 100644 --- a/maloja/web/static/js/edit.js +++ b/maloja/web/static/js/edit.js @@ -310,17 +310,82 @@ function markForMerge() { showValidMergeIcons(); } -function markForAssociate() { +function markForAssociate(element) { + console.log(element); + const parentElement = element.closest('[data-entity_id]'); + console.log(parentElement); + // use local element for entity data, otherwise use from global scope (on entity info page) + var l_entity_type = parentElement ? parentElement.dataset.entity_type : entity_type; + var l_entity_id = parentElement ? parentElement.dataset.entity_id : entity_id; + var l_entity_name = parentElement ? parentElement.dataset.entity_name : entity_name; + l_entity_id = parseInt(l_entity_id); + + + const lcst = window.sessionStorage; + var key = "marked_for_associate_" + l_entity_type; + var current_stored = (lcst.getItem(key) || '').split(","); + current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x)); + current_stored.push(l_entity_id); + current_stored = [...new Set(current_stored)]; + lcst.setItem(key,current_stored); //this already formats it correctly + var whattoadd = ((l_entity_type == 'track') ? "Artists or Album" : "Artists") + notify("Marked " + l_entity_name + " to add " + whattoadd,"Currently " + current_stored.length + " marked!") + if (!parentElement) { + showValidMergeIcons(); + } + else { + toggleAssociationIcons(parentElement); + } + +} + +function umarkForAssociate(element) { + const parentElement = element.closest('[data-entity_id]'); + // use local element for entity data, otherwise use from global scope (on entity info page) + var l_entity_type = parentElement ? parentElement.dataset.entity_type : entity_type; + var l_entity_id = parentElement ? parentElement.dataset.entity_id : entity_id; + var l_entity_name = parentElement ? parentElement.dataset.entity_name : entity_name; + l_entity_id = parseInt(l_entity_id); + + const lcst = window.sessionStorage; + var key = "marked_for_associate_" + l_entity_type; + var current_stored = (lcst.getItem(key) || '').split(","); + current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x)); + + if (current_stored.indexOf(l_entity_id) > -1) { + current_stored.splice(current_stored.indexOf(l_entity_id),1); + current_stored = [...new Set(current_stored)]; + lcst.setItem(key,current_stored); //this already formats it correctly + var whattoadd = ((l_entity_type == 'track') ? "Artists or Album" : "Artists") + notify("Unmarked " + l_entity_name + " to add " + whattoadd,"Currently " + current_stored.length + " marked!") + if (!parentElement) { + showValidMergeIcons(); + } + else { + toggleAssociationIcons(parentElement); + } + } + else { + notify(entity_name + " was not marked!","") + } + +} + +function toggleAssociationIcons(element) { + var entity_type = element.dataset.entity_type; + var entity_id = element.dataset.entity_id; + entity_id = parseInt(entity_id); + const lcst = window.sessionStorage; var key = "marked_for_associate_" + entity_type; var current_stored = (lcst.getItem(key) || '').split(","); current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x)); - current_stored.push(entity_id); - current_stored = [...new Set(current_stored)]; - lcst.setItem(key,current_stored); //this already formats it correctly - var whattoadd = ((entity_type == 'track') ? "Artists or Album" : "Artists") - notify("Marked " + entity_name + " to add " + whattoadd,"Currently " + current_stored.length + " marked!") - showValidMergeIcons(); + + if (current_stored.indexOf(entity_id) > -1) { + element.classList.add('marked'); + } else { + element.classList.remove('marked'); + } } function merge() {