Jury inline doc preview, download fix, category tags, admin eval reset
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m55s
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m55s
- Replace MultiWindowDocViewer with FileViewer for inline previews (PDF/image/video/Office) - Fix cross-origin download using fetch+blob instead of <a download> - Show Startup/Business Concept badge on jury project detail + evaluate pages - Add admin resetEvaluation procedure with audit logging - Add dropdown menu on admin assignment rows with Reset Evaluation + Delete - Make file action buttons responsive on mobile (separate row below file info) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,7 @@ import {
|
|||||||
Check,
|
Check,
|
||||||
ChevronsUpDown,
|
ChevronsUpDown,
|
||||||
Search,
|
Search,
|
||||||
|
MoreHorizontal,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
import {
|
import {
|
||||||
Command,
|
Command,
|
||||||
@@ -2331,6 +2332,14 @@ function IndividualAssignmentsTable({
|
|||||||
onError: (err) => toast.error(err.message),
|
onError: (err) => toast.error(err.message),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const resetEvalMutation = trpc.evaluation.resetEvaluation.useMutation({
|
||||||
|
onSuccess: () => {
|
||||||
|
utils.assignment.listByStage.invalidate({ roundId })
|
||||||
|
toast.success('Evaluation reset — juror can now start over')
|
||||||
|
},
|
||||||
|
onError: (err) => toast.error(err.message),
|
||||||
|
})
|
||||||
|
|
||||||
const createMutation = trpc.assignment.create.useMutation({
|
const createMutation = trpc.assignment.create.useMutation({
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
utils.assignment.listByStage.invalidate({ roundId })
|
utils.assignment.listByStage.invalidate({ roundId })
|
||||||
@@ -2457,17 +2466,17 @@ function IndividualAssignmentsTable({
|
|||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className="space-y-1 max-h-[500px] overflow-y-auto">
|
<div className="space-y-1 max-h-[500px] overflow-y-auto">
|
||||||
<div className="grid grid-cols-[1fr_1fr_100px_60px] gap-2 text-xs text-muted-foreground font-medium px-3 py-2 sticky top-0 bg-background border-b">
|
<div className="grid grid-cols-[1fr_1fr_100px_70px] gap-2 text-xs text-muted-foreground font-medium px-3 py-2 sticky top-0 bg-background border-b">
|
||||||
<span>Juror</span>
|
<span>Juror</span>
|
||||||
<span>Project</span>
|
<span>Project</span>
|
||||||
<span>Status</span>
|
<span>Status</span>
|
||||||
<span />
|
<span>Actions</span>
|
||||||
</div>
|
</div>
|
||||||
{assignments.map((a: any, idx: number) => (
|
{assignments.map((a: any, idx: number) => (
|
||||||
<div
|
<div
|
||||||
key={a.id}
|
key={a.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
'grid grid-cols-[1fr_1fr_100px_60px] gap-2 items-center px-3 py-2 rounded-md text-sm transition-colors',
|
'grid grid-cols-[1fr_1fr_100px_70px] gap-2 items-center px-3 py-2 rounded-md text-sm transition-colors',
|
||||||
idx % 2 === 1 ? 'bg-muted/20' : 'hover:bg-muted/20',
|
idx % 2 === 1 ? 'bg-muted/20' : 'hover:bg-muted/20',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -2479,22 +2488,50 @@ function IndividualAssignmentsTable({
|
|||||||
'text-[10px] justify-center',
|
'text-[10px] justify-center',
|
||||||
a.evaluation?.status === 'SUBMITTED'
|
a.evaluation?.status === 'SUBMITTED'
|
||||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||||
: a.evaluation?.status === 'IN_PROGRESS'
|
: a.evaluation?.status === 'DRAFT'
|
||||||
? 'bg-blue-50 text-blue-700 border-blue-200'
|
? 'bg-blue-50 text-blue-700 border-blue-200'
|
||||||
: 'bg-gray-50 text-gray-600 border-gray-200',
|
: 'bg-gray-50 text-gray-600 border-gray-200',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{a.evaluation?.status || 'PENDING'}
|
{a.evaluation?.status || 'PENDING'}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Button
|
<DropdownMenu>
|
||||||
variant="ghost"
|
<DropdownMenuTrigger asChild>
|
||||||
size="icon"
|
<Button variant="ghost" size="icon" className="h-7 w-7">
|
||||||
className="h-7 w-7"
|
<MoreHorizontal className="h-3.5 w-3.5 text-muted-foreground" />
|
||||||
onClick={() => deleteMutation.mutate({ id: a.id })}
|
</Button>
|
||||||
disabled={deleteMutation.isPending}
|
</DropdownMenuTrigger>
|
||||||
>
|
<DropdownMenuContent align="end">
|
||||||
<Trash2 className="h-3.5 w-3.5 text-muted-foreground hover:text-red-500" />
|
{a.evaluation && (
|
||||||
</Button>
|
<>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
if (confirm(`Reset evaluation by ${a.user?.name || a.user?.email} for "${a.project?.title}"? This will erase all scores and feedback so they can start over.`)) {
|
||||||
|
resetEvalMutation.mutate({ assignmentId: a.id })
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={resetEvalMutation.isPending}
|
||||||
|
>
|
||||||
|
<RotateCcw className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Reset Evaluation
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="text-destructive focus:text-destructive"
|
||||||
|
onClick={() => {
|
||||||
|
if (confirm(`Remove assignment for ${a.user?.name || a.user?.email} on "${a.project?.title}"?`)) {
|
||||||
|
deleteMutation.mutate({ id: a.id })
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
disabled={deleteMutation.isPending}
|
||||||
|
>
|
||||||
|
<Trash2 className="h-3.5 w-3.5 mr-2" />
|
||||||
|
Delete Assignment
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { Skeleton } from '@/components/ui/skeleton'
|
|||||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { MultiWindowDocViewer } from '@/components/jury/multi-window-doc-viewer'
|
import { MultiWindowDocViewer } from '@/components/jury/multi-window-doc-viewer'
|
||||||
|
import { Badge } from '@/components/ui/badge'
|
||||||
import { ArrowLeft, Save, Send, AlertCircle, ThumbsUp, ThumbsDown, Clock, CheckCircle2 } from 'lucide-react'
|
import { ArrowLeft, Save, Send, AlertCircle, ThumbsUp, ThumbsDown, Clock, CheckCircle2 } from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { toast } from 'sonner'
|
||||||
import type { EvaluationConfig } from '@/types/competition-configs'
|
import type { EvaluationConfig } from '@/types/competition-configs'
|
||||||
@@ -433,7 +434,21 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) {
|
|||||||
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
|
<h1 className="text-2xl font-bold tracking-tight text-brand-blue dark:text-foreground">
|
||||||
Evaluate Project
|
Evaluate Project
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-muted-foreground mt-1">{project.title}</p>
|
<div className="flex items-center gap-2 mt-1">
|
||||||
|
<p className="text-muted-foreground">{project.title}</p>
|
||||||
|
{project.competitionCategory && (
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className={
|
||||||
|
project.competitionCategory === 'STARTUP'
|
||||||
|
? 'bg-violet-100 text-violet-700 border-violet-200 dark:bg-violet-950 dark:text-violet-300'
|
||||||
|
: 'bg-sky-100 text-sky-700 border-sky-200 dark:bg-sky-950 dark:text-sky-300'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -95,15 +95,24 @@ export default function JuryProjectDetailPage() {
|
|||||||
<CardContent className="space-y-6">
|
<CardContent className="space-y-6">
|
||||||
{/* Project metadata */}
|
{/* Project metadata */}
|
||||||
<div className="flex flex-wrap gap-3">
|
<div className="flex flex-wrap gap-3">
|
||||||
|
{project.competitionCategory && (
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className={
|
||||||
|
project.competitionCategory === 'STARTUP'
|
||||||
|
? 'bg-violet-100 text-violet-700 border-violet-200 dark:bg-violet-950 dark:text-violet-300'
|
||||||
|
: 'bg-sky-100 text-sky-700 border-sky-200 dark:bg-sky-950 dark:text-sky-300'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{project.competitionCategory === 'STARTUP' ? 'Startup' : 'Business Concept'}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
{project.country && (
|
{project.country && (
|
||||||
<Badge variant="outline" className="gap-1">
|
<Badge variant="outline" className="gap-1">
|
||||||
<MapPin className="h-3 w-3" />
|
<MapPin className="h-3 w-3" />
|
||||||
{project.country}
|
{project.country}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{project.competitionCategory && (
|
|
||||||
<Badge variant="outline">{project.competitionCategory}</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Project tags */}
|
{/* Project tags */}
|
||||||
|
|||||||
@@ -1,137 +1,16 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
|
||||||
import { trpc } from '@/lib/trpc/client'
|
import { trpc } from '@/lib/trpc/client'
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { Badge } from '@/components/ui/badge'
|
|
||||||
import { Button } from '@/components/ui/button'
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton'
|
import { Skeleton } from '@/components/ui/skeleton'
|
||||||
import { FileText, Download, ExternalLink, Loader2 } from 'lucide-react'
|
import { FileText } from 'lucide-react'
|
||||||
import { toast } from 'sonner'
|
import { FileViewer } from '@/components/shared/file-viewer'
|
||||||
|
|
||||||
interface MultiWindowDocViewerProps {
|
interface MultiWindowDocViewerProps {
|
||||||
roundId: string
|
roundId: string
|
||||||
projectId: string
|
projectId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatFileSize(bytes: number): string {
|
|
||||||
if (bytes === 0) return '0 B'
|
|
||||||
const k = 1024
|
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB']
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k))
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFileIcon(mimeType: string) {
|
|
||||||
if (mimeType.startsWith('image/')) return '🖼️'
|
|
||||||
if (mimeType.startsWith('video/')) return '🎥'
|
|
||||||
if (mimeType.includes('pdf')) return '📄'
|
|
||||||
if (mimeType.includes('word') || mimeType.includes('document')) return '📝'
|
|
||||||
if (mimeType.includes('sheet') || mimeType.includes('excel')) return '📊'
|
|
||||||
if (mimeType.includes('presentation') || mimeType.includes('powerpoint')) return '📊'
|
|
||||||
return '📎'
|
|
||||||
}
|
|
||||||
|
|
||||||
function canPreviewInBrowser(mimeType: string): boolean {
|
|
||||||
return (
|
|
||||||
mimeType === 'application/pdf' ||
|
|
||||||
mimeType.startsWith('image/') ||
|
|
||||||
mimeType.startsWith('video/') ||
|
|
||||||
mimeType.startsWith('text/')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function FileCard({ file }: { file: { id: string; fileName: string; mimeType: string; size: number; bucket: string; objectKey: string } }) {
|
|
||||||
const [loadingAction, setLoadingAction] = useState<'download' | 'preview' | null>(null)
|
|
||||||
|
|
||||||
const downloadUrlQuery = trpc.file.getDownloadUrl.useQuery(
|
|
||||||
{ bucket: file.bucket, objectKey: file.objectKey },
|
|
||||||
{ enabled: false } // manual trigger
|
|
||||||
)
|
|
||||||
|
|
||||||
const handleAction = async (action: 'download' | 'preview') => {
|
|
||||||
setLoadingAction(action)
|
|
||||||
try {
|
|
||||||
const result = await downloadUrlQuery.refetch()
|
|
||||||
if (result.data?.url) {
|
|
||||||
if (action === 'preview' && canPreviewInBrowser(file.mimeType)) {
|
|
||||||
window.open(result.data.url, '_blank')
|
|
||||||
} else {
|
|
||||||
// Download: create temp link and click
|
|
||||||
const a = document.createElement('a')
|
|
||||||
a.href = result.data.url
|
|
||||||
a.download = file.fileName
|
|
||||||
a.target = '_blank'
|
|
||||||
document.body.appendChild(a)
|
|
||||||
a.click()
|
|
||||||
document.body.removeChild(a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
toast.error('Failed to get file URL')
|
|
||||||
} finally {
|
|
||||||
setLoadingAction(null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card className="overflow-hidden">
|
|
||||||
<CardContent className="p-4">
|
|
||||||
<div className="flex items-start gap-3">
|
|
||||||
<div className="text-2xl">{getFileIcon(file.mimeType || '')}</div>
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<p className="font-medium text-sm truncate" title={file.fileName}>
|
|
||||||
{file.fileName}
|
|
||||||
</p>
|
|
||||||
<div className="flex items-center gap-2 mt-1">
|
|
||||||
<Badge variant="outline" className="text-xs">
|
|
||||||
{file.mimeType?.split('/')[1]?.toUpperCase() || 'FILE'}
|
|
||||||
</Badge>
|
|
||||||
{file.size > 0 && (
|
|
||||||
<span className="text-xs text-muted-foreground">
|
|
||||||
{formatFileSize(file.size)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-2 mt-3">
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="outline"
|
|
||||||
className="h-7 text-xs"
|
|
||||||
onClick={() => handleAction('download')}
|
|
||||||
disabled={loadingAction !== null}
|
|
||||||
>
|
|
||||||
{loadingAction === 'download' ? (
|
|
||||||
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<Download className="mr-1 h-3 w-3" />
|
|
||||||
)}
|
|
||||||
Download
|
|
||||||
</Button>
|
|
||||||
{canPreviewInBrowser(file.mimeType) && (
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-7 text-xs"
|
|
||||||
onClick={() => handleAction('preview')}
|
|
||||||
disabled={loadingAction !== null}
|
|
||||||
>
|
|
||||||
{loadingAction === 'preview' ? (
|
|
||||||
<Loader2 className="mr-1 h-3 w-3 animate-spin" />
|
|
||||||
) : (
|
|
||||||
<ExternalLink className="mr-1 h-3 w-3" />
|
|
||||||
)}
|
|
||||||
Preview
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function MultiWindowDocViewer({ roundId, projectId }: MultiWindowDocViewerProps) {
|
export function MultiWindowDocViewer({ roundId, projectId }: MultiWindowDocViewerProps) {
|
||||||
const { data: files, isLoading } = trpc.file.listByProject.useQuery(
|
const { data: files, isLoading } = trpc.file.listByProject.useQuery(
|
||||||
{ projectId },
|
{ projectId },
|
||||||
@@ -166,53 +45,82 @@ export function MultiWindowDocViewer({ roundId, projectId }: MultiWindowDocViewe
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group files by round name or "General"
|
// Group files by round name for the grouped view
|
||||||
const grouped: Record<string, typeof files> = {}
|
const groupMap: Record<string, {
|
||||||
|
roundId: string | null
|
||||||
|
roundName: string
|
||||||
|
sortOrder: number
|
||||||
|
files: typeof files
|
||||||
|
}> = {}
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const groupName = file.requirement?.round?.name ?? 'General'
|
const roundName = file.requirement?.round?.name ?? 'General'
|
||||||
if (!grouped[groupName]) grouped[groupName] = []
|
const rId = file.requirement?.round?.id ?? null
|
||||||
grouped[groupName].push(file)
|
const sortOrder = file.requirement?.round?.sortOrder ?? 999
|
||||||
|
if (!groupMap[roundName]) {
|
||||||
|
groupMap[roundName] = { roundId: rId, roundName, sortOrder, files: [] }
|
||||||
|
}
|
||||||
|
groupMap[roundName].files.push(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupNames = Object.keys(grouped)
|
const groupedFiles = Object.values(groupMap)
|
||||||
|
|
||||||
return (
|
// If only one group, use flat view
|
||||||
<Card>
|
if (groupedFiles.length === 1) {
|
||||||
<CardHeader>
|
const mappedFiles = files.map((f) => ({
|
||||||
<CardTitle>Documents</CardTitle>
|
id: f.id,
|
||||||
<CardDescription>
|
fileType: (f.fileType ?? 'OTHER') as 'EXEC_SUMMARY' | 'PRESENTATION' | 'VIDEO' | 'OTHER' | 'BUSINESS_PLAN' | 'VIDEO_PITCH' | 'SUPPORTING_DOC',
|
||||||
{files.length} file{files.length !== 1 ? 's' : ''} submitted
|
fileName: f.fileName,
|
||||||
</CardDescription>
|
mimeType: f.mimeType,
|
||||||
</CardHeader>
|
size: f.size,
|
||||||
<CardContent>
|
bucket: f.bucket,
|
||||||
{groupNames.length === 1 ? (
|
objectKey: f.objectKey,
|
||||||
// Single group — no need for headers
|
version: f.version ?? undefined,
|
||||||
<div className="grid gap-3 sm:grid-cols-2">
|
requirementId: f.requirementId,
|
||||||
{grouped[groupNames[0]].map((file) => (
|
requirement: f.requirement ? {
|
||||||
<FileCard key={file.id} file={file} />
|
id: f.requirement.id,
|
||||||
))}
|
name: f.requirement.name,
|
||||||
</div>
|
description: f.requirement.description,
|
||||||
) : (
|
isRequired: f.requirement.isRequired,
|
||||||
// Multiple groups — show headers
|
} : undefined,
|
||||||
<div className="space-y-6">
|
pageCount: (f as any).pageCount ?? undefined,
|
||||||
{groupNames.map((groupName) => (
|
textPreview: (f as any).textPreview ?? undefined,
|
||||||
<div key={groupName}>
|
detectedLang: (f as any).detectedLang ?? undefined,
|
||||||
<h4 className="font-medium text-sm text-muted-foreground mb-3">
|
langConfidence: (f as any).langConfidence ?? undefined,
|
||||||
{groupName}
|
analyzedAt: (f as any).analyzedAt ?? undefined,
|
||||||
<Badge variant="secondary" className="ml-2 text-xs">
|
}))
|
||||||
{grouped[groupName].length}
|
|
||||||
</Badge>
|
return <FileViewer files={mappedFiles} />
|
||||||
</h4>
|
}
|
||||||
<div className="grid gap-3 sm:grid-cols-2">
|
|
||||||
{grouped[groupName].map((file) => (
|
// Multiple groups — use grouped view
|
||||||
<FileCard key={file.id} file={file} />
|
const mappedGroups = groupedFiles.map((g) => ({
|
||||||
))}
|
roundId: g.roundId,
|
||||||
</div>
|
roundName: g.roundName,
|
||||||
</div>
|
sortOrder: g.sortOrder,
|
||||||
))}
|
files: g.files.map((f) => ({
|
||||||
</div>
|
id: f.id,
|
||||||
)}
|
fileType: (f.fileType ?? 'OTHER') as 'EXEC_SUMMARY' | 'PRESENTATION' | 'VIDEO' | 'OTHER' | 'BUSINESS_PLAN' | 'VIDEO_PITCH' | 'SUPPORTING_DOC',
|
||||||
</CardContent>
|
fileName: f.fileName,
|
||||||
</Card>
|
mimeType: f.mimeType,
|
||||||
)
|
size: f.size,
|
||||||
|
bucket: f.bucket,
|
||||||
|
objectKey: f.objectKey,
|
||||||
|
version: f.version ?? undefined,
|
||||||
|
requirementId: f.requirementId,
|
||||||
|
requirement: f.requirement ? {
|
||||||
|
id: f.requirement.id,
|
||||||
|
name: f.requirement.name,
|
||||||
|
description: f.requirement.description,
|
||||||
|
isRequired: f.requirement.isRequired,
|
||||||
|
} : undefined,
|
||||||
|
pageCount: (f as any).pageCount ?? undefined,
|
||||||
|
textPreview: (f as any).textPreview ?? undefined,
|
||||||
|
detectedLang: (f as any).detectedLang ?? undefined,
|
||||||
|
langConfidence: (f as any).langConfidence ?? undefined,
|
||||||
|
analyzedAt: (f as any).analyzedAt ?? undefined,
|
||||||
|
})),
|
||||||
|
}))
|
||||||
|
|
||||||
|
return <FileViewer groupedFiles={mappedGroups} />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -252,75 +252,104 @@ function FileItem({ file }: { file: ProjectFile }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<div className="flex items-center gap-3 rounded-lg border p-3">
|
<div className="rounded-lg border p-3">
|
||||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-muted">
|
<div className="flex items-start gap-3">
|
||||||
<Icon className="h-5 w-5 text-muted-foreground" />
|
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-muted">
|
||||||
</div>
|
<Icon className="h-5 w-5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="flex-1 min-w-0">
|
<div className="flex-1 min-w-0">
|
||||||
{file.requirement && (
|
{file.requirement && (
|
||||||
<p className="text-xs font-semibold text-primary/80 mb-0.5 uppercase tracking-wide">
|
<p className="text-xs font-semibold text-primary/80 mb-0.5 uppercase tracking-wide">
|
||||||
{file.requirement.name}
|
{file.requirement.name}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<p className="font-medium truncate">{file.fileName}</p>
|
<p className="font-medium truncate">{file.fileName}</p>
|
||||||
|
{file.version != null && file.version > 1 && (
|
||||||
|
<Badge variant="outline" className="text-xs shrink-0">
|
||||||
|
v{file.version}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2 text-sm text-muted-foreground flex-wrap">
|
||||||
|
<Badge variant="secondary" className="text-xs">
|
||||||
|
{getFileTypeLabel(file.fileType)}
|
||||||
|
</Badge>
|
||||||
|
{file.isLate && (
|
||||||
|
<Badge variant="destructive" className="text-xs">
|
||||||
|
Late
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
<span>{formatFileSize(file.size)}</span>
|
||||||
|
{file.pageCount != null && (
|
||||||
|
<Badge variant="outline" className="text-xs gap-1">
|
||||||
|
<FileText className="h-3 w-3" />
|
||||||
|
{file.pageCount} {file.pageCount === 1 ? 'page' : 'pages'}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{file.detectedLang && file.detectedLang !== 'und' && (
|
||||||
|
<Badge
|
||||||
|
variant="outline"
|
||||||
|
className={cn('text-xs font-mono uppercase', {
|
||||||
|
'border-green-300 text-green-700 bg-green-50': file.langConfidence != null && file.langConfidence >= 0.8,
|
||||||
|
'border-amber-300 text-amber-700 bg-amber-50': file.langConfidence != null && file.langConfidence >= 0.4 && file.langConfidence < 0.8,
|
||||||
|
'border-red-300 text-red-700 bg-red-50': file.langConfidence != null && file.langConfidence < 0.4,
|
||||||
|
})}
|
||||||
|
title={`Language: ${file.detectedLang} (${Math.round((file.langConfidence ?? 0) * 100)}% confidence)`}
|
||||||
|
>
|
||||||
|
{file.detectedLang.toUpperCase()}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Desktop action buttons — hidden on mobile */}
|
||||||
|
<div className="hidden md:flex items-center gap-1 shrink-0">
|
||||||
{file.version != null && file.version > 1 && (
|
{file.version != null && file.version > 1 && (
|
||||||
<Badge variant="outline" className="text-xs shrink-0">
|
<VersionHistoryButton fileId={file.id} />
|
||||||
v{file.version}
|
|
||||||
</Badge>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
{canPreview && (
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground flex-wrap">
|
<Button
|
||||||
<Badge variant="secondary" className="text-xs">
|
|
||||||
{getFileTypeLabel(file.fileType)}
|
|
||||||
</Badge>
|
|
||||||
{file.isLate && (
|
|
||||||
<Badge variant="destructive" className="text-xs">
|
|
||||||
Late
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
<span>{formatFileSize(file.size)}</span>
|
|
||||||
{file.pageCount != null && (
|
|
||||||
<Badge variant="outline" className="text-xs gap-1">
|
|
||||||
<FileText className="h-3 w-3" />
|
|
||||||
{file.pageCount} {file.pageCount === 1 ? 'page' : 'pages'}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
{file.detectedLang && file.detectedLang !== 'und' && (
|
|
||||||
<Badge
|
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className={cn('text-xs font-mono uppercase', {
|
size="sm"
|
||||||
'border-green-300 text-green-700 bg-green-50': file.langConfidence != null && file.langConfidence >= 0.8,
|
onClick={() => setShowPreview(!showPreview)}
|
||||||
'border-amber-300 text-amber-700 bg-amber-50': file.langConfidence != null && file.langConfidence >= 0.4 && file.langConfidence < 0.8,
|
|
||||||
'border-red-300 text-red-700 bg-red-50': file.langConfidence != null && file.langConfidence < 0.4,
|
|
||||||
})}
|
|
||||||
title={`Language: ${file.detectedLang} (${Math.round((file.langConfidence ?? 0) * 100)}% confidence)`}
|
|
||||||
>
|
>
|
||||||
{file.detectedLang.toUpperCase()}
|
{showPreview ? (
|
||||||
</Badge>
|
<>
|
||||||
|
<X className="mr-2 h-4 w-4" />
|
||||||
|
Close
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Play className="mr-2 h-4 w-4" />
|
||||||
|
Preview
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
<FileOpenButton file={file} />
|
||||||
|
<FileDownloadButton file={file} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-1">
|
{/* Mobile action buttons — visible only on small screens */}
|
||||||
{file.version != null && file.version > 1 && (
|
<div className="flex md:hidden items-center gap-2 mt-3 pt-3 border-t">
|
||||||
<VersionHistoryButton fileId={file.id} />
|
|
||||||
)}
|
|
||||||
{canPreview && (
|
{canPreview && (
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
|
className="flex-1"
|
||||||
onClick={() => setShowPreview(!showPreview)}
|
onClick={() => setShowPreview(!showPreview)}
|
||||||
>
|
>
|
||||||
{showPreview ? (
|
{showPreview ? (
|
||||||
<>
|
<>
|
||||||
<X className="mr-2 h-4 w-4" />
|
<X className="mr-1.5 h-4 w-4" />
|
||||||
Close
|
Close
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Play className="mr-2 h-4 w-4" />
|
<Play className="mr-1.5 h-4 w-4" />
|
||||||
Preview
|
Preview
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
@@ -481,21 +510,28 @@ function BulkDownloadButton({ projectId, fileIds }: { projectId: string; fileIds
|
|||||||
try {
|
try {
|
||||||
const result = await refetch()
|
const result = await refetch()
|
||||||
if (result.data && Array.isArray(result.data)) {
|
if (result.data && Array.isArray(result.data)) {
|
||||||
// Open each download URL with a small delay to avoid popup blocking
|
// Download each file via fetch+blob to handle cross-origin URLs
|
||||||
for (let i = 0; i < result.data.length; i++) {
|
for (let i = 0; i < result.data.length; i++) {
|
||||||
const item = result.data[i] as { downloadUrl: string }
|
const item = result.data[i] as { downloadUrl: string; fileName?: string }
|
||||||
if (item.downloadUrl) {
|
if (item.downloadUrl) {
|
||||||
// Use link element to trigger download without popup
|
try {
|
||||||
const link = document.createElement('a')
|
const response = await fetch(item.downloadUrl)
|
||||||
link.href = item.downloadUrl
|
const blob = await response.blob()
|
||||||
link.target = '_blank'
|
const blobUrl = URL.createObjectURL(blob)
|
||||||
link.rel = 'noopener noreferrer'
|
const link = document.createElement('a')
|
||||||
document.body.appendChild(link)
|
link.href = blobUrl
|
||||||
link.click()
|
link.download = item.fileName || `file-${i + 1}`
|
||||||
document.body.removeChild(link)
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
URL.revokeObjectURL(blobUrl)
|
||||||
|
} catch {
|
||||||
|
// Fall back to opening in new tab if fetch fails
|
||||||
|
window.open(item.downloadUrl, '_blank')
|
||||||
|
}
|
||||||
// Small delay between downloads
|
// Small delay between downloads
|
||||||
if (i < result.data.length - 1) {
|
if (i < result.data.length - 1) {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 300))
|
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,17 +613,21 @@ function FileDownloadButton({ file }: { file: ProjectFile }) {
|
|||||||
try {
|
try {
|
||||||
const result = await refetch()
|
const result = await refetch()
|
||||||
if (result.data?.url) {
|
if (result.data?.url) {
|
||||||
// Force browser download via <a download>
|
// Fetch as blob to force download (cross-origin URLs ignore <a download>)
|
||||||
|
const response = await fetch(result.data.url)
|
||||||
|
const blob = await response.blob()
|
||||||
|
const blobUrl = URL.createObjectURL(blob)
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.href = result.data.url
|
link.href = blobUrl
|
||||||
link.download = file.fileName
|
link.download = file.fileName
|
||||||
link.rel = 'noopener noreferrer'
|
|
||||||
document.body.appendChild(link)
|
document.body.appendChild(link)
|
||||||
link.click()
|
link.click()
|
||||||
document.body.removeChild(link)
|
document.body.removeChild(link)
|
||||||
|
URL.revokeObjectURL(blobUrl)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to get download URL:', error)
|
console.error('Failed to download file:', error)
|
||||||
|
toast.error('Failed to download file')
|
||||||
} finally {
|
} finally {
|
||||||
setDownloading(false)
|
setDownloading(false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -230,6 +230,67 @@ export const evaluationRouter = router({
|
|||||||
return updated
|
return updated
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset (erase) an evaluation so a juror can start over (admin only)
|
||||||
|
* Deletes the evaluation record and resets the assignment's isCompleted flag.
|
||||||
|
*/
|
||||||
|
resetEvaluation: adminProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
assignmentId: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const assignment = await ctx.prisma.assignment.findUniqueOrThrow({
|
||||||
|
where: { id: input.assignmentId },
|
||||||
|
include: {
|
||||||
|
evaluation: true,
|
||||||
|
user: { select: { id: true, name: true, email: true } },
|
||||||
|
project: { select: { id: true, title: true } },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!assignment.evaluation) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: 'NOT_FOUND',
|
||||||
|
message: 'No evaluation found for this assignment',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the evaluation and reset assignment completion in a transaction
|
||||||
|
await ctx.prisma.$transaction([
|
||||||
|
ctx.prisma.evaluation.delete({
|
||||||
|
where: { id: assignment.evaluation.id },
|
||||||
|
}),
|
||||||
|
ctx.prisma.assignment.update({
|
||||||
|
where: { id: input.assignmentId },
|
||||||
|
data: { isCompleted: false },
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
// Audit log
|
||||||
|
await logAudit({
|
||||||
|
prisma: ctx.prisma,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
action: 'EVALUATION_RESET',
|
||||||
|
entityType: 'Evaluation',
|
||||||
|
entityId: assignment.evaluation.id,
|
||||||
|
detailsJson: {
|
||||||
|
assignmentId: input.assignmentId,
|
||||||
|
jurorId: assignment.user.id,
|
||||||
|
jurorName: assignment.user.name || assignment.user.email,
|
||||||
|
projectId: assignment.project.id,
|
||||||
|
projectTitle: assignment.project.title,
|
||||||
|
previousStatus: assignment.evaluation.status,
|
||||||
|
previousGlobalScore: assignment.evaluation.globalScore,
|
||||||
|
},
|
||||||
|
ipAddress: ctx.ip,
|
||||||
|
userAgent: ctx.userAgent,
|
||||||
|
})
|
||||||
|
|
||||||
|
return { success: true }
|
||||||
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get aggregated stats for a project (admin only)
|
* Get aggregated stats for a project (admin only)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user