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

101 lines
3.2 KiB
JavaScript

// Most of the websites dynamic functionality depends on the content of the logs
// This file is responsible for:
// 1) setting and displaying toast messages
// 2) toggling command execution/cancellation buttons
// 3) logs scrolling
// Each page that uses logs defines its own command execution/cancellation toggle functions with the same names
// We can safely call these functions and their functionality will be handeled by the page specific js
let shouldAutoScroll = true;
let isScrollingProgrammatically = false;
// When user manually scrolls, update behaviour
logsElement.addEventListener("scroll", function () {
if (!isScrollingProgrammatically) {
shouldAutoScroll = false;
}
});
let executedNewCommand = true;
let logsCount = 0;
let currentLogFile = null;
htmx.on("htmx:sseBeforeMessage", function (evt) {
logsCount += 1;
// Don't swap content, we want to append
evt.preventDefault();
const stdout = JSON.parse(evt.detail.data);
const text = document.createTextNode(stdout);
// First log element contains the name of logging file
if (logsCount === 1) {
currentLogFile = text.nodeValue.trim();
let lastLogFile = getCookie("last-log-file");
// If the new log file name is same as the previous log file name that means
// we have not executed a new command, they are logs of the last executed command
if (lastLogFile === currentLogFile) {
executedNewCommand = false;
} else {
// We are indeed executing a new command so show cancel button and update log file name
ShowCancelCommandButton();
}
} else if (logsCount === 2) {
// Second log element is the running command, make toast here
cmd = text.nodeValue.trim();
setToastContent(cmd);
evt.detail.elt.appendChild(text);
} else {
// Only show toast if it was a new command
if (executedNewCommand === true) {
// If command has run successfully update UI
if (stdout.includes("Success!")) {
setCookie("last-log-file", currentLogFile, 365);
// Do not show the toast if it is empty
if (toastTitle.textContent.trim() != "") {
showToast("info");
}
// Check if we are on the plugin page
if (typeof pluginName !== "undefined") {
// Successfull command means plugin is either successfully installed or upgraded
// In either case we can safely display the enable/disable bar
isPluginInstalled = true;
showPluginEnableDisableBar();
}
ShowRunCommandButton();
}
if (stdout.includes("Cancelled!")) {
ShowRunCommandButton();
}
}
evt.detail.elt.appendChild(text);
}
if (shouldAutoScroll) {
// Set flag so event listner knows we are scrolling programatically
isScrollingProgrammatically = true;
evt.detail.elt.scrollTop = evt.detail.elt.scrollHeight;
// Reset the flag after a short delay
setTimeout(() => {
isScrollingProgrammatically = false;
}, 10);
}
});
// Additional handlers for scroll inputs
logsElement.addEventListener(
"wheel",
function () {
shouldAutoScroll = false;
},
{ passive: true }
);
logsElement.addEventListener(
"touchstart",
function () {
shouldAutoScroll = false;
},
{ passive: true }
);