Skip to content

Commit

Permalink
Merge pull request #18 from ducompsoc/data-importing
Browse files Browse the repository at this point in the history
Customise import for DurHack DevPost and location strings
  • Loading branch information
tameTNT authored Oct 26, 2024
2 parents 02e5eb6 + 34590ff commit 26d89d9
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 204 deletions.
2 changes: 2 additions & 0 deletions client/src/components/admin/add-projects/NewProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { errorAlert } from '../../../util';

interface NewProjectData {
name: string;
location: string;
description: string;
url: string;
link: string;
Expand Down Expand Up @@ -45,6 +46,7 @@ const NewProjectForm = () => {
<h1 className="text-3xl mb-4">Add Project</h1>
<form className="flex flex-col w-full space-y-4" onSubmit={handleSubmit(onSubmit)}>
<TextInput name="name" placeholder="Name" register={register} />
<TextInput name="location" placeholder="Team location" register={register} />
<TextArea
name="description"
placeholder="Description"
Expand Down
27 changes: 18 additions & 9 deletions client/src/components/admin/tables/ProjectRow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react';
import {useEffect, useRef, useState} from 'react';
import { errorAlert, fixIfFloatDigits, timeSince } from '../../../util';
import DeletePopup from './DeletePopup';
import EditProjectPopup from './EditProjectPopup';
Expand Down Expand Up @@ -63,6 +63,15 @@ const ProjectRow = ({ project, idx, checked, handleCheckedChange }: ProjectRowPr
}
};

const onLocationChange = async (e) => {
const res = await postRequest<YesNoResponse>('/project/update-location', {id: project.id, location: e.target.value});
if (res.status === 200) {
fetchProjects();
} else {
errorAlert(res);
}
}

return (
<>
<tr
Expand All @@ -86,9 +95,15 @@ const ProjectRow = ({ project, idx, checked, handleCheckedChange }: ProjectRowPr
className="cursor-pointer hover:text-primary duration-100"
></input>
</td>
<td>{project.name}</td>
<td className="[&:not(:hover)]:truncate hover:break-words hover:text-wrap">{project.name}</td>
<td className="text-center py-1">
Table {project.location} {checked}
<input
className="w-full md:w-2/3"
name="location"
defaultValue={project.location}
type="text"
onBlur={(e) => onLocationChange(e)}
/>
</td>
<td className="text-center">{project.score}</td>
<td className="text-center">{project.seen}</td>
Expand All @@ -99,12 +114,6 @@ const ProjectRow = ({ project, idx, checked, handleCheckedChange }: ProjectRowPr
className="absolute flex flex-col bg-background rounded-md border-lightest border-2 font-normal text-sm"
ref={ref}
>
<div
className="py-1 pl-4 pr-2 cursor-pointer hover:bg-primary/20 duration-150"
onClick={() => doAction('edit')}
>
Edit
</div>
<div
className="py-1 pl-4 pr-2 cursor-pointer hover:bg-primary/20 duration-150"
onClick={() => doAction('hide')}
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/admin/tables/ProjectsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ const ProjectsTable = () => {
case ProjectSortField.Name:
sortFunc = (a, b) => a.name.localeCompare(b.name) * asc;
break;
case ProjectSortField.TableNumber:
sortFunc = (a, b) => (a.location - b.location) * asc;
case ProjectSortField.Location:
sortFunc = (a, b) => a.location.localeCompare(b.location) * asc;
break;
case ProjectSortField.Score:
sortFunc = (a, b) => (a.score - b.score) * asc;
Expand Down Expand Up @@ -94,9 +94,9 @@ const ProjectsTable = () => {
align='left'
/>
<HeaderEntry
name="Table"
name="Location"
updateSort={updateSort}
sortField={ProjectSortField.TableNumber}
sortField={ProjectSortField.Location}
sortState={sortState}
/>
<HeaderEntry
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/judge/ProjectDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const ProjectDisplay = (props: ProjectDisplayProps) => {

return (
<div className={twMerge('px-2', props.className)}>
<h1 className="text-3xl mb-1 font-bold">
<h1 className="text-3xl mb-1 font-bold break-words text-wrap">
<a href={project.url} target="_blank" rel="noopener noreferrer">
{project.name}
</a>
</h1>
<h2 className="text-xl mb-1">Table {project.location}</h2>
<h2 className="text-xl mb-1">Location: {project.location}</h2>
<Paragraph className="text-light" text={project.description} />
</div>
);
Expand Down
22 changes: 10 additions & 12 deletions client/src/components/judge/ProjectEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const ProjectEntry = ({ project, ranking }: ProjectEntryProps) => {
return null;
}

// Will truncate a string to 8 characters,
// adding a dot at the end if the length is > than 8 chars
const truncate = (s: string) => {
if (s.length <= 8) return s;
return s.substring(0, 4) + '.';
// Will truncate a string to width characters exactly,
// adding a dot at the end if the length is > than width chars
const truncate = (s: string, width: number = 8) => {
if (s.length <= width) return s;
return s.substring(0, width-1) + '.';
};

let rankColor = 'text-lightest';
Expand All @@ -38,22 +38,20 @@ const ProjectEntry = ({ project, ranking }: ProjectEntryProps) => {
{ranking !== -1 && (
<p className={twMerge('font-bold text-xl text-center w-6 shrink-0', rankColor)}>{ranking}</p>
)}
<div className="m-1 pl-2 py-1 bg-background border-solid border-2 border-lightest rounded-md grow">
<div className="m-1 pl-2 py-1 bg-background border-solid border-2 border-lightest rounded-md grow min-w-0">
<div className="flex flex-row">
<div>
<div className="min-w-0">
<h3 className="text-xl grow">
<a href={`/judge/project/${project.project_id}`}>
<b>Table {project.location}</b>
{': '}
{project.name}
<b>{truncate(project.name, 20)}</b>&nbsp;({truncate(project.location, 20)})
</a>
</h3>
<p className="text-light text-xs line-clamp-1">{project.notes}</p>
<div className="text-light flex flex-row">
<div className="text-light flex flex-wrap">
{Object.entries(project.categories).map(([name, score], i) => (
<div key={i}>
<span className="text-lighter text-xs mr-1">
{truncate(name)}
{truncate(name, 15)}
</span>
<span className="mr-2">{score}</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion client/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum JudgeSortField {

export enum ProjectSortField {
Name,
TableNumber,
Location,
Score,
Seen,
Updated,
Expand Down
36 changes: 0 additions & 36 deletions client/src/pages/admin/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,6 @@ const AdminSettings = () => {
getOptions();
}, []);

const reassignTables = async () => {
const res = await postRequest<YesNoResponse>('/project/reassign', null);
if (res.status !== 200 || res.data?.yes_no !== 1) {
errorAlert(res);
return;
}
alert('Table numbers reassigned!');
setReassignPopup(false);
};

const updateTimer = async () => {
// Convert judging timer to time
const [minutes, seconds] = judgingTimer.split(':');
Expand Down Expand Up @@ -320,21 +310,6 @@ const AdminSettings = () => {

<Section>Judging Parameters</Section>

<SubSection>Reassign Project Numbers</SubSection>
<Description>
Reassign all project numbers to the projects. This will keep the relative order
but reassign the project numbers starting from the first project.
</Description>
<Button
type="primary"
onClick={() => {
setReassignPopup(true);
}}
className="mt-4 mb-8 w-auto md:w-auto px-4 py-2 bg-gold text-black"
>
Reassign
</Button>

<SubSection>Set Minimum Project Views</SubSection>
<Description>
Set the minimum amount of times that a project should be seen during judging.
Expand Down Expand Up @@ -417,17 +392,6 @@ const AdminSettings = () => {
Drop Database
</Button>
</div>
<TextPopup
enabled={reassignPopup}
setEnabled={setReassignPopup}
onSubmit={reassignTables}
submitText="Reassign"
title="Heads Up!"
red
>
Are you sure you want to reassign project numbers? This should NOT be done DURING
judging; only beforehand!!
</TextPopup>
<TextPopup
enabled={clockResetPopup}
setEnabled={setClockResetPopup}
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/judge/project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const Project = () => {
{project.name}
</a>
</h1>
<h2 className="text-xl font-bold text-light mb-2">Table {project.location}</h2>
<h2 className="text-xl font-bold text-light mb-2">Location: {project.location}</h2>
<Ratings
prior={project.categories}
project={project}
Expand Down
10 changes: 5 additions & 5 deletions client/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface Project {
id: string;
name: string;
location: number;
location: string;
description: string;
url: string;
try_link: string;
Expand Down Expand Up @@ -59,9 +59,9 @@ type VotePopupState = 'vote' | 'skip' | 'flag';

interface VotingProjectInfo {
curr_name: string;
curr_location: number;
curr_location: string;
prev_name: string;
prev_location: number;
prev_location: string;
}

interface YesNoResponse {
Expand All @@ -77,7 +77,7 @@ interface JudgedProject {
categories: { [name: string]: number };
notes: string;
name: string;
location: number;
location: string;
description: string;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ interface Flag {
time: number;
project_name: string;
judge_name: string;
project_location: number;
project_location: string;
reason: string;
}

Expand Down
6 changes: 0 additions & 6 deletions server/database/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ func GetOptions(db *mongo.Database) (*models.Options, error) {
return &options, err
}

// UpdateOptions updates the current table number in the database
func UpdateCurrTableNum(db *mongo.Database, ctx context.Context, currTableNum int64) error {
_, err := db.Collection("options").UpdateOne(ctx, gin.H{}, gin.H{"$set": gin.H{"curr_table_num": currTableNum}})
return err
}

// UpdateOptions updates the clock in the database
func UpdateClock(db *mongo.Database, clock *models.ClockState) error {
_, err := db.Collection("options").UpdateOne(context.Background(), gin.H{}, gin.H{"$set": gin.H{"clock": clock}})
Expand Down
5 changes: 5 additions & 0 deletions server/database/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func SetProjectPrioritized(db *mongo.Database, id *primitive.ObjectID, prioritiz
return err
}

func UpdateProjectLocationValue(db *mongo.Database, id *primitive.ObjectID, location string) error {
_, err := db.Collection("projects").UpdateOne(context.Background(), gin.H{"_id": id}, gin.H{"$set": gin.H{"location": location}})
return err
}

// UpdateProjects will update ALL projects in the database
func UpdateProjects(db *mongo.Database, projects []*models.Project) error {
models := make([]mongo.WriteModel, 0, len(projects))
Expand Down
10 changes: 0 additions & 10 deletions server/database/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package database

import (
"context"
"server/models"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
Expand All @@ -22,11 +20,3 @@ func WithTransaction(db *mongo.Database, fn func(mongo.SessionContext) (interfac
_, err = session.WithTransaction(context.Background(), fn, txnOptions)
return err
}

// GetNextTableNum increments the table number and returns the new table number
// TODO: Are we updating the current table number in the database?
func GetNextTableNum(o *models.Options) int64 {
// Increment table number
o.CurrTableNum++
return o.CurrTableNum
}
Loading

0 comments on commit 26d89d9

Please sign in to comment.