delete schedule

This commit is contained in:
Simon 2024-05-06 21:01:46 +02:00
parent d90a53b89c
commit 400d1ce6a8
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
4 changed files with 141 additions and 86 deletions

View File

@ -1003,7 +1003,7 @@ class ScheduleView(ApiBaseView):
def delete(self, request):
"""delete schedule by task_name query"""
task_name = request.GET.get("task_name")
task_name = request.data.get("task_name")
try:
task = CustomPeriodicTask.objects.get(name=task_name)
except CustomPeriodicTask.DoesNotExist:

View File

@ -28,6 +28,7 @@
<p>Current rescan schedule: <span class="settings-current">
{% if update_subscribed %}
{{ update_subscribed.crontab.minute }} {{ update_subscribed.crontab.hour }} {{ update_subscribed.crontab.day_of_week }}
<button data-schedule="update_subscribed" onclick="deleteSchedule(this)" class="danger-button">Delete</button>
{% else %}
False
{% endif %}
@ -45,6 +46,7 @@
<p>Current Download schedule: <span class="settings-current">
{% if download_pending %}
{{ download_pending.crontab.minute }} {{ download_pending.crontab.hour }} {{ download_pending.crontab.day_of_week }}
<button data-schedule="download_pending" onclick="deleteSchedule(this)" class="danger-button">Delete</button>
{% else %}
False
{% endif %}
@ -62,6 +64,7 @@
<p>Current Metadata refresh schedule: <span class="settings-current">
{% if check_reindex %}
{{ check_reindex.crontab.minute }} {{ check_reindex.crontab.hour }} {{ check_reindex.crontab.day_of_week }}
<button data-schedule="check_reindex" onclick="deleteSchedule(this)" class="danger-button">Delete</button>
{% else %}
False
{% endif %}
@ -84,6 +87,7 @@
<p>Current thumbnail check schedule: <span class="settings-current">
{% if thumbnail_check %}
{{ thumbnail_check.crontab.minute }} {{ thumbnail_check.crontab.hour }} {{ thumbnail_check.crontab.day_of_week }}
<button data-schedule="thumbnail_check" onclick="deleteSchedule(this)" class="danger-button">Delete</button>
{% else %}
False
{% endif %}
@ -102,6 +106,7 @@
<p>Current index backup schedule: <span class="settings-current">
{% if run_backup %}
{{ run_backup.crontab.minute }} {{ run_backup.crontab.hour }} {{ run_backup.crontab.day_of_week }}
<button data-schedule="run_backup" onclick="deleteSchedule(this)" class="danger-button">Delete</button>
{% else %}
False
{% endif %}
@ -127,7 +132,10 @@
{% for task, notifications in notifications.items %}
<h3>{{ notifications.title }}</h3>
{% for url in notifications.urls %}
<p><button type="button" class="danger-button" data-url="{{ url }}" data-task="{{ task }}" onclick="deleteNotificationUrl(this)"> Delete</button>{{ url }}</p>
<p>
<button type="button" class="danger-button" data-url="{{ url }}" data-task="{{ task }}" onclick="deleteNotificationUrl(this)"> Delete</button>
<span> {{ url }}</span>
</p>
{% endfor %}
{% endfor %}
</div>

View File

@ -12,7 +12,7 @@ checkMessages();
// start to look for messages
function checkMessages() {
let notifications = document.getElementById('notifications');
if (notifications && notifications.childNodes.length === 0 ) {
if (notifications && notifications.childNodes.length === 0) {
let dataOrigin = notifications.getAttribute('data');
getMessages(dataOrigin);
}

View File

@ -203,18 +203,28 @@ function showAddToPlaylistMenu(input1) {
dataId = input1.getAttribute('data-id');
buttonId = input1.getAttribute('id');
playlists = getCustomPlaylists();
//hide the invoking button
input1.style.visibility = "hidden";
input1.style.visibility = 'hidden';
//show the form
form_code = '<div class="video-popup-menu"><img src="/static/img/icon-close.svg" class="video-popup-menu-close-button" title="Close menu" onclick="removeDotMenu(this, \''+buttonId+'\')"/><h3>Add video to...</h3>';
for(let i = 0; i < playlists.length; i++) {
let obj = playlists[i];
form_code += '<p onclick="addToCustomPlaylist(this, \''+dataId+'\',\''+obj.playlist_id+'\')"><img class="p-button" src="/static/img/icon-unseen.svg"/>'+obj.playlist_name+'</p>';
form_code =
'<div class="video-popup-menu"><img src="/static/img/icon-close.svg" class="video-popup-menu-close-button" title="Close menu" onclick="removeDotMenu(this, \'' +
buttonId +
'\')"/><h3>Add video to...</h3>';
for (let i = 0; i < playlists.length; i++) {
let obj = playlists[i];
form_code +=
'<p onclick="addToCustomPlaylist(this, \'' +
dataId +
"','" +
obj.playlist_id +
'\')"><img class="p-button" src="/static/img/icon-unseen.svg"/>' +
obj.playlist_name +
'</p>';
}
form_code += '<p><a href="/playlist">Create playlist</a></p></div>';
input1.parentNode.parentNode.innerHTML += form_code;
}
@ -222,18 +232,17 @@ function showAddToPlaylistMenu(input1) {
//handles user action of adding a video to a custom playlist
function addToCustomPlaylist(input, video_id, playlist_id) {
let apiEndpoint = '/api/playlist/' + playlist_id + '/';
let data = { "action": "create", "video_id": video_id };
let data = { action: 'create', video_id: video_id };
apiRequest(apiEndpoint, 'POST', data);
//mark the item added in the ui
input.firstChild.src='/static/img/icon-seen.svg';
input.firstChild.src = '/static/img/icon-seen.svg';
}
function removeDotMenu(input1, button_id) {
//show the menu button
document.getElementById(button_id).style.visibility = "visible";
document.getElementById(button_id).style.visibility = 'visible';
//remove the form
input1.parentNode.remove();
}
@ -243,20 +252,67 @@ function showCustomPlaylistMenu(input1, playlist_id, current_page, last_page) {
let dataId, form_code, buttonId;
dataId = input1.getAttribute('data-id');
buttonId = input1.getAttribute('id');
//hide the invoking button
input1.style.visibility = "hidden";
input1.style.visibility = 'hidden';
//show the form
form_code = '<div class="video-popup-menu"><img src="/static/img/icon-close.svg" class="video-popup-menu-close-button" title="Close menu" onclick="removeDotMenu(this, \''+buttonId+'\')"/><h3>Move Video</h3>';
form_code += '<img class="move-video-button" data-id="'+dataId+'" data-context="top" onclick="moveCustomPlaylistVideo(this,\''+playlist_id+'\','+current_page+','+last_page+')" src="/static/img/icon-arrow-top.svg" title="Move to top"/>';
form_code += '<img class="move-video-button" data-id="'+dataId+'" data-context="up" onclick="moveCustomPlaylistVideo(this,\''+playlist_id+'\','+current_page+','+last_page+')" src="/static/img/icon-arrow-up.svg" title="Move up"/>';
form_code += '<img class="move-video-button" data-id="'+dataId+'" data-context="down" onclick="moveCustomPlaylistVideo(this,\''+playlist_id+'\','+current_page+','+last_page+')" src="/static/img/icon-arrow-down.svg" title="Move down"/>';
form_code += '<img class="move-video-button" data-id="'+dataId+'" data-context="bottom" onclick="moveCustomPlaylistVideo(this,\''+playlist_id+'\','+current_page+','+last_page+')" src="/static/img/icon-arrow-bottom.svg" title="Move to bottom"/>';
form_code += '<img class="move-video-button" data-id="'+dataId+'" data-context="remove" onclick="moveCustomPlaylistVideo(this,\''+playlist_id+'\','+current_page+','+last_page+')" src="/static/img/icon-remove.svg" title="Remove from playlist"/>';
form_code =
'<div class="video-popup-menu"><img src="/static/img/icon-close.svg" class="video-popup-menu-close-button" title="Close menu" onclick="removeDotMenu(this, \'' +
buttonId +
'\')"/><h3>Move Video</h3>';
form_code +=
'<img class="move-video-button" data-id="' +
dataId +
'" data-context="top" onclick="moveCustomPlaylistVideo(this,\'' +
playlist_id +
"'," +
current_page +
',' +
last_page +
')" src="/static/img/icon-arrow-top.svg" title="Move to top"/>';
form_code +=
'<img class="move-video-button" data-id="' +
dataId +
'" data-context="up" onclick="moveCustomPlaylistVideo(this,\'' +
playlist_id +
"'," +
current_page +
',' +
last_page +
')" src="/static/img/icon-arrow-up.svg" title="Move up"/>';
form_code +=
'<img class="move-video-button" data-id="' +
dataId +
'" data-context="down" onclick="moveCustomPlaylistVideo(this,\'' +
playlist_id +
"'," +
current_page +
',' +
last_page +
')" src="/static/img/icon-arrow-down.svg" title="Move down"/>';
form_code +=
'<img class="move-video-button" data-id="' +
dataId +
'" data-context="bottom" onclick="moveCustomPlaylistVideo(this,\'' +
playlist_id +
"'," +
current_page +
',' +
last_page +
')" src="/static/img/icon-arrow-bottom.svg" title="Move to bottom"/>';
form_code +=
'<img class="move-video-button" data-id="' +
dataId +
'" data-context="remove" onclick="moveCustomPlaylistVideo(this,\'' +
playlist_id +
"'," +
current_page +
',' +
last_page +
')" src="/static/img/icon-remove.svg" title="Remove from playlist"/>';
form_code += '</div>';
input1.parentNode.parentNode.innerHTML += form_code;
}
@ -266,65 +322,46 @@ function moveCustomPlaylistVideo(input1, playlist_id, current_page, last_page) {
let dataId, dataContext;
dataId = input1.getAttribute('data-id');
dataContext = input1.getAttribute('data-context');
let apiEndpoint = '/api/playlist/' + playlist_id + '/';
let data = { "action": dataContext, "video_id": dataId };
let data = { action: dataContext, video_id: dataId };
apiRequest(apiEndpoint, 'POST', data);
let itemDom = input1.parentElement.parentElement.parentElement;
let listDom = itemDom.parentElement;
if (dataContext === "up")
{
let sibling = itemDom.previousElementSibling;
if (sibling !== null)
{
sibling.before(itemDom);
}
else if (current_page > 1)
{
itemDom.remove();
}
}
else if (dataContext === "down")
{
let sibling = itemDom.nextElementSibling;
if (sibling !== null)
{
sibling.after(itemDom);
}
else if (current_page !== last_page)
{
itemDom.remove();
}
}
else if (dataContext === "top")
{
let sibling = listDom.firstElementChild;
if (sibling !== null)
{
sibling.before(itemDom);
}
if (current_page > 1)
{
itemDom.remove();
}
}
else if (dataContext === "bottom")
{
let sibling = listDom.lastElementChild;
if (sibling !== null)
{
sibling.after(itemDom);
}
if (current_page !== last_page)
{
itemDom.remove();
}
}
else if (dataContext === "remove")
{
itemDom.remove();
if (dataContext === 'up') {
let sibling = itemDom.previousElementSibling;
if (sibling !== null) {
sibling.before(itemDom);
} else if (current_page > 1) {
itemDom.remove();
}
} else if (dataContext === 'down') {
let sibling = itemDom.nextElementSibling;
if (sibling !== null) {
sibling.after(itemDom);
} else if (current_page !== last_page) {
itemDom.remove();
}
} else if (dataContext === 'top') {
let sibling = listDom.firstElementChild;
if (sibling !== null) {
sibling.before(itemDom);
}
if (current_page > 1) {
itemDom.remove();
}
} else if (dataContext === 'bottom') {
let sibling = listDom.lastElementChild;
if (sibling !== null) {
sibling.after(itemDom);
}
if (current_page !== last_page) {
itemDom.remove();
}
} else if (dataContext === 'remove') {
itemDom.remove();
}
}
@ -505,6 +542,17 @@ function deleteNotificationUrl(button) {
button.parentElement.remove();
}
function deleteSchedule(button) {
console.log('delete schedule');
let apiEndpoint = '/api/schedule/';
let data = { task_name: button.dataset.schedule };
apiRequest(apiEndpoint, 'DELETE', data);
let message = document.createElement('span');
message.innerText = 'False';
message.classList.add('settings-current');
button.parentElement.replaceWith(message);
}
// delete from file system
function deleteConfirm() {
let to_show = document.getElementById('delete-button');
@ -1533,7 +1581,6 @@ document.addEventListener('readystatechange', textExpandButtonVisibilityUpdate);
window.addEventListener('resize', textExpandButtonVisibilityUpdate);
function showForm(id) {
let id2 = id === undefined ? 'hidden-form' : id;
let formElement = document.getElementById(id2);
let displayStyle = formElement.style.display;