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
7 changes: 7 additions & 0 deletions backend/fixtures/5-instrument_log_permission.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"id": 1,
"permission": "canWriteLogs",
"instrumentInfo": null
}
]
3 changes: 2 additions & 1 deletion backend/fixtures/5-user_account.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
{ "id": 10 },
{ "id": 11 },
{ "id": 12 }
]
],
"instrumentLogPermissions": [{ "id": 1 }]
},
{
"id": 2,
Expand Down
24 changes: 21 additions & 3 deletions backend/tests/integration/parallel/__snapshots__/auth.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ exports[`GET /auth/login returns admin permissions 1`] = `
{
"fullName": null,
"id": 1,
"instrumentLogPermissions": [],
"instrumentLogPermissions": [
{
"id": 1,
"instrumentInfoUuid": null,
"permission": "canWriteLogs",
},
],
"orcidId": null,
"permissions": [
{
Expand Down Expand Up @@ -61,7 +67,13 @@ exports[`GET /auth/me returns current user with cookie from login 1`] = `
{
"fullName": null,
"id": 1,
"instrumentLogPermissions": [],
"instrumentLogPermissions": [
{
"id": 1,
"instrumentInfoUuid": null,
"permission": "canWriteLogs",
},
],
"orcidId": null,
"permissions": [
{
Expand Down Expand Up @@ -118,7 +130,13 @@ exports[`GET /auth/me returns current user with new cookie 1`] = `
{
"fullName": null,
"id": 1,
"instrumentLogPermissions": [],
"instrumentLogPermissions": [
{
"id": 1,
"instrumentInfoUuid": null,
"permission": "canWriteLogs",
},
],
"orcidId": null,
"permissions": [
{
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/integration/sequential/instrumentLog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ beforeAll(async () => {
const instrumentInfoRepo = dataSource.getRepository(InstrumentInfo);

await logRepo.createQueryBuilder().delete().execute();
await permRepo.createQueryBuilder().delete().execute();
await userRepo.createQueryBuilder().delete().execute();
await permRepo.createQueryBuilder().delete().execute();

const instrumentInfo = await instrumentInfoRepo.findOneByOrFail({ uuid: instrumentInfoUuid });
instrumentPid = instrumentInfo.pid;
Expand Down
54 changes: 42 additions & 12 deletions frontend/src/components/instrument/InstrumentLogbook.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,21 @@
<BaseButton v-if="form.time" type="secondary" size="small" @click="form.time = ''">Clear</BaseButton>
</div>
</div>
<div class="form-group" v-if="requiresTimeRange">
<div class="form-group" v-if="showEndDate">
<label>End date and time (UTC)</label>
<div class="date-time-row">
<DatePicker name="event-end-date" v-model="form.endDate" :end="today" />
<input id="event-end-time" type="time" v-model="form.endTime" required />
<input id="event-end-time" type="time" v-model="form.endTime" :required="requiresTimeRange" />
<BaseButton type="secondary" size="small" @click="setEndNow">Now</BaseButton>
<BaseButton v-if="form.endTime" type="secondary" size="small" @click="form.endTime = ''">Clear</BaseButton>
<BaseButton v-if="!requiresTimeRange" type="secondary" size="small" @click="removeEndDate"
>Remove</BaseButton
>
</div>
</div>
<div v-else-if="!requiresTimeRange" class="add-end-date">
<BaseButton type="secondary" size="small" @click="addEndDate">+ Add end date</BaseButton>
</div>
<div class="form-group">
<label for="event-notes">{{ requiresNotes ? "Notes" : "Notes (optional)" }}</label>
<textarea id="event-notes" v-model="form.notes" rows="6" :required="requiresNotes" />
Expand Down Expand Up @@ -279,14 +285,19 @@ const defaultForm = () => ({
result: "",
date: today as string | null,
time: "",
endDate: today as string | null,
endDate: null as string | null,
endTime: "",
notes: "",
});

function extractTime(dateStr: string): string {
const t = dateStr.slice(11, 16);
return t && t !== "00:00" ? t : "";
}

function formatDate(dateStr: string): string {
const timePart = dateStr.slice(11, 16);
if (timePart && timePart !== "00:00") {
const timePart = extractTime(dateStr);
if (timePart) {
return `${dateStr.slice(0, 10)} ${timePart}`;
}
return dateStr.slice(0, 10);
Expand All @@ -295,13 +306,15 @@ function formatDate(dateStr: string): string {
function formatDateRange(entry: InstrumentLog): string {
const start = formatDate(entry.date);
if (!entry.endDate) return start;
const end = formatDate(entry.endDate);
if (start === end) return start;
const startDay = entry.date.slice(0, 10);
const endDay = entry.endDate.slice(0, 10);
const endTime = entry.endDate.slice(11, 16);
const endTime = extractTime(entry.endDate);
if (startDay === endDay && endTime) {
return `${start} – ${endTime}`;
}
return `${start} – ${formatDate(entry.endDate)}`;
return `${start} – ${end}`;
}

function setNow() {
Expand All @@ -316,6 +329,15 @@ function setEndNow() {
form.value.endTime = now.toISOString().slice(11, 16);
}

function addEndDate() {
form.value.endDate = form.value.date ?? today;
}

function removeEndDate() {
form.value.endDate = null;
form.value.endTime = "";
}

function formatTimestamp(entry: InstrumentLog): string {
let text = `Added on ${entry.createdAt.slice(0, 10)} ${entry.createdAt.slice(11, 16)} UTC`;
if (entry.updatedAt) {
Expand Down Expand Up @@ -351,6 +373,7 @@ const availableDetails = computed(() => {

const availableResults = computed(() => resultOptions[form.value.eventType] ?? []);
const requiresTimeRange = computed(() => timeRangeDetails.has(form.value.detail));
const showEndDate = computed(() => requiresTimeRange.value || form.value.endDate != null);
const requiresNotes = computed(
() =>
notesRequiredEvents.has(form.value.eventType) ||
Expand All @@ -369,9 +392,8 @@ watch(
watch(
() => form.value.detail,
() => {
if (!requiresTimeRange.value) {
if (requiresTimeRange.value && !form.value.endDate) {
form.value.endDate = today;
form.value.endTime = "";
}
},
);
Expand Down Expand Up @@ -420,6 +442,10 @@ async function submitEntry() {
return;
}
endDateStr = `${form.value.endDate}T${form.value.endTime}`;
} else if (form.value.endDate) {
endDateStr = form.value.endTime ? `${form.value.endDate}T${form.value.endTime}` : form.value.endDate;
}
if (endDateStr) {
if (new Date(endDateStr + "Z") < new Date(dateStr + "Z")) {
submitError.value = "End date/time cannot be before start.";
return;
Expand Down Expand Up @@ -484,9 +510,9 @@ async function modifyEntry(entry: InstrumentLog) {
detail: "",
result: "",
date: entry.date.slice(0, 10),
time: entry.date.slice(11, 16) || "",
endDate: entry.endDate ? entry.endDate.slice(0, 10) : today,
endTime: entry.endDate ? entry.endDate.slice(11, 16) : "",
time: extractTime(entry.date),
endDate: entry.endDate ? entry.endDate.slice(0, 10) : null,
endTime: entry.endDate ? extractTime(entry.endDate) : "",
notes: entry.notes ?? "",
};
await nextTick();
Expand Down Expand Up @@ -635,6 +661,10 @@ onMounted(fetchEntries);
margin-top: 1rem;
}

.add-end-date {
margin-bottom: 1rem;
}

.date-time-row {
display: flex;
align-items: center;
Expand Down