From e3ae8df4d87033132a21c28953fbf6bc75657619 Mon Sep 17 00:00:00 2001 From: Hugo Sampaio Date: Fri, 31 Jan 2025 11:50:06 -0300 Subject: [PATCH] new changes --- ajax.php | 77 +++++++++++++++++++++++++++++++++ database_updates.php | 2 +- db.sql | 2 +- plugins/dragula/dragula.min.css | 1 + plugins/dragula/dragula.min.js | 1 + post/user/ticket_kanban.php | 50 --------------------- tickets.php | 10 +++-- tickets_kanban.php | 36 +++++++-------- 8 files changed, 107 insertions(+), 72 deletions(-) create mode 100644 plugins/dragula/dragula.min.css create mode 100644 plugins/dragula/dragula.min.js delete mode 100644 post/user/ticket_kanban.php diff --git a/ajax.php b/ajax.php index 36b232db..59ce8bf9 100644 --- a/ajax.php +++ b/ajax.php @@ -529,3 +529,80 @@ if (isset($_GET['get_totp_token_via_id'])) { if (isset($_GET['get_readable_pass'])) { echo json_encode(GenerateReadablePassword(4)); } + +/* + * ITFlow - POST request handler for client tickets + */ +if (isset($_POST['update_kanban_status_position'])) { + // Update multiple ticket status kanban orders + enforceUserPermission('module_support', 2); + + $positions = $_POST['positions']; + + foreach ($positions as $position) { + $status_id = intval($position['status_id']); + $kanban = intval($position['status_kanban']); + + mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_order = $kanban WHERE ticket_status_id = $status_id"); + } + + // return a response + echo json_encode(['status' => 'success']); + exit; +} + +if (isset($_POST['update_kanban_ticket'])) { + // Update ticket kanban order and status + enforceUserPermission('module_support', 2); + + + // have to do new logic, to update only one dragged ticket + $positions = $_POST['positions']; //old and new position + + + + + // old logic that updated all tickets on the column + $positions = $_POST['positions']; + + foreach ($positions as $position) { + $ticket_id = intval($position['ticket_id']); + $kanban = intval($position['ticket_kanban']); // ticket kanban position + $status = intval($position['ticket_status']); // ticket statuses + $oldStatus = intval($position['ticket_oldStatus']); // ticket old status if moved + + $statuses['Closed'] = 5; + $statuses['Resolved'] = 4; + + // Continue if status is null / Closed + if ($status === null || $status === $statuses['Closed']) { + continue; + } + + + if ($oldStatus === false) { + // if ticket was not moved, just uptdate the order on kanban + mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban WHERE ticket_id = $ticket_id"); + customAction('ticket_update', $ticket_id); + } else { + // If the ticket was moved from a resolved status to another status, we need to update ticket_resolved_at + if ($oldStatus === $statuses['Resolved']) { + mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status, ticket_resolved_at = NULL WHERE ticket_id = $ticket_id"); + customAction('ticket_update', $ticket_id); + } elseif ($status === $statuses['Resolved']) { + // If the ticket was moved to a resolved status, we need to update ticket_resolved_at + mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id"); + customAction('ticket_update', $ticket_id); + } else { + // If the ticket was moved from any status to another status + mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status WHERE ticket_id = $ticket_id"); + customAction('ticket_update', $ticket_id); + } + } + + } + + // return a response + echo json_encode(['status' => 'success','payload' => $positions]); + exit; +} \ No newline at end of file diff --git a/database_updates.php b/database_updates.php index bac093b9..d0610d0a 100644 --- a/database_updates.php +++ b/database_updates.php @@ -2472,7 +2472,7 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { if (CURRENT_DATABASE_VERSION == '1.8.0') { - mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_kanban` int(11)"); + mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_order` int(11)"); mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_kanban` int(11);"); diff --git a/db.sql b/db.sql index b8236e31..c1c4ea8d 100644 --- a/db.sql +++ b/db.sql @@ -2019,7 +2019,7 @@ CREATE TABLE `ticket_statuses` ( `ticket_status_name` varchar(200) NOT NULL, `ticket_status_color` varchar(200) NOT NULL, `ticket_status_active` tinyint(1) NOT NULL DEFAULT 1, - `ticket_status_kanban` int(11), + `ticket_status_order` int(11), PRIMARY KEY (`ticket_status_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/plugins/dragula/dragula.min.css b/plugins/dragula/dragula.min.css new file mode 100644 index 00000000..a080100e --- /dev/null +++ b/plugins/dragula/dragula.min.css @@ -0,0 +1 @@ +.gu-mirror{position:fixed!important;margin:0!important;z-index:9999!important;opacity:.8}.gu-hide{display:none!important}.gu-unselectable{-webkit-user-select:none!important;-moz-user-select:none!important;-ms-user-select:none!important;user-select:none!important}.gu-transit{opacity:.2} \ No newline at end of file diff --git a/plugins/dragula/dragula.min.js b/plugins/dragula/dragula.min.js new file mode 100644 index 00000000..dd61cd87 --- /dev/null +++ b/plugins/dragula/dragula.min.js @@ -0,0 +1 @@ +!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).dragula=e()}(function(){return function o(r,i,u){function c(t,e){if(!i[t]){if(!r[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(a)return a(t,!0);throw(n=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",n}n=i[t]={exports:{}},r[t][0].call(n.exports,function(e){return c(r[t][1][e]||e)},n,n.exports,o,r,i,u)}return i[t].exports}for(var a="function"==typeof require&&require,e=0;ee.left+G(e)/2);return n(u>e.top+J(e)/2)}:function(){var e,t,n,o=r.children.length;for(e=0;ei)return t;if(!c&&n.top+n.height/2>u)return t}return null})();function n(e){return e?Z(t):t}}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./classes":1,"contra/emitter":5,crossvent:6}],3:[function(e,t,n){t.exports=function(e,t){return Array.prototype.slice.call(e,t)}},{}],4:[function(e,t,n){"use strict";var o=e("ticky");t.exports=function(e,t,n){e&&o(function(){e.apply(n||null,t||[])})}},{ticky:10}],5:[function(e,t,n){"use strict";var c=e("atoa"),a=e("./debounce");t.exports=function(r,e){var i=e||{},u={};return void 0===r&&(r={}),r.on=function(e,t){return u[e]?u[e].push(t):u[e]=[t],r},r.once=function(e,t){return t._once=!0,r.on(e,t),r},r.off=function(e,t){var n=arguments.length;if(1===n)delete u[e];else if(0===n)u={};else{e=u[e];if(!e)return r;e.splice(e.indexOf(t),1)}return r},r.emit=function(){var e=c(arguments);return r.emitterSnapshot(e.shift()).apply(this,e)},r.emitterSnapshot=function(o){var e=(u[o]||[]).slice(0);return function(){var t=c(arguments),n=this||r;if("error"===o&&!1!==i.throws&&!e.length)throw 1===t.length?t[0]:t;return e.forEach(function(e){i.async?a(e,t,n):e.apply(n,t),e._once&&r.off(o,e)}),r}},r}},{"./debounce":4,atoa:3}],6:[function(n,o,e){(function(r){"use strict";var i=n("custom-event"),u=n("./eventmap"),c=r.document,e=function(e,t,n,o){return e.addEventListener(t,n,o)},t=function(e,t,n,o){return e.removeEventListener(t,n,o)},a=[];function l(e,t,n){t=function(e,t,n){var o,r;for(o=0;o 'success']); - exit; -} - -if (isset($_POST['update_kanban_ticket'])) { - // Update ticket kanban order and status - enforceUserPermission('module_support', 2); - - $positions = $_POST['positions']; - - foreach ($positions as $position) { - $ticket_id = intval($position['ticket_id']); - $kanban = intval($position['ticket_kanban']); // ticket kanban position - $status = intval($position['ticket_status']); // ticket statuses - - // Continue if status is null - if ($status === null) { - continue; - } - - mysqli_query($mysqli, "UPDATE tickets SET ticket_kanban = $kanban, ticket_status = $status WHERE ticket_id = $ticket_id"); - customAction('ticket_update', $ticket_id); - } - - // return a response - echo json_encode(['status' => 'success','payload' => $positions]); - exit; -} diff --git a/tickets.php b/tickets.php index e70d7b29..d7d8fd24 100644 --- a/tickets.php +++ b/tickets.php @@ -41,10 +41,12 @@ if (isset($_GET['category'])) { if ($category == 'empty') { $category_snippet = "AND ticket_category = 0 "; } elseif ($category == 'all') { - $category_snippet = ""; + $category_snippet = ''; } else { $category_snippet = "AND ticket_category = " . $category; } +} else { + $category_snippet = ''; } @@ -166,8 +168,10 @@ $sql_categories = mysqli_query( List Compact List + Kanban +
@@ -353,9 +357,9 @@ $sql_categories = mysqli_query(
- +