Skip to content

Commit

Permalink
Merge pull request #277 from YujithIsura/master
Browse files Browse the repository at this point in the history
done changes for pdf service internal url
  • Loading branch information
YujithIsura authored Mar 5, 2020
2 parents ae4c50d + e457711 commit a4ff8b1
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 18 deletions.
2 changes: 1 addition & 1 deletion client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WORKDIR /app
RUN npm ci
ENV REACT_APP_API_BASE_URL=https://apim-gateway.ecdev.opensource.lk/nominations/0.9
# ENV REACT_APP_PDF_GENARATION_SERVICE_URL=http://pdf-service-1hcnse.pxe-dev-platformer-1552477983757-1pdna.svc
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://pdf.ecdev.opensource.lk
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://apim-gateway.ecdev.opensource.lk/nominations/0.9
ENV REACT_APP_AUTH_BASE_URL=https://nominations.ecdev.opensource.lk
ENV REACT_APP_NOMINATION_URL=https://nominations.ecdev.opensource.lk
RUN npm run build
Expand Down
3 changes: 2 additions & 1 deletion client/Staging.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ WORKDIR /app
RUN npm ci
ENV REACT_APP_API_BASE_URL=https://apim-gw.ecstag.opensource.lk/nominations/0.9
# ENV REACT_APP_PDF_GENARATION_SERVICE_URL=http://pdf-service-z1jkglv.pxe-dev-platformer-1552477983757-1pdna.svc
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://pdf.ecstag.opensource.lk
# ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://pdf.ecstag.opensource.lk
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://apim-gw.ecstag.opensource.lk/nominations/0.9
ENV REACT_APP_AUTH_BASE_URL=https://nominations.ecstag.opensource.lk
ENV REACT_APP_NOMINATION_URL=https://nominations.ecstag.opensource.lk

Expand Down
3 changes: 2 additions & 1 deletion client/Training.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ WORKDIR /app
RUN npm ci
ENV REACT_APP_API_BASE_URL=https://apim-gw.training.elections.gov.lk/nominations/0.9
# ENV REACT_APP_PDF_GENARATION_SERVICE_URL=http://pdf-service-z1jkglv.pxe-dev-platformer-1552477983757-1pdna.svc
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://pdf.ecstag.opensource.lk
# ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://pdf.ecstag.opensource.lk
ENV REACT_APP_PDF_GENARATION_SERVICE_URL=https://apim-gw.training.elections.gov.lk/nominations/0.9
ENV REACT_APP_AUTH_BASE_URL=https://nominations.training.elections.gov.lk
ENV REACT_APP_NOMINATION_URL=https://nominations.training.elections.gov.lk

Expand Down
3 changes: 2 additions & 1 deletion client/src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var API_BASE_URL = 'http://localhost:8280/nominations/0.9';
var PDF_GENARATION_SERVICE_URL = 'http://localhost:5000/';
// var PDF_GENARATION_SERVICE_URL = 'http://localhost:5000/';
var PDF_GENARATION_SERVICE_URL = 'http://localhost:8280/nominations/0.9';
var AUTH_BASE_URL = 'http://localhost:3001/';


Expand Down
4 changes: 3 additions & 1 deletion client/src/modules/nomination/CreateNomination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class Home extends React.Component {
this.setState({ election });
});
this.props.getTeams();
this.props.getNominationList();
if(sessionStorage.getItem('party_id') !== "all"){
this.props.getNominationList(sessionStorage.getItem('party_id'));
}
this.props.getNominationStatus(sessionStorage.getItem('election_id'));
}

Expand Down
26 changes: 16 additions & 10 deletions client/src/modules/nomination/state/NominationAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,17 +461,12 @@ const nominationListLoaded = (getNominationList) => {
};

export function getNominationList(teamId) {
if(teamId){
var partyId = teamId
}else{
var partyId = sessionStorage.getItem('party_id');
}

return function (dispatch) {

const response = axios
.get(
`${API_BASE_URL}/elections/${sessionStorage.getItem('election_id')}/teams/${partyId}/divisions/${sessionStorage.getItem('division_id')}`,
`${API_BASE_URL}/elections/${sessionStorage.getItem('election_id')}/teams/${teamId}/divisions/${sessionStorage.getItem('division_id')}`,
)
.then(response => {
const getNominationList = response.data;
Expand Down Expand Up @@ -703,9 +698,20 @@ export function validateNominationPayment(nominationId) {
//--------------- End of get security deposit details ---------------------------

//--------------- Start of genarate pdf ---------------------------

function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}

const firstAPI = axios.create({
baseURL: PDF_GENARATION_SERVICE_URL
baseURL: PDF_GENARATION_SERVICE_URL,
headers: {
'Authorization': "Bearer " +getCookie('somekey')
}
})

export const createAndDownloadNominationPaySlipPdf = function createAndDownloadNominationPaySlipPdf(paymentData) {
let templateData = {
"margin.top": "0.5",
Expand All @@ -719,7 +725,7 @@ export const createAndDownloadNominationPaySlipPdf = function createAndDownloadN
templateData['file']['paymentData'] = paymentData;

firstAPI.post(`/generate`, templateData)
.then((res) => firstAPI.get(res.data.url, { responseType: 'blob' }))
.then((res) => firstAPI.get(res.data.path, { responseType: 'blob' }))
.then((res) => {
const pdfBlob = new Blob([res.data], { type: 'application/pdf' });
saveAs(pdfBlob, 'nomination_payslip.pdf');
Expand Down Expand Up @@ -758,7 +764,7 @@ export const createAndDownloadPdfPresidentialNominationForm = function createAnd
templateData['file']['nominationData'] = nominationData;

firstAPI.post(`/generate`, templateData)
.then((res) => firstAPI.get(res.data.url, { responseType: 'blob' }))
.then((res) => firstAPI.get(res.data.path, { responseType: 'blob' }))
.then((res) => {
const pdfBlob = new Blob([res.data], { type: 'application/pdf' });
saveAs(pdfBlob, type + '.pdf');
Expand Down Expand Up @@ -791,7 +797,7 @@ export const createAndDownloadPdfParliamentaryNominationForm = function createAn
templateData['file']['nominationData'] = nominationData;

firstAPI.post(`/generate`, templateData)
.then((res) => firstAPI.get(res.data.url, { responseType: 'blob' }))
.then((res) => firstAPI.get(res.data.path, { responseType: 'blob' }))
.then((res) => {
const pdfBlob = new Blob([res.data], { type: 'application/pdf' });
saveAs(pdfBlob, type + '.pdf');
Expand Down
5 changes: 3 additions & 2 deletions client/src/modules/nomination/state/NominationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,17 @@ export default function reducer(state = initialState, action) {
};
case RECEIVE_NOMINATION_STATUS:
const nominationList = state.nominationList;
debugger;
const index2 = findDivisionIndex(nominationList, action.payload.divisionId);
const nomination = nominationList[index2].nomination;
const index3 = findNominationIndex(nomination, action.payload.nominationId);
// const index3 = findNominationIndex(nomination, action.payload.nominationId);
return {
...state,
nominationList: nominationList.map((nomination, nominationIndex) => {
if (nominationIndex === index2) {
return {
...nominationList[index2],
nomination: update(nominationList[index2].nomination, {[index3]: {status: {$set: 'SUBMIT'}}})
nomination: update(nominationList[index2].nomination, {[0]: {status: {$set: 'SUBMIT'}}})
}
} else {
return nomination
Expand Down
3 changes: 2 additions & 1 deletion server/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ DB_COLLECTION=
DB_CONNECTION_TYPE=SEQUELIZE
REDIS_SERVER_HOST=localhost
REDIS_SERVER_PORT=6379
SERVER_PORT=9001
SERVER_PORT=9001
NOMINATION_PDF_GENARATION_SERVICE_URL=http://localhost:5000
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"flow-runtime": "^0.2.1",
"fraction.js": "^3.3.1",
"globule": "^1.1.0",
"http-proxy-middleware": "^1.0.1",
"is_js": "^0.8.0",
"joi": "^9.2.0",
"join-js": "^1.0.1",
Expand Down
22 changes: 22 additions & 0 deletions server/src/middleware/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import cookieParser from 'cookie-parser';
import bodyParser from 'body-parser';
import { bindMiddlewares } from './WSMiddleware';
import configService from '../config/ConfigService';
// import {PDF_GENARATION_SERVICE_URL} from '../config/config';
import { createProxyMiddleware } from 'http-proxy-middleware';
var jwtDecode = require('jwt-decode');

let log4js = require('log4js');
Expand All @@ -12,6 +14,26 @@ let logger = log4js.getLogger("app");
const app = express();

app.use(cookieParser());

// move this to a config file
const PDF_GENARATION_SERVICE_URL = process.env.NOMINATION_PDF_GENARATION_SERVICE_URL;

let generateProxy = createProxyMiddleware('/ec-election/generate', {
target: PDF_GENARATION_SERVICE_URL+'/generate',
pathRewrite: function (path, req) {
return path.replace('/ec-election/generate', '')
}
});
app.use(generateProxy);

let exportsProxy = createProxyMiddleware('/ec-election/exports', {
target: PDF_GENARATION_SERVICE_URL+'/exports',
pathRewrite: function (path, req) {
return path.replace('/ec-election/exports', '')
}
});
app.use(exportsProxy);

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

Expand Down

0 comments on commit a4ff8b1

Please # to comment.