From d85d25e9297bc40ec403d059e6d61d1b74707b4f Mon Sep 17 00:00:00 2001 From: Radoslav Popov Date: Wed, 8 Mar 2023 22:25:38 +0100 Subject: [PATCH] add total field for paper-machine selection --- .../process_protocols/VerifyProtocolInfo.js | 2 +- .../validation_form/ProtocolForm.js | 34 ++++++++++++++----- .../validation_form/SectionDetails.js | 8 ++--- .../validation_form/ValidationFormState.js | 34 ++++++++++++++++--- 4 files changed, 61 insertions(+), 17 deletions(-) diff --git a/src/components/process_protocols/VerifyProtocolInfo.js b/src/components/process_protocols/VerifyProtocolInfo.js index b1b0eb5..b6dfbb5 100644 --- a/src/components/process_protocols/VerifyProtocolInfo.js +++ b/src/components/process_protocols/VerifyProtocolInfo.js @@ -183,7 +183,7 @@ export default (props) => { }) ) - setMachineCount(0) + setMachineCount(protocolType == 'paper-machine' ? 1 : 0) }, [protocolType]) useEffect(() => { diff --git a/src/components/process_protocols/validation_form/ProtocolForm.js b/src/components/process_protocols/validation_form/ProtocolForm.js index 0253bb3..db34ea6 100644 --- a/src/components/process_protocols/validation_form/ProtocolForm.js +++ b/src/components/process_protocols/validation_form/ProtocolForm.js @@ -3,7 +3,7 @@ import React from 'react' import styled from 'styled-components' const ProtocolDetailsTable = styled.table` - table-layout: fixed; + table-layout: inherit; button { width: 100%; @@ -11,8 +11,6 @@ const ProtocolDetailsTable = styled.table` } input { - width: 100%; - box-sizing: border-box; width: 100%; box-sizing: border-box; border: 1px solid #ddd; @@ -44,7 +42,7 @@ const ProtocolDetailsTable = styled.table` ` const PartyResultsTable = styled.table` - table-layout: fixed; + table-layout: inherit; width: 100%; border-collapse: collapse; @@ -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 ? ` @@ -190,6 +190,23 @@ export default (props) => { /> ))} + {props.protocolType === 'paper-machine' && ( + + + + )} ) } @@ -360,6 +377,7 @@ export default (props) => { {[...Array(props.machineCount).keys()].map((i, index) => ( M{i + 1} ))} + {props.protocolType === 'paper-machine' && Общ} @@ -368,7 +386,7 @@ export default (props) => { .map(partyRow)} - {props.machineCount === 1 && + {/* {props.machineCount === 1 && props.machineHash.length === props.machineCount ? ( <>
@@ -454,7 +472,7 @@ export default (props) => { - ) : null} + ) : null} */} ) } diff --git a/src/components/process_protocols/validation_form/SectionDetails.js b/src/components/process_protocols/validation_form/SectionDetails.js index 30b095e..40c23f0 100644 --- a/src/components/process_protocols/validation_form/SectionDetails.js +++ b/src/components/process_protocols/validation_form/SectionDetails.js @@ -189,13 +189,13 @@ export default (props) => {
Изберете вид протокол
- props.setProtocolType('machine')} /> - + */} { /> - {props.protocolType === 'machine' || + {/* {props.protocolType === 'machine' || props.protocolType === 'paper-machine' ? ( <>
Брой машини
@@ -238,7 +238,7 @@ export default (props) => { - ) : null} + ) : null} */}
) diff --git a/src/components/process_protocols/validation_form/ValidationFormState.js b/src/components/process_protocols/validation_form/ValidationFormState.js index 8041f8e..514ead7 100644 --- a/src/components/process_protocols/validation_form/ValidationFormState.js +++ b/src/components/process_protocols/validation_form/ValidationFormState.js @@ -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') { @@ -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 ) @@ -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 + ) + } } } @@ -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) => { @@ -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') { @@ -220,6 +239,7 @@ export default class ValidationFormState { if (protocolType === 'machine' || protocolType === 'paper-machine') { result.machineVotes = [] + result.totalVotes = [] } if (protocolType === 'paper' || protocolType === 'paper-machine') { @@ -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) }