Skip to content

Commit

Permalink
Merge pull request #191 from yasirunilan/master
Browse files Browse the repository at this point in the history
fixed the issue #143 and #146
  • Loading branch information
YujithIsura authored Feb 16, 2020
2 parents f9c6305 + 2a39d89 commit 15da8c9
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 32 deletions.
38 changes: 24 additions & 14 deletions client/src/components/CandidateFileUpload/CandidateFileUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import DoneOutline from '@material-ui/icons/DoneOutline';
import CloseIcon from '@material-ui/icons/Cancel';
import { API_BASE_URL } from "../../config.js";
import axios from "axios";
import download from 'downloadjs';



Expand Down Expand Up @@ -177,6 +178,15 @@ componentDidMount() {
}
};

handleFileDownload = (doc) => {
axios.get(`${API_BASE_URL}/nominations/candidates/${this.props.index}/support-docs/${doc.id}/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), doc.originalname, response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};

handleChangeButton = (e) => {
const { onCloseModal } = this.props;
if(e.currentTarget.value==="Submit&Clouse"){
Expand Down Expand Up @@ -234,20 +244,20 @@ componentDidMount() {
<Grid item lg={6}>
{docs.doc}
</Grid>
<Grid item lg={4}>
<FileUpload value={docs.id} doneElement={doneElement} onSelectFiles={this.onSelectFiles} />
{
this.state.supportdoc.map(sdoc => (
sdoc.id === docs.id ?
<Typography variant="caption" gutterBottom>
{sdoc.originalname}<div className={classes.done}>
<CloseIcon ref={this.state.currentSdocId} onClick={this.handleRese} color="red"/>
</div>
</Typography>
: ' '
))
}
</Grid>
<Grid item lg={4}>
<FileUpload value={docs.id} doneElement={doneElement} onSelectFiles={this.onSelectFiles} />
{
this.state.supportdoc.map(sdoc => (
sdoc.id === docs.id ?
<Typography variant="caption" gutterBottom style={{cursor: 'pointer'}} onClick={() => { this.handleFileDownload(sdoc) }}>
{sdoc.originalname}<div className={classes.done}>
<CloseIcon ref={this.state.currentSdocId} onClick={this.handleRese} color="red"/>
</div>
</Typography>
: ' '
))
}
</Grid>

<Grid item lg={12}>
<Divider className={classes.divider} variant="middle"/>
Expand Down
38 changes: 24 additions & 14 deletions client/src/components/NominationStep3/NominationStep3.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import { createAndDownloadPdfPresidentialNominationForm, createAndDownloadPdfPar
import ProgressButton from "../ProgressButton";
import DoneOutline from '@material-ui/icons/DoneOutline';
import CloseIcon from '@material-ui/icons/Cancel';
import axios from "axios";
import {API_BASE_URL} from "../../config";
import download from "downloadjs";

const styles = theme => ({
container: {
Expand Down Expand Up @@ -93,6 +96,15 @@ class TextFields extends React.Component {
var filesArray = this.state.files;
};

handleFileDownload = (doc) => {
axios.get(`${API_BASE_URL}/nominations/${this.props.customProps}/support-docs/${doc.id}/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), doc.originalname, response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};



handlePdfGenarationButton = (e) => {
Expand Down Expand Up @@ -158,21 +170,19 @@ class TextFields extends React.Component {
</Grid>
<Grid item lg={2}>
<span ><FileUpload value={docs.id} doneElement={doneElement} onSelectFiles={onSelectFiles} /></span>

</Grid>
<Grid style={{marginLeft:-44}} item lg={1}>
{
supportdoc.map(sdoc => (
sdoc.id === docs.id ?
<Typography variant="caption" gutterBottom>
{sdoc.originalname}<div className={classes.done}>
<CloseIcon color="red"/>
</div>
</Typography>
: ' '
))
}

</Grid>
{
supportdoc.map(sdoc => (
sdoc.id === docs.id ?
<Typography variant="caption" gutterBottom style={{cursor: 'pointer'}} onClick={() => { this.handleFileDownload(sdoc) }}>
{sdoc.originalname}<div className={classes.done}>
<CloseIcon color="red"/>
</div>
</Typography>
: ' '
))
}
{/* {docs.id === 'b20dd58c-e5bb-469d-98c9-8711d6da1879' ?
<Grid item lg={5}>
<span><FileUpload style={{textAlign: 'right'}} value={docs.id} doneElement={doneElement} onSelectFiles={onSelectFiles} /></span>
Expand Down
32 changes: 32 additions & 0 deletions client/src/modules/nomination/Nomination_review.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import CommentIcon from '@material-ui/icons/InsertComment';
import IconButton from "@material-ui/core/IconButton";
import Slide from '@material-ui/core/Slide';
import TextField from '@material-ui/core/TextField';
import axios from "axios";
import {API_BASE_URL} from "../../config";
import download from "downloadjs";
import GetAppIcon from '@material-ui/icons/GetApp';

const drawerWidth = 240;

Expand Down Expand Up @@ -230,6 +234,25 @@ class NominationReview extends React.Component {
[name]: event.target.value,
});
};

downloadCandidateDocuments = (candidate) => {
axios.get(`${API_BASE_URL}/nominations/candidates/${candidate.id}/support-docs/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), 'candidate_support_docs_'+candidate.id+'.zip', response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};

downloadNominationDocuments = (nomination) => {
axios.get(`${API_BASE_URL}/nominations/${nomination.id}/support-docs/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), 'nomination_support_docs_'+nomination.id+'.zip', response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};

render() {
const { classes, nominations, ApproveElections, partyList } = this.props;
const { expandedPanelIndex } = this.state;
Expand Down Expand Up @@ -270,6 +293,9 @@ class NominationReview extends React.Component {
<TableCell className={classes.candidate_table_cell} align="left">
{candidate.address}
</TableCell>
<TableCell onClick={() => { this.downloadCandidateDocuments(candidate) }} className={classes.candidate_table_cell} align="left">
<GetAppIcon style={{marginRight:10,marginBottom:-2}} className={classes.left_icon} />
</TableCell>
</TableRow>
</React.Fragment>
);
Expand Down Expand Up @@ -321,6 +347,7 @@ class NominationReview extends React.Component {
<TableCell align="left">Full Name</TableCell>
<TableCell align="left">Occupation</TableCell>
<TableCell align="left">Address</TableCell>
<TableCell align="left">Documents</TableCell>
</TableHead>
<TableBody>
{
Expand Down Expand Up @@ -360,6 +387,11 @@ class NominationReview extends React.Component {
</Grid>
<br />
</ExpansionPanelDetails>
<Button
onClick={() => { this.downloadNominationDocuments(nomination) }}
className={classNames(classes.button, classes.green_button)}>Download Nomination Documents
<GetAppIcon style={{marginRight:10,marginBottom:-2}} className={classes.left_icon} />
</Button>
</ExpansionPanel>
));

Expand Down
68 changes: 68 additions & 0 deletions server/api-docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,74 @@ paths:
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/payments/{paymentId}/download':
get:
parameters:
- name: paymentId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/candidates/{candidateId}/support-docs/{documentId}/download':
get:
parameters:
- name: candidateId
in: path
required: true
type: string
- name: documentId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/{nominationId}/support-docs/{documentId}/download':
get:
parameters:
- name: nominationId
in: path
required: true
type: string
- name: documentId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/candidates/{candidateId}/support-docs/download':
get:
parameters:
- name: candidateId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/{nominationId}/support-docs/download':
get:
parameters:
- name: nominationId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
info:
title: Nomination
version: '0.9'
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dotenv": "^2.0.0",
"express": "^4.14.0",
"express-fileupload": "^1.1.1-alpha.1",
"express-zip": "^3.0.0",
"flow-runtime": "^0.2.1",
"fraction.js": "^3.3.1",
"globule": "^1.1.0",
Expand Down
84 changes: 82 additions & 2 deletions server/src/repository/supportdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,34 @@ const PAYMENT_SUPPORT_DOC_SELECT_QUERY = `SELECT
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM PAYMENT_SUPPORT_DOC WHERE PAYMENT_ID=:paymentId AND STATUS = 'NEW' LIMIT 1`;



const CANDIDATE_SUPPORT_DOC_BY_DOC_ID_AND_CANDIDATE_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM CANDIDATE_SUPPORT_DOC WHERE SUPPORT_DOC_CONFIG_ID=:documentId AND CANDIDATE_ID=:candidateId`;

const CANDIDATE_SUPPORT_DOC_BY_DOC_ID_AND_NOMINATION_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM NOMINATION_SUPPORT_DOC WHERE SUPPORT_DOC_CONFIG_ID=:documentId AND NOMINATION_ID=:nominationId`;


const CANDIDATE_SUPPORT_DOCS_BY_CANDIDATE_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM CANDIDATE_SUPPORT_DOC WHERE CANDIDATE_ID=:candidateId`;


const CANDIDATE_SUPPORT_DOCS_BY_NOMINATION_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM NOMINATION_SUPPORT_DOC WHERE NOMINATION_ID=:nominationId`;

const getSupportDocByNomination = (nominationId) => {
const params = { nominationId: nominationId };
return DbConnection()
Expand Down Expand Up @@ -191,6 +218,55 @@ const getSupportDocByPayment = (paymentId) => {
});
}

const getSupportDocByCandidateIdAndDocId = (documentId, candidateId) => {
const params = { documentId: documentId, candidateId: candidateId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOC_BY_DOC_ID_AND_CANDIDATE_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}

const getSupportDocByNominationIdAndDocId = (documentId, nominationId) => {
const params = { documentId: documentId, nominationId: nominationId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOC_BY_DOC_ID_AND_NOMINATION_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}

const getSupportDocsByCandidateId = (candidateId) => {
const params = { candidateId: candidateId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOCS_BY_CANDIDATE_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}


const getSupportDocsByNominationId = (nominationId) => {
const params = { nominationId: nominationId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOCS_BY_NOMINATION_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}




Expand Down Expand Up @@ -269,5 +345,9 @@ export default {
getSupportDocByCandidate,
savePaymentSupportDocs,
updatePaymentSupportDocs,
getSupportDocByPayment
getSupportDocByPayment,
getSupportDocByCandidateIdAndDocId,
getSupportDocByNominationIdAndDocId,
getSupportDocsByCandidateId,
getSupportDocsByNominationId
}
3 changes: 2 additions & 1 deletion server/src/routes/constants/URLSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ export const URL_SCHEMA = Joi.object().keys({
templateName: Joi.string(),
keyName: Joi.string(),
sid: Joi.string(),
teamType: Joi.string()
teamType: Joi.string(),
documentId: Joi.string().max(36).regex(/^[A-Za-z0-9-]+$/)
});
Loading

0 comments on commit 15da8c9

Please sign in to comment.