Skip to content

Commit

Permalink
standings is now disabled from user side when there is 30 minutes lef… (
Browse files Browse the repository at this point in the history
#257)

* standings is now disabled from user side when there is 30 minutes left in a competition

* added check to see if the user is a team

* changed wording of recently graded to released

* Prettified Code!

Co-authored-by: MrKevinOConnell <MrKevinOConnell@users.noreply.github.com>
  • Loading branch information
MrKevinOConnell and MrKevinOConnell committed Apr 7, 2022
1 parent 642baeb commit 65c91de
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 17 deletions.
1 change: 0 additions & 1 deletion backend/src/api/contest/putContest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const schema: Record<string, ParamSchema> = {
* Request body does not match required schema.
*/
export const putContest = async (req: Request, res: Response): Promise<void> => {

if (req?.user?.role !== 'admin') {
res.status(403).send({ message: 'Unauthroized' })
return
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/db/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default class MongoDB extends Database {

scan(TableName: string, query?: ScanOptions, page?: number): Promise<Item[]> {
var obj = { _id: 0 }
if(query?.columns){
obj = query.columns.reduce((o, key) => ({ ...o, [key]: 1}), { _id: 0 })
if (query?.columns) {
obj = query.columns.reduce((o, key) => ({ ...o, [key]: 1 }), { _id: 0 })
}

const pageSize = 25
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"express": "^4.17.1",
"file-saver": "^2.0.5",
"jsonwebtoken": "^8.5.1",
"moment": "^2.29.1",
"moment": "^2.29.2",
"monaco-editor": "^0.28.1",
"prop-types": "^15.7.2",
"react": "^17.0.2",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ const LoginModal = ({ trigger, open }: LoginModalProps): JSX.Element => {

useEffect(() => {
return () => {
setFormData({ username: '', password: '' });
setFormData({ username: '', password: '' })
setOpen(false)
setLoggingIn(false)
};
}, []);
}
}, [])

const handleChange = ({ target: { name, value } }: ChangeEvent<HTMLInputElement>) =>
setFormData({ ...formData, [name]: value })
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/pages/admin/users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,15 @@ const Users = (): JSX.Element => {
try {
const response = await fetch('https://mu.acm.org/api/registered_teams')
const teams = await response.json()
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-+";
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-+'

let i = 1

for (const team of teams) {
if (team.division === 'eagle') continue
let password = ""

for (var j = 0; j < 9; j++)
password += possible.charAt(Math.floor(Math.random() * possible.length));
let password = ''

for (var j = 0; j < 9; j++) password += possible.charAt(Math.floor(Math.random() * possible.length))

const username = 'team' + i

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/pages/blue/Standings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import config from 'environment'
import '../Standings.scss'
import { AppContext, SocketContext } from 'context'
import { Helmet } from 'react-helmet'
import moment from 'moment'
import { isThirtyMinutesBefore } from 'utils'

const Standings = (): JSX.Element => {
const { user, settings } = useContext(AppContext)
Expand Down Expand Up @@ -70,6 +72,18 @@ const Standings = (): JSX.Element => {
</>
)

if (settings && user && isThirtyMinutesBefore(settings.end_date) && user.role === 'team')
return (
<>
{helmet}
<Countdown />
<Block size="xs-12">
<h1>Competition almost finished!</h1>
<p>Scoreboard is disabled for the remainder of the competition.</p>
</Block>
</>
)

let rk = 0
let last = 0

Expand Down
14 changes: 14 additions & 0 deletions frontend/src/pages/gold/Standings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import config from 'environment'
import { Table } from 'semantic-ui-react'
import { Link } from 'react-router-dom'
import '../Standings.scss'
import moment from 'moment'
import { isThirtyMinutesBefore } from 'utils'

interface GoldStandingsUser {
uid: string
Expand Down Expand Up @@ -84,6 +86,18 @@ const Standings = (): JSX.Element => {
</>
)

if (settings && user && isThirtyMinutesBefore(settings.end_date) && user.role === 'team')
return (
<>
{helmet}
<Countdown />
<Block size="xs-12">
<h1>Competition almost finished!</h1>
<p>Scoreboard is disabled for the remainder of the competition.</p>
</Block>
</>
)

if (isLoading) return <PageLoading />

if (!standings || !problems)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/judge/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const Home = (): JSX.Element => {

<Block transparent size="xs-6">
<h1>
<Link to="/judge/submissions?filter=recently_graded">Recently Graded Submissions</Link>
<Link to="/judge/submissions?filter=recently_graded">Recently Released Submissions</Link>
</h1>

<Table>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { User } from 'abacus'
import moment from 'moment'

// Convert's stored language values in to syntax highlighter friendly values
export const syntax_lang = (language: string): string => {
Expand Down Expand Up @@ -71,3 +72,12 @@ export const compare = (o1: string | number, o2: string | number): number => {
}
return 0
}

export const isThirtyMinutesBefore = (time: Date) => {
const newDate = new Date()
var beginningTime = moment(newDate)
var endTime = moment(time)
var diff = endTime.diff(beginningTime, 'minutes')
console.log('diff', diff)
return diff <= 30
}
8 changes: 4 additions & 4 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8366,10 +8366,10 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

moment@^2.29.1:
version "2.29.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
moment@^2.29.2:
version "2.29.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.2.tgz#00910c60b20843bcba52d37d58c628b47b1f20e4"
integrity sha512-UgzG4rvxYpN15jgCmVJwac49h9ly9NurikMWGPdVxm8GZD6XjkKPxDTjQQ43gtGgnV3X0cAyWDdP2Wexoquifg==

monaco-editor@^0.27.0:
version "0.27.0"
Expand Down

0 comments on commit 65c91de

Please sign in to comment.