Skip to content

Commit

Permalink
add total field for paper-machine selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Radoslav Popov committed Mar 8, 2023
1 parent 6ddf2f2 commit d85d25e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/process_protocols/VerifyProtocolInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default (props) => {
})
)

setMachineCount(0)
setMachineCount(protocolType == 'paper-machine' ? 1 : 0)
}, [protocolType])

useEffect(() => {
Expand Down
34 changes: 26 additions & 8 deletions src/components/process_protocols/validation_form/ProtocolForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import React from 'react'
import styled from 'styled-components'

const ProtocolDetailsTable = styled.table`
table-layout: fixed;
table-layout: inherit;
button {
width: 100%;
box-sizing: border-box;
}
input {
width: 100%;
box-sizing: border-box;
width: 100%;
box-sizing: border-box;
border: 1px solid #ddd;
Expand Down Expand Up @@ -44,7 +42,7 @@ const ProtocolDetailsTable = styled.table`
`

const PartyResultsTable = styled.table`
table-layout: fixed;
table-layout: inherit;
width: 100%;
border-collapse: collapse;
Expand Down Expand Up @@ -107,10 +105,12 @@ const PartyResultsTable = styled.table`
`
: props.colCount === 2
? `
td:nth-child(1), th:nth-child(1) { width: 8%; }
td:nth-child(2), th:nth-child(2) { width: 72%; }
td:nth-child(1), th:nth-child(1) { width: 7%; }
td:nth-child(2), th:nth-child(2) { width: 60%; }
td:nth-child(3), th:nth-child(3) { width: 10%; }
td:nth-child(4), th:nth-child(4) { width: 10%; }
td:nth-child(5), th:nth-child(5) { width: 10%; }
`
: props.colCount === 3
? `
Expand Down Expand Up @@ -190,6 +190,23 @@ export default (props) => {
/>
</td>
))}
{props.protocolType === 'paper-machine' && (
<td>
<input
type="text"
className={
props.fieldStatus[`party${party.id}total`].invalid
? 'invalid'
: props.fieldStatus[`party${party.id}total`].changed
? 'changed'
: ''
}
name={`party${party.id}total`}
value={props.formState.resultsData[`party${party.id}total`] ?? ''}
onChange={props.handleResultsChange}
/>
</td>
)}
</tr>
)
}
Expand Down Expand Up @@ -360,6 +377,7 @@ export default (props) => {
{[...Array(props.machineCount).keys()].map((i, index) => (
<th key={index}>M{i + 1}</th>
))}
{props.protocolType === 'paper-machine' && <th>Общ</th>}
</tr>
</thead>
<tbody>
Expand All @@ -368,7 +386,7 @@ export default (props) => {
.map(partyRow)}
</tbody>
</PartyResultsTable>
{props.machineCount === 1 &&
{/* {props.machineCount === 1 &&
props.machineHash.length === props.machineCount ? (
<>
<hr />
Expand Down Expand Up @@ -454,7 +472,7 @@ export default (props) => {
</tbody>
</ProtocolDetailsTable>
</>
) : null}
) : null} */}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ export default (props) => {
</ChooseProtocolType>
<h5 style={{ margin: '10px 0' }}>Изберете вид протокол</h5>
<ChooseProtocolType>
<input
{/* <input
type="radio"
id="machine"
name="protocolType"
onClick={() => props.setProtocolType('machine')}
/>
<label htmlFor="machine">Машинен</label>
<label htmlFor="machine">Машинен</label> */}
<input
type="radio"
id="paper"
Expand All @@ -211,7 +211,7 @@ export default (props) => {
/>
<label htmlFor="paper-machine">Хартиено-машинен</label>
</ChooseProtocolType>
{props.protocolType === 'machine' ||
{/* {props.protocolType === 'machine' ||
props.protocolType === 'paper-machine' ? (
<>
<h5 style={{ margin: '10px 0' }}>Брой машини</h5>
Expand All @@ -238,7 +238,7 @@ export default (props) => {
<label htmlFor="2machines">2 машини</label>
</ChooseProtocolType>
</>
) : null}
) : null} */}
<hr />
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default class ValidationFormState {
this.formData['machineVotesCount'] = zeroIfEmpty(
protocol.results.machineVotesCount
)
this.formData['totalVotesCount'] = zeroIfEmpty(
protocol.results.totalVotesCount
)
}

if (protocolType === 'paper' || protocolType === 'paper-machine') {
Expand All @@ -60,18 +63,21 @@ export default class ValidationFormState {

for (const party of parties) {
//check if should add paper
if (protocolType === 'paper' || protocolType === 'machine-paper') {
if (protocolType === 'paper' || protocolType === 'paper-machine') {
this.resultsData[`party${party.id}paper`] = ''
}

//add machines
//add machines and total votes
for (let i = 0; i < machineCount; i++) {
this.resultsData[`party${party.id}machine${i + 1}`] = ''
}

if (protocolType === 'paper-machine') {
this.resultsData[`party${party.id}total`] = ''
}
}

for (const result of protocol.results) {
if (protocolType === 'paper' || protocolType === 'machine-paper') {
if (protocolType === 'paper' || protocolType === 'paper-machine') {
this.resultsData[`party${result.party}paper`] = emptyStrIfNull(
result.nonMachineVotesCount
)
Expand All @@ -82,6 +88,12 @@ export default class ValidationFormState {
this.resultsData[`party${result.party}machine${i + 1}`] =
emptyStrIfNull(result.machineVotes[i])
}

if (protocolType === 'paper-machine') {
this.resultsData[`party${result.party}total`] = emptyStrIfNull(
result.totalVotes
)
}
}
}

Expand Down Expand Up @@ -144,6 +156,11 @@ export default class ValidationFormState {
originalResult
)
}
const originalTotalResult = emptyStrIfNull(result.totalVotes)
fieldStatus[`party${party.id}total`] = compareResult(
`party${party.id}total`,
originalTotalResult
)
}

const addStatusForResultField = (fieldName) => {
Expand All @@ -167,6 +184,8 @@ export default class ValidationFormState {
if (protocolType === 'paper-machine') {
addStatusForResultField('nonMachineVotesCount')
addStatusForResultField('machineVotesCount')
addStatusForResultField('totalVotesCount')
addStatusForResultField('totalVotes')
}

if (protocolType === 'paper' || protocolType === 'paper-machine') {
Expand Down Expand Up @@ -220,6 +239,7 @@ export default class ValidationFormState {

if (protocolType === 'machine' || protocolType === 'paper-machine') {
result.machineVotes = []
result.totalVotes = []
}

if (protocolType === 'paper' || protocolType === 'paper-machine') {
Expand All @@ -235,6 +255,12 @@ export default class ValidationFormState {
)
}

if (protocolType === 'paper-machine') {
result.totalVotes.push(
parseInt(this.resultsData[`party${party.id}total`], 10)
)
}

results.push(result)
}

Expand Down

0 comments on commit d85d25e

Please sign in to comment.