diff --git a/ballot/api/comments.py b/ballot/api/comments.py new file mode 100644 index 0000000..6e4e475 --- /dev/null +++ b/ballot/api/comments.py @@ -0,0 +1,74 @@ +import frappe +from .user import get_user_details + + +@frappe.whitelist(allow_guest=True) +def get_all_comments(doctype: str, docname: str) -> list: + """ + Get all the comments of a doctype's document. + + args: + doctype: doctype name/id + docname: id of document whose comment's are needed + + returns: + list: list of all comments + """ + if ( + frappe.db.count( + "Comment", + {"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, + ) + == 0 + ): + return [] + + comments = frappe.db.get_all( + "Comment", + {"reference_doctype": doctype, "reference_name": docname, "comment_type": "Comment"}, + [ + "comment_email", + "subject", + "content", + "comment_by", + "name", + "reference_doctype", + "reference_name", + "creation", + ], + page_length=9999, + ) + + for comment in comments: + user = get_user_details(comment.comment_email) + comment["full_name"] = user.full_name + comment["user_image"] = user.user_image + comment["replies"] = get_all_comments("Comment", comment.name) + + return comments + + +@frappe.whitelist() +def add_comment(reference_doctype: str, reference_name: str, content: str) -> None: + """ + Add a comment to permitted doctypes + + args: + reference_doctype: doctype to add comment to + reference_name: name of the document + content: content of the comment + """ + + if reference_doctype not in ["Election Candidate Application", "Comment"]: + frappe.throw("Not allowed to add comment to this doctype", frappe.PermissionError) + + comment = frappe.get_doc( + { + "doctype": "Comment", + "comment_type": "Comment", + "reference_doctype": reference_doctype, + "reference_name": reference_name, + "content": content, + } + ) + comment.insert(ignore_permissions=True) diff --git a/frontend/src/components/comments/CommentBox.vue b/frontend/src/components/comments/CommentBox.vue new file mode 100644 index 0000000..fc95862 --- /dev/null +++ b/frontend/src/components/comments/CommentBox.vue @@ -0,0 +1,88 @@ + + + Login to comment + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/src/components/comments/CommentSection.vue b/frontend/src/components/comments/CommentSection.vue new file mode 100644 index 0000000..c440af6 --- /dev/null +++ b/frontend/src/components/comments/CommentSection.vue @@ -0,0 +1,40 @@ + + + + Comments + + + Comments will be public and non-anonymous. + + + + + + diff --git a/frontend/src/components/comments/CommentsList.vue b/frontend/src/components/comments/CommentsList.vue new file mode 100644 index 0000000..8953069 --- /dev/null +++ b/frontend/src/components/comments/CommentsList.vue @@ -0,0 +1,41 @@ + + + + + + diff --git a/frontend/src/components/comments/RenderComment.vue b/frontend/src/components/comments/RenderComment.vue new file mode 100644 index 0000000..93ff5a2 --- /dev/null +++ b/frontend/src/components/comments/RenderComment.vue @@ -0,0 +1,62 @@ + + + + + + {{ comment.full_name }} + + {{ getRelativeTime(comment.creation) }} + + + + + + + + + + + + + + + + + + diff --git a/frontend/src/pages/Home.vue b/frontend/src/pages/Home.vue index 695e4ab..fd758d3 100644 --- a/frontend/src/pages/Home.vue +++ b/frontend/src/pages/Home.vue @@ -16,6 +16,10 @@ const sidebarItems = [ label: 'Dashboard', route: '/dashboard', }, + { + label: 'My Submissions', + route: '/my-submissions', + }, { label: 'All Elections', route: '/elections', diff --git a/frontend/src/pages/election/CandidatureSubmissionPublic.vue b/frontend/src/pages/election/CandidatureSubmissionPublic.vue index b5f7f41..3779e82 100644 --- a/frontend/src/pages/election/CandidatureSubmissionPublic.vue +++ b/frontend/src/pages/election/CandidatureSubmissionPublic.vue @@ -34,6 +34,10 @@ :field="field" /> + @@ -44,6 +48,7 @@ import Breadcrumb from '@/components/Breadcrumb.vue' import Avatar from 'primevue/avatar' import Header from '@/components/Header.vue' import RenderFieldData from '@/components/candidature/RenderFieldData.vue' +import CommentSection from '@/components/comments/CommentSection.vue' import { createResource, LoadingText } from 'frappe-ui' import { ref } from 'vue' import { useRoute } from 'vue-router' diff --git a/frontend/src/pages/submissions/MySubmissions.vue b/frontend/src/pages/submissions/MySubmissions.vue index 0aff2fd..a0d0e4a 100644 --- a/frontend/src/pages/submissions/MySubmissions.vue +++ b/frontend/src/pages/submissions/MySubmissions.vue @@ -1,4 +1,8 @@ - + + + My Submissions + +
+ Comments will be public and non-anonymous. +