diff --git a/app/Http/Controllers/Api/V1/ReportController.php b/app/Http/Controllers/Api/V1/ReportController.php
index 46fe7208..5a53fb64 100644
--- a/app/Http/Controllers/Api/V1/ReportController.php
+++ b/app/Http/Controllers/Api/V1/ReportController.php
@@ -148,6 +148,8 @@ public function update(Organization $organization, Report $report, ReportUpdateR
$report->share_secret = null;
$report->public_until = null;
}
+ } elseif ($report->is_public && $request->has('public_until')) {
+ $report->public_until = $request->getPublicUntil();
}
$report->save();
diff --git a/e2e/organization.spec.ts b/e2e/organization.spec.ts
index ebb4a539..3b1e046e 100644
--- a/e2e/organization.spec.ts
+++ b/e2e/organization.spec.ts
@@ -230,7 +230,9 @@ test('test that format settings are reflected in the dashboard', async ({
await expect(page.getByText('0.00€')).toBeVisible();
// check that 00:00 is displayed
- await expect(page.getByText('0:00', { exact: true }).nth(0)).toBeVisible();
+ await expect(
+ page.getByText('0:00 h', { exact: true }).nth(0)
+ ).toBeVisible();
// check that 0h 00min is not displayed
await expect(
page.getByText('0h 00min', { exact: true }).nth(0)
diff --git a/e2e/projects.spec.ts b/e2e/projects.spec.ts
index 156d66e6..d30ac382 100644
--- a/e2e/projects.spec.ts
+++ b/e2e/projects.spec.ts
@@ -102,7 +102,7 @@ test('test that updating billable rate works with existing time entries', async
await page.getByRole('row').first().getByRole('button').click();
await page.getByRole('menuitem').getByText('Edit').first().click();
- await page.getByText('Non-Billable').click();
+ await page.getByText('Non-Billable').click();
await page.getByText('Custom Rate').click();
await page
.getByPlaceholder('Billable Rate')
@@ -136,6 +136,49 @@ test('test that updating billable rate works with existing time entries', async
).toBeVisible();
});
+test('test that creating and updating project time estimate works', async ({ page }) => {
+ const newProjectName = 'New Project ' + Math.floor(1 + Math.random() * 10000);
+ const timeEstimate = '10';
+
+ await goToProjectsOverview(page);
+ await page.getByRole('button', { name: 'Create Project' }).click();
+ await page.getByLabel('Project Name').fill(newProjectName);
+ await page.getByLabel('Time Estimated').fill(timeEstimate);
+
+ await Promise.all([
+ page.getByRole('button', { name: 'Create Project' }).click(),
+ page.waitForResponse(
+ async (response) =>
+ response.url().includes('/projects') &&
+ response.request().method() === 'POST' &&
+ response.status() === 201 &&
+ (await response.json()).data.estimated_time === parseInt(timeEstimate) * 60 * 60
+ ),
+ ]);
+
+ // Check that time estimate is displayed in the projects table
+ await expect(page.getByTestId('project_table')).toContainText(timeEstimate + 'h');
+
+ // Edit project to remove time estimate
+ await page.getByRole('row').first().getByRole('button').click();
+ await page.getByRole('menuitem').getByText('Edit').first().click();
+ await page.getByLabel('Time Estimated').fill('');
+
+ await Promise.all([
+ page.getByRole('button', { name: 'Update Project' }).click(),
+ page.waitForResponse(
+ async (response) =>
+ response.url().includes('/projects') &&
+ response.request().method() === 'PUT' &&
+ response.status() === 200 &&
+ (await response.json()).data.estimated_time === null
+ ),
+ ]);
+
+ // Check that time estimate is no longer displayed
+ await expect(page.getByTestId('project_table')).not.toContainText(timeEstimate + 'h');
+});
+
// Create new project with new Client
// Create new project with existing Client
diff --git a/resources/js/Components/Common/Report/ReportCreateModal.vue b/resources/js/Components/Common/Report/ReportCreateModal.vue
index 085b7989..c21f1693 100644
--- a/resources/js/Components/Common/Report/ReportCreateModal.vue
+++ b/resources/js/Components/Common/Report/ReportCreateModal.vue
@@ -15,6 +15,7 @@ import { api } from '@/packages/api/src';
import { Checkbox } from '@/packages/ui/src';
import DatePicker from '@/packages/ui/src/Input/DatePicker.vue';
import { useNotificationsStore } from '@/utils/notification';
+import { getLocalizedDayJs } from '@/packages/ui/src/utils/time';
const show = defineModel('show', { default: false });
const saving = ref(false);
@@ -47,10 +48,14 @@ const report = ref({
const { handleApiRequestNotifications } = useNotificationsStore();
async function submit() {
+ const { public_until, ...reportProperties } = report.value;
await handleApiRequestNotifications(
() =>
createReportMutation.mutateAsync({
- ...report.value,
+ ...reportProperties,
+ public_until: public_until
+ ? getLocalizedDayJs(public_until).utc().format()
+ : null,
properties: { ...props.properties },
}),
'Success',
@@ -103,13 +108,16 @@ async function submit() {
diff --git a/resources/js/Components/Common/Report/ReportEditModal.vue b/resources/js/Components/Common/Report/ReportEditModal.vue
index 6d9b161d..cbef9692 100644
--- a/resources/js/Components/Common/Report/ReportEditModal.vue
+++ b/resources/js/Components/Common/Report/ReportEditModal.vue
@@ -13,6 +13,7 @@ import { Checkbox } from '@/packages/ui/src';
import DatePicker from '@/packages/ui/src/Input/DatePicker.vue';
import { useNotificationsStore } from '@/utils/notification';
import type { Report } from '@/packages/api/src';
+import { getLocalizedDayJs } from '@/packages/ui/src/utils/time';
const show = defineModel('show', { default: false });
const saving = ref(false);
@@ -64,8 +65,15 @@ watch(
const { handleApiRequestNotifications } = useNotificationsStore();
async function submit() {
+ const { public_until, ...reportProperties } = report.value;
await handleApiRequestNotifications(
- () => updateReportMutation.mutateAsync(report.value),
+ () =>
+ updateReportMutation.mutateAsync({
+ ...reportProperties,
+ public_until: public_until
+ ? getLocalizedDayJs(public_until).utc().format()
+ : null,
+ }),
'Success',
'Error',
() => {
@@ -118,7 +126,10 @@ async function submit() {
v-if="report.is_public"
class="flex items-center space-x-4">
-
+
diff --git a/resources/js/Pages/Time.vue b/resources/js/Pages/Time.vue
index 1d011e6f..7d02016f 100644
--- a/resources/js/Pages/Time.vue
+++ b/resources/js/Pages/Time.vue
@@ -119,7 +119,8 @@ function deleteSelected() {
-
+
-
-
+
diff --git a/resources/js/packages/ui/src/Input/DatePicker.vue b/resources/js/packages/ui/src/Input/DatePicker.vue
index 74bf6bb4..1ea265b5 100644
--- a/resources/js/packages/ui/src/Input/DatePicker.vue
+++ b/resources/js/packages/ui/src/Input/DatePicker.vue
@@ -1,76 +1,96 @@
-
-
-
+
+
+
+
+
+
+
+
-
-
diff --git a/resources/js/packages/ui/src/Input/DurationInput.vue b/resources/js/packages/ui/src/Input/DurationInput.vue
index 184e303a..efafd53d 100644
--- a/resources/js/packages/ui/src/Input/DurationInput.vue
+++ b/resources/js/packages/ui/src/Input/DurationInput.vue
@@ -2,6 +2,10 @@
import { computed, ref } from 'vue';
import { TextInput } from '@/packages/ui/src';
+defineProps<{
+ id?: string;
+}>();
+
const model = defineModel
({
default: null,
});
@@ -16,6 +20,8 @@ function updateDuration() {
const hours = parseInt(temporaryCustomTimerEntry.value);
if (!isNaN(hours)) {
model.value = hours * 60 * 60;
+ } else {
+ model.value = null;
}
temporaryCustomTimerEntry.value = '';
}
@@ -54,6 +60,7 @@ function updateAndSubmit() {
();
const input = ref(null);
@@ -21,6 +22,7 @@ const model = defineModel();
-import { ref, watch } from 'vue';
-import { getLocalizedDayJs } from '@/packages/ui/src/utils/time';
+import { ref, watch, inject, type ComputedRef } from 'vue';
+import { getLocalizedDayJs, formatTime } from '@/packages/ui/src/utils/time';
import { useFocus } from '@vueuse/core';
import { TextInput } from '@/packages/ui/src';
import { twMerge } from 'tailwind-merge';
+import type { Organization } from '@/packages/api/src';
// This has to be a localized timestamp, not UTC
const model = defineModel({
default: null,
});
+const organization = inject>('organization');
+
const props = withDefaults(
defineProps<{
size?: 'base' | 'large';
@@ -24,62 +27,95 @@ const props = withDefaults(
function updateTime(event: Event) {
const target = event.target as HTMLInputElement;
const newValue = target.value.trim();
- if (newValue.split(':').length === 2) {
- const [hours, minutes] = newValue.split(':');
- if (!isNaN(parseInt(hours)) && !isNaN(parseInt(minutes))) {
+
+ // Get current hours and minutes for comparison
+ const currentTime = model.value ? getLocalizedDayJs(model.value) : null;
+ const currentHours = currentTime?.hour() ?? 0;
+ const currentMinutes = currentTime?.minute() ?? 0;
+
+ // Handle AM/PM format
+ const amPmMatch = newValue.match(/^(\d{1,2}):?(\d{2})?\s*(AM|PM|am|pm)$/);
+ if (amPmMatch) {
+ let hours = amPmMatch[1];
+ const minutes = amPmMatch[2] ?? '00';
+ const period = amPmMatch[3];
+
+ hours = parseInt(hours).toString();
+ if (period.toUpperCase() === 'PM' && hours !== '12') {
+ hours = (parseInt(hours) + 12).toString();
+ } else if (period.toUpperCase() === 'AM' && hours === '12') {
+ hours = '0';
+ }
+
+ const newHours = parseInt(hours);
+ const newMinutes = parseInt(minutes);
+
+ if (newHours !== currentHours || newMinutes !== currentMinutes) {
model.value = getLocalizedDayJs(model.value)
- .set('hours', Math.min(parseInt(hours), 23))
- .set('minutes', Math.min(parseInt(minutes), 59))
+ .set('hours', newHours)
+ .set('minutes', newMinutes)
+ .set('seconds', 0)
.format();
emit('changed', model.value);
}
+ return;
+ }
+
+ // Handle existing formats
+ if (newValue.split(':').length === 2) {
+ const [hours, minutes] = newValue.split(':');
+ if (!isNaN(parseInt(hours)) && !isNaN(parseInt(minutes))) {
+ const newHours = Math.min(parseInt(hours), 23);
+ const newMinutes = Math.min(parseInt(minutes), 59);
+
+ if (newHours !== currentHours || newMinutes !== currentMinutes) {
+ model.value = getLocalizedDayJs(model.value)
+ .set('hours', newHours)
+ .set('minutes', newMinutes)
+ .set('seconds', 0)
+ .format();
+ emit('changed', model.value);
+ }
+ }
}
// check if input is only numbers
else if (/^\d+$/.test(newValue)) {
+ let newHours = currentHours;
+ let newMinutes = currentMinutes;
+
if (newValue.length === 4) {
// parse 1300 to 13:00
- const [hours, minutes] = [
- newValue.slice(0, 2),
- newValue.slice(2, 4),
- ];
- model.value = getLocalizedDayJs(model.value)
- .set('hours', Math.min(parseInt(hours), 23))
- .set('minutes', Math.min(parseInt(minutes), 59))
- .format();
- emit('changed', model.value);
+ newHours = Math.min(parseInt(newValue.slice(0, 2)), 23);
+ newMinutes = Math.min(parseInt(newValue.slice(2, 4)), 59);
} else if (newValue.length === 3) {
// parse 130 to 01:30
- const [hours, minutes] = [
- newValue.slice(0, 1),
- newValue.slice(1, 3),
- ];
- model.value = getLocalizedDayJs(model.value)
- .set('hours', Math.min(parseInt(hours), 23))
- .set('minutes', Math.min(parseInt(minutes), 59))
- .format();
- emit('changed', model.value);
+ newHours = Math.min(parseInt(newValue.slice(0, 1)), 23);
+ newMinutes = Math.min(parseInt(newValue.slice(1, 3)), 59);
} else if (newValue.length === 2) {
// parse 13 to 13:00
- model.value = getLocalizedDayJs(model.value)
- .set('hours', Math.min(parseInt(newValue), 23))
- .set('minutes', 0)
- .format();
- emit('changed', model.value);
+ newHours = Math.min(parseInt(newValue), 23);
+ newMinutes = 0;
} else if (newValue.length === 1) {
// parse 1 to 01:00
+ newHours = Math.min(parseInt(newValue), 23);
+ newMinutes = 0;
+ }
+
+ if (newHours !== currentHours || newMinutes !== currentMinutes) {
model.value = getLocalizedDayJs(model.value)
- .set('hours', Math.min(parseInt(newValue), 23))
- .set('minutes', 0)
+ .set('hours', newHours)
+ .set('minutes', newMinutes)
+ .set('seconds', 0)
.format();
emit('changed', model.value);
}
}
-
- inputValue.value = getLocalizedDayJs(model.value).format('HH:mm');
}
watch(model, (value) => {
- inputValue.value = value ? getLocalizedDayJs(value).format('HH:mm') : null;
+ inputValue.value = value
+ ? formatTime(value, organization?.value?.time_format || '24-hours')
+ : null;
});
const timeInput = ref(null);
@@ -88,7 +124,12 @@ const emit = defineEmits(['changed']);
useFocus(timeInput, { initialValue: props.focus });
const inputValue = ref(
- model.value ? getLocalizedDayJs(model.value).format('HH:mm') : null
+ model.value
+ ? formatTime(
+ model.value,
+ organization?.value?.time_format || '24-hours'
+ )
+ : null
);
@@ -98,7 +139,7 @@ const inputValue = ref(
ref="timeInput"
v-model="inputValue"
:class="
- twMerge('text-center w-24 px-3 py-2', size === 'large' && 'w-28')
+ twMerge('text-center w-28 px-3 py-2', size === 'large' && 'w-28')
"
data-testid="time_picker_input"
type="text"
diff --git a/resources/js/packages/ui/src/Input/TimeRangeSelector.vue b/resources/js/packages/ui/src/Input/TimeRangeSelector.vue
index d4b94627..4e0f2bd8 100644
--- a/resources/js/packages/ui/src/Input/TimeRangeSelector.vue
+++ b/resources/js/packages/ui/src/Input/TimeRangeSelector.vue
@@ -52,26 +52,22 @@ watch(focused, (newValue, oldValue) => {
-
-
emit('close'))">
-
Start
+
+
+ Start
+
emit('close'))"
@keydown.exact.tab.shift.stop.prevent="emit('close')"
@changed="updateTimeEntry">
-
@@ -80,16 +76,31 @@ watch(focused, (newValue, oldValue) => {
emit('close'))"
@changed="updateTimeEntry">
-
-- : --
-
-
+
+
+
+
+
+
+
+
diff --git a/resources/js/packages/ui/src/TimeEntry/TimeEntryCreateModal.vue b/resources/js/packages/ui/src/TimeEntry/TimeEntryCreateModal.vue
index 1e670dd6..4a9d61d1 100644
--- a/resources/js/packages/ui/src/TimeEntry/TimeEntryCreateModal.vue
+++ b/resources/js/packages/ui/src/TimeEntry/TimeEntryCreateModal.vue
@@ -29,7 +29,7 @@ import DurationHumanInput from '@/packages/ui/src/Input/DurationHumanInput.vue';
import { InformationCircleIcon } from '@heroicons/vue/20/solid';
import type { Tag, Task } from '@/packages/api/src';
-import TimePickerSimple from "@/packages/ui/src/Input/TimePickerSimple.vue";
+import TimePickerSimple from '@/packages/ui/src/Input/TimePickerSimple.vue';
const show = defineModel('show', { default: false });
const saving = ref(false);
@@ -148,9 +148,7 @@ type BillableOption = {
+ :enable-estimated-time="
+ enableEstimatedTime
+ ">
@@ -242,37 +242,33 @@ type BillableOption = {
-
-
Start
-
+
-
- Cancel
+ Cancel
{
const inputField = ref(null);
const timeRangeSelector = ref(null);
+const isMouseDown = ref(false);
function openModalOnTab(e: FocusEvent) {
// check if the source is inside the dropdown
+
+ console.log(e.target);
const source = e.relatedTarget as HTMLElement;
if (
source &&
window.document.body
.querySelector('#app')
- ?.contains(source)
+ ?.contains(source) &&
+ !isMouseDown.value
) {
open.value = true;
}
@@ -153,6 +157,8 @@ function closeAndFocusInput() {
@keydown.exact.tab="focusNextElement"
@keydown.exact.shift.tab="open = false"
@blur="updateTimerAndStartLiveTimerUpdate"
+ @mousedown="isMouseDown = true"
+ @mouseup="isMouseDown = false"
@keydown.enter="onTimeEntryEnterPress" />
diff --git a/resources/js/packages/ui/src/utils/time.ts b/resources/js/packages/ui/src/utils/time.ts
index d856ddac..fe6b072e 100644
--- a/resources/js/packages/ui/src/utils/time.ts
+++ b/resources/js/packages/ui/src/utils/time.ts
@@ -13,7 +13,6 @@ import updateLocale from 'dayjs/plugin/updateLocale';
import { computed } from 'vue';
import { formatNumber } from './number';
-
export type DateFormat =
| 'point-separated-d-m-yyyy'
| 'slash-separated-mm-dd-yyyy'
@@ -28,7 +27,7 @@ const dateFormatMap: Record = {
'slash-separated-dd-mm-yyyy': 'DD/MM/YYYY',
'hyphen-separated-dd-mm-yyyy': 'DD-MM-YYYY',
'hyphen-separated-mm-dd-yyyy': 'MM-DD-YYYY',
- 'hyphen-separated-yyyy-mm-dd': 'YYYY-MM-DD'
+ 'hyphen-separated-yyyy-mm-dd': 'YYYY-MM-DD',
};
export type TimeFormat = '12-hours' | '24-hours';
@@ -84,7 +83,7 @@ export function formatHumanReadableDuration(
case 'hours-minutes':
return `${hours}h ${minutes.toString().padStart(2, '0')}min`;
case 'hours-minutes-colon-separated':
- return `${hours}:${minutes.toString().padStart(2, '0')}`;
+ return `${hours}:${minutes.toString().padStart(2, '0')} h`;
case 'hours-minutes-seconds-colon-separated':
return `${hours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
default:
@@ -129,7 +128,10 @@ export function getLocalizedDateFromTimestamp(timestamp: string) {
* Returns a formatted date.
* @param date - date in the format of 'YYYY-MM-DD'
*/
-export function formatDate(date: string, format: DateFormat = 'point-separated-d-m-yyyy'): string {
+export function formatDate(
+ date: string,
+ format: DateFormat = 'point-separated-d-m-yyyy'
+): string {
if (date?.includes('+')) {
console.warn(
'Date contains timezone information, use formatDateLocalized instead'
@@ -142,11 +144,18 @@ export function formatDate(date: string, format: DateFormat = 'point-separated-d
* Returns a formatted date.
* @param date - date in the format of 'YYYY-MM-DD'
*/
-export function formatDateLocalized(date: string, format: DateFormat = 'point-separated-d-m-yyyy'): string {
+export function formatDateLocalized(
+ date: string,
+ format: DateFormat = 'point-separated-d-m-yyyy'
+): string {
return getLocalizedDayJs(date).format(dateFormatMap[format]);
}
-export function formatDateTimeLocalized(date: string, dateFormat?: DateFormat, timeFormat?: TimeFormat): string {
+export function formatDateTimeLocalized(
+ date: string,
+ dateFormat?: DateFormat,
+ timeFormat?: TimeFormat
+): string {
const format = `${dateFormatMap[dateFormat ?? 'point-separated-d-m-yyyy']} ${timeFormat === '12-hours' ? 'hh:mm A' : 'HH:mm'}`;
return getLocalizedDayJs(date).format(format);
}
@@ -172,7 +181,11 @@ export function formatWeekday(date: string) {
return dayjs(date).format('dddd');
}
-export function formatStartEnd(start: string, end: string | null, timeFormat: TimeFormat = '24-hours') {
+export function formatStartEnd(
+ start: string,
+ end: string | null,
+ timeFormat: TimeFormat = '24-hours'
+) {
if (end) {
return `${formatTime(start, timeFormat)} - ${formatTime(end, timeFormat)}`;
} else {
diff --git a/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php b/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php
index 0239e050..8c54c346 100644
--- a/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php
+++ b/tests/Unit/Endpoint/Api/V1/ReportEndpointTest.php
@@ -340,6 +340,35 @@ public function test_update_endpoint_does_not_change_the_secret_of_a_public_repo
);
}
+ public function test_update_endpoint_can_update_public_until_without_changing_secret(): void
+ {
+ // Arrange
+ $data = $this->createUserWithPermission([
+ 'reports:update',
+ ]);
+ $report = Report::factory()->public()->forOrganization($data->organization)->create();
+ $secret = $report->share_secret;
+ $newPublicUntil = Carbon::now()->addDays(30)->toIso8601ZuluString();
+ Passport::actingAs($data->user);
+
+ // Act
+ $response = $this->putJson(route('api.v1.reports.update', [$data->organization->getKey(), $report->getKey()]), [
+ 'public_until' => $newPublicUntil,
+ ]);
+
+ // Assert
+ $report->refresh();
+ $this->assertTrue($report->is_public);
+ $this->assertSame($secret, $report->share_secret);
+ $this->assertSame($newPublicUntil, $report->public_until->toIso8601ZuluString());
+ $response->assertStatus(200);
+ $response->assertJson(fn (AssertableJson $json) => $json
+ ->has('data')
+ ->where('data.is_public', true)
+ ->where('data.shareable_link', $report->getShareableLink())
+ );
+ }
+
public function test_update_endpoint_can_update_the_report_all_properties_set(): void
{
// Arrange