2
0
Tranga/Website/interaction.js

230 lines
8.0 KiB
JavaScript
Raw Normal View History

2023-05-22 23:52:35 +02:00
const slideInRight = [
{ right: "-20rem" },
{ right: "0" }
];
const slideInRightTiming = {
duration: 200,
iterations: 1,
fill: "forwards",
easing: "ease-out"
}
const slideOutRightTiming = {
direction: "reverse",
duration: 200,
iterations: 1,
fill: "forwards",
easing: "ease-in"
}
2023-05-23 17:57:48 +02:00
let publications = [];
let tasks = [];
2023-05-23 18:28:27 +02:00
let toEditId;
2023-05-23 17:57:48 +02:00
2023-05-23 14:44:59 +02:00
const taskTypesSelect = document.querySelector("#taskTypes")
2023-05-23 16:27:09 +02:00
const searchPublicationQuery = document.querySelector("#searchPublicationQuery");
const selectPublication = document.querySelector("#taskSelectOutput");
const connectorSelect = document.querySelector("#connectors");
const settingsTab = document.querySelector("#settingstab");
const settingsCog = document.querySelector("#settingscog");
const selectRecurrence = document.querySelector("#selectReccurrence");
const tasksContent = document.querySelector("content");
2023-05-23 18:46:06 +02:00
const addTaskPopup = document.querySelector("#addTaskPopup");
const publicationViewerPopup = document.querySelector("#publicationViewerPopup");
const publicationViewerWindow = document.querySelector("publication-viewer");
2023-05-23 17:57:48 +02:00
const publicationViewerDescription = document.querySelector("#publicationViewerDescription");
const publicationViewerName = document.querySelector("#publicationViewerName");
const publicationViewerAuthor = document.querySelector("#publicationViewerAuthor");
const pubviewcover = document.querySelector("#pubviewcover");
const publicationDelete = document.querySelector("publication-delete");
2023-05-23 18:28:27 +02:00
const publicationAdd = document.querySelector("publication-add");
2023-05-23 16:27:09 +02:00
const closetaskpopup = document.querySelector("#closePopupImg");
settingsCog.addEventListener("click", () => slide());
2023-05-23 18:46:06 +02:00
closetaskpopup.addEventListener("click", () => HideAddTaskPopup());
document.querySelector("#blurBackgroundTaskPopup").addEventListener("click", () => HideAddTaskPopup());
document.querySelector("#blurBackgroundPublicationPopup").addEventListener("click", () => HidePublicationPopup());
2023-05-23 18:07:15 +02:00
publicationDelete.addEventListener("click", () => DeleteTaskClick());
2023-05-23 18:46:06 +02:00
publicationAdd.addEventListener("click", () => AddTaskClick());
2023-05-23 16:27:09 +02:00
2023-05-23 18:07:15 +02:00
/*
2023-05-23 14:44:59 +02:00
let availableTaskTypes;
GetTaskTypes()
.then(json => availableTaskTypes = json)
.then(json =>
json.forEach(taskType => {
var option = document.createElement('option');
option.value = taskType;
option.innerText = taskType;
taskTypesSelect.appendChild(option);
2023-05-23 18:07:15 +02:00
}));*/
2023-05-23 14:44:59 +02:00
let availableConnectors;
GetAvailableControllers()
.then(json => availableConnectors = json)
2023-05-23 15:15:29 +02:00
//.then(json => console.log(json))
.then(json =>
2023-05-23 14:44:59 +02:00
json.forEach(connector => {
2023-05-23 15:15:29 +02:00
var option = document.createElement('option');
option.value = connector;
option.innerText = connector;
connectorSelect.appendChild(option);
})
);
2023-05-23 14:44:59 +02:00
2023-05-23 15:15:29 +02:00
searchPublicationQuery.addEventListener("keypress", (event) => {
if(event.key === "Enter"){
2023-05-23 18:46:06 +02:00
selectRecurrence.disabled = true;
connectorSelect.disabled = true;
searchPublicationQuery.disabled = true;
selectPublication.replaceChildren();
2023-05-23 15:15:29 +02:00
GetPublication(connectorSelect.value, searchPublicationQuery.value)
//.then(json => console.log(json));
.then(json =>
json.forEach(publication => {
2023-05-23 16:27:09 +02:00
var option = CreatePublication(publication, connectorSelect.value);
2023-05-23 18:46:06 +02:00
option.addEventListener("click", (mouseEvent) => {
ShowPublicationViewerWindow(publication.internalId, mouseEvent, true);
2023-05-23 15:15:29 +02:00
});
selectPublication.appendChild(option);
}
2023-05-23 18:46:06 +02:00
))
.then(() => {
selectRecurrence.disabled = false;
connectorSelect.disabled = false;
searchPublicationQuery.disabled = false;
});
2023-05-23 15:15:29 +02:00
}
});
2023-05-23 14:44:59 +02:00
2023-05-23 16:27:09 +02:00
function CreatePublication(publication, connector){
2023-05-23 17:57:48 +02:00
var publicationElement = document.createElement('publication');
publicationElement.setAttribute("id", publication.internalId);
2023-05-23 15:15:29 +02:00
var img = document.createElement('img');
img.src = publication.posterUrl;
2023-05-23 17:57:48 +02:00
publicationElement.appendChild(img);
2023-05-23 15:15:29 +02:00
var info = document.createElement('publication-information');
var connectorName = document.createElement('connector-name');
2023-05-23 16:27:09 +02:00
connectorName.innerText = connector;
2023-05-23 15:15:29 +02:00
connectorName.className = "pill";
info.appendChild(connectorName);
var publicationName = document.createElement('publication-name');
publicationName.innerText = publication.sortName;
info.appendChild(publicationName);
2023-05-23 17:57:48 +02:00
publicationElement.appendChild(info);
if(publications.filter(pub => pub.internalId === publication.internalId) < 1)
publications.push(publication);
return publicationElement;
2023-05-23 15:15:29 +02:00
}
2023-05-23 18:07:15 +02:00
function DeleteTaskClick(){
2023-05-23 18:28:27 +02:00
taskToDelete = tasks.filter(tTask => tTask.publication.internalId === toEditId)[0];
DeleteTask("DownloadNewChapters", taskToDelete.connectorName, toEditId);
HidePublicationPopup();
2023-05-23 18:46:06 +02:00
}
function AddTaskClick(){
CreateTask("DownloadNewChapters", selectRecurrence.value, connectorSelect.value, toEditId, "en")
HideAddTaskPopup();
HidePublicationPopup();
2023-05-23 15:15:29 +02:00
}
2023-05-23 14:44:59 +02:00
2023-05-22 23:52:35 +02:00
var slideIn = true;
2023-05-23 17:57:48 +02:00
function slide() {
if (slideIn)
2023-05-22 23:52:35 +02:00
settingsTab.animate(slideInRight, slideInRightTiming);
else
settingsTab.animate(slideInRight, slideOutRightTiming);
slideIn = !slideIn;
}
2023-05-23 16:27:09 +02:00
function ResetContent(){
tasksContent.replaceChildren();
var add = document.createElement("div");
add.setAttribute("id", "addPublication")
var plus = document.createElement("p");
plus.innerText = "+";
add.appendChild(plus);
add.addEventListener("click", () => ShowNewTaskWindow());
tasksContent.appendChild(add);
}
2023-05-23 18:28:27 +02:00
function ShowPublicationViewerWindow(publicationId, event, add){
2023-05-23 18:46:06 +02:00
publicationViewerWindow.style.top = `${event.clientY - 60}px`;
publicationViewerWindow.style.left = `${event.clientX}px`;
2023-05-23 17:57:48 +02:00
var publication = publications.filter(pub => pub.internalId === publicationId)[0];
publicationViewerName.innerText = publication.sortName;
publicationViewerDescription.innerText = publication.description;
publicationViewerAuthor.innerText = publication.author;
pubviewcover.src = publication.posterUrl;
2023-05-23 18:28:27 +02:00
toEditId = publicationId;
2023-05-23 17:57:48 +02:00
2023-05-23 18:28:27 +02:00
if(add){
publicationAdd.style.display = "block";
publicationDelete.style.display = "none";
}
2023-05-23 18:46:06 +02:00
else{
publicationAdd.style.display = "none";
publicationDelete.style.display = "block";
}
2023-05-23 18:28:27 +02:00
toEditId = publicationId;
2023-05-23 18:46:06 +02:00
publicationViewerPopup.style.display = "block";
2023-05-23 17:57:48 +02:00
}
2023-05-23 16:27:09 +02:00
function ShowNewTaskWindow(){
selectPublication.replaceChildren();
2023-05-23 18:46:06 +02:00
addTaskPopup.style.display = "block";
}
function HideAddTaskPopup(){
addTaskPopup.style.display = "none";
2023-05-23 16:27:09 +02:00
}
2023-05-23 18:46:06 +02:00
function HidePublicationPopup(){
publicationViewerPopup.style.display = "none";
2023-05-23 16:27:09 +02:00
}
const fadeIn = [
{ opacity: "0" },
{ opacity: "1" }
];
const fadeInTiming = {
2023-05-23 17:57:48 +02:00
duration: 50,
2023-05-23 16:27:09 +02:00
iterations: 1,
fill: "forwards"
}
ResetContent();
GetTasks()
//.then(json => console.log(json))
.then(json => json.forEach(task => {
var publication = CreatePublication(task.publication, task.connectorName);
publication.addEventListener("click", (event) => ShowPublicationViewerWindow(task.publication.internalId, event, false));
2023-05-23 16:27:09 +02:00
tasksContent.appendChild(publication);
tasks.push(task);
2023-05-23 16:27:09 +02:00
}));
2023-05-23 14:44:59 +02:00
setInterval(() => {
var cTasks = [];
2023-05-23 16:27:09 +02:00
GetTasks()
//.then(json => console.log(json))
.then(json => json.forEach(task => cTasks.push(task)))
.then(() => {
if(tasks.length != cTasks.length) {
ResetContent();
2023-05-23 18:19:46 +02:00
cTasks.forEach(task => {
var publication = CreatePublication(task.publication, task.connectorName);
publication.addEventListener("click", (event) => ShowPublicationViewerWindow(task.publication.internalId, event, false));
2023-05-23 18:19:46 +02:00
tasksContent.appendChild(publication);
})
tasks = cTasks;
}
}
);
2023-05-23 18:12:45 +02:00
}, 1000);