Muhammad Labeeb f14516793e
Fix UI bugs and add new features
* fix ui bugs

* fix warning on plugin enable

* add tooltip

* change install icon

* stop autoscroll on user scroll

* add separate js for logs scrolling

* redirect to marketplace from plugins detail page

* home page goes to installed plugins

* add tab for local launch

* add simple toast

* add toast

* show toast after command completed

* fix toast ui

* add toast after local launch

* add cancel button

* change naming

* separate pagination handlers

* refractor plugins installed

* remove repitition of modal

* rename local launch

* fix toast on mobile

* hide pagination if not required

* disable auto remove toast

* remove ask local launch flag

* use success message instead of exit code

* show enable toggle after installation is completed

* update page button dynamically

* fix typo local launch

* remove repeating declaration

* dynamic cancel button on local launch

* refresh redirects to plugin store

* fix toast error

* remove sysmodules pop

* fix alignment

* add advanced tab

* add advanced tab

* add click dependency

* move autocomplete to tutorclient

* fix make command typo

* ui enhancements

* improve advenced tab search bar

* make plugins card clickable

* add enabled disabled to marketplce

* add dynamic search

* update comments

* move warning js to proper template

* only 1 modal button

* fix missing modal button

* config multi set

* add command to logs, prevent multiple toasts on pages with logs

* do not display repeated toast for anything

* fix local launch cancellation

* change icons

* small ui fixes

* my plugins now clickable

* single function for execution cancellation

* switch fix

* reset log creation logic

* single config update button

* move toast logic to frontend

* just values in config fields

* fix checkbox value error

* add htmx indicator

* no toast for plugin disable

* separate toast manager

* update only changed config items

* fix templated value updates

* rename launch platform

* change dropdown style

* do not run commands if thread is alive

* fix warning

* cancelling local launch does not remove warning cookies

* resolve js code comments

* do not show toast when last log file is null

* allow cancellation even after page reload

* update shared template context

* create separate utils

* single view for set and unset

* add plugin name to url

* fix cancel button

* adjust modal size
2025-03-24 18:59:29 +05:00

117 lines
3.3 KiB
JavaScript

function setCookie(name, value, days) {
let expires = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = "; expires=" + date.toUTCString();
}
document.cookie = `${name}=${value || ""}${expires}; path=/`;
}
function getCookie(name) {
let nameEQ = name + "=";
return (
document.cookie
.split(";")
.map((cookie) => cookie.trim())
.find((cookie) => cookie.startsWith(nameEQ))
?.slice(nameEQ.length) || null
);
}
function eraseCookie(name) {
document.cookie =
name + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
}
// Handle modal
const modalContainer = document.getElementById("modal_container");
const openModalButton = document.querySelector(".open-modal-button");
const closeModalButton = document.querySelector(".close-modal-button");
openModalButton?.addEventListener("click", () => {
modalContainer.classList.add("show");
});
closeModalButton?.addEventListener("click", () => {
modalContainer.classList.remove("show");
});
// Handle toast
const toast = document.querySelector(".toast");
let closeToastButtons = document.querySelectorAll(".close-toast-button");
closeToastButtons.forEach((button) => {
button.addEventListener("click", () => {
hideToast(toast);
});
});
function showToast() {
if (toast) {
if (toastTitle === "Launch platform was successfully executed") {
document.cookie.split(";").forEach((cookie) => {
let name = cookie.split("=")[0].trim();
if (name.startsWith("warning-cookie")) {
eraseCookie(name);
}
});
}
toast.style.display = "flex";
setTimeout(() => {
void toast.offsetHeight;
toast.classList.add("active");
}, 1);
}
}
function hideToast() {
if (toast) {
toast.classList.remove("active");
setTimeout(() => {
toast.style.display = "none";
}, 500);
}
}
const TOAST_CONFIGS = {
"$ tutor plugins enable": {
title: "Your plugin was successfully enabled",
description:
"Running launch platform will allow all changes to plugins to take effect. This could take a few minutes to complete.",
showFooter: true,
},
"$ tutor plugins upgrade": {
title: "Your plugin was successfully updated",
description:
"Running launch platform will allow all changes to plugins to take effect. This could take a few minutes to complete.",
showFooter: true,
},
"$ tutor plugins install": {
title: "Plugin Installed Successfully",
description: "Enable it now to start using its features",
showFooter: false,
},
"$ tutor config save": {
title: "You have successfully modified parameters",
description:
"Running launch platform will allow all changes to plugins to take effect. This could take a few minutes to complete.",
showFooter: true,
},
"$ tutor local launch": {
title: "Launch platform was successfully executed",
description: "",
showFooter: false,
},
};
let toastTitle = document.getElementById("toast-title");
let toastDescription = document.getElementById("toast-description");
let toastFooter = document.getElementById("toast-footer");
function setToastContent(cmd) {
const matchedPrefix = Object.keys(TOAST_CONFIGS).find((prefix) =>
cmd.startsWith(prefix)
);
if (matchedPrefix) {
const config = TOAST_CONFIGS[matchedPrefix];
toastTitle.textContent = config.title;
toastDescription.textContent = config.description;
toastFooter.style.display = config.showFooter ? "flex" : "none";
}
}