mirror of
https://github.com/itflow-org/itflow
synced 2026-03-06 05:44:52 +00:00
Ticket time tracking
Bugfix for ticket time tracking as this was broken since the open ticket timer was removed
This commit is contained in:
@@ -1,147 +0,0 @@
|
|||||||
// ticketCounter.js
|
|
||||||
(function() {
|
|
||||||
function getRunningTicketCount() {
|
|
||||||
let count = 0;
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
|
||||||
let key = localStorage.key(i);
|
|
||||||
if (key.includes("ticket-timer-running")) {
|
|
||||||
let isRunning = JSON.parse(localStorage.getItem(key));
|
|
||||||
if (isRunning) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTicketCountDisplay() {
|
|
||||||
let count = getRunningTicketCount();
|
|
||||||
let countDisplay = document.getElementById("runningTicketsCount");
|
|
||||||
if (countDisplay) {
|
|
||||||
countDisplay.innerText = count;
|
|
||||||
}
|
|
||||||
if (count == 0) {
|
|
||||||
countDisplay.classList.remove('badge-danger');
|
|
||||||
} else {
|
|
||||||
//check to see if more than one ticket
|
|
||||||
if (count > 1) {
|
|
||||||
countDisplay.classList.add('badge-danger');
|
|
||||||
}
|
|
||||||
//if count is one, check to see if its open in the current window by looking at the post variable ticket_id in url
|
|
||||||
if (count == 1) {
|
|
||||||
let urlParams = new URLSearchParams(window.location.search);
|
|
||||||
let ticketID = urlParams.get('ticket_id');
|
|
||||||
console.log(ticketID);
|
|
||||||
// If ticket number equals one in local storage, then add badge-danger class
|
|
||||||
if (localStorage.getItem("ticket-timer-running-") == ticketID) {
|
|
||||||
countDisplay.classList.add('badge-danger');
|
|
||||||
} else {
|
|
||||||
countDisplay.classList.remove('badge-danger');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getElapsedSeconds(ticketID) {
|
|
||||||
let storedStartTime = parseInt(localStorage.getItem(ticketID + "-startTime") || "0");
|
|
||||||
let pausedTime = parseInt(localStorage.getItem(ticketID + "-pausedTime") || "0");
|
|
||||||
if (!storedStartTime) return pausedTime;
|
|
||||||
let timeSinceStart = Math.floor((Date.now() - storedStartTime) / 1000);
|
|
||||||
return pausedTime + timeSinceStart;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatTime(seconds) {
|
|
||||||
let hours = Math.floor(seconds / 3600);
|
|
||||||
let minutes = Math.floor((seconds % 3600) / 60);
|
|
||||||
let secs = seconds % 60;
|
|
||||||
return `${hours}h ${minutes}m ${secs}s`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadOpenTickets() {
|
|
||||||
let openTicketsContainer = document.getElementById('openTicketsContainer');
|
|
||||||
openTicketsContainer.innerHTML = ''; // Clear existing content
|
|
||||||
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
|
||||||
let key = localStorage.key(i);
|
|
||||||
|
|
||||||
if (key.startsWith("ticket-timer-running-")) {
|
|
||||||
let ticketID = key.replace("ticket-timer-running-", "");
|
|
||||||
let isRunning = JSON.parse(localStorage.getItem(key));
|
|
||||||
|
|
||||||
let ticketDiv = document.createElement('div');
|
|
||||||
ticketDiv.classList.add('card', 'card-outline', 'mb-3');
|
|
||||||
// Add class based on ticket status
|
|
||||||
ticketDiv.classList.add(isRunning ? 'card-info' : 'card-warning');
|
|
||||||
ticketDiv.id = 'ticket-' + ticketID;
|
|
||||||
|
|
||||||
let elapsedSecs = getElapsedSeconds(ticketID);
|
|
||||||
let timeString = formatTime(elapsedSecs);
|
|
||||||
|
|
||||||
ticketDiv.innerHTML = `
|
|
||||||
<div class="card-header">
|
|
||||||
<h3 class="card-title">Ticket ID: ${ticketID}</h3>
|
|
||||||
<a href="/ticket.php?ticket_id=${ticketID}" class="btn btn-primary float-right">View Ticket</a>
|
|
||||||
</div>
|
|
||||||
<div class="card-body">
|
|
||||||
<p id="time-${ticketID}">Total Time: ${timeString}</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
openTicketsContainer.appendChild(ticketDiv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requestAnimationFrame(() => updateRunningTickets());
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateRunningTickets() {
|
|
||||||
let runningTickets = document.querySelectorAll('[id^="ticket-"]');
|
|
||||||
runningTickets.forEach(ticket => {
|
|
||||||
let ticketID = ticket.id.replace("ticket-", "");
|
|
||||||
let isRunning = JSON.parse(localStorage.getItem("ticket-timer-running-" + ticketID));
|
|
||||||
|
|
||||||
if (isRunning) {
|
|
||||||
let updatedTime = formatTime(getElapsedSeconds(ticketID));
|
|
||||||
document.getElementById('time-' + ticketID).innerText = 'Total Time: ' + updatedTime;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
requestAnimationFrame(updateRunningTickets);
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearAllTimers() {
|
|
||||||
// Collect keys to be removed
|
|
||||||
let keysToRemove = [];
|
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
|
||||||
let key = localStorage.key(i);
|
|
||||||
if (key.startsWith("ticket-timer-running-") || key.endsWith("-startTime") || key.endsWith("-pausedTime")) {
|
|
||||||
keysToRemove.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove collected keys
|
|
||||||
keysToRemove.forEach(key => localStorage.removeItem(key));
|
|
||||||
|
|
||||||
// Update the display and redirect
|
|
||||||
updateTicketCountDisplay();
|
|
||||||
window.location.href = "/tickets.php";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial update on script load
|
|
||||||
updateTicketCountDisplay();
|
|
||||||
|
|
||||||
// update every 10 seconds
|
|
||||||
setInterval(updateTicketCountDisplay, 10000);
|
|
||||||
|
|
||||||
// Add event listener to modal
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
let modal = document.getElementById('openTicketsModal');
|
|
||||||
if (modal) {
|
|
||||||
$('#openTicketsModal').on('show.bs.modal', loadOpenTickets);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add event listener to clear all timers button
|
|
||||||
document.getElementById('clearAllTimers').addEventListener('click', clearAllTimers);
|
|
||||||
|
|
||||||
})();
|
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
var ticketID = getCurrentTicketID();
|
var ticketID = getCurrentTicketID();
|
||||||
var elapsedSecs = getElapsedSeconds();
|
var elapsedSecs = getElapsedSeconds();
|
||||||
|
|
||||||
updateRunningTicketsCount();
|
|
||||||
|
|
||||||
function getCurrentTicketID() {
|
function getCurrentTicketID() {
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
return urlParams.get('ticket_id');
|
return urlParams.get('ticket_id');
|
||||||
@@ -55,7 +53,6 @@
|
|||||||
timerInterval = setInterval(countTime, 1000);
|
timerInterval = setInterval(countTime, 1000);
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
document.getElementById("startStopTimer").innerText = "Pause";
|
document.getElementById("startStopTimer").innerText = "Pause";
|
||||||
updateRunningTicketsCount();
|
|
||||||
localStorage.setItem("ticket-timer-running-" + ticketID, "true");
|
localStorage.setItem("ticket-timer-running-" + ticketID, "true");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -70,7 +67,6 @@
|
|||||||
localStorage.removeItem(getLocalStorageKey("startTime"));
|
localStorage.removeItem(getLocalStorageKey("startTime"));
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
document.getElementById("startStopTimer").innerText = "Start";
|
document.getElementById("startStopTimer").innerText = "Start";
|
||||||
updateRunningTicketsCount();
|
|
||||||
localStorage.setItem("ticket-timer-running-" + ticketID, "false");
|
localStorage.setItem("ticket-timer-running-" + ticketID, "false");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,7 +87,6 @@
|
|||||||
document.getElementById("startStopTimer").innerText = "Start";
|
document.getElementById("startStopTimer").innerText = "Start";
|
||||||
}
|
}
|
||||||
localStorage.setItem("ticket-timer-running-" + ticketID, "false");
|
localStorage.setItem("ticket-timer-running-" + ticketID, "false");
|
||||||
updateRunningTicketsCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function forceResetTimer() {
|
function forceResetTimer() {
|
||||||
@@ -125,18 +120,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateRunningTicketsCount() {
|
|
||||||
let runningTickets = parseInt(document.getElementById('runningTicketsCount').innerText, 10);
|
|
||||||
|
|
||||||
if (!isPaused && timerInterval) {
|
|
||||||
runningTickets += 1;
|
|
||||||
} else {
|
|
||||||
runningTickets = Math.max(0, runningTickets - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById('runningTicketsCount').innerText = runningTickets.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to check status and pause timer
|
// Function to check status and pause timer
|
||||||
function checkStatusAndPauseTimer() {
|
function checkStatusAndPauseTimer() {
|
||||||
var status = document.querySelector('select[name="status"]').value;
|
var status = document.querySelector('select[name="status"]').value;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
<!-- Center navbar links -->
|
<!-- Center navbar links -->
|
||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- SEARCH FORM -->
|
<!-- SEARCH FORM -->
|
||||||
<form class="form-inline" action="global_search.php">
|
<form class="form-inline" action="global_search.php">
|
||||||
<div class="input-group input-group-sm">
|
<div class="input-group input-group-sm">
|
||||||
|
|||||||
Reference in New Issue
Block a user