mirror of
https://github.com/krateng/maloja.git
synced 2025-04-16 16:52:18 +03:00
Implemented client logic for association, GH-227
This commit is contained in:
parent
f189be2309
commit
d645707ff1
@ -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' %}
|
||||
<script>showValidMergeIcons();</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -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' %}
|
||||
<script>showValidMergeIcons();</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div title="Add to Album" id="addalbumicon" class="clickable_icon" onclick="markTrackToAddAlbum()">
|
||||
<div title="Add to Album" id="associatealbumicon" class="clickable_icon" onclick="associate()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path d="M2 4.75C2 3.784 2.784 3 3.75 3h4.971a1.75 1.75 0 0 1 1.447.765l1.404 2.063a.25.25 0 0 0 .207.11h8.471c.966 0 1.75.783 1.75 1.75V19.25A1.75 1.75 0 0 1 20.25 21H4.75a.75.75 0 0 1 0-1.5h15.5a.25.25 0 0 0 .25-.25V7.688a.25.25 0 0 0-.25-.25h-8.471a1.751 1.751 0 0 1-1.447-.766L8.928 4.609a.252.252 0 0 0-.207-.109H3.75a.25.25 0 0 0-.25.25v3.5a.75.75 0 0 1-1.5 0v-3.5Z"></path>
|
||||
<path d="m9.308 12.5-2.104-2.236a.75.75 0 1 1 1.092-1.028l3.294 3.5a.75.75 0 0 1 0 1.028l-3.294 3.5a.75.75 0 1 1-1.092-1.028L9.308 14H4.09a2.59 2.59 0 0 0-2.59 2.59v3.16a.75.75 0 0 1-1.5 0v-3.16a4.09 4.09 0 0 1 4.09-4.09h5.218Z"></path>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div title="Add Artist" id="addartisticon" class="clickable_icon" onclick="markTrackToAddArtist()">
|
||||
<div title="Add Artist" id="associateartisticon" class="clickable_icon" onclick="associate()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path d="M4 9.5a5 5 0 1 1 7.916 4.062 7.973 7.973 0 0 1 5.018 7.166.75.75 0 1 1-1.499.044 6.469 6.469 0 0 0-12.932 0 .75.75 0 0 1-1.499-.044 7.972 7.972 0 0 1 5.059-7.181A4.994 4.994 0 0 1 4 9.5ZM9 6a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7Zm10.25-5a.75.75 0 0 1 .75.75V4h2.25a.75.75 0 0 1 0 1.5H20v2.25a.75.75 0 0 1-1.5 0V5.5h-2.25a.75.75 0 0 1 0-1.5h2.25V1.75a.75.75 0 0 1 .75-.75Z"></path>
|
||||
</svg>
|
||||
|
7
maloja/web/jinja/icons/association_cancel.jinja
Normal file
7
maloja/web/jinja/icons/association_cancel.jinja
Normal file
@ -0,0 +1,7 @@
|
||||
<div title="Cancel Track Association" id="associationcancelicon" class="clickable_icon" onclick="cancelAssociate()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path d="M2.345 20.595 8.47 14.47q.219-.22.53-.22.311 0 .53.22.22.219.22.53 0 .311-.22.53l-6.125 6.125q-.219.22-.53.22-.311 0-.53-.22-.22-.219-.22-.53 0-.311.22-.53Z"></path>
|
||||
<path d="m16.72 11.97.358-.358a6.738 6.738 0 0 1 2.326-1.518l1.896-.738a.25.25 0 0 0 .086-.409l-6.333-6.333a.25.25 0 0 0-.409.086l-.521 1.34a8.663 8.663 0 0 1-2.243 3.265.75.75 0 0 1-1.01-1.11 7.132 7.132 0 0 0 1.854-2.699l.521-1.34a1.75 1.75 0 0 1 2.869-.603l6.333 6.333a1.75 1.75 0 0 1-.603 2.869l-1.896.737a5.26 5.26 0 0 0-1.81 1.18l-.358.358a.749.749 0 1 1-1.06-1.06Zm-12.549-.738a1.75 1.75 0 0 1 .757-2.92l3.366-.962.412 1.443-3.366.961a.25.25 0 0 0-.108.417l8.597 8.597a.25.25 0 0 0 .417-.108l.961-3.366 1.443.412-.962 3.366a1.75 1.75 0 0 1-2.92.757Z"></path>
|
||||
<path d="m3.405 2.095 18.75 18.75q.22.219.22.53 0 .311-.22.53-.219.22-.53.22-.311 0-.53-.22L2.345 3.155q-.22-.219-.22-.53 0-.311.22-.53.219-.22.53-.22.311 0 .53.22Z"></path>
|
||||
</svg>
|
||||
</div>
|
5
maloja/web/jinja/icons/association_mark.jinja
Normal file
5
maloja/web/jinja/icons/association_mark.jinja
Normal file
@ -0,0 +1,5 @@
|
||||
<div title="Mark to associate artists or album" id="associationmarkicon" class="clickable_icon" onclick="markForAssociate()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
||||
<path d="m16.114 1.553 6.333 6.333a1.75 1.75 0 0 1-.603 2.869l-1.63.633a5.67 5.67 0 0 0-3.395 3.725l-1.131 3.959a1.75 1.75 0 0 1-2.92.757L9 16.061l-5.595 5.594a.749.749 0 1 1-1.06-1.06L7.939 15l-3.768-3.768a1.75 1.75 0 0 1 .757-2.92l3.959-1.131a5.666 5.666 0 0 0 3.725-3.395l.633-1.63a1.75 1.75 0 0 1 2.869-.603ZM5.232 10.171l8.597 8.597a.25.25 0 0 0 .417-.108l1.131-3.959A7.17 7.17 0 0 1 19.67 9.99l1.63-.634a.25.25 0 0 0 .086-.409l-6.333-6.333a.25.25 0 0 0-.409.086l-.634 1.63a7.17 7.17 0 0 1-4.711 4.293L5.34 9.754a.25.25 0 0 0-.108.417Z"></path>
|
||||
</svg>
|
||||
</div>
|
@ -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' %}
|
||||
<script>showValidMergeIcons();</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
@ -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!","")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user