Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticket design fix #2854

Merged
merged 9 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/Domain/Comments/Hxcontrollers/CommentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CommentList extends HtmxController
*/
private Comments $commentService;

private Language $language;
public Language $language;

/**
* Controller constructor
Expand All @@ -42,14 +42,13 @@ public function save(): void

if ($editComment > 0 && $this->commentService->editComment($_POST, $editComment)) {
$this->tpl->setNotification($this->language->__('notifications.comment_saved_success'), 'success');
} elseif ($editComment == '' && $this->commentService->addComment($_POST, $module, $moduleId)) {
} elseif (($editComment == ''||$editComment==null) && $this->commentService->addComment($_POST, $module, $moduleId)) {
$this->tpl->setNotification($this->language->__('notifications.comment_create_success'), 'success');
} else {
$this->tpl->setNotification($this->language->__('notifications.comment_create_error'), 'error');
}

$comments = $this->commentService->getComments($module, $moduleId);

$this->tpl->assign('module', $module);
$this->tpl->assign('moduleId', $moduleId);
$this->tpl->assign('includeStatus', $includeStatus);
Expand Down
6 changes: 3 additions & 3 deletions app/Domain/Comments/Services/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function getComments(string $module, int $moduleId, int $commentOrder = 0

//Comes back as flat list
$comments = $this->commentRepository->getComments($module, $moduleId, $parent, $commentOrder);

/* @var array<comments> */
$commentsArray = [];

Expand Down Expand Up @@ -99,7 +98,7 @@ public function addComment($values, $module, $entityId): bool
throw new AuthException('User is not authorized to add comments');
}

if (isset($values['text']) && $values['text'] != '' && isset($values['father']) && isset($module) && isset($entityId) && isset($entity)) {
if (isset($values['text']) && $values['text'] != '' && isset($values['father']) && isset($module) && isset($entityId)) {
$mapper = [
'text' => $values['text'],
'date' => dtHelper()->dbNow()->formatDateTimeForDb(),
Expand All @@ -109,6 +108,7 @@ public function addComment($values, $module, $entityId): bool
'status' => $values['status'] ?? '',
];


$comment = $this->commentRepository->addComment($mapper, $module);

if ($comment) {
Expand All @@ -117,7 +117,7 @@ public function addComment($values, $module, $entityId): bool
$currentUrl = CURRENT_URL;

switch ($module) {
case 'ticket':
case 'tickets':
$entity = $this->ticketService->getTicket($entityId);
$subject = sprintf($this->language->__('email_notifications.new_comment_todo_with_type_subject'), $this->language->__('label.'.strtolower($entity->type)), $entity->id, $entity->headline);
$message = sprintf($this->language->__('email_notifications.new_comment_todo_with_type_message'), session('userdata.name'), $this->language->__('label.'.strtolower($entity->type)), $entity->headline, $values['text']);
Expand Down
21 changes: 11 additions & 10 deletions app/Domain/Tickets/Controllers/NewTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function init(
$this->userService = $userService;

if (! session()->exists('lastPage')) {
session(['lastPage' => BASE_URL.'/tickets/showKanban/']);
session(['lastPage' => BASE_URL . '/tickets/showKanban/']);
}
}

Expand Down Expand Up @@ -117,14 +117,15 @@ public function post($params): Response

if (is_array($result) === false) {
$this->tpl->setNotification($this->language->__('notifications.ticket_saved'), 'success');
return response()->json(['success' => true]);

if (isset($params['saveAndCloseTicket']) === true && $params['saveAndCloseTicket'] == 1) {
return Frontcontroller::redirectHtmx('#/tickets/showTicket/'.$result.'?closeModal=1');
} else {
return Frontcontroller::redirectHtmx('#/tickets/showTicket/'.$result);
}
// if (isset($params['saveAndCloseTicket']) === true && $params['saveAndCloseTicket'] == 1) {
// return Frontcontroller::redirectHtmx('#/tickets/showTicket/'.$result.'?closeModal=1');
// } else {
// return Frontcontroller::redirectHtmx('#/tickets/showTicket/'.$result);
// }
} else {
$this->tpl->setNotification($this->language->__($result['msg']), 'error');
// $this->tpl->setNotification($this->language->__($result['msg']), 'error');

$ticket = app()->makeWith(TicketModel::class, ['values' => $params]);
$ticket->userLastname = session('userdata.name');
Expand All @@ -150,12 +151,12 @@ public function post($params): Response
$allAssignedprojects = $this->projectService->getProjectsUserHasAccessTo(session('userdata.id'), 'open');
$this->tpl->assign('allAssignedprojects', $allAssignedprojects);

return $this->tpl->displayPartial('tickets::partials.newTicketModal');
// return $this->tpl->displayPartial('tickets::partials.newTicketModal');
return response()->json(['success' => false]);
}
}

return Frontcontroller::redirect(BASE_URL.'/tickets/newTicket');
return response()->json(['success' => true]);
}
}

}
10 changes: 5 additions & 5 deletions app/Domain/Tickets/Controllers/ShowTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function init(
$this->userService = $userService;

if (session()->exists('lastPage') === false) {
session(['lastPage' => BASE_URL.'/tickets/showKanban']);
session(['lastPage' => BASE_URL . '/tickets/showKanban']);
}
}

Expand All @@ -74,15 +74,15 @@ public function get($params): Response
if (session('currentProject') != $ticket->projectId) {
$this->projectService->changeCurrentSessionProject($ticket->projectId);

return Frontcontroller::redirect(BASE_URL.'/tickets/showTicket/'.$id);
return Frontcontroller::redirect(BASE_URL . '/tickets/showTicket/' . $id);
}

//Delete file
if (isset($params['delFile']) === true) {
if ($result = $this->fileService->deleteFile($params['delFile'])) {
$this->tpl->setNotification($this->language->__('notifications.file_deleted'), 'success');

return Frontcontroller::redirect(BASE_URL.'/tickets/showTicket/'.$id.'#files');
return Frontcontroller::redirect(BASE_URL . '/tickets/showTicket/' . $id . '#files');
}

$this->tpl->setNotification($result['msg'], 'error');
Expand Down Expand Up @@ -201,14 +201,14 @@ public function post($params): Response
}

if (isset($params['saveAndCloseTicket']) === true && $params['saveAndCloseTicket'] == 1) {
$response = Frontcontroller::redirect(BASE_URL.'/tickets/showTicket/'.$id.'?closeModal=1');
$response = Frontcontroller::redirect(BASE_URL . '/tickets/showTicket/' . $id . '?closeModal=1');
$response->headers->set('HX-Trigger', 'ticketUpdate');

return $response;
}
}

$response = Frontcontroller::redirect(BASE_URL.'/tickets/showTicket/'.$id.''.$tab);
$response = Frontcontroller::redirect(BASE_URL . '/tickets/showTicket/' . $id . '' . $tab);
$response->headers->set('HX-Trigger', 'ticketUpdate');

return $response;
Expand Down
71 changes: 71 additions & 0 deletions app/Domain/Tickets/Hxcontrollers/NewTicket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Leantime\Domain\Tickets\Hxcontrollers;

use Leantime\Core\Controller\HtmxController;
use Leantime\Domain\Tickets\Services\Tickets;
use Leantime\Domain\Timesheets\Services\Timesheets;
use Leantime\Domain\Projects\Services\Projects;
use Symfony\Component\HttpFoundation\Response;
use Leantime\Core\Support\FromFormat;
use Leantime\Domain\Sprints\Services\Sprints as SprintService;
use Leantime\Domain\Tickets\Models\Tickets as TicketModel;
use Leantime\Domain\Users\Services\Users as UserService;

class NewTicket extends HtmxController
{
protected static string $view = 'tickets::components.ticket-column';

private Tickets $ticketService;
private Projects $projectService;
private Timesheets $timesheetService;
private SprintService $sprintService;
private UserService $userService;

/**
* Controller constructor
*
* @param Timesheets $timesheetService
*/
public function init(Tickets $ticketService, Projects $projectService, Timesheets $timesheetService, SprintService $sprintService, UserService $userService): void
{
$this->ticketService = $ticketService;
$this->projectService = $projectService;
$this->timesheetService = $timesheetService;
$this->sprintService = $sprintService;
$this->userService = $userService;
}

public function post($params): Response
{
if (!empty($params['tags']) && is_array($params['tags'])) {
$params['tags'] = implode(',', $params['tags']);
}
if (isset($params['saveTicket']) || isset($params['saveAndCloseTicket'])) {

$params['timeToFinish'] = format(value: $params['timeToFinish'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();
$params['timeFrom'] = format(value: $params['timeFrom'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();
$params['timeTo'] = format(value: $params['timeTo'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();

$result = $this->ticketService->addTicket($params);

if (is_array($result) === false) {
$this->tpl->setNotification($this->language->__('notifications.ticket_saved'), 'success');
return response()->json(['success' => true]);
} else {

$ticket = app()->makeWith(TicketModel::class, ['values' => $params]);
$ticket->userLastname = session('userdata.name');
return response()->json(['success' => false]);
}
}

return response()->json(['success' => true]);
}


public function get(): Response
{
return response()->json(['success' => true]);
}
}
109 changes: 109 additions & 0 deletions app/Domain/Tickets/Hxcontrollers/ShowTicket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace Leantime\Domain\Tickets\Hxcontrollers;

use Leantime\Core\Controller\HtmxController;
use Leantime\Domain\Tickets\Services\Tickets;
use Leantime\Domain\Timesheets\Services\Timesheets;
use Leantime\Domain\Projects\Services\Projects;
use Symfony\Component\HttpFoundation\Response;
use Leantime\Core\Support\FromFormat;


class ShowTicket extends HtmxController
{
protected static string $view = 'tickets::components.ticket-column';

private Tickets $ticketService;
private Projects $projectService;
private Timesheets $timesheetService;
/**
* Controller constructor
*
* @param Timesheets $timesheetService
*/
public function init(Tickets $ticketService, Projects $projectService, Timesheets $timesheetService): void
{
$this->ticketService = $ticketService;
$this->projectService = $projectService;
$this->timesheetService = $timesheetService;
}

// public function post($params): Response
// {
// // $ticketId = (int) ($params['id']);
// $statusKey = (int) ($params['status']);
// $allTickets = $this->ticketService->getAll(['status' => $statusKey]);
// $ticketTypeIcons = $this->ticketService->getTypeIcons();
// $priorities = $this->ticketService->getPriorityLabels();
// $efforts = $this->ticketService->getEffortLabels();
// $milestones = $this->ticketService->getAllMilestones(['sprint' => '', 'type' => 'milestone', 'currentProject' => session('currentProject')]);
// $users = $this->projectService->getUsersAssignedToProject(session('currentProject'));
// $onTheClock = $this->timesheetService->isClocked(session('userdata.id'));

// $this->tpl->assign('onTheClock', $onTheClock);
// $this->tpl->assign("efforts", $efforts);
// $this->tpl->assign("milestones", $milestones);
// $this->tpl->assign("users", $users);
// $this->tpl->assign("allTickets", $allTickets);
// $this->tpl->assign("ticketTypeIcons", $ticketTypeIcons);
// $this->tpl->assign("priorities", $priorities);
// $this->tpl->assign("statusKey", $statusKey);
// }

public function post($params): Response
{
if (! isset($_GET['id'])) {
return $this->tpl->display('errors.error400', responseCode: 400);
}

// dd($params);

$tab = '';
$id = (int) ($_GET['id']);
$ticket = $this->ticketService->getTicket($id);

if ($ticket === false) {
return $this->tpl->display('errors.error500', responseCode: 500);
}

if (!empty($params['tags']) && is_array($params['tags'])) {
$params['tags'] = implode(',', $params['tags']);
}

//Log time
if (isset($params['saveTimes']) === true) {
$result = $this->timesheetService->logTime($id, $params);

if ($result === true) {
$this->tpl->setNotification($this->language->__('notifications.time_logged_success'), 'success');
} else {
$this->tpl->setNotification($this->language->__($result['msg']), 'error');
}
}

//Save Ticket
$params['projectId'] = $ticket->projectId;
$params['id'] = $id;

//Prepare values, time comes in as 24hours from time input. Service expects time to be in local user format
$params['timeToFinish'] = format(value: $params['timeToFinish'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();
$params['timeFrom'] = format(value: $params['timeFrom'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();
$params['timeTo'] = format(value: $params['timeTo'] ?? '', fromFormat: FromFormat::User24hTime)->userTime24toUserTime();

$result = $this->ticketService->updateTicket($params);

if ($result === true) {
$this->tpl->setNotification($this->language->__('notifications.ticket_saved'), 'success');
} else {
$this->tpl->setNotification($this->language->__($result['msg']), 'error');
}

if (isset($params['saveAndCloseTicket']) === true && $params['saveAndCloseTicket'] == 1) {
return response()->json(['success' => $result]);
}


return response()->json(['success' => $result]);
}
}
Loading
Loading