Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging Gov portal submissions #265

Draft
wants to merge 11 commits into
base: dev
Choose a base branch
from
12 changes: 11 additions & 1 deletion database/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ async function getNewsletterCount () {
return newsletterCounts;
}

async function getSubmissions () {
return await Submission.find().lean();
}

async function deleteSubmission (link) {
const sub = await Submission.findOneAndDelete({ link: link });
return sub;
}

module.exports = {
createNewUser,
Expand Down Expand Up @@ -396,5 +404,7 @@ module.exports = {
addTeam,
addSubmission,
updateNewsletterCount,
getNewsletterCount
getNewsletterCount,
getSubmissions,
deleteSubmission
};
16 changes: 16 additions & 0 deletions routes/govportal.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ router.patch('/delete-option', async (req, res) => {
}
});

router.get('/submission-management', async (req, res) => {
const submissions = await dbh.getSubmissions();
return res.renderFile('govportal/submissions-management.njk', { submissions });
});

router.post('/submission-management', async (req, res) => {
const data = req.body.data;
let response;
try {
response = await dbh.deleteSubmission(data);
return res.send({ success: true, message: 'Successfully deleted post', response: response });
} catch (e) {
return res.send({ success: false, message: 'Something Went Wrong' });
}
});

module.exports = {
route: '/gov-portal',
router
Expand Down
4 changes: 4 additions & 0 deletions templates/govportal/govportal.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},{
href: 'newsletter',
name: 'Newsletter'
},{
href: 'submission',
name: 'Submission'
}] %}

{% block navbar %}
Expand Down Expand Up @@ -68,6 +71,7 @@
<a href="/gov-portal/add-poll" class="add-item"> Add Poll </a>
<a href="/gov-portal/add-post" class="add-item"> Add Post </a>
<a href="/gov-portal/newsletter-management" class="add-item"> View Newsletter Count </a>
<a href="/gov-portal/submission-management" class="add-item"> View Submissions </a>
</div>
{% endblock %}
</div>
Expand Down
198 changes: 198 additions & 0 deletions templates/govportal/submissions-management.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{% extends "govportal/govportal.njk" %}

{% set thispage = 'Submission' %}
{% set pagetitle = 'Governor Portal | Submission Management' %}
{% set actionname = 'Submission Management' %}

{% set scripts = ['https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js'] %}

{% block actioncontent %}
<div class="message hidden"></div>
{% for submission in submissions %}
<div class="container">
<div class="card1">
{% for key, value in submission %}
{% if key != '_id' and key != '__v' and key != 'metadata' %}
<b> {{ key | capitalize }}: </b> {% if key != 'date' %} {{ value }} {% else %} {{ value | string | truncate(15, true, "") }} {% endif %}<br>
{% endif %}
{% endfor %}
</div>

<div class="card2">
<button class="deleteP" onclick="deleteSubmission('{{submission.link}}')">Delete</button>
</div>
</div>
{% endfor %}

{% endblock %}

{% block customcss %}
{{ super() }}
<style>
#add-item {
display: block;
width: fit-content;
margin: 20px auto;
border: 3px solid var(--off-white);
border-radius: 5px;
padding: 10px;
background-color: var(--dark-gray);
transition: color 0.3s, border-color 0.3s, background-color 0.3s;
}
#add-item:hover {
color: var(--error-red);
border-color: var(--white);
background-color: var(--darker-gray);
}
.container {
margin: 3rem auto;
display:flex;
flex-direction:row;
border: 2px solid rgba(255,255,255,0.1);
border-radius: 8px;
padding: 20px 5px;
width: 80%;
background-color: rgba(255,255,255,0.13);
backdrop-filter: blur(5px);
align-self:center;
}
.card1{
flex:80%;
width:40%;
padding-left:5px;
word-wrap: break-word;
text-align: left;
}
.card2{
flex:20%;
display:flex;
flex-direction:column;
justify-content: center;
align-items: center;
}
table{
word-wrap: break-word;
}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
word-wrap: break-word;
overflow-wrap: anywhere;
}
th{
width:30%;
}
.deleteP {
border-radius: 4px;
color:white;
cursor: pointer;
border: 0px;
padding: 2% 3%;
margin: 10px 20px;
}
button{
background-color: var(--red);
width: 7em;
height: 2.5em;
}
.message {
position: absolute;
top: 0;
right: calc(50vw - 220px);
padding: 20px;
z-index: 1;
color: #fff;
font-weight: 600;
font-size: 18px;
width: 400px;
transform-origin: top;
transition: transform 0.3s ease;
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
}
.error {
background-color: rgba(255, 51, 51, 0.85);
}
.success {
background-color: rgba(75, 189, 67, 0.85);
}
.hidden {
transform: scaleY(0);
}

@media (max-width: 600px) {
button{
width:4rem;
}
.container{
margin-left:3rem;
}
}

@media (max-width: 500px) {
.container {
flex-direction:column;
}
.card1{
width:95%;
}
.card2{
flex-direction:row;
}
button{
margin-right:5rem;
}
.editP{
margin:1rem 3rem;
}
.deleteP{
margin:1rem 2rem;
}
.container{
margin-left:2rem;
}
}
@media (max-width:300px){
.editP{
margin-right:1rem;
margin-left:2rem;
}
.deleteP{
margin-left:1rem;
}
.container{
margin-left:1.5rem;
}
}

</style>
{% endblock %}

{% block customjs %}
<script>
axios.defaults.withCredentials = true;
axios.defaults.headers.common['X-CSRF-TOKEN'] = '{{ csrfToken }}';

async function postSubmission (data) {
var res = (await axios.post('/gov-portal/submission-management', { data: data })).data;
const e = document.getElementsByClassName('message')[0];
e.innerHTML = res.message;
e.classList.add(res.success ? 'success' : 'error');
e.classList.remove('hidden');
setTimeout(function () {e.classList.add('hidden')}, 2000);
if (res.success) {
setTimeout(function () { location.reload() }, 3000);
}
}
function deleteSubmission (link) {
console.log(link);
if (confirm("Are you sure you want to delete the submission?")) {
postSubmission(link);
}
}
</script>
{% endblock %}
Loading