Commit ae8ae3e9 authored by Hasitha Samarasekara's avatar Hasitha Samarasekara

Merge branch 'IT18050240' into 'master'

upload Web UI

See merge request !7
parents 5ca7d3f7 f503a3fd
ATLAS_URI = mongodb+srv://admin:admin@cluster0.wmb3b.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
\ No newline at end of file
ATLAS_URI = mongodb+srv://admin:admin@cluster0.wmb3b.mongodb.net/SmartCoach?retryWrites=true&w=majority
\ No newline at end of file
const questionRouter = require('express').Router();
let Question = require('../models/question.model.js');
let Question = require('../models/question.model');
const mongoose = require('mongoose');
questionRouter.route('/').get(function(req, res) {
......@@ -76,25 +76,28 @@ questionRouter.route('/update/:id').post((req, res) => {
Question.findById(req.params.id,function(err, question){
if(!question)
req.status(404).send("data is not found");
else
question.category = req.body.category;
question.name =req.body.name;
question.question_text = req.body.question_text;
question.defult_mark = req.body.defult_mark;
question.q_type = req.body.q_type;
question.time_createdby = req.body.time_createdby;
question.time_modifiedby = req.body.time_modifiedby;
question.general_feedback = req.body.general_feedback;
else {
question.category = req.body.category;
question.name = req.body.name;
question.question_text = req.body.question_text;
question.question_answer = req.body.question_answer;
question.defult_mark = req.body.defult_mark;
question.q_type = req.body.q_type;
question.time_modifiedby = req.body.time_modifiedby;
question.general_feedback = req.body.general_feedback;
}
question.save().then(question =>{
res.json('Item update!');
})
res.json('Item update!');
})
.catch(err =>{
res.status(400).send("Update not possible");
});
});
});
questionRouter.route('/delete/:id').delete((req, res) => {
Question.findByIdAndDelete(req.params.id)
.then(() => res.json('Product Deleted.'))
......
......@@ -5437,6 +5437,11 @@
"es6-symbol": "^3.1.1"
}
},
"es6-object-assign": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz",
"integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw="
},
"es6-symbol": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz",
......@@ -12126,6 +12131,11 @@
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
"integrity": "sha1-mEcocL8igTL8vdhoEputEsPAKeM="
},
"promise-polyfill": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz",
"integrity": "sha1-36lpQ+qcEh/KTem1hoyznTRy4Fc="
},
"prompts": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz",
......@@ -14334,6 +14344,15 @@
"util.promisify": "~1.0.0"
}
},
"sweetalert": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/sweetalert/-/sweetalert-2.1.2.tgz",
"integrity": "sha512-iWx7X4anRBNDa/a+AdTmvAzQtkN1+s4j/JJRWlHpYE8Qimkohs8/XnFcWeYHH2lMA8LRCa5tj2d244If3S/hzA==",
"requires": {
"es6-object-assign": "^1.1.0",
"promise-polyfill": "^6.0.2"
}
},
"symbol-tree": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz",
......
......@@ -13,6 +13,7 @@
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"react-star-rating-component": "^1.4.1",
"sweetalert": "^2.1.2",
"web-vitals": "^1.1.1"
},
"scripts": {
......
......@@ -9,6 +9,10 @@ import ItemNav from "./Components/Navbar";
import Home from "./Components/Home";
import SignUp from "./Components/SignUp";
import Dashboard from "./Components/Admin/Dashboard";
import QuestionDetails from "./Components/IT18050240/question_details"
import QuestionLayout from "./Components/IT18050240/question_layout"
import AdminQuestionManagement from "./Components/IT18050240/admin_question_management.js"
import QuestionBank from "./Components/IT18050240/question_bank"
function App() {
return (
......@@ -22,6 +26,11 @@ function App() {
{/*<Route path="/" exact component={Dashboard}/>*/}
<Switch>
<Route path="/admin"><Dashboard/></Route>
<Route path="/questiondetails" exact component={QuestionDetails}/>
<Route path="/question" exact component={QuestionLayout}/>
<Route path="/questionmanagement" exact component={AdminQuestionManagement}/>
<Route path="/questionbank" exact component={QuestionBank}/>
<Route path="/edititem/:id" exact component={AdminQuestionManagement}/>
</Switch>
</div>
</Router>
......
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.quantity.item_id}</td>*/}
<td>{props.quantity.question_text}</td>
<td>{props.quantity.question_answer}</td>
<td>{props.quantity.time_modifiedby}</td>
<td>
<div>
<Link className="mx-1 text-success fas fa-pen text-decoration-none" to={"/edititem/"+props.quantity._id}></Link> <span className=" mx-1 text-danger fas fa-trash" href='#' onClick={()=>{props.deleteProduct(props.quantity._id)}} ></span>
</div>
</td>
</tr>
);
export default class QuestionBankUI extends Component {
constructor(props) {
super(props);
this.onChangeQType = this.onChangeQType.bind(this);
this.deleteProduct = this.deleteProduct.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.state = {
q_type: '',
quantity: []
}
}
quantityList() {
return this.state.quantity.map(currentTodo => {
return <Quantity quantity={currentTodo} deleteProduct={this.deleteProduct} key={currentTodo._id} />
});
}
componentDidUpdate() {
axios.get('http://localhost:5000/questions/')
.then(response => {
this.setState({ quantity: response.data });
})
.catch(function (error) {
console.log(error);
})
}
componentDidMount() {
axios.get('http://localhost:5000/questions/')
.then(response => {
this.setState({ quantity: response.data });
})
.catch(function (error) {
console.log(error);
})
}
onChangeQType(e) {
this.setState({
q_type: e.target.value
});
}
onSubmit(e) {
e.preventDefault();
console.log(`Question type: ${this.state.q_type}`);
if (this.state.q_type == "Multiple_choice") {
window.location = '/questionmanagement/';
} else {
}
//window.location = '/admin/pcategory';
}
deleteProduct(pid){
axios.delete('http://localhost:5000/questions/delete/'+pid)
.then(res => console.log(res.data));
this.setState({
quantity:this.state.quantity.filter(el => el.pid !==pid)
});
}
render() {
return (
<div className="container text-left">
<div className="col-sm-10" >
<h4> Business Studies</h4>
<h6>Dashboard/My courses/Business Studies/Question bank/Questions</h6>
<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>
</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>
</div>
</div></div>
</form>
<br/>
<div className="col-sm-10">
<table className="table" >
<thead>
<tr>
<th><h6>Question Text</h6></th>
<th><h6>Question Answer</h6></th>
<th><h6>Last modified by</h6></th>
<th className="col-sm-1"><h6>Action </h6></th>
</tr>
</thead>
<tbody>
{this.quantityList()}
</tbody>
</table>
</div>
</div>
)
}
}
\ No newline at end of file
import React, { Component } from 'react';
import axios from 'axios';
//import swal from 'sweetalert';
import { Link } from "react-router-dom";
export default class AddEditItem extends Component {
render() {
return (
<div className="container">
<div class="border">
<div style={{margin: "15px"}}>
<h5 className="text-left"> 1st Term Examination </h5>
<p className="text-center"> Attempts allowed : 1 </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>
<h5 className="text-left"> Summary of your pervious attempts </h5>
<table class="table table-striped">
<thead>
<tr>
<th>Attempt</th>
<th>State</th>
<th>Review</th>
</tr>
</thead>
<tbody>
<tr>
<td>Preview</td>
<td>In progress</td>
<td></td>
</tr>
</tbody>
</table>
<p className="text-center"> This quiz is not currently available</p>
<button className="text-center" type="button" class="btn btn-secondary btn-sm">Back to the course</button>
</div>
</div></div>
)
}
}
\ No newline at end of file
import React, { Component } from 'react';
import axios from 'axios';
//import swal from 'sweetalert';
import { Link } from "react-router-dom";
export default class QuestionLayout extends Component {
constructor(props) {
super(props);
this.onChangeCategory = this.onChangeCategory.bind(this);
this.onChangeName = this.onChangeName.bind(this);
this.onChangeQuestionText = this.onChangeQuestionText.bind(this);
this.onChangeDefultMark = this.onChangeDefultMark.bind(this);
this.onChangeQType = this.onChangeQType.bind(this);
this.onChangeGeneralFeedback = this.onChangeGeneralFeedback.bind(this);
this.onChangeNext = this.onChangeNext.bind(this);
this.state = {
question_id : '',
category : '',
name : '',
question_text : '',
defult_mark : '',
q_type : '',
general_feedback : '',
categoryArray: [],
nextvalue: 0,
}
}
onChangeCategory(e){
this.setState({
category :e.target.value
});
}
onChangeName(e){
this.setState({
name :e.target.value
});
}
onChangeQuestionText(e){
this.setState({
question_text :e.target.value
});
}
onChangeDefultMark(e){
this.setState({
defult_mark :e.target.value
});
}
onChangeQType(e){
this.setState({
q_type :e.target.value
});
}
onChangeGeneralFeedback(e){
this.setState({
general_feedback :e.target.value
});
}
onChangeNext(e){
if(this.state.nextvalue<this.state.categoryArray.length-1){
this.setState({
nextvalue : this.state.nextvalue+1
});
}else
console.log("press");
}
componentDidMount() {
// axios.get('http://localhost:5000/questions/60d9c51296f586320087e10f')
// .then(response =>{
// this.setState({
// category : response.data.category,
// name : response.data.name,
// question_text : response.data.question_text,
// defult_mark : response.data.defult_mark,
// q_type : response.data.q_type,
// time_createdby: response.data.currentTime,
// time_modifiedby: response.data.currentTime,
// general_feedback : response.data.general_feedback
// })
// })
// .catch(function (error) {
// console.log(error)
// })
// if (this.state.item_id != null) {
axios.get('http://localhost:5000/questions/')
.then(response => {
//this.setState({productQuantities: response.data});
let CategoryList = [];
for (let i = 0; i < response.data.length; i++) {
CategoryList.push(response.data[i].question_text);
}
this.setState({
categoryArray: CategoryList,
})
})
.catch(function (error) {
console.log(error);
})
// } else {
// this.setState({categoryArray: []});
// }
}
render() {
return (
<div className="container">
<div class="border border-primary">
<div style={{ margin: "15px" }}>
<div style={{ margin: "5px" }}>
<h6>Question {this.state.nextvalue+1} </h6>
<p>Not yet answered Mark out of 5.00</p>
</div>
<div class="p-3 mb-2 bg-light text-dark">
<div className="text-left" style={{ margin: "10px" }}>
{this.state.categoryArray[this.state.nextvalue]}
<textarea
className="form-control" required
value ={this.state.general_feedback}
onChange={this.onChangeGeneralFeedback}
/>
</div>
</div>
<br/>
<div style={{ display: 'flex', justifyContent: 'flex-end' }}>
<button className="text-center" type="button" onClick = {this.onChangeNext} class="btn btn-secondary btn-sm">Next</button>
</div>
</div>
</div> </div>
)
}
}
\ No newline at end of file
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