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

Fix tickets #2909

Open
wants to merge 3 commits into
base: 4.0-dev
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions app/Domain/Goalcanvas/Controllers/EditCanvasItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ public function get($params): Response
]);
$this->tpl->assign('milestones', $allProjectMilestones);

return $this->tpl->displayPartial('goalcanvas::partials.canvasDialog');
if (!empty($params['id'])) {
return $this->tpl->displayPartial('goalcanvas::partials.canvasDialog');
} else {
return $this->tpl->displayPartial('goalcanvas::partials.newCanvasDialog');
}
}

/**
Expand All @@ -84,7 +88,7 @@ public function post($params): Response
$this->notifyOnCommentCreation($params, $commentId);
$this->tpl->setNotification($this->language->__('notifications.comment_create_success'), 'success');

return Frontcontroller::redirect(BASE_URL.'/goalcanvas/editCanvasItem/'.$_GET['id']);
return Frontcontroller::redirect(BASE_URL . '/goalcanvas/editCanvasItem/' . $_GET['id']);
}
}

Expand All @@ -94,13 +98,12 @@ public function post($params): Response
if ($result) {
$this->notifyOnItemUpdate($result['canvasItem']);
$canvasTypes = $this->goalService->getCanvasTypes();
$this->tpl->setNotification($canvasTypes[$params['box']]['title'].' successfully '.($result['isNew'] ? 'created' : 'updated'), 'success');
$this->tpl->setNotification($canvasTypes[$params['box']]['title'] . ' successfully ' . ($result['isNew'] ? 'created' : 'updated'), 'success');

$this->tpl->closeModal();
$this->tpl->htmxRefresh();

return $this->tpl->emptyResponse();

} else {
$this->tpl->setNotification($this->language->__('notification.please_enter_title'), 'error');
}
Expand All @@ -115,7 +118,7 @@ private function notifyOnCommentCreation($params, $commentId): void
{
$notification = app()->make(NotificationModel::class);
$notification->url = [
'url' => BASE_URL.'/goalcanvas/editCanvasItem/'.(int) $_GET['id'],
'url' => BASE_URL . '/goalcanvas/editCanvasItem/' . (int) $_GET['id'],
'text' => $this->language->__('email_notifications.canvas_item_update_cta'),
];
$notification->entity = array_merge($params, ['id' => $commentId]);
Expand All @@ -135,7 +138,7 @@ private function notifyOnItemUpdate($canvasItem): void
{
$notification = app()->make(NotificationModel::class);
$notification->url = [
'url' => BASE_URL.'/goalcanvas/editCanvasItem/'.(int) $canvasItem['canvasId'],
'url' => BASE_URL . '/goalcanvas/editCanvasItem/' . (int) $canvasItem['canvasId'],
'text' => $this->language->__('email_notifications.canvas_item_update_cta'),
];
$notification->entity = $canvasItem;
Expand Down
2 changes: 2 additions & 0 deletions app/Domain/Goalcanvas/Hxcontrollers/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public function get($params): void
$users = $this->projectService->getUsersAssignedToProject(session('currentProject'));
$canvasItems = $this->goalService->getCanvasItemsById($id);


$this->tpl->assign("canvasId", $id);
$this->tpl->assign('canvas', $canvas);
$this->tpl->assign('statusLabels', $statusLabels);
$this->tpl->assign('relatesLabels', $relatesLabels);
Expand Down
51 changes: 51 additions & 0 deletions app/Domain/Goalcanvas/Hxcontrollers/EditCanvasItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Leantime\Domain\Goalcanvas\Hxcontrollers;

use Leantime\Core\Controller\HtmxController;
use Leantime\Domain\Goalcanvas\Services\Goalcanvas as GoalcanvasService;
use Leantime\Domain\Projects\Services\Projects;
use Symfony\Component\HttpFoundation\Response;
use Leantime\Core\Controller\Frontcontroller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Leantime\Domain\Users\Services\Users as UserService;
use Leantime\Domain\Auth\Services\Auth as AuthService;

class EditCanvasItem extends HtmxController
{
protected static string $view = 'goalcanvas::components.canvas';

private GoalcanvasService $goalService;

private Projects $projectService;

/**
* Controller constructor
*/
public function init(GoalcanvasService $goalService, Projects $projectService): void
{
$this->goalService = $goalService;
$this->projectService = $projectService;
}

public function patch($params): Response
{

if (! AuthService::userIsAtLeast(Roles::$editor)) {
return $this->tpl->displayJson(['error' => 'Not Authorized'], 403);
}

if (! isset($params['id'])) {
return $this->tpl->displayJson(['error' => 'ID not set'], 400);
}

if (! $this->goalService->patch($params['id'], $params)) {
return $this->tpl->displayJson(['error' => 'Could not update status'], 500);
}

//$this->tpl->setNotification($this->tpl->__('notifications.ticket_updated'), 'success');

return $this->tpl->emptyResponse();
}
}
28 changes: 17 additions & 11 deletions app/Domain/Goalcanvas/Services/Goalcanvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function pollForUpdatedGoals(?int $projectId = null, ?int $board = null):

foreach ($goals as $key => $goal) {
$goals[$key] = $this->prepareDatesForApiResponse($goal);
$goals[$key]['id'] = $goal['id'].'-'.$goal['modified'];
$goals[$key]['id'] = $goal['id'] . '-' . $goal['modified'];
}

return $goals;
Expand Down Expand Up @@ -472,7 +472,7 @@ private function calculateItemPercentage(array $item): float

private function determineCurrentCanvasId(array $allCanvas, array $params): int
{
$sessionKey = 'current'.strtoupper('goal').'Canvas';
$sessionKey = 'current' . strtoupper('goal') . 'Canvas';

if (isset($params['id'])) {
$currentCanvasId = (int) $params['id'];
Expand Down Expand Up @@ -567,7 +567,7 @@ public function getAllCanvas()
// Retrieves the stored canvas ID from the session
private function getStoredCanvasId()
{
$sessionKey = 'current'.strtoupper('goal').'Canvas';
$sessionKey = 'current' . strtoupper('goal') . 'Canvas';

return session()->exists($sessionKey) ? session($sessionKey) : -1;
}
Expand All @@ -582,7 +582,7 @@ private function getStoredCanvasId()

private function storeCurrentCanvasId($canvasId)
{
$sessionKey = 'current'.strtoupper('goal').'Canvas';
$sessionKey = 'current' . strtoupper('goal') . 'Canvas';
session([$sessionKey => $canvasId]);
}

Expand Down Expand Up @@ -615,7 +615,7 @@ public function createNewCanvas(string $title): array

$this->notifyUsers('canvas_created', $title);

session(['current'.strtoupper('goal').'Canvas' => $canvasId]);
session(['current' . strtoupper('goal') . 'Canvas' => $canvasId]);

return ['success' => true, 'message' => $this->language->__('notification.board_created')];
}
Expand Down Expand Up @@ -677,7 +677,7 @@ public function cloneCanvas(string $title, int $canvasId): array
$title
);

session(['current'.strtoupper('goal').'Canvas' => $newCanvasId]);
session(['current' . strtoupper('goal') . 'Canvas' => $newCanvasId]);

return ['success' => true, 'message' => $this->language->__('notification.board_copied')];
}
Expand Down Expand Up @@ -725,7 +725,7 @@ public function importCanvas(?array $file): array
throw new \Exception($this->language->__('notification.board_import_failed'));
}

$uploadfile = tempnam(sys_get_temp_dir(), 'leantime.').'.xml';
$uploadfile = tempnam(sys_get_temp_dir(), 'leantime.') . '.xml';

if (! move_uploaded_file($file['tmp_name'], $uploadfile)) {
throw new \Exception($this->language->__('notification.board_import_failed'));
Expand All @@ -734,7 +734,7 @@ public function importCanvas(?array $file): array
$services = app()->make(CanvasService::class);
$importCanvasId = $services->import(
$uploadfile,
'goal'.'canvas',
'goal' . 'canvas',
projectId: session('currentProject'),
authorId: session('userdata.id')
);
Expand All @@ -744,7 +744,7 @@ public function importCanvas(?array $file): array
throw new \Exception($this->language->__('notification.board_import_failed'));
}

session(['current'.strtoupper('goal').'Canvas' => $importCanvasId]);
session(['current' . strtoupper('goal') . 'Canvas' => $importCanvasId]);
$canvas = $this->goalRepository->getSingleCanvas($importCanvasId);
$this->notifyUsers('canvas_imported', $canvas[0]['title']);

Expand All @@ -771,7 +771,7 @@ private function notifyUsers(string $action, string $canvasTitle): void
$message = sprintf(
$this->language->__("email_notifications.canvas_{$action}_message"),
session('userdata.name'),
"<a href='".$actual_link."'>".$canvasTitle.'</a>'
"<a href='" . $actual_link . "'>" . $canvasTitle . '</a>'
);
$mailer->setHtml($message);

Expand Down Expand Up @@ -835,7 +835,7 @@ public function getCanvasData(array $params): array|false
'numComments' => $numComments,
'canvasIcon' => $this->goalRepository->getIcon(),
'canvasTypes' => $this->goalRepository->getCanvasTypes(),
'statusLabels' => $this->goalRepository->getStatusLabels(),
'statusLabels' => $this->getGoalStatusLabels(),
'dataLabels' => $this->goalRepository->getDataLabels(),
];
}
Expand Down Expand Up @@ -1123,5 +1123,11 @@ private function prepareDatesForApiResponse($goal)

return $goal;
}


public function patch($id, $params)
{
return $this->goalRepository->patchCanvasItem($id, $params);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<div class="col-md-12">
<x-global::forms.button scale="sm" class="pull-right" tag="a"
href="#/goalcanvas/editCanvasItem?type=goal&canvasId={{ $canvasId }}">
<i class="fa fa-plus"></i> Create New Goal
{!! __('links.add_new_canvas_itemgoal') !!}

</x-global::forms.button>
<h5 class="text-lg font-extralight">
<a class="text-primary" href='{{ BASE_URL }}/goalcanvas/showCanvas/{{ $canvasId }}'>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@props([
'contentRole' => 'ghost',
'variant' => '',
'labelPosition' => 'top',
'goal' => null,
'showLabel' => false,
])


<x-global::forms.datepicker no-date-label="{{ __('text.anytime') }}" :value="$goal->startDate" name="startDate"
dateName="dueDate-{{ $goal->id }}" :label-position="$labelPosition" :variant="$variant"
hx-post="{{ BASE_URL }}/hx/goalCanvas/editCanvasItem/patch/{{ $goal->id }}" hx-trigger="change" hx-swap="none"
:content-role="$contentRole" :state="$state">
<x-slot:leading-visual>
<x-global::content.icon icon="alarm" class="text-lg text-trivial" />
</x-slot:leading-visual>

@if ($showLabel)
<x-slot:label-text>
<x-global::content.icon icon="alarm" /> <span>{!! __('label.due') !!}</span>
</x-slot:label-text>
@endif

</x-global::forms.datepicker>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@props([
'contentRole' => 'primary',
'variant' => 'chip', //chip, select
'statuses' => [],
'showLabel' => false,
'labelPosition' => 'top',
'dropdownPosition' => 'start',
'goal' => null,
])

<x-global::forms.select name='status' search="false" :dropdown-position="$dropdownPosition" :label-position="$labelPosition" :variant="$variant"
:content-role="$contentRole" hx-post="{{ BASE_URL }}/hx/goalCanvas/editCanvasItem/patch/{{ $goal->id }}"
hx-trigger="change" hx-swap="none">

@if ($showLabel)
<x-slot:label-text>
<x-global::content.icon icon="clock_loader_90" /> {!! __('label.status') !!}
</x-slot:label-text>
@endif


@foreach ($statuses as $key => $label)
<x-global::forms.select.option :value="strtolower($key)" :selected="strtolower($key) == strtolower($goal->status ?? '')">
<x-global::elements.badge :state="$label['dropdown']" :outline="true">

<x-global::content.icon :icon="$label['icon']" /> {{ $label['title'] }}
</x-global::elements.badge>

</x-global::forms.select.option>
@endforeach
</x-global::forms.select>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{{ $row['title'] }}
</a>
</h4>

<strong>Metric:</strong> {{ $row['description'] }}
<br /><br />

Expand All @@ -85,39 +85,25 @@ class="sr-only">{{ sprintf(__('text.percent_complete'), $row['goalProgress']) }}
</div>
</div>

<x-global::actions.dropdown :label-text="'status'" contentRole="link" position="bottom" align="start"
:selectable="true" class="status">
<x-slot:menu>
<li class="nav-header border">{{ __('dropdown.choose_milestone') }}</li>
<x-global::actions.dropdown.item style="background-color: #b0b0b0"
href="javascript:void(0);" data-label="Select status" data-value="status">
{!! __('dropdown.choose_status') !!}
</x-global::actions.dropdown.item>

@foreach ($statusLabels as $key => $data)
<li class='dropdown-item'>
<a href="javascript:void(0);" class="label-{{ $data['dropdown'] }}"
data-label='{{ $data['title'] }}' data-value="{{ $row['id'] . '/' . $key }}"
id="ticketStatusChange{{ $row['id'] . $key }}">{!! $data['title'] !!}</a>
</li>
@endforeach
</x-slot:menu>
</x-global::actions.dropdown>
<div class="flex justify-between mt-2">
<x-goalcanvas::chips.status-select :statuses="$statusLabels" :goal="(object) $row" :showLabel="false"
dropdown-position="start" />

@if (!empty($relatesLabels))
<x-global::forms._archive.dropdownPill>
@foreach ($relatesLabels as $key => $data)
<x-global::forms._archive.dropdownPillOption value="{{ $key }}"
:selected="$row['relates'] === $key">
{{ $data['title'] }}
</x-global::forms._archive.dropdownPillOption>
@endforeach
</x-global::forms._archive.dropdownPill>
@endif
@if (!empty($relatesLabels))
<x-global::forms._archive.dropdownPill>
@foreach ($relatesLabels as $key => $data)
<x-global::forms._archive.dropdownPillOption value="{{ $key }}"
:selected="$row['relates'] === $key">
{{ $data['title'] }}
</x-global::forms._archive.dropdownPillOption>
@endforeach
</x-global::forms._archive.dropdownPill>
@endif

<div class="right">
<span class="fas fa-comments"></span>
<small>{{ $nbcomments }}</small>
<div class="right">
<span class="fas fa-comments"></span>
<small>{{ $nbcomments }}</small>
</div>
</div>
</div>
</div>
Expand Down
Loading
Loading