diff --git a/qp-template-master/package-lock.json b/qp-template-master/package-lock.json index f6f152b..5b1b115 100644 --- a/qp-template-master/package-lock.json +++ b/qp-template-master/package-lock.json @@ -7885,6 +7885,11 @@ } } }, + "font-awesome": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/font-awesome/-/font-awesome-4.7.0.tgz", + "integrity": "sha1-j6jPBBGhoxr9B7BtKQK7n8gVoTM=" + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/qp-template-master/package.json b/qp-template-master/package.json index 1e3d8da..700763e 100644 --- a/qp-template-master/package.json +++ b/qp-template-master/package.json @@ -11,6 +11,7 @@ "@testing-library/react": "^9.5.0", "@testing-library/user-event": "^7.2.1", "bootstrap": "^4.5.0", + "font-awesome": "^4.7.0", "katex": "^0.11.1", "popups": "^1.1.3", "react": "^16.13.1", diff --git a/qp-template-master/src/App.css b/qp-template-master/src/App.css index e395509..dbcdb6a 100644 --- a/qp-template-master/src/App.css +++ b/qp-template-master/src/App.css @@ -6,6 +6,16 @@ border-color: white; } + .preview{ + padding-left: 30px; + } + + .button{ + background-color: violet; + } + + + .row-align{ justify-content: center; } diff --git a/qp-template-master/src/App.js b/qp-template-master/src/App.js index 12474e3..2f44e13 100644 --- a/qp-template-master/src/App.js +++ b/qp-template-master/src/App.js @@ -11,15 +11,17 @@ class template extends Component { super(); this.state={ date:'', + rollno:'', subject:'', semester:'', course:'', regulation:'', time:'', marks:'', - touched:[ + touched: { date:false, + rollno:false, subject:false, semester:false, course:false, @@ -27,15 +29,16 @@ class template extends Component { time:false, marks:false, } - ] + } this.handleBlur=this.handleBlur.bind(this) } - validate(date,subject,semester,course,regulation,time,marks){ + validate(date,rollno,subject,semester,course,regulation,time,marks){ const errors={ date:'', + rollno:'', subject:'', semester:'', course:'', @@ -47,6 +50,9 @@ class template extends Component { if(this.state.touched.date&&date=='') errors.date="Date should not be empty"; + if(this.state.touched.rollno&&rollno=='') + errors.rollno="Rollno should not be empty"; + if(this.state.touched.subject&&subject=='') errors.subject="Subject should not be empty"; @@ -84,21 +90,29 @@ class template extends Component { render(){ - const errors=this.validate(this.state.date,this.state.subject,this.state.semester,this.state.course,this.state.regulation,this.state.time,this.state.marks) + const errors=this.validate(this.state.date,this.state.rollno,this.state.subject,this.state.semester,this.state.course,this.state.regulation,this.state.time,this.state.marks) return(
- - + + {errors.date} + + + {errors.rollno} + diff --git a/qp-template-master/src/copy.js b/qp-template-master/src/copy.js new file mode 100644 index 0000000..7aadaa7 --- /dev/null +++ b/qp-template-master/src/copy.js @@ -0,0 +1,703 @@ +Gmail Dinesh Kumar +Re: Webex meeting invitation: Qp-Template-Demo +kishor kumar Fri, Jun 12, 2020 at 12:08 PM +To: dkdinesh6688@gmail.com +import React, { Component } from "react"; +import {Row,Col,Input, Label, Button, FormFeedback} from 'reactstrap' +import Math from './math' +import { confirmAlert } from 'react-confirm-alert'; +import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css +import './App.css'; +import 'katex/dist/katex.min.css'; +import { PDFViewer,Page, Text, View, Document, StyleSheet } from "@react-pdf/renderer"; +import Popup from 'reactjs-popup'; +import Mydoc from './mydoc.js'; +import Scroll from 'react-scroll'; +import { PDFExport } from "@progress/kendo-react-pdf"; + +var qpaMark=0 +var qpbMark=0 +var qpcMark=0 + +class Partc extends Component { + + constructor(props){ + super(props); + + this.state={ + subload:false, + noMatch:false, + noMatchA:false, + noMatchB:false, + noMatchC:false, + total:'', + touched:[ + { + total:false + } + ], + open:false, + sub:["a","b","c","d"], + qp: + [ + { + + question:"", + mark:"", + touched:{ + question:false, + mark:false, + }, + file: '', + imagePreviewUrl: '', + errors:{ + question :"error", + mark:"error" + }, + subqp: + [ + + ] + } + ] + + } + this.handleBlur=this.handleBlur.bind(this) + this._handleImageChange = this._handleImageChange.bind(this); + this._handleImageSubChange = this._handleImageSubChange.bind(this); + this._handleSubmit = this._handleSubmit.bind(this); + } + + handleBlurTotal=(field)=>(evt)=>{ + this.setState({ + touched:{...this.state.touched,[field]:true} + }) + } + + _handleSubmit(e) { + e.preventDefault(); + // TODO: do something with -> this.state.file + } + + _handleImageChange(e,index) { + e.preventDefault(); + + let reader = new FileReader(); + let file = e.target.files[0]; + + reader.onloadend = () => { + const list = [...this.state.qp]; + list[index].file =file; + list[index].imagePreviewUrl=reader.result; + this.setState({ + qp:list + }); + } + if(file) + reader.readAsDataURL(file) + } + _handleImageSubChange(e,id,index) { + e.preventDefault(); + + let reader = new FileReader(); + let file = e.target.files[0]; + + reader.onloadend = () => { + this.state.qp[id].subqp[index].file=file; + this.state.qp[id].subqp[index].imagePreviewUrl=reader.result; + this.setState( + this.state.qp[id].subqp[index] + ); + } + if(file) + reader.readAsDataURL(file) + } + submit = (e,id) => { + e.preventDefault(); + confirmAlert({ + customUI: ({ onClose }) => { + return ( +
+

Are you sure?

+

You want to delete this Question + ?

+ +
+ +
+
+ ); + } + }); + }; + + submitsub (e,id,subid) { + e.preventDefault(); + confirmAlert({ + customUI: ({ onClose }) => { + return ( +
+

Are you sure?

+

You want to delete this Question + ?

+ +
+ +
+
+ ); + } + }); + }; + + + handletotal=e=>{ + const {value} = e.target; + this.setState({total:value}) + } + + validate(total){ + const errors={ + total:'', + } + + if(this.state.touched.total&&total=='') + errors.total="Total should not be empty"; + + return errors; + } + validateQp(question,mark,id){ + if(this.state.qp[id].touched.question&&question=='') + this.state.qp[id].errors.question="Question should not be empty"; + if(this.state.qp[id].touched.mark&&mark=='') + this.state.qp[id].errors.mark="Mark should not be empty"; + + } + validateSubQp(question,mark,id,subid){ + if(this.state.qp[id].subqp[subid].touched.question&&question=='') + this.state.qp[id].subqp[subid].errors.question="Question should not be empty"; + if(this.state.qp[id].subqp[subid].touched.mark&&mark=='') + this.state.qp[id].subqp[subid].errors.mark="Mark should not be empty"; + } + exportPDFWithComponent = () => { + this.pdfExportComponent.save(); +}; + + openModal=(event) =>{ + event.preventDefault(); + this.setState({ open: true }); + } + + closeModal=(event)=> { + + this.setState({ open: false }); + } + + + // handle input change + handleInputChange = (e, index) => { + const { name, value } = e.target; + const list = [...this.state.qp]; + list[index][name] = value; + if(name=="question"&&list[index][name]!='') + { + list[index].errors.question='error'; + this.setState({qp:list}) + } + if(name=="mark"&&list[index][name]!='') + { + list[index].errors.mark='error'; + this.setState({qp:list}) + } + this.setState({qp:list}) + }; + + handleInputsubChange = (e, index,subid) => { + const { name, value } = e.target; + this.state.qp[index].subqp[subid][name] = value; + if(name=="question"&&this.state.qp[index].subqp[subid].question!=''){ + this.state.qp[index].subqp[subid].errors.question='error' + this.setState(this.state.qp[index].subqp[subid]) + } + if(name=="mark"&&this.state.qp[index].subqp[subid].mark!=""){ + this.state.qp[index].subqp[subid].errors.mark='error' + this.setState(this.state.qp[index].subqp[subid]) + } + this.setState(this.state.qp[index].subqp[subid]) + + }; + + // handle click event of the Remove button + handleRemoveClick = index => { + const list = [...this.state.qp]; + list.splice(index, 1); + this.setState({qp:list}) + }; + + handleRemovesubClick = (index,subid) => { + this.state.qp[index].subqp.splice(subid, 1); + this.setState(this.state.qp[index].subqp) + }; + + // handle click event of the Add button + handleAddClick = (id) => { + this.setState((prevState)=>({ + qp:[...prevState.qp,{question:"",mark:"",subqp:[],touched:{ + question:false, + mark:false, + }, + file: '', + imagePreviewUrl: '', + errors:{ + question :"error", + mark:"error" + }}] + })) + }; + + handleSubClick = index => { + this.state.qp[index].subqp.push({question:"",mark:"",file: '', + imagePreviewUrl: '',touched:{ + question:false, + mark:false, + }, + errors:{ + question :"error", + mark:"error" + }}) + this.setState({subload:true}) + }; + + onClick = (e) => { + e.preventDefault(); + var qpa=''+qpaMark + var tota=''+(this.props.sab.total) + var qpb=''+qpbMark + var totb=''+(this.props.sb.total) + var qpc=''+qpcMark + var totc=''+(this.state.total) + var tot=''+this.props.header.marks + // console.log(tot) + var total=parseInt(this.props.sab.total)+parseInt(this.props.sb.total)+parseInt(this.state.total) + //console.log(total) + var total_abc=''+total + // console.log(typeof(total_abc)) + if(qpa!=tota){ + this.state.noMatchA=true + } + if(qpa==tota){ + this.state.noMatchA=false + } + if(qpb!=totb){ + this.state.noMatchB=true + } + if(qpb==totb){ + this.state.noMatchB=false + } + if(qpc!=totc){ + this.state.noMatchC=true + } + if(qpc==totc){ + this.state.noMatchC=false + } + if(tot!=total_abc){ + this.state.noMatch=true + console.log(this.state.noMatch) + } + if(tot==total_abc){ + this.state.noMatch=false + console.log(this.state.noMatch) + } + if(this.state.noMatch){ + alert("Total is not equal") + } + else if(this.state.noMatchA){ + alert("Total is not equal in Part-A") + } + else if(this.state.noMatchB){ + alert("Total is not equal in Part-B") + } + else if(this.state.noMatchC){ + alert("Total is not equal in Part-C") + } + if(this.state.noMatchA||this.state.noMatchB||this.state.noMatchC||this.state.noMatch){ + this.setState({open:false}) + } + else{ + this.setState({open:true}) + } + //this.setState({open:true}) +} + +handleBlur=(field,id)=>(evt)=>{ + const list = [...this.state.qp]; + list[id].touched[field] = true; + this.setState({qp:list}) +} + +handleBlurSubQp=(field,index,subid)=>(evt)=>{ + console.log(this.state.qp[index].subqp[subid].touched[field]) + this.state.qp[index].subqp[subid].touched[field]=true; + this.setState(this.state.qp[index].subqp[subid]) + } + + handlecheck(){ + var qpamark=0; + var qpasubmark=0; + var qpbmark=0; + var qpbsubmark=0; + var qpcmark=0; + var qpcsubmark=0; + this.props.sab.qp.map((x,id)=>{ + qpamark=qpamark+parseInt(x.mark) + this.props.sab.qp[id].subqp.map((xb,id)=>{ + qpasubmark=qpasubmark+parseInt(xb.mark) + }) + }) + qpaMark=qpamark+qpasubmark + // console.log(qpaMark) + + this.props.sb.qp.map((x,id)=>{ + qpbmark=qpbmark+parseInt(x.mark) + this.props.sb.qp[id].subqp.map((xb,id)=>{ + qpbsubmark=qpbsubmark+parseInt(xb.mark) + }) + }) + qpbMark=qpbmark+qpbsubmark + //console.log(qpbMark) + + this.state.qp.map((x,id)=>{ + qpcmark=qpcmark+parseInt(x.mark) + this.state.qp[id].subqp.map((xb,id)=>{ + qpcsubmark=qpcsubmark+parseInt(xb.mark) + }) + }) + qpcMark=qpcmark+qpcsubmark + // console.log(qpcMark) + } + + + + render(){ + const errors=this.validate(this.state.total) + return ( +
+ + + + + + { } + + + + {errors.total} + + + + { + this.state.qp.map((x,id) => { + return ( +
+ {this.validateQp(x.question,x.mark,id)} + + + {this.state.qp.length !== 1 && x.subqp.length<1 &&} + + + + + {this.state.qp[id].subqp.length!==0? + :} + + + + this.handleInputChange(e, id)}/> + + {x.errors.question} + + + + this.handleInputChange(e, id)}/> + {x.errors.mark} + + + {} + + +
{this.state.qp[id].subqp.map((xb,subid)=>
+ {this.validateSubQp(xb.question,xb.mark,id,subid)} + + + {} + + + + + + this.handleInputsubChange(e, id, subid)}/> + {xb.errors.question} + + + + + this.handleInputsubChange(e, id,subid)}/> + {xb.errors.mark} + + + {} + +
)}
+
+ ); + } + )} +
+ {this.handlecheck()} +
+ + + + + + +
+ + × + + (this.pdfExportComponent = component)} + paperSize="a4" + margin={40} + fileName={`Report for ${new Date().getFullYear()}`} + author="KendoReact Team" + + > +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + this.props.sab.qp.map((x,id) => { + return( +
+ + + {this.props.sab.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + + {this.props.sab.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); + }) + } +
+
+ + + + + { + this.props.sb.qp.map((x,id) => { + return( +
+ + + {this.props.sb.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + {this.props.sb.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); + }) + } +
+
+ + + + + + { + this.state.qp.map((x,id) => { + return( +
+ + + {this.state.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + {this.state.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); + }) + } +
+
+
+ +
+ + +
+ +
+ +
+ ); + }} + +export default Partc; + diff --git a/qp-template-master/src/parta.js b/qp-template-master/src/parta.js index ac0335e..2713d4b 100644 --- a/qp-template-master/src/parta.js +++ b/qp-template-master/src/parta.js @@ -6,6 +6,8 @@ import Partb from './partb' import Popup from 'reactjs-popup'; import Math from './math' import 'katex/dist/katex.min.css'; +import '../node_modules/font-awesome/css/font-awesome.min.css' +import subdivide from './subdivide.png' @@ -284,9 +286,9 @@ class Parta extends Component { - { } + { } - + - {this.state.qp.length !== 1 && x.subqp.length<1 &&} + {this.state.qp.length !== 1 && x.subqp.length<1 &&} @@ -315,10 +317,11 @@ class Parta extends Component { this.handleInputChange(e, id)}/> - - {x.errors.question} - + {x.errors.question}
+ + + {x.errors.mark} - {} + {}
{this.state.qp[id].subqp.map((xb,subid)=>
@@ -335,7 +338,7 @@ class Parta extends Component { - {} + {} @@ -344,10 +347,10 @@ class Parta extends Component { this.handleInputsubChange(e, id, subid)}/> - {xb.errors.question} + {xb.errors.question}
- + this._handleImageSubChange(e,id,subid)} /> + {xb.errors.mark} - {} + {}
)}
diff --git a/qp-template-master/src/partb.js b/qp-template-master/src/partb.js index 2b83f50..00e62d2 100644 --- a/qp-template-master/src/partb.js +++ b/qp-template-master/src/partb.js @@ -5,6 +5,7 @@ import { confirmAlert } from 'react-confirm-alert'; import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css import Math from './math' import 'katex/dist/katex.min.css'; +import subdivide from './subdivide.png' class Partb extends Component { constructor(){ @@ -267,9 +268,9 @@ class Partb extends Component { - { } + { } - + - {this.state.qp.length !== 1 && x.subqp.length<1 &&} + {this.state.qp.length !== 1 && x.subqp.length<1 &&} @@ -298,10 +299,10 @@ class Partb extends Component { this.handleInputChange(e, id)}/> + {x.errors.question}
- {x.errors.question} - + this._handleImageChange(e,id)} /> + {x.errors.mark} - {} + {}
{this.state.qp[id].subqp.map((xb,subid)=>
{this.validateSubQp(xb.question,xb.mark,id,subid)} - {} + {} @@ -326,10 +327,10 @@ class Partb extends Component { this.handleInputsubChange(e, id, subid)}/> - {xb.errors.question} + {xb.errors.question}
- + this._handleImageSubChange(e,id,subid)} /> + {xb.errors.mark} - {} + {}
)}
diff --git a/qp-template-master/src/partc.js b/qp-template-master/src/partc.js index 6f850a2..d586412 100644 --- a/qp-template-master/src/partc.js +++ b/qp-template-master/src/partc.js @@ -10,6 +10,7 @@ import Popup from 'reactjs-popup'; import Mydoc from './mydoc.js'; import Scroll from 'react-scroll'; import { PDFExport } from "@progress/kendo-react-pdf"; +import subdivide from './subdivide.png' var qpaMark=0 var qpbMark=0 @@ -22,6 +23,7 @@ class Partc extends Component { this.state={ subload:false, + field:false, noMatch:false, noMatchA:false, noMatchB:false, @@ -316,9 +318,12 @@ class Partc extends Component { } if(tot==total_abc){ this.state.noMatch=false - console.log(this.state.noMatch) + //console.log(this.state.noMatch) } - if(this.state.noMatch){ + if(this.state.field){ + alert("Some Field is not typed") + } + else if(this.state.noMatch){ alert("Total is not equal") } else if(this.state.noMatchA){ @@ -358,10 +363,35 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ var qpbsubmark=0; var qpcmark=0; var qpcsubmark=0; + + var head=this.props.header.touched + + if(head.date==false||head.rollno==false||head.subject==false||head.semester==false|| + head.course==false||head.regulation==false||head.time==false||head.marks==false){ + this.state.field=true + } + else{ + this.state.field=false + } + this.props.sab.qp.map((x,id)=>{ qpamark=qpamark+parseInt(x.mark) + if(x.touched.question==false||x.touched.mark==false){ + this.state.field=true + // console.log(this.state.field) + } + else{ + this.state.field=false + // console.log(this.state.field) + } this.props.sab.qp[id].subqp.map((xb,id)=>{ qpasubmark=qpasubmark+parseInt(xb.mark) + if(xb.touched.question==false||xb.touched.mark==false){ + this.state.field=true + } + else{ + this.state.field=false + } }) }) qpaMark=qpamark+qpasubmark @@ -369,8 +399,20 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ this.props.sb.qp.map((x,id)=>{ qpbmark=qpbmark+parseInt(x.mark) + if(x.touched.question==false||x.touched.mark==false){ + this.state.field=true + } + else{ + this.state.field=false + } this.props.sb.qp[id].subqp.map((xb,id)=>{ qpbsubmark=qpbsubmark+parseInt(xb.mark) + if(xb.touched.question==false||xb.touched.mark==false){ + this.state.field=true + } + else{ + this.state.field=false + } }) }) qpbMark=qpbmark+qpbsubmark @@ -378,8 +420,20 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ this.state.qp.map((x,id)=>{ qpcmark=qpcmark+parseInt(x.mark) + if(x.touched.question==false||x.touched.mark==false){ + this.state.field=true + } + else{ + this.state.field=false + } this.state.qp[id].subqp.map((xb,id)=>{ qpcsubmark=qpcsubmark+parseInt(xb.mark) + if(xb.touched.question==false||xb.touched.mark==false){ + this.state.field=true + } + else{ + this.state.field=false + } }) }) qpcMark=qpcmark+qpcsubmark @@ -397,9 +451,9 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ - { } + { } - + (evt)=>{ {this.validateQp(x.question,x.mark,id)} - {this.state.qp.length !== 1 && x.subqp.length<1 &&} + {this.state.qp.length !== 1 && x.subqp.length<1 &&} @@ -429,10 +483,10 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ this.handleInputChange(e, id)}/> + {x.errors.question}
- {x.errors.question} - + this._handleImageChange(e,id)} /> + (evt)=>{ {x.errors.mark} - {} + {}
{this.state.qp[id].subqp.map((xb,subid)=>
{this.validateSubQp(xb.question,xb.mark,id,subid)} - {} + {} @@ -457,10 +511,10 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{ this.handleInputsubChange(e, id, subid)}/> - {xb.errors.question} + {xb.errors.question}
- + this._handleImageSubChange(e,id,subid)} /> + (evt)=>{ {xb.errors.mark} - {} + {}
)}
@@ -479,10 +533,11 @@ handleBlurSubQp=(field,index,subid)=>(evt)=>{
{this.handlecheck()}
- - + + + + + (evt)=>{ >
- - - + + + - - - - + + - - - + - - - - + + - - - - + + + + + - - - - - - - + + + + + + - - - - - - - - - + + + + { - this.props.sab.qp.map((x,id) => { - return( -
- - - {this.props.sab.qp[id].subqp.length!==0? - :} - - - - - - - - - - - - - {this.props.sab.qp[id].subqp.map((xb,subid)=>{ - return( - - - - - - - - - - - - - - ); - })} - -
- ); + this.props.sab.qp.map((x,id) => { + return( +
+ + + {this.props.sab.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + + {this.props.sab.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); }) }
- - - - - - - - + + + { - this.props.sb.qp.map((x,id) => { - return( -
- - - {this.props.sb.qp[id].subqp.length!==0? - :} - - - - - - - - - - - - - {this.props.sb.qp[id].subqp.map((xb,subid)=>{ - return( - - - - - - - - - - - - - - ); - })} - -
- ); + this.props.sb.qp.map((x,id) => { + return( +
+ + + {this.props.sb.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + {this.props.sb.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); }) }
- - - - - - - - + + + + { - this.state.qp.map((x,id) => { - return( -
- - - {this.state.qp[id].subqp.length!==0? - :} - - - - - - - - - - - - - {this.state.qp[id].subqp.map((xb,subid)=>{ - return( - - - - - - - - - - - - - - ); - })} - -
- ); + this.state.qp.map((x,id) => { + return( +
+ + + {this.state.qp[id].subqp.length!==0? + :} + + + + + + + + + + + + + {this.state.qp[id].subqp.map((xb,subid)=>{ + return( + + + + + + + + + + + + + + ); + })} + +
+ ); }) } -
- -
- - - - - - - - - - ); - }} - -export default Partc; - - + + + + + + + + + + + + + ); + }} +export default Partc; \ No newline at end of file diff --git a/qp-template-master/src/subdivide.png b/qp-template-master/src/subdivide.png new file mode 100644 index 0000000..4e1fe3b Binary files /dev/null and b/qp-template-master/src/subdivide.png differ