Skip to content

Commit aee7034

Browse files
updated task
1 parent 7cd5340 commit aee7034

5 files changed

Lines changed: 345 additions & 177 deletions

File tree

Backend/Controllers/Teacher/controller.teacherTask.js

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
const formidable = require("formidable");
22
const _ = require("lodash");
33
const fs = require("fs");
4+
const {next} = require("lodash");
45
const teacherTask = require('../../Modules/Class/module.class');
56

6-
7-
8-
97
const createteacherTask = async (req, res) => {
108
if(req.body) {
119
const teacher = new teacherTask(req.body);
@@ -19,49 +17,47 @@ const createteacherTask = async (req, res) => {
1917
}
2018
}
2119
const getAllteacherTask = async (req, res) => {
22-
await teacherTask.find({})
23-
.then(data=>{
24-
res.status(200).send({data: data});
25-
})
26-
.catch(error =>{
27-
res.status(500).send({error: error.message});
20+
let order = req.query.order ? req.query.order : 'asc'
21+
let sortBy = req.query.sortBy ? req.query.sortBy : '_id'
22+
23+
teacherTask.find()
24+
.sort([[sortBy, order]])
25+
.exec((err, teacherTask) => {
26+
if(err) {
27+
return res.status(400).json ({
28+
error: 'No task Found'
29+
});
30+
}
31+
res.json(teacherTask);
2832
});
2933
}
3034

3135
const viewteacherTaskById = async (req, res) => {
32-
if (req.params && req.params.id) {
33-
await teacherTask.findById(req.params.id)
34-
.populate('classess', '_id tasktitle taskdescription teacherid implevel validtill')
35-
.then(response => {
36-
res.status(200).send({ data: response });
37-
})
38-
.catch(error => {
39-
res.status(500).send({ error: error.message });
40-
});
41-
}
36+
teacherTask.findById(req.params.id, (error, data) =>{
37+
if (error) {
38+
return next(error)
39+
} else {
40+
res.json(data)
41+
}
42+
})
4243
}
4344

4445

4546
const updateById = async (req, res) => {
46-
const id = req.params.id;
47-
const status = req.body;
48-
const updateTask = {
49-
status
50-
}
51-
const update = await teacherTask.findByIdAndUpdate(id, updateTask.status)
52-
.then(() => {
53-
res.status(200).send({status: "teacher task Updated"})
54-
}).catch((err) => {
55-
console.log(err);
56-
res.status(500).send({status: " Error", error:err.message});
47+
const { slug } = req.params
48+
const {tasktitle,taskdescription,teacherid,implevel,validtill,status} = req.body
49+
teacherTask.findOneAndUpdate({slug}, {tasktitle,taskdescription,teacherid,implevel,validtill,status}, {new: true})
50+
.exec((err,topic) => {
51+
if(err) console.log(err)
52+
res.json(topic);
5753
})
5854
}
5955

6056
const deleteById = async (req, res) => {
61-
const id = req.params.id
57+
const id = req.params.id
6258
await teacherTask.findByIdAndRemove(id).exec()
63-
res.send('Couldnt delete');
64-
}
59+
res.send("Deleted successfully");
60+
};
6561

6662

6763

frontend/src/Class/teacher.js

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,75 @@ import '../Student/Payments/style/button.css';
33
import my from "../Student/Payments/image/paymentForm.png";
44
import '../Student/Payments/style/forms.css'
55
import '../Student/Payments/style/alert.css'
6-
6+
import axios from "axios";
77

88
const TaskTeacher = () => {
9-
const [values, setValues] = useState({
9+
const [state, setState] = useState({
1010
tasktitle: '',
1111
taskdescription: '',
1212
teacherid: '',
13-
implevel: 0,
13+
implevel: '',
1414
validtill: '',
15-
status: 'not done',
1615
loading: false,
1716
error: '',
18-
formData: ''
1917
});
2018

2119
const {
2220
tasktitle,
2321
taskdescription,
2422
teacherid,
2523
implevel,
26-
loading,
2724
validtill,
28-
formData
29-
} = values;
25+
loading
26+
} = state;
3027

31-
useEffect(() => {
32-
setValues({...values, formData: new FormData()})
33-
}, [])
28+
const [content, setContent] = useState('')
3429

35-
const handleChange = name => event => {
36-
const value = name === 'TeacherTask' ? event.target.files[0] : event.target.value
37-
formData.set(name,value)
38-
setValues({...values, [name]: value})
39-
};
30+
const handleContent = (event) => {
31+
console.log(event);
32+
setContent(event);
33+
}
4034

41-
const createTeacherTask = (data) => {
42-
return fetch(`http://localhost:8081/teacher-task/create`, {
43-
method: "POST",
44-
headers: {
45-
Accept: "application/json"
46-
},
47-
body: data
48-
})
49-
.then(response => {
50-
return response.json();
51-
})
52-
.catch(err => {
53-
console.log(err);
54-
});
35+
const handleChange = (name) => (event) => {
36+
setState({...state, [name]:event.target.value})
5537
};
5638

57-
const clickSubmit = (event) => {
58-
event.preventDefault();
59-
setValues({...values, error: "", loading: true})
60-
createTeacherTask(formData)
61-
.then(data => {
62-
if (data.error) {
63-
setValues({...values, error: data.error})
64-
} else {
65-
window.location.href = "/teacherTaskList/";
39+
const clickSubmit = payment => {
40+
payment.preventDefault();
41+
axios
42+
.post(`http://localhost:8081/teacher-task/createTeacherTask`, {tasktitle, taskdescription, teacherid, implevel,validtill}, {
43+
headers: {
6644
}
45+
})
46+
.then(response => {
47+
//empty the state
48+
setState({...state, tasktitle: '',taskdescription:'', teacherid: '', implevel: '', validtill:'',loading: true, error: ''})
49+
setContent('');
50+
window.location.href = "/teacherTaskList/";
51+
})
52+
.catch(error => {
53+
console.log(error.response);
54+
alert(error.response.data.error);
6755
});
6856
};
6957

7058
const showLoading = () =>
71-
loading && (<div aria-live="polite" aria-atomic="true" className="position-relative">
72-
<div className="toast-container position-absolute top-0 end-0 p-3">
73-
<div className="toast" role="alert" aria-live="assertive" aria-atomic="true">
74-
<div className="toast-header">
75-
<div className="spinner-border text-warning" role="status">
76-
<span className="visually-hidden">Loading...</span>
59+
loading && (<div aria-live="polite" aria-atomic="true" className="position-relative">
60+
<div className="toast-container position-absolute top-0 end-0 p-3">
61+
<div className="toast" role="alert" aria-live="assertive" aria-atomic="true">
62+
<div className="toast-header">
63+
<div className="spinner-border text-warning" role="status">
64+
<span className="visually-hidden">Loading...</span>
65+
</div>
66+
<strong className="me-auto">&nbsp;&nbsp;Loading</strong>
67+
<small className="text-muted">just now</small>
68+
<button type="button" className="btn-close" data-bs-dismiss="toast"
69+
aria-label="Close"></button>
7770
</div>
78-
<strong className="me-auto">&nbsp;&nbsp;Loading</strong>
79-
<small className="text-muted">just now</small>
80-
<button type="button" className="btn-close" data-bs-dismiss="toast"
81-
aria-label="Close"></button>
8271
</div>
8372
</div>
8473
</div>
85-
</div>);
74+
);
8675

8776
return (
8877
<div className="background">
@@ -172,7 +161,7 @@ const TaskTeacher = () => {
172161
/>
173162
</div>
174163
</div>
175-
<button className="button-purple button2-purple">Submit Payment</button>
164+
<button className="button-purple button2-purple">Submit Task</button>
176165
</form>
177166
</div>
178167
</div>

frontend/src/Class/teacherTask.js

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import '../Student/Payments/style/loading.css';
77
import '../Accountant/style/viewStudentPayment.css';
88

99
const TeacherTaskList = () => {
10-
const [tasklist, settasklist] = useState([]);
10+
const [taskList, setTaskList] = useState([]);
1111
const [setError] = useState([]);
1212
const [q, setQ] = useState("");
13-
const [searchParam] = useState(["date", "name", "type"]);
13+
const [searchParam] = useState(["tasktitle", "implevel", "teacherid"]);
1414
const [filterParam] = useState(["All"]);
1515
const [values, setValues] = useState({
1616
loading: false,
@@ -20,7 +20,7 @@ const TeacherTaskList = () => {
2020
} = values;
2121

2222
const search = () => {
23-
return tasklist.filter((item) => {
23+
return taskList.filter((item) => {
2424
if (item.region === filterParam) {
2525
return searchParam.some((newItem) => {
2626
return (
@@ -43,6 +43,45 @@ const TeacherTaskList = () => {
4343
});
4444
}
4545

46+
const getTasks = () => {
47+
setValues({...values,loading: true})
48+
return fetch(`http://localhost:8081/teacher-task/TeacherTask`, {
49+
method: "GET"
50+
})
51+
.then(response => {
52+
return response.json();
53+
})
54+
.catch(err => console.log(err));
55+
};
56+
57+
const loadTask = () => {
58+
getTasks()
59+
.then(data => {
60+
if(data.error) {
61+
setError(data.error)
62+
} else {
63+
setValues({...values,loading: false})
64+
console.log(data[0].date)
65+
setTaskList(data)
66+
}
67+
})
68+
};
69+
70+
const deleteTask = (e, id) => {
71+
const r = window.confirm("Do you really want to delete this task ?");
72+
if(r == true) {
73+
axios.delete(`http://localhost:8081/teacher-task/TeacherTask/${id}`)
74+
.then(response => {
75+
loadTask()
76+
})
77+
}
78+
79+
};
80+
81+
82+
useEffect(() => {
83+
loadTask()
84+
}, [])
4685

4786
const showLoading = () =>
4887
loading && (<div className="overlay-top">
@@ -68,7 +107,7 @@ const TeacherTaskList = () => {
68107
<div className="row g-2">
69108
<div className="col-md">
70109
<Link to={`/teacherTask/`}>
71-
<button className="button-purple button2-purple">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i className="fas fa-plus-circle">&nbsp;&nbsp;&nbsp;&nbsp;Add New Task</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>
110+
<button className="button-purple button2-purple">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i className="fas fa-plus-circle">&nbsp;&nbsp;&nbsp;&nbsp;Add New Record</i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>
72111
</Link>
73112

74113
</div>
@@ -78,9 +117,9 @@ const TeacherTaskList = () => {
78117
<div className="input-group justify-content-md-end">
79118
<Typed
80119
strings={[
81-
'Search by name',
82-
'Search by type',
83-
'Search by name',]}
120+
'Search by task tile',
121+
'Search by impotent level',
122+
'Search by teacher ID',]}
84123
typeSpeed={40}
85124
backSpeed={50}
86125
attr="placeholder"
@@ -108,12 +147,39 @@ const TeacherTaskList = () => {
108147
<th>Teacher ID</th>
109148
<th>Importance Level</th>
110149
<th>Valid Till</th>
150+
<th>Status</th>
111151
<th>Update</th>
112152
<th>Delete</th>
113153
</tr>
114154
</thead>
115155
<tbody>
116-
156+
{search(taskList).map((c, i) => (
157+
<tr key={i} className="align-top">
158+
<td>{c.tasktitle}</td>
159+
<td>{c.taskdescription}</td>
160+
<td>{c.teacherid}</td>
161+
<td>{c.implevel}</td>
162+
<td>{c.validtill}</td>
163+
{c.status === "done" &&
164+
<td><span className="badge bg-success">{c.status}</span></td>
165+
}
166+
{c.status === "not done" &&
167+
<td><span className="badge bg-warning">{c.status}</span></td>
168+
}
169+
<td>
170+
<Link to={`/teacherTaskUpdate/${c._id}`}>
171+
<button className="btn btn-outline-warning me-md-2">
172+
<i className="fas fa-edit"></i>
173+
</button>
174+
</Link>
175+
</td>
176+
<td>
177+
<button className="btn btn-outline-danger" onClick={e => deleteTask(e, c._id)}>
178+
<i className="fas fa-trash"></i>
179+
</button>
180+
</td>
181+
</tr>
182+
))}
117183
</tbody>
118184
</table>
119185
</div>

0 commit comments

Comments
 (0)