tagedit v1 lol

This commit is contained in:
Flummi 2022-03-27 18:34:13 +02:00
parent 8c556baecd
commit 0839a574d7
4 changed files with 86 additions and 2 deletions

View File

@ -88,6 +88,7 @@ const flash = ({ type, msg }) => {
a.href = `/tag/${tag.tag}`;
a.style = "color: inherit !important";
a.innerHTML = tag.tag;
a.addEventListener("click", editTagEvent); // tmp
const span = document.createElement("span");
span.classList.add("badge", "mr-2");
@ -265,8 +266,70 @@ const flash = ({ type, msg }) => {
}
};
let tmptt = null;
const editTagEvent = async e => { // mousedown
e.preventDefault();
if(e.detail === 2) {
clearTimeout(tmptt);
const old = e.target;
const parent = e.target.parentElement;
const oldtag = e.target.innerText;
const textfield = document.createElement('input');
textfield.value = e.target.innerText;
textfield.size = 10;
parent.insertAdjacentElement('afterbegin', textfield);
textfield.focus();
parent.removeChild(e.target);
parent.querySelector('a:last-child').style.display = 'none';
textfield.addEventListener("keyup", async e => {
if(e.key === 'Enter') {
// send
let res = await fetch('/api/v2/admin/tags/' + encodeURIComponent(oldtag), {
method: 'PUT',
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
newtag: textfield.value
})
});
const status = res.status;
res = await res.json();
switch(status) {
case 200: // success, change
case 201:
parent.removeChild(textfield);
parent.insertAdjacentElement('afterbegin', old);
parent.querySelector('a:last-child').style.display = '';
old.href = `/tag/${res.tag}`;
old.innerText = res.tag.trim();
break;
default:
console.log(res);
break;
}
}
else if(e.key === 'Escape') {
parent.removeChild(textfield);
parent.insertAdjacentElement('afterbegin', old);
parent.querySelector('a:last-child').style.display = '';
}
});
}
else
tmptt = setTimeout(() => location.href = e.target.href, 250);
return false;
};
_addtag.addEventListener("click", addtagClick);
document.querySelector("a#a_toggle").addEventListener("click", toggleEvent);
[...document.querySelectorAll("#tags > .badge > a:first-child")].map(t => t.addEventListener("click", editTagEvent));
[...document.querySelectorAll("#tags > .badge > a:last-child")].map(t => t.addEventListener("click", deleteEvent));
document.querySelector("svg#a_delete").addEventListener("click", deleteButtonEvent);
document.querySelector("svg#a_favo").addEventListener("click", toggleFavEvent);

View File

@ -99,7 +99,7 @@ export default router => {
}, 400); // bad request
}
const tagname = req.params.tagname;
const tagname = decodeURIComponent(req.params.tagname);
const newtag = req.post.newtag;
const tmptag = (

View File

@ -91,6 +91,27 @@ export default async bot => {
}
return;
break;
/*case "renameTag":
const origTag = e.args.slice(1).join(' ');
if(origTag.length <= 1)
return e.reply("absichtliche Provokation!");
const origTagID = (await sql('tags').where('tag', origTag))[0].id;
const affected = (await sql('tags_assign')
.update({ 'tag_id': sql.raw('(select id from tags where tag = ?)', [ origTag ]) })
.whereIn('tag_id', sql.raw('select id from tags where normalized = slugify(?)', [ origTag ]))
).toString();
const deleted = (await sql('tags')
.where('normalized', sql.raw('slugify(?)', [ origTag ]))
.andWhereNot('id', origTagID)
.del()
);
e.reply(JSON.stringify({ affected, deleted }));
break;*/
case "help":
e.reply("cmds: stats, limit, thumb, cache, uptime, restart, cleanTags, clearTmp, status");
break;

View File

@ -66,7 +66,7 @@
<span class="badge badge-dark" id="tags">
@if(typeof item.tags !== "undefined")
@each(item.tags as tag)
<span @if(session)tooltip="{{ tag.user }} ({{ tag.normalized }})"@endif class="badge {{ tag.badge }} mr-2">
<span @if(session)tooltip="{{ tag.user }}"@endif class="badge {{ tag.badge }} mr-2">
<a href="/tag/{{ tag.tag }}">{!! tag.tag !!}</a>@if(session)&nbsp;<a href="#">&#215;</a>@endif
</span>
@endeach