OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
87
app/Domain/Timesheets/Hxcontrollers/Stopwatch.php
Normal file
87
app/Domain/Timesheets/Hxcontrollers/Stopwatch.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Domain\Timesheets\Hxcontrollers;
|
||||
|
||||
use Error;
|
||||
use Leantime\Core\Auth\Permissions\RequiresPermission;
|
||||
use Leantime\Core\Controller\HtmxController;
|
||||
use Leantime\Domain\Timesheets\Permissions\TimesheetsPermissions;
|
||||
use Leantime\Domain\Timesheets\Services\Timesheets;
|
||||
|
||||
class Stopwatch extends HtmxController
|
||||
{
|
||||
protected static string $view = 'timesheets::partials.stopwatch';
|
||||
|
||||
private Timesheets $timesheetService;
|
||||
|
||||
/**
|
||||
* Controller constructor
|
||||
*/
|
||||
public function init(Timesheets $timesheetService): void
|
||||
{
|
||||
$this->timesheetService = $timesheetService;
|
||||
}
|
||||
|
||||
/**
|
||||
* show stop watch
|
||||
*/
|
||||
#[RequiresPermission(TimesheetsPermissions::VIEW, global: true)]
|
||||
public function getStatus(): void
|
||||
{
|
||||
|
||||
$onTheClock = session()->exists('userdata') ? $this->timesheetService->isClocked(session('userdata.id')) : false;
|
||||
$this->tpl->assign('onTheClock', $onTheClock);
|
||||
}
|
||||
|
||||
/**
|
||||
* show stop watch
|
||||
*/
|
||||
#[RequiresPermission(TimesheetsPermissions::CREATE, global: true)]
|
||||
public function stopTimer(): void
|
||||
{
|
||||
if ($this->incomingRequest->getMethod() !== 'PATCH') {
|
||||
throw new Error('This endpoint only supports PATCH requests');
|
||||
}
|
||||
|
||||
$params = $this->incomingRequest->request->all();
|
||||
|
||||
if (isset($params['action']) && $params['action'] === 'stop') {
|
||||
$ticketId = (int) filter_var($params['ticketId'], FILTER_SANITIZE_NUMBER_INT);
|
||||
$hoursBooked = $this->timesheetService->punchOut($ticketId);
|
||||
}
|
||||
|
||||
$this->tpl->setHTMXEvent('timerUpdate');
|
||||
|
||||
$onTheClock = session()->exists('userdata') ? $this->timesheetService->isClocked(session('userdata.id')) : false;
|
||||
$this->tpl->assign('onTheClock', $onTheClock);
|
||||
}
|
||||
|
||||
#[RequiresPermission(TimesheetsPermissions::CREATE, global: true)]
|
||||
public function startTimer(): void
|
||||
{
|
||||
if ($this->incomingRequest->getMethod() !== 'PATCH') {
|
||||
throw new Error('This endpoint only supports PATCH requests');
|
||||
}
|
||||
|
||||
$params = $this->incomingRequest->request->all();
|
||||
|
||||
if (isset($params['action']) && $params['action'] === 'start') {
|
||||
$ticketId = (int) filter_var($params['ticketId'], FILTER_SANITIZE_NUMBER_INT);
|
||||
|
||||
if ($ticketId > 0) {
|
||||
$result = $this->timesheetService->punchIn($ticketId);
|
||||
|
||||
if ($result) {
|
||||
$this->tpl->setNotification(__('short_notifications.timer_started'), 'success');
|
||||
} else {
|
||||
$this->tpl->setNotification(__('short_notifications.timer_start_failed'), 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->tpl->setHTMXEvent('timerUpdate');
|
||||
|
||||
$onTheClock = session()->exists('userdata') ? $this->timesheetService->isClocked(session('userdata.id')) : false;
|
||||
$this->tpl->assign('onTheClock', $onTheClock);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user