Updated
This commit is contained in:
@@ -5,30 +5,41 @@ import Timer from '../../components/Timer.vue';
|
||||
import { db } from '../../db';
|
||||
import { timeEntries, clients, members, tags, timeEntryTags, categories, users } from '../../db/schema';
|
||||
import { eq, desc, asc, and, sql, or, like } from 'drizzle-orm';
|
||||
import { formatTimeRange } from '../../lib/formatTime';
|
||||
|
||||
const user = Astro.locals.user;
|
||||
if (!user) return Astro.redirect('/login');
|
||||
|
||||
const userOrg = await db.select()
|
||||
// Get current team from cookie
|
||||
const currentTeamId = Astro.cookies.get('currentTeamId')?.value;
|
||||
|
||||
const userMemberships = await db.select()
|
||||
.from(members)
|
||||
.where(eq(members.userId, user.id))
|
||||
.get();
|
||||
.all();
|
||||
|
||||
if (!userOrg) return Astro.redirect('/dashboard');
|
||||
if (userMemberships.length === 0) return Astro.redirect('/dashboard');
|
||||
|
||||
// Use current team or fallback to first membership
|
||||
const userMembership = currentTeamId
|
||||
? userMemberships.find(m => m.organizationId === currentTeamId) || userMemberships[0]
|
||||
: userMemberships[0];
|
||||
|
||||
const organizationId = userMembership.organizationId;
|
||||
|
||||
const allClients = await db.select()
|
||||
.from(clients)
|
||||
.where(eq(clients.organizationId, userOrg.organizationId))
|
||||
.where(eq(clients.organizationId, organizationId))
|
||||
.all();
|
||||
|
||||
const allCategories = await db.select()
|
||||
.from(categories)
|
||||
.where(eq(categories.organizationId, userOrg.organizationId))
|
||||
.where(eq(categories.organizationId, organizationId))
|
||||
.all();
|
||||
|
||||
const allTags = await db.select()
|
||||
.from(tags)
|
||||
.where(eq(tags.organizationId, userOrg.organizationId))
|
||||
.where(eq(tags.organizationId, organizationId))
|
||||
.all();
|
||||
|
||||
// Query params
|
||||
@@ -43,7 +54,7 @@ const filterStatus = url.searchParams.get('status') || '';
|
||||
const sortBy = url.searchParams.get('sort') || 'start-desc';
|
||||
const searchTerm = url.searchParams.get('search') || '';
|
||||
|
||||
const conditions = [eq(timeEntries.organizationId, userOrg.organizationId)];
|
||||
const conditions = [eq(timeEntries.organizationId, organizationId)];
|
||||
|
||||
if (filterClient) {
|
||||
conditions.push(eq(timeEntries.clientId, filterClient));
|
||||
@@ -113,15 +124,6 @@ const runningEntry = await db.select({
|
||||
))
|
||||
.get();
|
||||
|
||||
function formatDuration(start: Date, end: Date | null) {
|
||||
if (!end) return 'Running...';
|
||||
const ms = end.getTime() - start.getTime();
|
||||
const minutes = Math.round(ms / (1000 * 60));
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const mins = minutes % 60;
|
||||
return `${hours}h ${mins}m`;
|
||||
}
|
||||
|
||||
function getPaginationPages(currentPage: number, totalPages: number): number[] {
|
||||
const pages: number[] = [];
|
||||
const numPagesToShow = Math.min(5, totalPages);
|
||||
@@ -146,7 +148,7 @@ function getPaginationPages(currentPage: number, totalPages: number): number[] {
|
||||
const paginationPages = getPaginationPages(page, totalPages);
|
||||
---
|
||||
|
||||
<DashboardLayout title="Time Tracker - Zamaan">
|
||||
<DashboardLayout title="Time Tracker - Chronus">
|
||||
<h1 class="text-3xl font-bold mb-6">Time Tracker</h1>
|
||||
|
||||
{allClients.length === 0 ? (
|
||||
@@ -313,7 +315,7 @@ const paginationPages = getPaginationPages(page, totalPages);
|
||||
<span class="badge badge-success">Running</span>
|
||||
)}
|
||||
</td>
|
||||
<td class="font-mono">{formatDuration(entry.startTime, entry.endTime)}</td>
|
||||
<td class="font-mono">{formatTimeRange(entry.startTime, entry.endTime)}</td>
|
||||
<td>
|
||||
<form method="POST" action={`/api/time-entries/${entry.id}/delete`} class="inline">
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user