Commit 3491792d authored by Devinda's avatar Devinda

add lesson upload page and route

parent 244d3fbd
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
let Answer = new Schema({
answer_id: mongoose.Schema.Types.ObjectId,
student_id: {
type: String
},
student_name:{
type:String
},
lesson_no:{
type:Number
},
no_of_questions:{
type:Number
},
question_text:{
type:String
},
question_answer:{
type:String
},
defult_mark:{
type:Number
}
});
module.exports = mongoose.model('Answer',Answer);
\ No newline at end of file
const answerRoute = require('express').Router();
let answer = require('../models/answer.model');
const mongoose = require('mongoose');
answerRoute.route('/').get(function(req, res) {
answer.find(function(err, questions) {
if (err) {
console.log(err);
res.render('index');
} else {
res.json(questions);
}
});
});
answerRoute.route('/:id').get(function (req, res) {
let id = req.params.id;
answer.findById(id, function (err, question) {
res.json(question);
});
});
answerRoute.route('/questionId/:id').get(function (req, res) {
console.log("Question ID");
console.log(req.params.id);
let id = req.params.id;
answer.find({"_id" : id}, function (err, question) {
res.json(question);
});
});
answerRoute.route('/add').post(function(req, res) {
const ans = new answer({
answer_id: new mongoose.Types.ObjectId(),
student_id : req.body.student_id,
student_name : req.body.student_name,
lesson_no : req.body.lesson_no,
no_of_questions : req.body.no_of_questions,
question_text: req.body.question_text,
question_answer:req.body.question_answer,
defult_mark: req.body.defult_mark,
});
ans.save().then(ans =>{
res.json('Item update!');
})
.catch(err =>{
res.status(400).send("Update not possible");
});
});
answerRoute.route('/update/:id').post((req, res) => {
answer.findById(req.params.id,function(err, answer){
if(!answer)
req.status(404).send("data is not found");
else {
answer.lesson_no = req.body.lesson_no,
answer.student_id = req.body.student_id,
answer.student_name = req.body.student_name,
answer.no_of_questions = req.body.no_of_questions,
answer.question_text = req.body.question_text,
answer.question_answer = req.body.question_answer,
answer.defult_mark = req.body.defult_mark
}
answer.save().then(answer =>{
res.json('Item update!');
})
.catch(err =>{
res.status(400).send("Update not possible");
});
});
});
answerRoute.route('/lessonNo/:id').get(function (req, res) {
console.log("Product Item ID");
console.log(req.params.id);
let id = req.params.id;
answer.find({"lesson_no" : id}, function (err, answer) {
res.json(answer);
});
});
answerRoute.route('/delete/:id').delete((req, res) => {
answer.findByIdAndDelete(req.params.id)
.then(() => res.json('Product Deleted.'))
.catch(err => res.status(400).json('Error: ' + err));
});
module.exports = answerRoute;
\ No newline at end of file
......@@ -13,6 +13,7 @@ questionRouter.route('/').get(function(req, res) {
});
});
questionRouter.route('/:id').get(function (req, res) {
let id = req.params.id;
Question.findById(id, function (err, question) {
......
......@@ -82,12 +82,14 @@ const questionManage = require('./routes/question.route');
const financeRouter = require('./routes/finance.route');
const studentResult = require('./routes/studentALResult.route');
const imageRouter = require('./routes/pdf.route');
const answerManage = require('./routes/answer_route');
app.use('/studentSingUp',studentRouter);
app.use('/tutorSingUp',tutorRouter);
app.use('/instituteSingUp',instituteRouter);
app.use('/userAccount',userAccount);
app.use('/questions', questionManage);
app.use('/answer', answerManage);
app.use('/admin/finance', financeRouter);
app.use('/studentResults', studentResult);
app.use('/', imageRouter(upload));
......
......@@ -2305,11 +2305,28 @@
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.2.3.tgz",
"integrity": "sha512-PijRCG/K3s3w1We6ynUKdxEc5AcuuH3NBmMDP8uvKVp6X43UY7NQlTzczakXP3DJR0F4dfNQIGjU2cUeRYs2AA=="
},
"@types/prop-types": {
"version": "15.7.4",
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.4.tgz",
"integrity": "sha512-rZ5drC/jWjrArrS8BR6SIr4cWpW09RNTYt9AMZo3Jwwif+iacXAqgVjm0B0Bv/S1jhDXKHqRVNCbACkJ89RAnQ==",
"dev": true
},
"@types/q": {
"version": "1.5.4",
"resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.4.tgz",
"integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug=="
},
"@types/react": {
"version": "17.0.26",
"resolved": "https://registry.npmjs.org/@types/react/-/react-17.0.26.tgz",
"integrity": "sha512-MXxuXrH2xOcv5cp/su4oz69dNQnSA90JjFw5HBd5wifw6Ihi94j7dRJm7qNsB30tnruXSCPc9qmlhGop4nh9Hw==",
"dev": true,
"requires": {
"@types/prop-types": "*",
"@types/scheduler": "*",
"csstype": "^3.0.2"
}
},
"@types/resolve": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz",
......@@ -2318,6 +2335,12 @@
"@types/node": "*"
}
},
"@types/scheduler": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz",
"integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==",
"dev": true
},
"@types/source-list-map": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
......@@ -4775,6 +4798,12 @@
}
}
},
"csstype": {
"version": "3.0.9",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.0.9.tgz",
"integrity": "sha512-rpw6JPxK6Rfg1zLOYCSwle2GFOOsnjmDYDaBwEcwoOg4qlsIVCN789VkBZDJAGi4T07gI4YSutR43t9Zz4Lzuw==",
"dev": true
},
"cyclist": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/cyclist/-/cyclist-1.0.1.tgz",
......@@ -12341,6 +12370,14 @@
"object-assign": "^4.1.1"
}
},
"react-addons-shallow-compare": {
"version": "15.6.3",
"resolved": "https://registry.npmjs.org/react-addons-shallow-compare/-/react-addons-shallow-compare-15.6.3.tgz",
"integrity": "sha512-EDJbgKTtGRLhr3wiGDXK/+AEJ59yqGS+tKE6mue0aNXT6ZMR7VJbbzIiT6akotmHg1BLj46ElJSb+NBMp80XBg==",
"requires": {
"object-assign": "^4.1.0"
}
},
"react-app-polyfill": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/react-app-polyfill/-/react-app-polyfill-2.0.0.tgz",
......@@ -12645,6 +12682,14 @@
"prop-types": "^15.6.1"
}
},
"react.pure.component": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/react.pure.component/-/react.pure.component-1.2.0.tgz",
"integrity": "sha1-8nuetnM3rtQ8XQ2sY4lD7Zux3hE=",
"requires": {
"react-addons-shallow-compare": "^15.3.2"
}
},
"read-pkg": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz",
......@@ -14881,6 +14926,11 @@
"is-typedarray": "^1.0.0"
}
},
"typescript": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.3.tgz",
"integrity": "sha512-4xfscpisVgqqDfPaJo5vkd+Qd/ItkoagnHpufr+i2QCHBsNYp+G7UAoyFl8aPtx879u38wPV65rZ8qbGZijalA=="
},
"unbox-primitive": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz",
......
......@@ -18,7 +18,9 @@
"react-scripts": "4.0.3",
"react-select-search": "^3.0.8",
"react-star-rating-component": "^1.4.1",
"react.pure.component": "^1.2.0",
"sweetalert": "^2.1.2",
"typescript": "^4.4.3",
"web-vitals": "^1.1.1"
},
"scripts": {
......@@ -46,6 +48,7 @@
]
},
"devDependencies": {
"@types/react": "^17.0.26",
"axios": "^0.21.1",
"react-notify-toast": "^0.5.1"
}
......
......@@ -17,6 +17,8 @@ import QuestionLayout from "./Components/IT18050240/question_layout"
import AdminQuestionManagement from "./Components/IT18050240/admin_question_management.js"
import QuestionBank from "./Components/IT18050240/question_bank"
import LessonAndExam from "./Components/IT18050240/lessonandexampage";
import AutomaticQuestion from "./Components/IT18050240/automatic_question"
import Upload from "./Components/IT18050240/UploadPage";
function App() {
return (
......@@ -41,6 +43,8 @@ function App() {
<Route path="/questionbank" exact component={QuestionBank}/>
<Route path="/questionmanagement" exact component={AdminQuestionManagement}/>
<Route path="/lesson" exact component={LessonAndExam}/>
<Route path="/automaticquestion" exact component={AutomaticQuestion}/>
<Route path="/upload" exact component={Upload}/>
</Switch>
......
import React, { PureComponent } from 'react';
import axios from 'axios';
import Upload from '../../Images/upload.png';
import PDF from '../../Images/pdficon.png';
import PW from '../../Images/pptxicon.png';
interface UploadState {
recentImage: any;
caption: string;
uploadedImageUrl: string;
uploadedImage: any;
imagename: string;
filetype :string,
lessonname:string,
lessonno: string,
};
class UploadPage extends PureComponent<{}, UploadState> {
constructor(props: {}) {
super(props);
this.state = {
recentImage: {},
caption: '',
uploadedImageUrl: '',
uploadedImage: {},
imagename : '',
filetype: '',
lessonname:'',
lessonno:'',
};
}
componentDidMount = () => {
this.fetchRecent();
}
componentDidUpdate=()=> {
// let str = this.state.recentImage.filename;
//
// if (str.includes(".pdf")) {
// this.setState({
// imagename: PDF,
// filetype : ".pdf"
// });
// }else if (str.includes(".pptx")) {
// this.setState({
// imagename: PW,
// filetype :".pptx"
// });
// }
// else {
//
// }
}
fetchRecent = () => {
axios.get('http://localhost:5000/recent')
.then((response) => {
this.setState({ recentImage: response.data.image });
})
.catch(err => alert('Error: ' + err));
if(this.state.filetype==""){
this.setState({
imagename: PW,
filetype :"",
lessonname:"",
lessonno:"",
});
}
}
uploadImage = () => {
if (!this.state.caption.trim() || !this.state.uploadedImage.name) {
return alert('Caption or file is missing');
}
let formData = new FormData();
formData.append('caption', this.state.caption);
formData.append('file', this.state.uploadedImage);
formData.append('lessonno', this.state.lessonno);
formData.append('lessonname', this.state.lessonname);
axios.post('http://localhost:5000/', formData)
.then((response) => {
response.data.success ? alert('File successfully uploaded') : alert('File already exists');
this.fetchRecent();
})
.catch(err => alert('Error: ' + err));
}
render() {
return (
<div className="UploadPage">
<div className="Recent">
<div className="row">
<div className="col-sm-5">
<label>Lesson name: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ lessonname: event.target.value })}
value={this.state.lessonname}/>
</div>
</div>
<div className="col-sm-5">
<label>Lesson no: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ lessonno: event.target.value })}
value={this.state.lessonno}/>
</div>
</div>
</div>
<div className="row">
<div className="col-sm-5">
<label>Lesson caption: </label>
<div style={{padding: '0px'}}>
<input
type="text"
className="form-control"
placeholder="Enter caption..."
onChange={event => this.setState({ caption: event.target.value })}
value={this.state.caption}
/>
</div>
</div>
<div className="col-sm-5">
<label>Upload file: </label>
<div style={{padding: '0px'}}>
<input
type="file"
className="Upload__Input"
onChange={(event: any) => {
this.setState({
uploadedImageUrl: URL.createObjectURL(event.target.files[0]),
uploadedImage: event.target.files[0],
})
}}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-sm-5">
<button type ="submit" value ="Submit"
className = "btn btn-block btn-warning mt-3" onClick={this.uploadImage}> ADD
</button>
</div>
<div className="col-sm-5">
<button type ="submit" value ="Submit"
className = "btn btn-block btn-success mt-3" onClick={this.uploadImage}> ADD
</button>
</div>
</div>
</div>
<br/><br/>
<div className="border">
<div style={{margin: "15px"}}>
<h5 className="text-center"> Recent Upload File </h5>
{/*<p className="text-center"> File type : ({this.state.filetype} ) <img src={this.state.imagename} alt="upload-image" style={{width:'30px'}}/> </p>*/}
{/*<p className="text-center"> This quiz closed on Sunday,02 May 2021,7:10PM</p>*/}
<p className="text-center"> time limit :1 hour 30 mins</p>
<p className="text-center">Grading method: highest grade</p>
</div>
</div>
</div>
);
}
}
export default UploadPage;
import React, { Component } from 'react';
import axios from 'axios';
//import swal from 'sweetalert';
import { Link } from "react-router-dom";
export default class Automatic_question extends Component {
render() {
return (
<div className="container">
<form onSubmit={this.onSubmit}>
<div className="row">
<div className="col-sm-5">
<label>Lesson name: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ })}
/>
</div>
</div>
<div className="col-sm-5">
<label>Lesson no: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ })}
/>
</div>
</div>
<div className="col-sm-5">
<label>defult_mark: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ })}
/>
</div>
</div>
<div className="col-sm-5">
<label>general_feedback: </label>
<div style={{padding: '0px'}}>
<input type="text" required className="form-control"
onChange={event => this.setState({ })}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-sm-10">
<label style={{textAlign: 'left'}} >Question text: </label>
<textarea
className="form-control" required
/>
<br/>
<button className="btn btn-block btn btn-secondary" type="submit" value="Submit" style={{ color: "white" }}>Create new Question</button>
</div>
</div>
</form>
</div>
)
}
}
\ No newline at end of file
import React, { Component } from 'react';
import axios from 'axios';
import { Link } from "react-router-dom";
import swal from 'sweetalert';
const Quantity = props => (
<tr>
<td>{props.questions.lesson_name}</td>
<td>{props.questions.lesson_no}</td>
<td>{props.questions.question_text}</td>
<td>{props.questions.question_answer}</td>
<td>
......@@ -73,13 +73,9 @@ export default class QuestionBankUI extends Component {
onSubmit(e) {
e.preventDefault();
console.log(`Question type: ${this.state.q_type}`);
if (this.state.q_type == "Multiple_choice") {
window.location = '/questionmanagement/';
} else {
//console.log(`Question type: ${this.state.q_type}`);
window.location = '/questionmanagement/';
}
//window.location = '/admin/pcategory';
}
......@@ -101,40 +97,23 @@ export default class QuestionBankUI extends Component {
<hr />
</div>
<form onSubmit={this.onSubmit}>
<div className="col-sm-10" >
<div className="row" >
<div className="col-sm-1 mt-1"><label>Category: </label>
</div>
<div className="col-sm-5">
<div style={{ padding: '0px' }}>
<select style={{ width: '100%' }} className="browser-default custom-select"
onChange={(e) => this.onChangeQType(e)}>
<option>Select Question Type</option>
<option key="Multiple_choice" value="Multiple_choice">Multiple choice</option>
<option key="True_False" value="True_False">True/False</option>)
</select>
</div>
</div>
<div className="col-sm-3">
<button className="btn btn-block btn btn-secondary" type="submit" value="Submit" style={{ color: "white" }}>Create new Question</button>
<Link style={{textDecoration:"none"}} to={"/questionmanagement"}><button className="btn btn-block btn btn-secondary" style={{color:"white"}}>Create new Question</button></Link>
</div>
<div className="col-sm-3">
<button className="btn btn-block btn btn-info" type="submit" value="Submit" style={{ color: "white" }}>Auto Genarate Question</button>
<Link style={{textDecoration:"none"}} to={"/automaticquestion"}><button className="btn btn-block btn btn-info" style={{color:"white"}}>Auto Genarate Question</button></Link>
</div>
</div></div>
</form>
<br/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment