ticket kanban settings

This commit is contained in:
Hugo Sampaio 2025-02-04 17:07:42 -03:00
parent 65bb1b4007
commit ee2e4b671d
7 changed files with 59 additions and 42 deletions

View File

@ -2476,6 +2476,10 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_order` int(11) NOT NULL DEFAULT 0");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_default_view` tinyint(1) NOT NULL DEFAULT 0");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_ordering` tinyint(1) NOT NULL DEFAULT 0");
mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_moving_columns` tinyint(1) NOT NULL DEFAULT 1");
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.8.1'");
}

3
db.sql
View File

@ -1704,6 +1704,9 @@ CREATE TABLE `settings` (
`config_ticket_autoclose_hours` int(5) NOT NULL DEFAULT 72,
`config_ticket_new_ticket_notification_email` varchar(200) DEFAULT NULL,
`config_ticket_default_billable` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_default_view` tinyint(1) NOT NULL DEFAULT 0,
`config_ticket_moving_columns` tinyint(1) NOT NULL DEFAULT 1,
`config_ticket_ordering` tinyint(1) NOT NULL DEFAULT 0,
`config_enable_cron` tinyint(1) NOT NULL DEFAULT 0,
`config_recurring_auto_send_invoice` tinyint(1) NOT NULL DEFAULT 1,
`config_enable_alert_domain_expire` tinyint(1) NOT NULL DEFAULT 1,

View File

@ -75,6 +75,9 @@ $config_ticket_client_general_notifications = intval($row['config_ticket_client_
$config_ticket_autoclose_hours = intval($row['config_ticket_autoclose_hours']);
$config_ticket_new_ticket_notification_email = $row['config_ticket_new_ticket_notification_email'];
$config_ticket_default_billable = intval($row['config_ticket_default_billable']);
$config_ticket_default_view = intval($row['config_ticket_default_view']);
$config_ticket_moving_columns = intval($row['config_ticket_moving_columns']);
$config_ticket_ordering = intval($row['config_ticket_ordering']);
// Cron
$config_enable_cron = intval($row['config_enable_cron']);

View File

@ -1,20 +1,25 @@
$(document).ready(function() {
console.log('CONFIG_TICKET_MOVING_COLUMNS: ' + CONFIG_TICKET_MOVING_COLUMNS);
console.log('CONFIG_TICKET_ORDERING: ' + CONFIG_TICKET_ORDERING);
// Initialize Dragula for the Kanban board
let boardDrake = dragula([
document.querySelector('#kanban-board')
], {
moves: function(el, container, handle) {
return handle.classList.contains('panel-title');
},
accepts: function(el, target, source, sibling) {
return CONFIG_TICKET_MOVING_COLUMNS === 1;
}
});
// Log the event of moving the column panel-title
boardDrake.on('drag', function(el) {
console.log('Dragging column:', el.querySelector('.panel-title').innerText);
//console.log('Dragging column:', el.querySelector('.panel-title').innerText);
});
boardDrake.on('drop', function(el, target, source, sibling) {
console.log('Dropped column:', el.querySelector('.panel-title').innerText);
//console.log('Dropped column:', el.querySelector('.panel-title').innerText);
// Get all columns and their positions
let columns = document.querySelectorAll('#kanban-board .kanban-column');
@ -55,6 +60,11 @@ $(document).ready(function() {
drake.on('drop', function (el, target, source, sibling) {
// Log the target ID to the console
//console.log('Dropped into:', target.getAttribute('data-column-name'));
if (CONFIG_TICKET_ORDERING === 0 && source == target) {
drake.cancel(true); // Move the card back to its original position
return;
}
// Get all cards in the target column and their positions
let cards = $(target).children('.task');

View File

@ -14,8 +14,11 @@ if (isset($_POST['edit_ticket_settings'])) {
if (filter_var($_POST['config_ticket_new_ticket_notification_email'], FILTER_VALIDATE_EMAIL)) {
$config_ticket_new_ticket_notification_email = sanitizeInput($_POST['config_ticket_new_ticket_notification_email']);
}
mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_email_parse = $config_ticket_email_parse, config_ticket_email_parse_unknown_senders = $config_ticket_email_parse_unknown_senders, config_ticket_autoclose_hours = $config_ticket_autoclose_hours, config_ticket_new_ticket_notification_email = '$config_ticket_new_ticket_notification_email', config_ticket_default_billable = $config_ticket_default_billable WHERE company_id = 1");
$config_ticket_default_view = intval($_POST['config_ticket_default_view']);
$config_ticket_moving_columns = intval($_POST['config_ticket_moving_columns']);
$config_ticket_ordering = intval($_POST['config_ticket_ordering']);
mysqli_query($mysqli,"UPDATE settings SET config_ticket_prefix = '$config_ticket_prefix', config_ticket_next_number = $config_ticket_next_number, config_ticket_email_parse = $config_ticket_email_parse, config_ticket_email_parse_unknown_senders = $config_ticket_email_parse_unknown_senders, config_ticket_autoclose_hours = $config_ticket_autoclose_hours, config_ticket_new_ticket_notification_email = '$config_ticket_new_ticket_notification_email', config_ticket_default_billable = $config_ticket_default_billable, config_ticket_default_view = $config_ticket_default_view, config_ticket_moving_columns = $config_ticket_moving_columns, config_ticket_ordering = $config_ticket_ordering WHERE company_id = 1");
// Logging
logAction("Settings", "Edit", "$session_name edited ticket settings");
@ -24,4 +27,4 @@ if (isset($_POST['edit_ticket_settings'])) {
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
}

View File

@ -357,7 +357,7 @@ $sql_categories = mysqli_query(
</div>
</div>
<?php
<?php
if (isset($_GET["view"])) {
if ($_GET["view"] == "list") {
@ -369,7 +369,15 @@ if (isset($_GET["view"])) {
}
} else {
// here we have to get default view setting
require_once "tickets_list.php";
if ($config_ticket_default_view === 0) {
require_once "tickets_list.php";
} elseif ($config_ticket_default_view === 1) {
require_once "tickets_compact.php";
} elseif ($config_ticket_default_view === 2) {
require_once "tickets_kanban.php";
} else {
require_once "tickets_list.php";
}
}
?>

View File

@ -20,6 +20,19 @@ while ($status_row = mysqli_fetch_array($status_sql)) {
$statuses[$id]->order = $kanban_order; // Store the order
}
$ordering_snippet = "ORDER BY
CASE
WHEN ticket_priority = 'High' THEN 1
WHEN ticket_priority = 'Medium' THEN 2
WHEN ticket_priority = 'Low' THEN 3
ELSE 4
END,
ticket_id DESC";
if ($config_ticket_ordering === 1) {
$ordering_snippet = "ORDER BY ticket_order ASC";
}
// Fetch tickets and merge into statuses
$sql = mysqli_query(
$mysqli,
@ -37,13 +50,12 @@ $sql = mysqli_query(
AND DATE(ticket_created_at) BETWEEN '$dtf' AND '$dtt'
AND (CONCAT(ticket_prefix,ticket_number) LIKE '%$q%' OR client_name LIKE '%$q%' OR ticket_subject LIKE '%$q%' OR ticket_status_name LIKE '%$q%' OR ticket_priority LIKE '%$q%' OR user_name LIKE '%$q%' OR contact_name LIKE '%$q%' OR asset_name LIKE '%$q%' OR vendor_name LIKE '%$q%' OR ticket_vendor_ticket_number LIKE '%q%')
$ticket_permission_snippet
ORDER BY $sort $order"
$ordering_snippet"
);
while ($row = mysqli_fetch_array($sql)) {
$id = $row['ticket_status_id'];
$ticket_order = $row['ticket_order'];
$row['ticket_order'] = $ticket_order; // Store the ticket order
// Loop over all items in $row to apply nullable_htmlentities only if the content is a string
foreach ($row as $key => $value) {
@ -58,38 +70,7 @@ while ($row = mysqli_fetch_array($sql)) {
}
// Convert associative array to indexed array for sorting
$kanban_array = array_values($statuses);
// Sort the array by the 'order' field, moving null values to the end
usort($kanban_array, function($a, $b) {
if ($a->order === null) {
return 1;
}
if ($b->order === null) {
return -1;
}
return $a->order - $b->order;
});
// Sort tickets within each column by 'ticket_order'
foreach ($kanban_array as $kanban_column) {
usort($kanban_column->tickets, function($a, $b) {
return $a['ticket_order'] - $b['ticket_order'];
});
}
// Re-index the sorted array back to associative array if needed
$ordered_kanban = [];
foreach ($kanban_array as $item) {
$ordered_kanban[$item->id] = $item;
}
$kanban = $ordered_kanban;
$kanban = array_values($statuses);
?>
@ -161,6 +142,11 @@ $kanban = $ordered_kanban;
</div>
<?php
echo "<script>";
echo "const CONFIG_TICKET_MOVING_COLUMNS = " . json_encode($config_ticket_moving_columns) . ";";
echo "const CONFIG_TICKET_ORDERING = " . json_encode($config_ticket_ordering) . ";";
echo "</script>";
?>
<script src="/plugins/dragula/dragula.min.js"></script>
<script src="/js/tickets_kanban.js"></script>