From d645707ff1ccc3ff2d5f9126ddc41129aea6dcaa Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 11 Aug 2023 18:57:27 +0200 Subject: [PATCH] Implemented client logic for association, GH-227 --- maloja/web/jinja/album.jinja | 4 +- maloja/web/jinja/artist.jinja | 2 +- maloja/web/jinja/icons/add_album.jinja | 2 +- maloja/web/jinja/icons/add_artist.jinja | 2 +- .../web/jinja/icons/association_cancel.jinja | 7 + maloja/web/jinja/icons/association_mark.jinja | 5 + maloja/web/jinja/track.jinja | 4 +- maloja/web/static/js/edit.js | 128 ++++++++++++++++++ 8 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 maloja/web/jinja/icons/association_cancel.jinja create mode 100644 maloja/web/jinja/icons/association_mark.jinja diff --git a/maloja/web/jinja/album.jinja b/maloja/web/jinja/album.jinja index b697b07..3142c9c 100644 --- a/maloja/web/jinja/album.jinja +++ b/maloja/web/jinja/album.jinja @@ -23,7 +23,9 @@ {% include 'icons/merge.jinja' %} {% include 'icons/merge_mark.jinja' %} {% include 'icons/merge_cancel.jinja' %} - {% include 'icons/add_album_confirm.jinja' %} + {% include 'icons/add_album.jinja' %} + {% include 'icons/association_mark.jinja' %} + {% include 'icons/association_cancel.jinja' %} {% endif %} {% endblock %} diff --git a/maloja/web/jinja/artist.jinja b/maloja/web/jinja/artist.jinja index ccde8a2..189005e 100644 --- a/maloja/web/jinja/artist.jinja +++ b/maloja/web/jinja/artist.jinja @@ -33,7 +33,7 @@ {% include 'icons/merge.jinja' %} {% include 'icons/merge_mark.jinja' %} {% include 'icons/merge_cancel.jinja' %} - {% include 'icons/add_artist_confirm.jinja' %} + {% include 'icons/add_artist.jinja' %} {% endif %} {% endblock %} diff --git a/maloja/web/jinja/icons/add_album.jinja b/maloja/web/jinja/icons/add_album.jinja index 1a3d942..11d2d67 100644 --- a/maloja/web/jinja/icons/add_album.jinja +++ b/maloja/web/jinja/icons/add_album.jinja @@ -1,4 +1,4 @@ -
+
diff --git a/maloja/web/jinja/icons/add_artist.jinja b/maloja/web/jinja/icons/add_artist.jinja index a86e973..07a958f 100644 --- a/maloja/web/jinja/icons/add_artist.jinja +++ b/maloja/web/jinja/icons/add_artist.jinja @@ -1,4 +1,4 @@ -
+
diff --git a/maloja/web/jinja/icons/association_cancel.jinja b/maloja/web/jinja/icons/association_cancel.jinja new file mode 100644 index 0000000..a8d9615 --- /dev/null +++ b/maloja/web/jinja/icons/association_cancel.jinja @@ -0,0 +1,7 @@ +
+ + + + + +
diff --git a/maloja/web/jinja/icons/association_mark.jinja b/maloja/web/jinja/icons/association_mark.jinja new file mode 100644 index 0000000..6b68dae --- /dev/null +++ b/maloja/web/jinja/icons/association_mark.jinja @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/maloja/web/jinja/track.jinja b/maloja/web/jinja/track.jinja index cad536b..f1c084a 100644 --- a/maloja/web/jinja/track.jinja +++ b/maloja/web/jinja/track.jinja @@ -28,8 +28,8 @@ {% include 'icons/merge.jinja' %} {% include 'icons/merge_mark.jinja' %} {% include 'icons/merge_cancel.jinja' %} - {% include 'icons/add_artist.jinja' %} - {% include 'icons/add_album.jinja' %} + {% include 'icons/association_mark.jinja' %} + {% include 'icons/association_cancel.jinja' %} {% endif %} {% endblock %} diff --git a/maloja/web/static/js/edit.js b/maloja/web/static/js/edit.js index e25f9c9..c9369b4 100644 --- a/maloja/web/static/js/edit.js +++ b/maloja/web/static/js/edit.js @@ -190,6 +190,8 @@ function doneEditing() { // MERGING function showValidMergeIcons() { + + // merge const lcst = window.sessionStorage; var key = "marked_for_merge_" + entity_type; var current_stored = (lcst.getItem(key) || '').split(","); @@ -218,6 +220,74 @@ function showValidMergeIcons() { } } + // mark for association + if ((entity_type == 'track') || (entity_type == 'album')) { + 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)); + + var associationmarkicon = document.getElementById('associationmarkicon'); + var associationcancelicon = document.getElementById('associationcancelicon'); + + associationmarkicon.classList.add('hide'); + associationcancelicon.classList.add('hide'); + + + if (current_stored.length == 0) { + associationmarkicon.classList.remove('hide'); + } + else { + associationcancelicon.classList.remove('hide'); + + if (current_stored.includes(entity_id)) { + + } + else { + associationmarkicon.classList.remove('hide'); + } + } + } + + + + // association confirm + if ((entity_type == 'artist') || (entity_type == 'album')) { + var target_entity_types = {artist:['album','track'], album:['track']}; + var to_associate = {}; + var to_associate_all = []; + for (var target_entity_type of target_entity_types[entity_type]) { + const lcst = window.sessionStorage; + var key = "marked_for_associate_" + target_entity_type; + var current_stored = (lcst.getItem(key) || '').split(","); + to_associate[target_entity_type] = current_stored.filter((x)=>x).map((x)=>parseInt(x)); + to_associate_all = to_associate_all.concat(to_associate[target_entity_type]); + } + + var associateicon = document.getElementById('associate' + entity_type + 'icon'); + + associateicon.classList.add('hide'); + + + if (to_associate_all.length == 0) { + + } + else { + associateicon.classList.remove('hide'); + if (entity_type == 'artist') { + associateicon.title = "Add this artist to " + to_associate['album'].length + " albums and " + to_associate['track'].length + " tracks"; + } + else { + associateicon.title = "Add " + to_associate['track'].length + " tracks to this album"; + } + + } + } + + + + + } @@ -233,6 +303,19 @@ function markForMerge() { showValidMergeIcons(); } +function markForAssociate() { + 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(); +} + function merge() { const lcst = window.sessionStorage; var key = "marked_for_merge_" + entity_type; @@ -262,6 +345,44 @@ function merge() { lcst.removeItem(key); } + + +function associate() { + const lcst = window.sessionStorage; + var target_entity_types = {artist:['album','track'], album:['track']}; + for (var target_entity_type of target_entity_types[entity_type]) { + var key = "marked_for_associate_" + target_entity_type; + console.log('get',key); + var current_stored = (lcst.getItem(key) || '').split(","); + current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x)); + + callback_func = function(req){ + if (req.status == 200) { + //window.location.reload(); + showValidMergeIcons(); + notifyCallback(req); + } + else { + notifyCallback(req); + } + }; + + neo.xhttpreq( + "/apis/mlj_1/associate_" + target_entity_type + "s_to_" + entity_type, + data={ + 'source_ids':current_stored, + 'target_id':entity_id + }, + method="POST", + callback=callback_func, + json=true + ); + + lcst.removeItem(key); + } + +} + function cancelMerge() { const lcst = window.sessionStorage; var key = "marked_for_merge_" + entity_type; @@ -269,3 +390,10 @@ function cancelMerge() { showValidMergeIcons(); notify("Cancelled merge!","") } +function cancelAssociate() { + const lcst = window.sessionStorage; + var key = "marked_for_associate_" + entity_type; + lcst.setItem(key,[]); + showValidMergeIcons(); + notify("Cancelled association!","") +}