Skip to content

Commit

Permalink
Merge pull request #337 from YujithIsura/newNomination
Browse files Browse the repository at this point in the history
fixing issues after connecting config api
  • Loading branch information
YujithIsura authored Aug 4, 2022
2 parents 2197b99 + 2b0c82f commit 6abaf48
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 59 deletions.
33 changes: 22 additions & 11 deletions client/src/components/CheckboxTable/CheckboxTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CheckboxTableGrid extends React.Component {

componentWillMount() {
const { rows, cols, CallElectionData } = this.props;
debugger;
let rowHeaders = [''];
this.props.rows.map((value) => {
rowHeaders.push(value.name);
Expand All @@ -92,6 +93,7 @@ class CheckboxTableGrid extends React.Component {
rawCount++;
for (let j = 0; j < cols.length; j++) {
for (let h = 0; h < CallElectionData.rowData.length; h++) {
// debugger;
if (cols[j].id === CallElectionData.rowData[h].division_id && rows[i].id === CallElectionData.rowData[h].team_id) {

let allow_party = {
Expand All @@ -107,32 +109,40 @@ class CheckboxTableGrid extends React.Component {
}
this.setState({ rowData: this.state.rowData });

this.setState({ rowHeaders, columnHeaders, checkboxGrid });
this.setState({ rowHeaders, columnHeaders });
var rawCount = 0;
var prevCol = cols[0].id;
var colCount = 0;
var selectedIndex = '';
for (let i = 0; i < rows.length; i++) {
for (let m = 0; m < rows.length; m++) {
debugger;
// console.log("DDD",m);
let row = [];
for (let j = 0; j < cols.length; j++) {
for (let n = 0; n < cols.length; n++) {
debugger;
// console.log("ggg",m,"rrr",n);
CallElectionData.rowData.map((value) => {
if (cols[j].id === value.division_id && rows[i].id === value.team_id) {
if (prevCol === cols[j].id) {
// debugger;
// console.log("cols["+n+"].id = "+ cols[n].id+" value.division_id = "+value.division_id+" rows["+m+"].id "+rows[m].id+" value.team_id "+value.team_id);
if (cols[n].id == value.division_id && rows[m].id == value.team_id) {
console.log("cols["+n+"].id = "+ cols[n].id+" value.division_id = "+value.division_id+" rows["+m+"].id "+rows[m].id+" value.team_id "+value.team_id);
if (prevCol === cols[n].id) {
colCount++;
prevCol = cols[j].id;
selectedIndex = j;
prevCol = cols[n].id;
selectedIndex = n;
} else {
if (j !== cols.length - 1) {
prevCol = cols[j + 1].id;
if (n !== cols.length - 1) {
prevCol = cols[n + 1].id;
}
}
rawCount++;
checkboxGrid[i + 1][j + 1] = true;
checkboxGrid[m + 1][n + 1] = true;
}
});
}
}
this.findIndex(checkboxGrid);
// this.findIndex(checkboxGrid);
this.setState({checkboxGrid});

}

Expand Down Expand Up @@ -296,6 +306,7 @@ class CheckboxTableGrid extends React.Component {
pagination: false,
viewColumns:false
};
debugger;

return (
<MuiThemeProvider theme={this.getMuiTheme()}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ class CheckboxTableGrid extends React.Component {
let row = [];
for (let j = 0; j < cols.length; j++) {
rowData.map((value) => {
debugger;
if (cols[j].id === value.division_id && rows[i].id === value.team_id) {
if (cols[j].id == value.division_id && rows[i].id == value.team_id) {
if (prevCol === cols[j].id) {
colCount++;
prevCol = cols[j].id;
Expand Down Expand Up @@ -281,7 +280,7 @@ class CheckboxTableGrid extends React.Component {
}
} else {
if(i!==0 && j!==1){
colData.push(<Checkbox color="primary" checked={true} onChange={this.handleChange(i, j - 1, data)}></Checkbox>);
colData.push(<Checkbox color="primary" checked={this.state.checkboxGrid[i][j - 1]} onChange={this.handleChange(i, j - 1, data)}></Checkbox>);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions client/src/components/NominationStep2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class NominationPayments extends React.Component {
}

if (this.state.election && name === 'party') {
debugger;
this.props.getNominationListForPayment(this.state.election, event.value);
} else if (this.state.party && name === 'election') {
this.props.getNominationListForPayment(event.value, this.state.party)
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/NominationStep3/NominationStep3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class TextFields extends React.Component {
}
render() {
const {classes,onSelectFiles,doneElement,supportdoc,closeElement,supportingDocs,handleUploadView,errorTextFileUpload} = this.props;

debugger;

const supportingDocItems = supportingDocs.map(docs => (
<div>
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/election/ActiveElectionForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ class ActiveElectionForm extends React.Component {
const { CallElectionData,rowHeaders } = this.props;
var rowHeadersForRpp = rowHeaders.filter(x => x.team_party_type === "RPP");
var rowHeadersForIg = rowHeaders.filter(x => x.team_party_type === "IND");
debugger;
const { errorTextNominationStart, errorTextNominationEnd, errorTextObjectionStart, errorTextObjectionEnd, errorTextPaymentStart, errorTextPaymentEnd, errorTextApprovalStart, errorTextApprovalEnd } = this.state;
const errorTextItems = { errorTextNominationStart, errorTextNominationEnd, errorTextObjectionStart, errorTextObjectionEnd, errorTextPaymentStart, errorTextPaymentEnd, errorTextApprovalStart, errorTextApprovalEnd }

Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/election/AllowNomination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class AllowNomination extends React.Component {
<div className={classes.content}>
<CardContent>
<form ref="form" onSubmit={this.handleSubmit}>
<CheckboxTable title="" data={nomination_setup} rows={rowHeadersForRpp}></CheckboxTable>
<CheckboxTable title="" data={nomination_setup} rows={data}></CheckboxTable>
<CheckboxTableIg title="" data={nomination_setup} rows={rowHeadersForIg}></CheckboxTableIg>
</form>
</CardContent>
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/election/AllowNominationView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class AllowNomination extends React.Component {

render() {
const { classes,electionData,errorTextElectorates ,rowData,rowHeaders} = this.props;
debugger;
// const data = rowHeaders.map((record) => {
// record.id = record.team_id;
// record.name = record.team_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class Dashboard extends React.Component {
<Typography variant="subtitle2" className={classes.text_a} component="p">Calculation Type : </Typography>
</Grid>
<Grid item xs={3} sm={2} justify="center">
<Typography component="p">{(CalculationType === 'vote_and_prefrence') ? 'Vote & Preferential Based' : (CalculationType === 'pure_prefrence_based') ? 'Pure preference-based' : (CalculationType === 'pure_vote_based') ? 'Pure vote-based' : ''}</Typography>
<Typography component="p">{CalculationType}</Typography>
</Grid>
{/* <Grid item xs={12} sm={6}>
<Grid container spacing={24}>
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/nomination/state/NominationAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export const setNominationStatus = (nominationSuppertDocs) => {
candidateSupportDocs:nominationSuppertDocs.supportdoc,
divisionId:divisionId
}
debugger;
return function (dispatch) {

const response = axios
Expand Down
83 changes: 43 additions & 40 deletions server/src/manager/candidate/candidateManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Candidate } from 'Models';
import { Candidate } from 'Models';
var joinjs = require('join-js').default;
import {List} from 'typed-immutable';
import { List } from 'typed-immutable';
import _ from 'lodash';
import moment from 'moment';

Expand All @@ -10,13 +10,13 @@ const resultMaps = [
mapId: 'candidateMap',
idProperty: 'ID',
// properties: ['FULL_NAME', 'DES','OCCUPATION','NIC', 'DATE_OF_BIRTH', 'GENDER','ADDRESS', 'NOMINATION_ID']
properties: ['CONFIG_ID', 'KEY_NAME','VALUE']
properties: ['CONFIG_ID', 'KEY_NAME', 'VALUE']
}
];


const mapToCandidateModel = (candidates) => {
console.log('candidates',candidates);
console.log('candidates', candidates);
var groupedCandidates = _.groupBy(candidates, 'CANDIDATE_ID');
var expected = _.map(groupedCandidates, function (candidateProperties) {
var orderedProps = [];
Expand All @@ -27,40 +27,41 @@ const mapToCandidateModel = (candidates) => {
});
orderedProps = _.sortBy(orderedProps, 'CANDIDATE_CONFIG_ID');

var candidateInfoMap = {CANDIDATE_ID:id};
var candidateInfoMap = { CANDIDATE_ID: id };
_.each(orderedProps, function (property) {
if(property.CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH'){
if (property.CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH') {
candidateInfoMap[property.CANDIDATE_KEY_NAME] = moment(new Date(parseInt(property.CANDIDATE_VALUE))).format('YYYY-MM-DD');
}else{
} else {
candidateInfoMap[property.CANDIDATE_KEY_NAME] = property.CANDIDATE_VALUE;
}
});

return candidateInfoMap;
});
console.log('expected',expected);
console.log('expected', expected);
return expected;
// const mappedCandidates = joinjs.map(candidates, resultMaps, 'candidateMap', 'CANDIDATE_');
// const mappedCandidates = expected;
// const mappedCandidates = expected;

// console.log("mappedCandidatesmappedCandidatesmappedCandidates",mappedCandidates);
// return _.reduce(mappedCandidates, function(result, candidate) {

// console.log("mappedCandidatesmappedCandidatesmappedCandidates",mappedCandidates);
// return _.reduce(mappedCandidates, function(result, candidate) {

// return result.push({
// "id": candidate.ID,
// "configId": candidate.CONFIG_ID,
// "keyName": candidate.KEY_NAME,
// "value": candidate.VALUE
// return result.push({
// "id": candidate.ID,
// "configId": candidate.CONFIG_ID,
// "keyName": candidate.KEY_NAME,
// "value": candidate.VALUE

// });
// },List(Candidate)());
// });
// },List(Candidate)());


};

const mapToPartyCandidateModel = (candidates,party_list,division_list) => {
console.log('candidates',candidates);
const mapToPartyCandidateModel = (candidates, party_list, division_list) => {
console.log('party_list', party_list);
var groupedCandidates = _.groupBy(candidates, 'CANDIDATE_ID');
console.log('division_list', division_list);
var expected = _.map(groupedCandidates, function (candidateProperties) {
var orderedProps = [];
var id = "";
Expand All @@ -70,33 +71,35 @@ const mapToPartyCandidateModel = (candidates,party_list,division_list) => {
});
orderedProps = _.sortBy(orderedProps, 'CANDIDATE_CONFIG_ID');

var candidateInfoMap = {CANDIDATE_ID:id};
var candidateInfoMap = { CANDIDATE_ID: id };
_.each(orderedProps, function (property) {
if(property.CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH'){
if (property.CANDIDATE_KEY_NAME === 'DATE_OF_BIRTH') {
candidateInfoMap[property.CANDIDATE_KEY_NAME] = moment(new Date(parseInt(property.CANDIDATE_VALUE))).format('YYYY-MM-DD');
}else{
} else {
candidateInfoMap[property.CANDIDATE_KEY_NAME] = property.CANDIDATE_VALUE;
}
});

return candidateInfoMap;
});

const expectedWithParty = party_list.map(item => {
//check and change the team_id variable name after finishing the party list endpoint
const item2 = expected.find(o => o.team_id === item.team_id);
return { ...item, ...item2};
});

const expectedWithPartyDivision = division_list.map(item => {
//check and change the vivision_id variable name after finishing the division list endpoint
const item2 = expectedWithParty.find(o => o.division_id === item.division_id);
return { ...item, ...item2};
return candidateInfoMap;
});

if (party_list) {
const expectedWithParty = party_list.map(item => {
//check and change the team_id variable name after finishing the party list endpoint
const item2 = expected.find(o => o.team_id === item.team_id);
return { ...item, ...item2 };
});
}
if (division_list) {
const expectedWithPartyDivision = division_list.map(item => {
//check and change the vivision_id variable name after finishing the division list endpoint
const item2 = expectedWithParty.find(o => o.division_id === item.division_id);
return { ...item, ...item2 };
});
}

console.log('expected',expected);
return expectedWithPartyDivision;
console.log('expected', expected);
return expected;
};

export default {
Expand Down
2 changes: 1 addition & 1 deletion server/src/repository/division.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ FROM NOMINATION N LEFT JOIN DIVISION_CONFIG DC ON N.DIVISION_CONFIG_ID=DC.ID
LEFT JOIN CANDIDATE_DATA C ON N.ID=C.NOMINATION_ID
LEFT JOIN CANDIDATE_CONFIG CC ON C.CANDIDATE_CONFIG_ID = CC.ID
LEFT JOIN PAYMENT P ON N.ID=P.NOMINATION_ID
WHERE N.ELECTION_ID=:election_id AND N.TEAM_ID=:team_id AND N.DIVISION_CONFIG_ID=:divisionId GROUP BY N.ID,CC.ID`;
WHERE N.ELECTION_ID=:election_id AND N.TEAM_ID=:team_id GROUP BY N.ID,CC.ID`;

const DIVISIONS_WITH_NOMINATION_SELECT_QUERY_ALL = `SELECT
N.DIVISION_CONFIG_ID AS division_id,
Expand Down
2 changes: 1 addition & 1 deletion server/src/service/divisionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const getDivisionsWithNomination = async (req) => {
const teamId = req.params.teamId;
const divisionId = req.params.divisionId;
const divisions = await DivisionRepo.fetchDivisionsWithNomination(electionId, teamId,divisionId);

console.log(divisions,"divisions");
if (!_.isEmpty(divisions)) {
return DivisionManager.mapToDivisionModelWithNominations(divisions);
} else {
Expand Down

0 comments on commit 6abaf48

Please sign in to comment.