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

3678: Require timelog comment via settings #39

Merged
merged 10 commits into from
Jan 29, 2025
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## [3.3.0] - 2025-01-17

* [PR-39](https://github.com/ITK-Leantime/leantime-timetable/pull/39)
* Require timelog comments via settings
* [PR-37](https://github.com/ITK-Leantime/leantime-timetable/pull/37)
* Reimplement ability to move timelog to another date

Expand Down
3 changes: 3 additions & 0 deletions Controllers/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function get(): Response
{
try {
$ticketCacheExpiration = (int) ($this->settingsRepo->getSetting('itk-leantime-timetable.ticketCacheExpiration') ?: self::DEFAULT_TICKET_EXPIRATION);
$requireTimeRegistrationComment = (int) ($this->settingsRepo->getSetting('itk-leantime-timetable.requireTimeRegistrationComment') ?: 0);
$this->template->assign('ticketCacheExpiration', $ticketCacheExpiration);
$this->template->assign('requireTimeRegistrationComment', $requireTimeRegistrationComment);
} catch (\Exception $e) {
$this->template->setNotification('An error occurred while saving the settings. ' . $e, 'error');
}
Expand All @@ -63,6 +65,7 @@ public function post(array $params): RedirectResponse
{
try {
$this->settingsRepo->saveSetting('itk-leantime-timetable.ticketCacheExpiration', (int)($params['ticketCacheExpiration'] ?? self::DEFAULT_TICKET_EXPIRATION));
$this->settingsRepo->saveSetting('itk-leantime-timetable.requireTimeRegistrationComment', (int)($params['requireTimeRegistrationComment'] ?? 0));
$this->template->setNotification('The settings were successfully saved.', 'success');
} catch (\Exception $e) {
$this->template->setNotification('An error occurred while saving the settings. ' . $e, 'error');
Expand Down
1 change: 1 addition & 0 deletions Controllers/TimeTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function get(): Response
$this->template->assign('fromDate', $fromDate);
$this->template->assign('toDate', $toDate);
$this->template->assign('allStateLabels', json_encode($allStateLabels));
$this->template->assign('requireTimeRegistrationComment', $this->settings->getSetting('itk-leantime-timetable.requireTimeRegistrationComment') ?? 0);
return $this->template->display('TimeTable.timetable');
}
}
9 changes: 9 additions & 0 deletions Templates/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
name="ticketCacheExpiration" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<label>Require timelog comment</label>
</div>
<div class="col-md-8">
<input type="checkbox" value="1" name="requireTimeRegistrationComment"
{{ (int) $requireTimeRegistrationComment === 1 ? 'checked' : '' }} />
</div>
</div>
<input type="submit" value="Save" id="saveBtn" />
</form>

Expand Down
7 changes: 5 additions & 2 deletions Templates/timetable.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<h1>{{ __('timeTable.headline') }}</h1>
</div>
</div>

<!-- page header -->
<div class="maincontent">
<div class="maincontentinner">
Expand Down Expand Up @@ -88,7 +89,8 @@ class="timetable-to-today btn btn-default">{{ __('timeTable.button_show_this_wee
$hours = $timesheetDate[0]['hours'] ?? null;
$hoursLeft = $timesheetDate[0]['hourRemaining'] ?? null;
$description = $timesheetDate[0]['description'] ?? null;
$isMissingDescription = isset($hours) && trim($description) === '';
$requireTimeRegistrationComment = $requireTimeRegistrationComment ?? 0;
$isMissingDescription = isset($hours) & (trim($description) === '') && $requireTimeRegistrationComment !== 0;

// accumulate hours
if ($hours) {
Expand Down Expand Up @@ -206,7 +208,8 @@ class="timetable-edit-entry {{ $weekendClass }} {{ $todayClass }} {{ $newWeekCla
{{-- Description input --}}
<div class="description-wrapper">
<textarea type="text" id="modal-description" name="timesheet-description"
placeholder="{{ __('timeTable.description') }}" required></textarea>
placeholder="{{ __('timeTable.description') }}"
{{ (int) $requireTimeRegistrationComment === 1 ? 'required' : '' }}></textarea>
</div>
<div class="timesheet-date-move-notifier hidden"><small><i class="fa fa-exclamation-circle"></i>
{{ __('timeTable.about_to_move') }}</small></div>
Expand Down
2 changes: 2 additions & 0 deletions assets/timeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jQuery(document).ready(function ($) {
const pluginSettings = {
userId: timetableSettings.settings.userId,
allStateLabels: $("#all-state-labels").val(),
requireTimeRegistrationComment:
timetableSettings.settings.requireTimeRegistrationComment,
};

class TimeTable {
Expand Down
2 changes: 1 addition & 1 deletion bin/create-release
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ find "${target_dir}" -type f -exec sed -i "s/%%VERSION%%/${tag}/g" {} \;

# Strip any leading `dev-` from tag name in package name.
name="${plugin_name}-${tag#dev-}.tar.gz"
tar --create --file "$name" -C "$release_dir" "$plugin_name"
tar --gzip --create --file "$name" -C "$release_dir" "$plugin_name"
sha256sum "$name" >| checksum.txt

# Clean up
Expand Down
2 changes: 1 addition & 1 deletion dist/js/timeTable.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions register.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ function () {
echo '<link rel="stylesheet" href="' . htmlspecialchars($timeTableStyle) . '"></link>';
$userId = htmlspecialchars(session('userdata.id'), ENT_QUOTES, 'UTF-8');
$ticketCacheExpiration = app()->make(Setting::class)->getSetting('itk-leantime-timetable.ticketCacheExpiration') ?: '1200';
$requireTimeRegistrationComment = app()->make(Setting::class)->getSetting('itk-leantime-timetable.requireTimeRegistrationComment') ?: '0';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 0 a sane default? what does 0 mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should '0' be a int perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really any reason to save it as int, so i changed it to just use the provided string "1" or setting it to "0"


echo '<script>';
echo 'const timetableSettings = ' . json_encode([
'settings' => [
'userId' => $userId,
'ticketCacheExpiration' => $ticketCacheExpiration,
'requireTimeRegistrationComment' => $requireTimeRegistrationComment,
],
], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
echo '</script>';
Expand Down
Loading