Commenting & segmenting into functions

This commit is contained in:
Corban-Lee Jones 2024-01-23 12:10:42 +00:00
parent 6effc6799e
commit 7c00552714

View File

@ -231,6 +231,13 @@ $("#strictTags").on("change", function() {
loadTicketItems();
});
/**
* Loads the list of ticket items using the current filters.
*
* @function loadTicketItems
* @param {Number} page For pagination, an invalid page will result in an error.
*/
function loadTicketItems(page=1) {
if (global_loadingTickets) {
@ -278,7 +285,26 @@ function loadTicketItems(page=1) {
// Iterate over and handle each ticket
response.results.forEach(function(ticket) {
$("#ticketsContainer .content").append(createTicketItem(ticket));
});
// Make tickets clickable
applyTicketClickFunction();
updateItemsState("content");
global_loadingTickets = false;
});
}
/**
* Returns a jquery object representing an element for a ticket item, constructed using the passed
* ticket and a predefined template.
*
* @function createTicketItem
* @param {Object} ticket An object representing a ticket.
* @return {jQuery} ticketElement to be appeneded as content.
*/
function createTicketItem(ticket) {
// Create a copy of the template using the ticket data
var template = $($("#ticketItemTemplate").html());
template.find(".ticket-item-author").text(`${ticket.author.forename} ${ticket.author.surname}`);
@ -296,14 +322,18 @@ function loadTicketItems(page=1) {
template.find(".ticket-item-tags").append(tagTemplate);
});
const priority = ticket.priority;
var priorityElem = template.find(".ticket-item-priority");
priorityElem.css("color", ticket.priority.colour);
priorityElem.css("background-color", ticket.priority.backgroundcolour);
priorityElem.attr("data-bs-title", ticket.priority.title + " Priority");
priorityElem.css("color", priority.colour);
priorityElem.css("background-color", priority.backgroundcolour);
priorityElem.attr("data-bs-title", priority.title + " Priority");
priorityElem.tooltip();
const department = ticket.author.department;
var departmentElem = template.find(".ticket-item-department");
if (ticket.author.department === null) {
if (department === null) {
departmentElem.hide();
}
else {
@ -313,18 +343,15 @@ function loadTicketItems(page=1) {
departmentElem.tooltip();
}
// Add the content to the interface
$("#ticketsContainer .content").append(template);
});
// Make tickets clickable
applyTicketClickFunction();
updateItemsState("content");
global_loadingTickets = false;
});
return template;
}
/**
* Load the content of a selected ticket.
*
* @function loadTicketContent
* @param {String} uuid A string representation of the ticket's UUID.
*/
function loadTicketContent(uuid) {
updateContentState("loading");
@ -338,7 +365,21 @@ function loadTicketContent(uuid) {
fetchTicketsPromise({uuid: uuid}).then((response) => {
ticket = response.results[0];
$("#ticketContent .content").append(createTicketContent(ticket));
updateContentState("content");
global_loadingTickets = false;
});
}
/**
* Returns a jquery object representing an element for a ticket content, constructed using the
* passed ticket and a predefined template.
*
* @function createTicketItem
* @param {Object} ticket An object representing a ticket.
* @return {jQuery} ticketElement to be shown as content.
*/
function createTicketContent(ticket) {
// Create a copy of the template using the ticket data
var template = $($("#ticketContentTemplate").html());
template.find(".ticket-content-author").text(`${ticket.author.forename} ${ticket.author.surname}`);
@ -355,15 +396,7 @@ function loadTicketContent(uuid) {
template.find(".ticket-content-badges").append(tagTemplate);
});
$("#ticketContent .content").append(template);
updateContentState("content");
global_loadingTickets = false;
});
// $("#ticketContent").empty();
// updateInterfaceState("showing-content");
return template;
}
function fetchTicketsPromise(queryFilters) {