Skip to content

Commit

Permalink
#133 : Delete Document Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
compgirl123 authored and PWatine committed Jan 17, 2020
1 parent a4e51f3 commit 0d7517d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
33 changes: 33 additions & 0 deletions tutify/backend/controllers/uploaded_files.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,36 @@ exports.viewCourseDocs = async function (req, res) {
});
});
}

// this method enables each class to view all of their shared documents.
exports.deleteFiles = async function (req, res) {
const {file_id} = req.body;
console.log(file_id);
/**Event.findByIdAndRemove(event_id, (err,event) => {
if (err) return res.send(err);
Tutor.findByIdAndUpdate(tutor_id,
{ "$pull": { "events": event_id } },
function (err, tutor) {
var index = tutor.events.indexOf(event_id);
if (index > -1) {
tutor.events.splice(index, 1);
}
event.students.forEach(function (student) {
Student.findByIdAndUpdate(student,
{ "$pull": { "events": event_id } },
function (err, student) {
if (err) throw err;
});
});
req.session.userInfo.events = tutor.events;
req.session.save(function (err) {
req.session.reload(function (err) {
return res.json({ success: true, userInfo: tutor });
});
});
});
}); */
}
4 changes: 4 additions & 0 deletions tutify/backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ router.get('/ViewTutorCourse/:coursename', uploadedFilesController.viewCourseDoc

router.get('/ViewCourse/:coursename', uploadedFilesController.viewCourseDocs);

// -------- DELETE ROUTES --------- //

router.post('/getFileToDelete', uploadedFilesController.deleteFiles);

module.exports = router;
23 changes: 20 additions & 3 deletions tutify/src/components/TutorProfile/DocList.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class DocList extends React.Component {
})
}

deleteListItem = () => {
/*deleteListItem = () => {
swal({
title: "Are you sure you want delete this document?",
icon: "warning",
Expand All @@ -158,7 +158,7 @@ class DocList extends React.Component {
.catch(err => console.log(err));
}
});
};
};*/

updateTutorOptions = () => {
var updatedProfileValues = [
Expand Down Expand Up @@ -225,7 +225,24 @@ class DocList extends React.Component {
this.getStudents();
})
.catch(err => console.log(err));
}

// tutor deletes a documents from files list
getSelectedFiletoDelete (event,encrypted_file_name) {
swal({
title: "Are you sure you want delete this document?",
icon: "warning",
buttons: [true, "Yes"],
dangerMode: true,
})
.then((willDelete) => {
console.log(willDelete);
axios.post('/api/getFileToDelete', {
file_id: encrypted_file_name
}).then((res) => {
})
.catch(err => console.log(err));
});
}

render() {
Expand Down Expand Up @@ -276,7 +293,7 @@ class DocList extends React.Component {
<td align="center"><Button type="button" variant="contained" className="submit" size="small" onClick={() => window.open("http://localhost:3000/tutorCourses/" + encrypted_file_name)} id={file._id}><MenuBookIcon /></Button></td>
<td align="center"><Button type="button" variant="contained" className="submit" size="small" onClick={() => window.open("http://localhost:3000/students/" + encrypted_file_name)} id={file._id}><GroupAddIcon /></Button></td>
<td align="center"><Button type="button" variant="contained" className="submit" size="small" onClick={() => window.open(link, "_blank")} id={file._id}><GetAppIcon /></Button></td>
<td align="center"><Button type="button" variant="contained" className="submit" size="small" onClick={e => this.deleteListItem()} ><DeleteIcon /></Button></td>
<td align="center"><Button type="button" variant="contained" className="submit" size="small" onClick={e => this.getSelectedFiletoDelete(e,encrypted_file_name)} ><DeleteIcon /></Button></td>
</TableRow>
)
})}
Expand Down

0 comments on commit 0d7517d

Please sign in to comment.