Skip to content

Commit

Permalink
Merge pull request #385 from mikefranze/election-settings
Browse files Browse the repository at this point in the history
Random candidate order and voter instruction confirmations
  • Loading branch information
mikefranze authored Nov 20, 2023
2 parents 3ddeafa + dc9abfb commit 68d560e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions domain_model/ElectionSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ export interface ElectionSettings {
ballot_updates?: boolean; // allows voters to update their ballots before election ends
public_results?: boolean; // allows public to view results
time_zone?: string; // Time zone for displaying election start/end times
random_candidate_order?: boolean; // Randomize order of candidates on the ballot
require_instruction_confirmation?: boolean // Require voter to confirm that they've read the instructions in order to vote
}
2 changes: 1 addition & 1 deletion frontend/src/components/Election/Election.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const TempWrapper = ({ authSession }: Props) => {
<Grid xs={12} sm={8}>
<Routes>
<Route path='/' element={<ElectionHome authSession={authSession} electionData={data} fetchElection={refreshElection} />} />
<Route path='/vote' element={<VotePage election={data.election} fetchElection={refreshElection} />} />
<Route path='/vote' element={<VotePage />} />
<Route path='/thanks' element={<Thanks election={data.election} />} />
<Route path='/results' element={<ViewElectionResults election={data.election} />} />
<Route path='/edit' element={<EditElection authSession={authSession} election={data.election} fetchElection={refreshElection} />} />
Expand Down
20 changes: 13 additions & 7 deletions frontend/src/components/Election/Voting/VotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Box, Container, Step, StepLabel, Stepper, SvgIcon } from "@mui/material
import Button from "@mui/material/Button";
import { usePostBallot } from "../../../hooks/useAPI";
import FiberManualRecordOutlinedIcon from '@mui/icons-material/FiberManualRecordOutlined';
import useElection from "../../ElectionContextProvider";

// I'm using the icon codes instead of an import because there was padding I couldn't get rid of
// https://stackoverflow.com/questions/65721218/remove-material-ui-icon-margin
Expand All @@ -36,15 +37,20 @@ function shuffle(array) {
return array;
}

const VotePage = ({ election, fetchElection }) => {
const VotePage = () => {

const { election } = useElection()
const makePages = () => {
// generate ballot pages
let pages = election.races.map((race, i) => ({
type: "ballot",
candidates: shuffle(race.candidates.map(c=> ({...c, score: null}))),
voting_method : race.voting_method,
race_index: i
}))
let pages = election.races.map((race, i) => {
let candidates = race.candidates.map(c=> ({...c, score: null}))
return {
type: "ballot",
candidates: election.settings.random_candidate_order ? shuffle(candidates) : candidates,
voting_method : race.voting_method,
race_index: i
}
})

// determine where to add info pages
// commented out for now in case we want to return to this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const CreateElectionTemplates = ({ authSession }: { authSession: IAuthSession })
ballot_updates: false,
public_results: true,
time_zone: DateTime.now().zone.name,
random_candidate_order: true,
require_instruction_confirmation: false,
}
}

Expand Down
15 changes: 14 additions & 1 deletion frontend/src/components/ElectionForm/ElectionSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ export default function ElectionSettings() {
<Grid item xs={12} sx={{ m: 0, my: 1, p: 1 }}>
<FormControl component="fieldset" variant="standard">
<FormGroup>
<FormControlLabel control={
<Checkbox
id="candidate-order"
name="Randomize Candidate Order"
checked={editedElectionSettings.random_candidate_order}
onChange={(e) => applySettingsUpdate(settings => { settings.random_candidate_order = e.target.checked })}
/>}
label="Randomize Candidate Order"
/>
<FormHelperText sx={{ pl: 4, mt: -1 }}>
Randomizes the order of candidates on the ballots.
</FormHelperText>
<FormControlLabel disabled control={
<Checkbox
id="ballot-updates"
Expand Down Expand Up @@ -134,7 +146,8 @@ export default function ElectionSettings() {
<Checkbox
id="require-instructions-confirmations"
name="Require Instruction Confirmations"
checked={false}
checked={editedElectionSettings.require_instruction_confirmation}
onChange={(e) => applySettingsUpdate(settings => { settings.require_instruction_confirmation = e.target.checked })}
/>}
label="Require Instruction Confirmations"
/>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/ElectionForm/QuickPoll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const QuickPoll = ({ authSession }) => {
},
ballot_updates: false,
public_results: true,
random_candidate_order: true,
require_instruction_confirmation: false,
}
}

Expand Down

0 comments on commit 68d560e

Please sign in to comment.