2022-04-07 21:23:03 +03:00
|
|
|
|
// JS for all web interface editing / deletion of scrobble data
|
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
// HELPERS
|
|
|
|
|
function selectAll(e) {
|
|
|
|
|
// https://stackoverflow.com/a/6150060/6651341
|
|
|
|
|
var range = document.createRange();
|
|
|
|
|
range.selectNodeContents(e);
|
|
|
|
|
var sel = window.getSelection();
|
|
|
|
|
sel.removeAllRanges();
|
|
|
|
|
sel.addRange(range);
|
|
|
|
|
}
|
2022-04-17 16:15:29 +03:00
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
// DELETION
|
2022-04-07 21:23:03 +03:00
|
|
|
|
function toggleDeleteConfirm(element) {
|
|
|
|
|
element.parentElement.parentElement.classList.toggle('active');
|
2022-04-22 19:29:09 +03:00
|
|
|
|
element.parentElement.parentElement.parentElement.classList.toggle('active');
|
2022-04-07 21:23:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteScrobble(id,element) {
|
2022-04-17 21:18:44 +03:00
|
|
|
|
var callback_func = function(req){
|
|
|
|
|
if (req.status == 200) {
|
2022-04-22 19:43:40 +03:00
|
|
|
|
element.parentElement.parentElement.parentElement.parentElement.classList.add('removed');
|
2022-04-17 21:18:44 +03:00
|
|
|
|
notifyCallback(req);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
notifyCallback(req);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
neo.xhttpreq("/apis/mlj_1/delete_scrobble",data={'timestamp':id},method="POST",callback=callback_func,json=true);
|
2022-04-07 21:23:03 +03:00
|
|
|
|
}
|
2022-04-15 19:16:54 +03:00
|
|
|
|
|
2022-04-22 19:29:09 +03:00
|
|
|
|
// REPARSING
|
|
|
|
|
|
|
|
|
|
function toggleReparseConfirm(element) {
|
|
|
|
|
element.parentElement.parentElement.classList.toggle('active');
|
|
|
|
|
element.parentElement.parentElement.parentElement.classList.toggle('active');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function reparseScrobble(id, element) {
|
|
|
|
|
toggleReparseConfirm(element);
|
|
|
|
|
|
2022-04-22 22:37:48 +03:00
|
|
|
|
callback_func = function(req){
|
|
|
|
|
if (req.status == 200) {
|
|
|
|
|
if (req.response.status != 'no_operation') {
|
2022-04-25 21:48:22 +03:00
|
|
|
|
//window.location.reload();
|
|
|
|
|
notifyCallback(req);
|
|
|
|
|
var newtrack = req.response.scrobble.track;
|
|
|
|
|
var row = element.parentElement.parentElement.parentElement.parentElement;
|
|
|
|
|
changeScrobbleRow(row,newtrack);
|
2022-04-22 22:37:48 +03:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
notifyCallback(req);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
notifyCallback(req);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
neo.xhttpreq("/apis/mlj_1/reparse_scrobble",data={'timestamp':id},method="POST",callback=callback_func,json=true);
|
2022-04-22 19:29:09 +03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-25 21:48:22 +03:00
|
|
|
|
function changeScrobbleRow(element,newtrack) {
|
|
|
|
|
element.classList.add('changed');
|
|
|
|
|
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
element.getElementsByClassName('track')[0].innerHTML = createTrackCell(newtrack);
|
|
|
|
|
},200);
|
|
|
|
|
setTimeout(function(){element.classList.remove('changed')},300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createTrackCell(trackinfo) {
|
|
|
|
|
|
|
|
|
|
var trackquery = new URLSearchParams();
|
|
|
|
|
trackinfo.artists.forEach((a)=>trackquery.append('artist',a));
|
|
|
|
|
trackquery.append('title',trackinfo.title);
|
|
|
|
|
|
|
|
|
|
tracklink = document.createElement('a');
|
|
|
|
|
tracklink.href = "/track?" + trackquery.toString();
|
|
|
|
|
tracklink.textContent = trackinfo.title;
|
|
|
|
|
|
|
|
|
|
artistelements = []
|
|
|
|
|
var artistholder = document.createElement('span');
|
|
|
|
|
artistholder.classList.add('artist_in_trackcolumn');
|
|
|
|
|
for (var a of trackinfo.artists) {
|
|
|
|
|
var artistquery = new URLSearchParams();
|
|
|
|
|
artistquery.append('artist',a);
|
|
|
|
|
|
|
|
|
|
artistlink = document.createElement('a');
|
|
|
|
|
artistlink.href = "/artist?" + artistquery.toString();
|
|
|
|
|
artistlink.textContent = a;
|
|
|
|
|
|
|
|
|
|
artistelements.push(artistlink.outerHTML)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
artistholder.innerHTML = artistelements.join(", ");
|
|
|
|
|
return artistholder.outerHTML + " – " + tracklink.outerHTML;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 19:16:54 +03:00
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
// EDIT NAME
|
2022-04-15 19:16:54 +03:00
|
|
|
|
function editEntity() {
|
2022-04-17 16:15:29 +03:00
|
|
|
|
|
2022-04-15 19:16:54 +03:00
|
|
|
|
var namefield = document.getElementById('main_entity_name');
|
2023-02-26 00:18:57 +03:00
|
|
|
|
try {
|
|
|
|
|
namefield.contentEditable = "plaintext-only"; // not supported by Firefox
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
namefield.contentEditable = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 19:16:54 +03:00
|
|
|
|
|
2022-04-17 16:15:29 +03:00
|
|
|
|
namefield.addEventListener('keydown',function(e){
|
|
|
|
|
// dont allow new lines, done on enter
|
|
|
|
|
if (e.key === "Enter") {
|
2022-04-15 19:16:54 +03:00
|
|
|
|
e.preventDefault();
|
2022-04-16 03:17:14 +03:00
|
|
|
|
namefield.blur(); // this leads to below
|
2022-04-15 19:16:54 +03:00
|
|
|
|
}
|
2022-04-17 16:15:29 +03:00
|
|
|
|
// cancel on esc
|
|
|
|
|
else if (e.key === "Escape" || e.key === "Esc") {
|
|
|
|
|
e.preventDefault();
|
2022-04-17 16:24:36 +03:00
|
|
|
|
namefield.textContent = entity_name;
|
2022-04-17 16:15:29 +03:00
|
|
|
|
namefield.blur();
|
|
|
|
|
}
|
2022-04-15 19:16:54 +03:00
|
|
|
|
})
|
2022-04-17 18:24:23 +03:00
|
|
|
|
|
2022-04-15 19:16:54 +03:00
|
|
|
|
// emergency, not pretty because it will move cursor
|
|
|
|
|
namefield.addEventListener('input',function(e){
|
2022-04-17 16:24:36 +03:00
|
|
|
|
if (namefield.textContent.includes("\n")) {
|
|
|
|
|
namefield.textContent = namefield.textContent.replace("\n","");
|
2022-04-15 19:16:54 +03:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-16 03:17:14 +03:00
|
|
|
|
// manually clicking away OR enter
|
2022-04-15 19:48:03 +03:00
|
|
|
|
namefield.addEventListener('blur',function(e){
|
|
|
|
|
doneEditing();
|
|
|
|
|
})
|
|
|
|
|
|
2022-04-15 19:16:54 +03:00
|
|
|
|
namefield.focus();
|
|
|
|
|
selectAll(namefield);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doneEditing() {
|
2022-04-17 17:36:33 +03:00
|
|
|
|
window.getSelection().removeAllRanges();
|
2022-04-15 19:16:54 +03:00
|
|
|
|
var namefield = document.getElementById('main_entity_name');
|
|
|
|
|
namefield.contentEditable = "false";
|
2022-04-17 16:24:36 +03:00
|
|
|
|
newname = namefield.textContent;
|
2022-04-15 20:41:44 +03:00
|
|
|
|
|
2022-04-17 16:15:29 +03:00
|
|
|
|
if (newname != entity_name) {
|
|
|
|
|
var searchParams = new URLSearchParams(window.location.search);
|
|
|
|
|
|
|
|
|
|
if (entity_type == 'artist') {
|
|
|
|
|
var endpoint = "/apis/mlj_1/edit_artist";
|
|
|
|
|
searchParams.set("artist", newname);
|
|
|
|
|
var payload = {'id':entity_id,'name':newname};
|
|
|
|
|
}
|
|
|
|
|
else if (entity_type == 'track') {
|
|
|
|
|
var endpoint = "/apis/mlj_1/edit_track";
|
|
|
|
|
searchParams.set("title", newname);
|
|
|
|
|
var payload = {'id':entity_id,'title':newname}
|
|
|
|
|
}
|
2023-03-29 01:19:40 +03:00
|
|
|
|
else if (entity_type == 'album') {
|
|
|
|
|
var endpoint = "/apis/mlj_1/edit_album";
|
|
|
|
|
searchParams.set("albumtitle", newname);
|
|
|
|
|
var payload = {'id':entity_id,'albumtitle':newname}
|
|
|
|
|
}
|
2022-04-17 16:15:29 +03:00
|
|
|
|
|
2022-04-17 21:18:44 +03:00
|
|
|
|
callback_func = function(req){
|
|
|
|
|
if (req.status == 200) {
|
|
|
|
|
window.location = "?" + searchParams.toString();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
notifyCallback(req);
|
2022-04-21 17:00:29 +03:00
|
|
|
|
namefield.textContent = entity_name;
|
2022-04-17 21:18:44 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-17 16:15:29 +03:00
|
|
|
|
neo.xhttpreq(
|
|
|
|
|
endpoint,
|
|
|
|
|
data=payload,
|
|
|
|
|
method="POST",
|
2022-04-17 21:18:44 +03:00
|
|
|
|
callback=callback_func,
|
2022-04-17 16:15:29 +03:00
|
|
|
|
json=true
|
|
|
|
|
);
|
2022-04-15 20:41:44 +03:00
|
|
|
|
}
|
2022-04-17 18:24:23 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MERGING
|
2022-04-15 19:48:03 +03:00
|
|
|
|
|
2022-04-21 18:02:10 +03:00
|
|
|
|
function showValidMergeIcons() {
|
|
|
|
|
const lcst = window.sessionStorage;
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
var mergeicon = document.getElementById('mergeicon');
|
|
|
|
|
var mergemarkicon = document.getElementById('mergemarkicon');
|
|
|
|
|
var mergecancelicon = document.getElementById('mergecancelicon');
|
|
|
|
|
|
|
|
|
|
mergeicon.classList.add('hide');
|
|
|
|
|
mergemarkicon.classList.add('hide');
|
|
|
|
|
mergecancelicon.classList.add('hide');
|
2022-04-07 21:23:03 +03:00
|
|
|
|
|
2022-04-21 18:02:10 +03:00
|
|
|
|
if (current_stored.length == 0) {
|
|
|
|
|
mergemarkicon.classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mergecancelicon.classList.remove('hide');
|
|
|
|
|
|
|
|
|
|
if (current_stored.includes(entity_id)) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
mergemarkicon.classList.remove('hide');
|
|
|
|
|
mergeicon.classList.remove('hide');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
function markForMerge() {
|
2022-04-17 21:23:49 +03:00
|
|
|
|
const lcst = window.sessionStorage;
|
2022-04-17 18:24:23 +03:00
|
|
|
|
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
|
2022-04-22 21:34:46 +03:00
|
|
|
|
notify("Marked " + entity_name + " for merge","Currently " + current_stored.length + " marked!")
|
2022-04-21 18:02:10 +03:00
|
|
|
|
showValidMergeIcons();
|
2022-04-17 18:24:23 +03:00
|
|
|
|
}
|
2022-04-17 16:15:29 +03:00
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
function merge() {
|
2022-04-17 21:23:49 +03:00
|
|
|
|
const lcst = window.sessionStorage;
|
2022-04-17 18:24:23 +03:00
|
|
|
|
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));
|
|
|
|
|
|
2022-04-17 21:18:44 +03:00
|
|
|
|
callback_func = function(req){
|
|
|
|
|
if (req.status == 200) {
|
|
|
|
|
window.location.reload();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
notifyCallback(req);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-17 18:24:23 +03:00
|
|
|
|
neo.xhttpreq(
|
|
|
|
|
"/apis/mlj_1/merge_" + entity_type + "s",
|
|
|
|
|
data={
|
|
|
|
|
'source_ids':current_stored,
|
|
|
|
|
'target_id':entity_id
|
|
|
|
|
},
|
|
|
|
|
method="POST",
|
2022-04-17 21:18:44 +03:00
|
|
|
|
callback=callback_func,
|
2022-04-17 18:24:23 +03:00
|
|
|
|
json=true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
lcst.removeItem(key);
|
2022-04-15 19:16:54 +03:00
|
|
|
|
}
|
2022-04-07 21:37:46 +03:00
|
|
|
|
|
2022-04-21 18:02:10 +03:00
|
|
|
|
function cancelMerge() {
|
|
|
|
|
const lcst = window.sessionStorage;
|
|
|
|
|
var key = "marked_for_merge_" + entity_type;
|
|
|
|
|
lcst.setItem(key,[]);
|
|
|
|
|
showValidMergeIcons();
|
2022-04-22 21:34:46 +03:00
|
|
|
|
notify("Cancelled merge!","")
|
2022-04-07 21:23:03 +03:00
|
|
|
|
}
|