Can add new MonitorTasks

This commit is contained in:
glax 2023-09-01 23:43:41 +02:00
parent 6c8dcee056
commit 6c209d0f9d

View File

@ -1,6 +1,7 @@
let jobs = []; let jobs = [];
let notificationConnectorTypes = []; let notificationConnectorTypes = [];
let libraryConnectorTypes = []; let libraryConnectorTypes = [];
let selectedManga;
const searchBox = document.querySelector("#searchbox"); const searchBox = document.querySelector("#searchbox");
const settingsPopup = document.querySelector("#settingsPopup"); const settingsPopup = document.querySelector("#settingsPopup");
@ -8,13 +9,13 @@ const settingsCog = document.querySelector("#settingscog");
const tasksContent = document.querySelector("content"); const tasksContent = document.querySelector("content");
const createMonitorTaskButton = document.querySelector("#createMonitorTaskButton"); const createMonitorTaskButton = document.querySelector("#createMonitorTaskButton");
const createDownloadChapterTaskButton = document.querySelector("#createDownloadChapterTaskButton"); const createDownloadChapterTaskButton = document.querySelector("#createDownloadChapterTaskButton");
const publicationViewerPopup = document.querySelector("#publicationViewerPopup"); const mangaViewerPopup = document.querySelector("#publicationViewerPopup");
const publicationViewerWindow = document.querySelector("publication-viewer"); const mangaViewerWindow = document.querySelector("publication-viewer");
const publicationViewerDescription = document.querySelector("#publicationViewerDescription"); const mangaViewerDescription = document.querySelector("#publicationViewerDescription");
const publicationViewerName = document.querySelector("#publicationViewerName"); const mangaViewerName = document.querySelector("#publicationViewerName");
const publicationViewerTags = document.querySelector("#publicationViewerTags"); const mangaViewerTags = document.querySelector("#publicationViewerTags");
const publicationViewerAuthor = document.querySelector("#publicationViewerAuthor"); const mangaViewerAuthor = document.querySelector("#publicationViewerAuthor");
const pubviewcover = document.querySelector("#pubviewcover"); const mangaViewCover = document.querySelector("#pubviewcover");
const publicationDelete = document.querySelector("publication-delete"); const publicationDelete = document.querySelector("publication-delete");
const publicationTaskStart = document.querySelector("publication-starttask"); const publicationTaskStart = document.querySelector("publication-starttask");
const settingDownloadLocation = document.querySelector("#downloadLocation"); const settingDownloadLocation = document.querySelector("#downloadLocation");
@ -59,15 +60,6 @@ function Setup(){
}); });
}); });
GetMonitorJobs().then((json) => {
json.forEach(job => {
if(!jobs.includes(job)){
jobs.push(job);
}
});
});
ResetContent();
} }
Setup(); Setup();
@ -96,22 +88,19 @@ function GetNewMangaItems(){
if(newMangaTitle.value.length < 4) if(newMangaTitle.value.length < 4)
return; return;
newMangaResult.replaceChildren();
newMangaConnector.disabled = true; newMangaConnector.disabled = true;
newMangaTitle.disabled = true; newMangaTitle.disabled = true;
GetPublicationFromConnector(newMangaConnector.value, newMangaTitle.value).then((json) => { GetPublicationFromConnector(newMangaConnector.value, newMangaTitle.value).then((json) => {
console.log(json); //console.log(json);
if(json.length > 0) if(json.length > 0)
newMangaResult.style.display = "flex"; newMangaResult.style.display = "flex";
json.forEach(result => { json.forEach(result => {
var item = document.createElement("div"); var mangaElement = CreateManga(result, newMangaConnector.value)
item.className = "mangaResultItem"; newMangaResult.appendChild(mangaElement);
mangaElement.addEventListener("click", (event) => {
var mangaTitle = document.createElement("span"); ShowMangaWindow(result, event, true);
mangaTitle.className = "mangaResultItemTitle"; });
mangaTitle.innerText = result.sortName;
item.appendChild(mangaTitle);
newMangaResult.appendChild(item);
}); });
newMangaConnector.disabled = false; newMangaConnector.disabled = false;
@ -120,49 +109,56 @@ function GetNewMangaItems(){
} }
//Returns a new "Publication" Item to display in the jobs section //Returns a new "Publication" Item to display in the jobs section
function CreatePublication(publication, connector){ function CreateManga(manga, connector){
var publicationElement = document.createElement('publication'); var mangaElement = document.createElement('publication');
publicationElement.setAttribute("id", publication.internalId); mangaElement.setAttribute("id", manga.internalId);
var img = document.createElement('img'); var mangaImage = document.createElement('img');
img.src = `imageCache/${publication.coverFileNameInCache}`; mangaImage.src = GetCoverUrl(manga.internalId);
publicationElement.appendChild(img); mangaElement.appendChild(mangaImage);
var info = document.createElement('publication-information'); var info = document.createElement('publication-information');
var connectorName = document.createElement('connector-name'); var connectorName = document.createElement('connector-name');
connectorName.innerText = connector; connectorName.innerText = connector;
connectorName.className = "pill"; connectorName.className = "pill";
info.appendChild(connectorName); info.appendChild(connectorName);
var publicationName = document.createElement('publication-name'); var mangaName = document.createElement('publication-name');
publicationName.innerText = publication.sortName; mangaName.innerText = manga.sortName;
info.appendChild(publicationName); info.appendChild(mangaName);
publicationElement.appendChild(info); mangaElement.appendChild(info);
if(publications.filter(pub => pub.internalId === publication.internalId) < 1) return mangaElement;
publications.push(publication);
return publicationElement;
} }
function ShowPublicationViewerWindow(publicationId, event, add){ createMonitorTaskButton.addEventListener("click", () => {
NewMonitorJob();
mangaViewerPopup.style.display = "none";
});
function NewMonitorJob(){
CreateMonitorJob(newMangaConnector.value, selectedManga.internalId);
UpdateJobs();
}
function ShowMangaWindow(manga, event, add){
selectedManga = manga;
//Show popup //Show popup
publicationViewerPopup.style.display = "block"; mangaViewerPopup.style.display = "block";
//Set position to mouse-position //Set position to mouse-position
if(event.clientY < window.innerHeight - publicationViewerWindow.offsetHeight) if(event.clientY < window.innerHeight - mangaViewerWindow.offsetHeight)
publicationViewerWindow.style.top = `${event.clientY}px`; mangaViewerWindow.style.top = `${event.clientY}px`;
else else
publicationViewerWindow.style.top = `${event.clientY - publicationViewerWindow.offsetHeight}px`; mangaViewerWindow.style.top = `${event.clientY - mangaViewerWindow.offsetHeight}px`;
if(event.clientX < window.innerWidth - publicationViewerWindow.offsetWidth) if(event.clientX < window.innerWidth - mangaViewerWindow.offsetWidth)
publicationViewerWindow.style.left = `${event.clientX}px`; mangaViewerWindow.style.left = `${event.clientX}px`;
else else
publicationViewerWindow.style.left = `${event.clientX - publicationViewerWindow.offsetWidth}px`; mangaViewerWindow.style.left = `${event.clientX - mangaViewerWindow.offsetWidth}px`;
//Edit information inside the window //Edit information inside the window
var publication = publications.filter(pub => pub.internalId === publicationId)[0]; mangaViewerName.innerText = manga.sortName;
publicationViewerName.innerText = publication.sortName; mangaViewerTags.innerText = manga.tags.join(", ");
publicationViewerTags.innerText = publication.tags.join(", "); mangaViewerDescription.innerText = manga.description;
publicationViewerDescription.innerText = publication.description; mangaViewerAuthor.innerText = manga.authors.join(',');
publicationViewerAuthor.innerText = publication.authors.join(','); mangaViewCover.src = GetCoverUrl(manga.internalId);
pubviewcover.src = `imageCache/${publication.coverFileNameInCache}`; toEditId = manga.internalId;
toEditId = publicationId;
//Check what action should be listed //Check what action should be listed
if(add){ if(add){
@ -324,3 +320,22 @@ function UpdateSettings(){
function utf8_to_b64(str) { function utf8_to_b64(str) {
return window.btoa(unescape(encodeURIComponent( str ))); return window.btoa(unescape(encodeURIComponent( str )));
} }
UpdateJobs();
setInterval(() => {
UpdateJobs();
}, 1000);
function UpdateJobs(){
GetMonitorJobs().then((json) => {
ResetContent();
console.log(json);
json.forEach(job => {
var mangaView = CreateManga(job.manga, job.mangaConnector.name);
mangaView.addEventListener("click", (event) => {
ShowMangaWindow(job.manga, event, false);
});
tasksContent.appendChild(mangaView);
});
});
}