Skip to content
Snippets Groups Projects
Commit 670436ff authored by Victor Löfgren's avatar Victor Löfgren
Browse files

Merge branch 'dev' of gitlab.liu.se:tddd96-grupp11/teknikattan-scoring-system...

Merge branch 'dev' of gitlab.liu.se:tddd96-grupp11/teknikattan-scoring-system into 155-add-correcting-instructions-in-question
parents 226d12ea be657153
No related branches found
No related tags found
1 merge request!116Resolve "Add correcting instructions in question"
Pipeline #43038 passed with warnings
...@@ -184,7 +184,7 @@ const CompetitionManager: React.FC = (props: any) => { ...@@ -184,7 +184,7 @@ const CompetitionManager: React.FC = (props: any) => {
typeName = 'Publik' typeName = 'Publik'
break break
case 4: case 4:
typeName = 'Tävlingsoperator' typeName = 'Tävlingsoperatör'
break break
default: default:
typeName = 'Typ hittades ej' typeName = 'Typ hittades ej'
......
import { import {
Box,
Button, Button,
createStyles,
Dialog, Dialog,
DialogActions, DialogActions,
DialogContent, DialogContent,
...@@ -8,7 +10,9 @@ import { ...@@ -8,7 +10,9 @@ import {
List, List,
ListItem, ListItem,
ListItemText, ListItemText,
makeStyles,
Popover, Popover,
Theme,
Tooltip, Tooltip,
Typography, Typography,
useMediaQuery, useMediaQuery,
...@@ -48,6 +52,8 @@ import { ...@@ -48,6 +52,8 @@ import {
SlideCounter, SlideCounter,
ToolBarContainer, ToolBarContainer,
} from './styled' } from './styled'
import axios from 'axios'
import { Team } from '../../interfaces/ApiModels'
/** /**
* Description: * Description:
...@@ -67,17 +73,47 @@ import { ...@@ -67,17 +73,47 @@ import {
* creates a bug where the competition can't be started. * creates a bug where the competition can't be started.
* =========================================== * ===========================================
*/ */
const useStyles = makeStyles((theme: Theme) =>
createStyles({
table: {
width: '100%',
},
margin: {
margin: theme.spacing(1),
},
paper: {
backgroundColor: theme.palette.background.paper,
boxShadow: theme.shadows[5],
padding: 4,
outline: 'none',
},
})
)
interface Code {
id: number
code: string
view_type_id: number
competition_id: number
team_id: number
}
const OperatorViewPage: React.FC = () => { const OperatorViewPage: React.FC = () => {
// for dialog alert // for dialog alert
const [openAlert, setOpen] = React.useState(false) const [openAlert, setOpen] = React.useState(false)
const [openAlertCode, setOpenCode] = React.useState(true) const [openAlertCode, setOpenCode] = React.useState(false)
const theme = useTheme() const [codes, setCodes] = React.useState<Code[]>([])
const fullScreen = useMediaQuery(theme.breakpoints.down('sm')) const [teams, setTeams] = React.useState<Team[]>([])
const teams = useAppSelector((state) => state.presentation.competition.teams) const [competitionName, setCompetitionName] = React.useState<string | undefined>(undefined)
//const fullScreen = useMediaQuery(theme.breakpoints.down('sm'))
const classes = useStyles()
//const teams = useAppSelector((state) => state.presentation.competition.teams)
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null) const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(null)
const { id, code }: ViewParams = useParams() const { id, code }: ViewParams = useParams()
const presentation = useAppSelector((state) => state.presentation) const presentation = useAppSelector((state) => state.presentation)
const activeId = useAppSelector((state) => state.presentation.competition.id)
const history = useHistory() const history = useHistory()
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const viewTypes = useAppSelector((state) => state.types.viewTypes) const viewTypes = useAppSelector((state) => state.types.viewTypes)
...@@ -88,6 +124,7 @@ const OperatorViewPage: React.FC = () => { ...@@ -88,6 +124,7 @@ const OperatorViewPage: React.FC = () => {
dispatch(setPresentationCode(code)) dispatch(setPresentationCode(code))
socket_connect() socket_connect()
socketSetSlide // Behövs denna? socketSetSlide // Behövs denna?
handleOpenCodes()
setTimeout(startCompetition, 1000) // Ghetto, wait for everything to load setTimeout(startCompetition, 1000) // Ghetto, wait for everything to load
// console.log(id) // console.log(id)
}, []) }, [])
...@@ -118,7 +155,10 @@ const OperatorViewPage: React.FC = () => { ...@@ -118,7 +155,10 @@ const OperatorViewPage: React.FC = () => {
setOpen(true) setOpen(true)
} }
const handleOpenCodes = () => { const handleOpenCodes = async () => {
await getCodes()
await getTeams()
await getCompetitionName()
setOpenCode(true) setOpenCode(true)
} }
...@@ -133,56 +173,108 @@ const OperatorViewPage: React.FC = () => { ...@@ -133,56 +173,108 @@ const OperatorViewPage: React.FC = () => {
window.location.reload(false) // TODO: fix this ugly hack, we "need" to refresh site to be able to run the competition correctly again window.location.reload(false) // TODO: fix this ugly hack, we "need" to refresh site to be able to run the competition correctly again
} }
const getCodes = async () => {
await axios
.get(`/api/competitions/${activeId}/codes`)
.then((response) => {
console.log(response.data)
setCodes(response.data.items)
})
.catch(console.log)
}
const getTeams = async () => {
await axios
.get(`/api/competitions/${activeId}/teams`)
.then((response) => {
console.log(response.data.items)
setTeams(response.data.items)
})
.catch((err) => {
console.log(err)
})
}
const getCompetitionName = async () => {
await axios
.get(`/api/competitions/${activeId}`)
.then((response) => {
console.log(response.data.name)
setCompetitionName(response.data.name)
})
.catch((err) => {
console.log(err)
})
}
const getTypeName = (code: Code) => {
let typeName = ''
switch (code.view_type_id) {
case 1:
const team = teams.find((team) => team.id === code.team_id)
if (team) {
typeName = team.name
} else {
typeName = 'Lagnamn hittades ej'
}
break
case 2:
typeName = 'Domare'
break
case 3:
typeName = 'Publik'
break
case 4:
typeName = 'Tävlingsoperatör'
break
default:
typeName = 'Typ hittades ej'
break
}
return typeName
}
return ( return (
<OperatorContainer> <OperatorContainer>
<Dialog <Dialog
fullScreen={fullScreen}
open={openAlertCode} open={openAlertCode}
onClose={handleClose} onClose={handleClose}
aria-labelledby="responsive-dialog-title" aria-labelledby="max-width-dialog-title"
maxWidth="xl"
fullWidth={false}
fullScreen={false}
> >
<DialogTitle id="responsive-dialog-title">{'Koder för tävlingen'}</DialogTitle> <DialogTitle id="max-width-dialog-title" className={classes.paper}>
Koder för {competitionName}
</DialogTitle>
<DialogContent> <DialogContent>
<ListItem> {/* <DialogContentText>Här visas tävlingskoderna till den valda tävlingen.</DialogContentText> */}
<ListItemText primary={`Domare: ${presentation.code}`} /> {codes.map((code) => (
<Tooltip title="Kopiera kod" arrow> <ListItem key={code.id} style={{ display: 'flex' }}>
<Button <ListItemText primary={`${getTypeName(code)}: `} />
onClick={() => { <Typography component="div">
navigator.clipboard.writeText(presentation.code) <ListItemText style={{ textAlign: 'right', marginLeft: '10px' }}>
}} <Box fontFamily="Monospace" fontWeight="fontWeightBold">
> {code.code}
<FileCopyIcon fontSize="small" /> </Box>
</Button> </ListItemText>
</Tooltip> </Typography>
</ListItem> <Tooltip title="Kopiera kod" arrow>
<ListItem> <Button
<ListItemText primary={`Tävlande: ${presentation.code}`} /> margin-right="0px"
<Tooltip title="Kopiera kod" arrow> onClick={() => {
<Button navigator.clipboard.writeText(code.code)
onClick={() => { }}
navigator.clipboard.writeText(presentation.code) >
}} <FileCopyIcon fontSize="small" />
> </Button>
<FileCopyIcon fontSize="small" /> </Tooltip>
</Button> </ListItem>
</Tooltip> ))}
</ListItem>
<ListItem>
<ListItemText primary={`Publik: ${presentation.code}`} />
<Tooltip title="Kopiera kod" arrow>
<Button
onClick={() => {
navigator.clipboard.writeText(presentation.code)
}}
>
<FileCopyIcon fontSize="small" />
</Button>
</Tooltip>
</ListItem>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button autoFocus onClick={handleClose} color="primary"> <Button onClick={handleClose} color="primary">
Ok Stäng
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>
...@@ -194,12 +286,7 @@ const OperatorViewPage: React.FC = () => { ...@@ -194,12 +286,7 @@ const OperatorViewPage: React.FC = () => {
</OperatorButton> </OperatorButton>
</Tooltip> </Tooltip>
<Dialog <Dialog open={openAlert} onClose={handleClose} aria-labelledby="responsive-dialog-title">
fullScreen={fullScreen}
open={openAlert}
onClose={handleClose}
aria-labelledby="responsive-dialog-title"
>
<DialogTitle id="responsive-dialog-title">{'Vill du avsluta tävlingen?'}</DialogTitle> <DialogTitle id="responsive-dialog-title">{'Vill du avsluta tävlingen?'}</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogContentText>
...@@ -305,7 +392,7 @@ const OperatorViewPage: React.FC = () => { ...@@ -305,7 +392,7 @@ const OperatorViewPage: React.FC = () => {
{teams && {teams &&
teams.map((team) => ( teams.map((team) => (
<ListItem key={team.id}> <ListItem key={team.id}>
{team.name} score: {team.question_answers}{' '} {team.name} score: {'666'}
</ListItem> </ListItem>
))} ))}
</List> </List>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment