Skip to content
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
2 changes: 1 addition & 1 deletion .idea/leantime-oss.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 60 additions & 12 deletions app/Domain/Timesheets/Controllers/ShowMyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
use Leantime\Core\Controller\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Auth\Services\Auth;
use Leantime\Domain\Clients\Services\Clients as ClientService;
use Leantime\Domain\Projects\Services\Projects as ProjectService;
use Leantime\Domain\Timesheets\Services\Timesheets as TimesheetService;
use Symfony\Component\HttpFoundation\Response;

class ShowMyList extends Controller
{
private TimesheetService $timesheetService;

public function init(TimesheetService $timesheetService): void
private ProjectService $projectService;

private ClientService $clientService;

public function init(TimesheetService $timesheetService, ProjectService $projectService, ClientService $clientService): void
{
$this->timesheetService = $timesheetService;
$this->projectService = $projectService;
$this->clientService = $clientService;
session(['lastPage' => BASE_URL.'/timesheets/showMyList']);
}

Expand All @@ -31,15 +39,38 @@ public function run(): Response

$kind = 'all';
if (! empty($_POST['kind'])) {
$kind = ($_POST['kind']);
$kind = (string) $_POST['kind'];
}

// Use UTC here as all data stored in the database should be UTC (start in user's timezone and convert to UTC).
// The front end javascript is hardcode to start the week on mondays, so we use that here too.
$projectId = -1;
if (isset($_POST['projectId']) && $_POST['projectId'] !== '' && $_POST['projectId'] !== 'all') {
$projectId = (int) $_POST['projectId'];
}

// Get start of the week in current users timezone and then switch to UTC
$dateFrom = dtHelper()->userNow()->startOfWeek(CarbonInterface::MONDAY)->setToDbTimezone();
$dateTo = dtHelper()->userNow()->endOfWeek()->setToDbTimezone();
$clientId = -1;
if (isset($_POST['clientId']) && $_POST['clientId'] !== '' && $_POST['clientId'] !== '-1') {
$clientId = (int) $_POST['clientId'];
}

$invEmplCheck = '-1';
if (isset($_POST['invEmpl']) && $_POST['invEmpl'] === '1') {
$invEmplCheck = '1';
}

$invCompCheck = '0';
if (isset($_POST['invComp'])) {
$invCompCheck = $_POST['invComp'] === 'on' || $_POST['invComp'] === '1' ? '1' : '0';
}

$paidCheck = '0';
if (isset($_POST['paid'])) {
$paidCheck = ($_POST['paid'] === 'on' || $_POST['paid'] === '1') ? '1' : '0';
}

// Use UTC here as all data stored in the database should be UTC (start in user's timezone and convert to UTC).
// Default view: This Month (start and end of current month in user's timezone).
$dateFrom = dtHelper()->userNow()->startOfMonth()->setToDbTimezone();
$dateTo = dtHelper()->userNow()->endOfMonth()->setToDbTimezone();

if (! empty($_POST['dateFrom'])) {
$dateFrom = dtHelper()->parseUserDateTime($_POST['dateFrom'])->setToDbTimezone();
Expand All @@ -49,19 +80,36 @@ public function run(): Response
$dateTo = dtHelper()->parseUserDateTime($_POST['dateTo'])->setToDbTimezone();
}

$userId = session('userdata.id');
$allProjects = $this->projectService->getProjectsUserHasAccessTo($userId);
if (! is_array($allProjects)) {
$allProjects = [];
}

$allClients = $this->clientService->getAll();

$this->tpl->assign('dateFrom', $dateFrom);
$this->tpl->assign('dateTo', $dateTo);
$this->tpl->assign('actKind', $kind);
$this->tpl->assign('projectFilter', $projectId);
$this->tpl->assign('allProjects', $allProjects);
$this->tpl->assign('clientFilter', $clientId);
$this->tpl->assign('allClients', $allClients);
$this->tpl->assign('invEmpl', $invEmplCheck);
$this->tpl->assign('invComp', $invCompCheck);
$this->tpl->assign('paid', $paidCheck);
$this->tpl->assign('kind', $this->timesheetService->getLoggableHourTypes());
$this->tpl->assign('allTimesheets', $this->timesheetService->getAll(
dateFrom: $dateFrom,
dateTo: $dateTo,
projectId: -1,
projectId: $projectId,
kind: $kind,
userId: session('userdata.id'),
invEmpl: -1,
invComp: -1,
paid: -1
userId: $userId,
invEmpl: $invEmplCheck,
invComp: $invCompCheck,
paid: $paidCheck,
ticketFilter: '-1',
clientId: (string) $clientId
));

// Pass user's hours format preference to template for CSV export
Expand Down
89 changes: 26 additions & 63 deletions app/Domain/Timesheets/Js/timesheetsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,74 +105,37 @@ leantime.timesheetsController = (function () {
});
};

var isReady = false;
var pendingClick = null;

document.addEventListener('click', function(e) {
var target = e.target.closest('.editTimeModal');
if (target && !isReady) {
e.preventDefault();
e.stopPropagation();

target.style.opacity = '0.5';
target.style.cursor = 'wait';

pendingClick = target;
}
}, true);

function initWhenReady() {

if (typeof jQuery.fn.nyroModal === 'undefined') {
setTimeout(initWhenReady, 100);
return;
}

initEditTimeModal();
isReady = true;

if (pendingClick) {
var $pending = jQuery(pendingClick);
pendingClick.style.opacity = '';
pendingClick.style.cursor = '';
$pending.trigger('click');
pendingClick = null;
}
}

var initEditTimeModal = function () {
var canvasoptions = {
sizes: {
minW: 700,
maxW: 1000,
minH: 1000,
},
resizable: false,
autoSizable: false,
callbacks: {
beforeShowCont: function () {
jQuery(".showDialogOnLoad").show();

if (closeModal === true) {
closeModal = false;
var initEditTimeModal = function () {
var canvasoptions = {
sizes: {
minW: 700,
maxW: 1000,
minH: 1000,
},
resizable: false,
autoSizable: false,
callbacks: {
beforeShowCont: function () {
jQuery(".showDialogOnLoad").show();

if (closeModal === true) {
closeModal = false;
location.reload();
}
},
beforeClose: function () {
location.reload();
}
},
beforeClose: function () {
location.reload();
}
},
titleFromIframe: true
};
titleFromIframe: true
};

jQuery(document).on('click', '.editTimeModal', function (e) {
if (!isReady) return;
e.preventDefault();
jQuery(this).nyroModal(canvasoptions);
});
};
jQuery(document).on('click', '.editTimeModal', function (e) {
e.preventDefault();
jQuery(this).nyroModal(canvasoptions);
});
};

initWhenReady();

var formatHours = function (hours) {
var hoursFormat = jQuery('.timesheetTable').data('hours-format') ||
Expand Down
3 changes: 0 additions & 3 deletions app/Domain/Timesheets/Templates/showMy.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@

jQuery("#finalSum").text(roundedSum);
});
<?php if ($login::userIsAtLeast($roles::$manager)) { ?>
leantime.timesheetsController.initEditTimeModal();
<?php } ?>
});
</script>

Expand Down
Loading
Loading