From 57e66fdafd3dea72231dfc9e5a03fd87543bb3b5 Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 17 Apr 2022 17:24:23 +0200 Subject: [PATCH] Added client logic for merging --- maloja/web/static/js/edit.js | 65 +++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/maloja/web/static/js/edit.js b/maloja/web/static/js/edit.js index 9df0c19..d60f7fd 100644 --- a/maloja/web/static/js/edit.js +++ b/maloja/web/static/js/edit.js @@ -1,19 +1,6 @@ // JS for all web interface editing / deletion of scrobble data - - -function toggleDeleteConfirm(element) { - element.parentElement.parentElement.classList.toggle('active'); -} - -function deleteScrobble(id,element) { - element.parentElement.parentElement.parentElement.classList.add('removed'); - - neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true); - -} - - +// HELPERS function selectAll(e) { // https://stackoverflow.com/a/6150060/6651341 var range = document.createRange(); @@ -23,6 +10,18 @@ function selectAll(e) { sel.addRange(range); } +// DELETION +function toggleDeleteConfirm(element) { + element.parentElement.parentElement.classList.toggle('active'); +} + +function deleteScrobble(id,element) { + element.parentElement.parentElement.parentElement.classList.add('removed'); + neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=(()=>null),json=true); +} + + +// EDIT NAME function editEntity() { var namefield = document.getElementById('main_entity_name'); @@ -40,20 +39,18 @@ function editEntity() { namefield.textContent = entity_name; namefield.blur(); } - }) + // emergency, not pretty because it will move cursor namefield.addEventListener('input',function(e){ if (namefield.textContent.includes("\n")) { namefield.textContent = namefield.textContent.replace("\n",""); } - }) // manually clicking away OR enter namefield.addEventListener('blur',function(e){ doneEditing(); - }) namefield.focus(); @@ -88,6 +85,36 @@ function doneEditing() { json=true ); } - - +} + +// MERGING + +function markForMerge() { + const lcst = window.localStorage; + var key = "marked_for_merge_" + 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 +} + +function merge() { + const lcst = window.localStorage; + var key = "marked_for_merge_" + entity_type; + var current_stored = lcst.getItem(key).split(","); + current_stored = current_stored.filter((x)=>x).map((x)=>parseInt(x)); + + neo.xhttpreq( + "/apis/mlj_1/merge_" + entity_type + "s", + data={ + 'source_ids':current_stored, + 'target_id':entity_id + }, + method="POST", + callback=(()=>window.location.reload()), + json=true + ); + + lcst.removeItem(key); }