-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added base for mass editor * Added functionality for each action in backend
- Loading branch information
Showing
10 changed files
with
462 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#-*- coding: utf-8 -*- | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import TYPE_CHECKING, List, Union | ||
|
||
from backend.custom_exceptions import InvalidKeyValue, VolumeDownloadedFor | ||
from backend.db import get_db | ||
from backend.naming import mass_rename | ||
from backend.search import auto_search | ||
from backend.volumes import Volume, refresh_and_scan | ||
|
||
if TYPE_CHECKING: | ||
from backend.download_queue import DownloadHandler | ||
|
||
class MassEditorVariables: | ||
download_handler: Union[None, DownloadHandler] = None | ||
|
||
def mass_editor_delete(volume_ids: List[int], **kwargs) -> None: | ||
delete_volume_folder = kwargs.get('delete_folder', False) | ||
if not isinstance(delete_volume_folder, bool): | ||
raise InvalidKeyValue('delete_folder', delete_volume_folder) | ||
|
||
logging.info(f'Using mass editor, deleting volumes: {volume_ids}') | ||
|
||
for volume_id in volume_ids: | ||
try: | ||
Volume(volume_id).delete(delete_volume_folder) | ||
except VolumeDownloadedFor: | ||
continue | ||
return | ||
|
||
def mass_editor_rename(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, renaming volumes: {volume_ids}') | ||
for volume_id in volume_ids: | ||
mass_rename(volume_id) | ||
return | ||
|
||
def mass_editor_update(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, updating volumes: {volume_ids}') | ||
for volume_id in volume_ids: | ||
refresh_and_scan(volume_id) | ||
return | ||
|
||
def mass_editor_search(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, auto searching for volumes: {volume_ids}') | ||
for volume_id in volume_ids: | ||
search_results = auto_search(volume_id) | ||
for result in search_results: | ||
MassEditorVariables.download_handler.add( | ||
result['link'], | ||
volume_id | ||
) | ||
return | ||
|
||
def mass_editor_convert(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, converting for volumes: {volume_ids}') | ||
return | ||
|
||
def mass_editor_unmonitor(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, unmonitoring volumes: {volume_ids}') | ||
for volume_id in volume_ids: | ||
Volume(volume_id)._unmonitor() | ||
return | ||
|
||
def mass_editor_monitor(volume_ids: List[int], **kwargs) -> None: | ||
logging.info(f'Using mass editor, monitoring volumes: {volume_ids}') | ||
for volume_id in volume_ids: | ||
Volume(volume_id)._monitor() | ||
return | ||
|
||
action_to_func = { | ||
'delete': mass_editor_delete, | ||
'rename': mass_editor_rename, | ||
'update': mass_editor_update, | ||
'search': mass_editor_search, | ||
'convert': mass_editor_convert, | ||
'unmonitor': mass_editor_unmonitor, | ||
'monitor': mass_editor_monitor | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
.nav-main > main > div { | ||
flex: none; | ||
} | ||
|
||
main { | ||
color: var(--text-color); | ||
padding: 1rem; | ||
} | ||
|
||
#loading-window { | ||
height: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
#loading-window h2 { | ||
font-size: clamp(1rem, 5vw, 2rem); | ||
font-weight: 500; | ||
text-align: center; | ||
} | ||
|
||
#list-window { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.action-bar { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 1rem; | ||
|
||
padding: .5rem; | ||
border-radius: 4px; | ||
background-color: var(--tool-bar-color); | ||
color: var(--light-color); | ||
} | ||
|
||
.action-divider { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 1rem; | ||
} | ||
|
||
.action-bar button { | ||
min-width: 5rem; | ||
|
||
border: 2px solid var(--border-color); | ||
border-radius: 4px; | ||
padding: .4rem .5rem; | ||
color: var(--text-color); | ||
background-color: var(--library-entry-color); | ||
|
||
transition: background-color 100ms linear; | ||
} | ||
|
||
.action-bar button:hover { | ||
background-color: var(--dark-hover-color); | ||
} | ||
|
||
.option-container { | ||
overflow: hidden; | ||
border-radius: 4px; | ||
border: 2px solid var(--border-color); | ||
background-color: var(--library-entry-color); | ||
} | ||
|
||
.option-container button { | ||
border-radius: none; | ||
border: none; | ||
} | ||
|
||
.option-container select { | ||
height: 100%; | ||
background-color: var(--library-entry-color); | ||
color: var(--text-color); | ||
} | ||
|
||
.list-container { | ||
position: relative; | ||
|
||
width: 100%; | ||
overflow-x: auto; | ||
|
||
padding-top: 1rem; | ||
} | ||
|
||
table { | ||
width: max(100%, 30rem); | ||
border-spacing: 0px; | ||
} | ||
|
||
th { | ||
text-align: left; | ||
} | ||
|
||
th, | ||
td { | ||
padding: .5rem; | ||
border-bottom: 1px solid var(--nav-color); | ||
} | ||
|
||
th:first-child, | ||
td:first-child { | ||
width: 3rem; | ||
padding-inline: 1rem; | ||
} | ||
|
||
tbody > tr { | ||
transition: background-color 150ms ease-in-out; | ||
} | ||
|
||
tbody > tr:hover { | ||
background-color: var(--dark-hover-color); | ||
} | ||
|
||
@media (max-width: 820px) { | ||
.action-bar { | ||
justify-content: center; | ||
} | ||
.action-divider { | ||
width: 100%; | ||
} | ||
.option-container { | ||
flex: 1 1 auto; | ||
} | ||
.action-bar button { | ||
flex: 1 1 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
const windows = { | ||
loading: document.querySelector('#loading-window'), | ||
list: document.querySelector('#list-window') | ||
}; | ||
|
||
function fillVolumeList(api_key) { | ||
document.querySelector('#selectall-input').checked = false; | ||
const table = document.querySelector('.volume-list'); | ||
table.innerHTML = ''; | ||
fetch(`${url_base}/api/volumes?api_key=${api_key}`) | ||
.then(response => response.json()) | ||
.then(json => { | ||
json.result.forEach(vol => { | ||
const entry = document.createElement('tr'); | ||
entry.dataset.id = vol.id; | ||
|
||
const select_container = document.createElement('td'); | ||
const select = document.createElement('input'); | ||
select.type = 'checkbox'; | ||
select.checked = false; | ||
select_container.appendChild(select); | ||
entry.appendChild(select_container); | ||
|
||
const title = document.createElement('td'); | ||
title.innerText = vol.title; | ||
entry.appendChild(title); | ||
|
||
const year = document.createElement('td'); | ||
year.innerText = vol.year; | ||
entry.appendChild(year); | ||
|
||
const volume_number = document.createElement('td'); | ||
volume_number.innerText = vol.volume_number; | ||
entry.appendChild(volume_number); | ||
|
||
table.appendChild(entry); | ||
}); | ||
}); | ||
}; | ||
|
||
function toggleSelection() { | ||
const checked = document.querySelector('#selectall-input').checked; | ||
document.querySelectorAll('.volume-list input[type="checkbox"]') | ||
.forEach(c => c.checked = checked); | ||
}; | ||
|
||
function runAction(api_key, action, args={}) { | ||
windows.list.classList.add('hidden'); | ||
windows.loading.classList.remove('hidden'); | ||
|
||
const volume_ids = [...document.querySelectorAll( | ||
'.volume-list input[type="checkbox"]:checked' | ||
)].map(v => parseInt(v.parentNode.parentNode.dataset.id)) | ||
|
||
fetch(`${url_base}/api/masseditor?api_key=${api_key}`, { | ||
'method': 'POST', | ||
'headers': {'Content-Type': 'application/json'}, | ||
'body': JSON.stringify({ | ||
'volume_ids': volume_ids, | ||
'action': action, | ||
'args': args | ||
}) | ||
}) | ||
.then(response => { | ||
fillVolumeList(api_key); | ||
windows.loading.classList.add('hidden'); | ||
windows.list.classList.remove('hidden'); | ||
}); | ||
}; | ||
|
||
// code run on load | ||
|
||
usingApiKey() | ||
.then(api_key => { | ||
fillVolumeList(api_key); | ||
addEventListener('.action-bar > div > button', 'click', | ||
e => runAction(api_key, e.target.dataset.action) | ||
); | ||
addEventListener('button[data-action="delete"]', 'click', | ||
e => runAction( | ||
api_key, | ||
e.target.dataset.action, | ||
{ | ||
'delete_folder': document.querySelector( | ||
'select[name="delete_folder"]' | ||
).value === "true" | ||
} | ||
) | ||
); | ||
}); | ||
|
||
addEventListener('#selectall-input', 'change', e => toggleSelection()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.