Skip to content

Commit

Permalink
refactor: Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilesh2000 committed Jan 1, 2021
1 parent b78bc41 commit bd9a889
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 55 deletions.
2 changes: 0 additions & 2 deletions models/Contact.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO : Add field for department preference
// TODO : Add field for number of HR's
const fs = require('fs');
const mongoose = require('mongoose');

Expand Down
1 change: 0 additions & 1 deletion models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const mongoose = require('mongoose');
const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const { format } = require('date-fns');
const { userInfo } = require('os');

const UserSchema = mongoose.Schema({
name: {
Expand Down
72 changes: 38 additions & 34 deletions public/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,31 @@ searchBox.addEventListener('keyup', function () {
}
});

// Colors for members, incharges and statuses
const contactIncharge = document.getElementsByClassName('contactIncharge');
// Colors for ED Incharges and Statuses
const contactStatus = document.getElementsByClassName('contactStatus');
const statusColors = {
'Emailed/Confirmed': '#00A878',
'Called/Accepted': '#00A878',
'Called/Declined': '#D62839',
'Emailed/Declined': '#D62839',
'Not Called': '#011627',
'Wrong Number': '#4B3832',
'Called/Not Reachable': '#F26419',
'Called/Postponed': '#7A3B69',
'Emailed/Awaiting Response': '#FDCA40',
};

for (let i = 0; i < contactStatus.length; i++) {
if (['Emailed/Confirmed', 'Called/Accepted'].includes(contactStatus[i].innerText)) {
contactStatus[i].style.backgroundColor = '#00A878';
} else if (['Called/Declined', 'Emailed/Declined'].includes(contactStatus[i].innerText)) {
contactStatus[i].style.backgroundColor = '#D62839';
} else if (contactStatus[i].innerText == 'Not Called') {
contactStatus[i].style.backgroundColor = '#011627';
} else if (contactStatus[i].innerText == 'Wrong Number') {
contactStatus[i].style.backgroundColor = '#4B3832';
} else if (contactStatus[i].innerText == 'Called/Not Reachable') {
contactStatus[i].style.backgroundColor = '#F26419';
} else if (contactStatus[i].innerText == 'Called/Postponed') {
contactStatus[i].style.backgroundColor = '#7A3B69';
} else if (contactStatus[i].innerText == 'Emailed/Awaiting Response') {
contactStatus[i].style.backgroundColor = '#FDCA40';
}
const status = contactStatus[i].innerText;
contactStatus[i].style.backgroundColor = statusColors[status];
}

const contactIncharge = document.getElementsByClassName('contactIncharge');
const edColors = { Adhihariharan: '#2191FB', Anuja: '#994636', Dhivya: '#005b96', Govind: '#FFAD05', Joann: '#CE6D8B' };

for (let i = 0; i < contactIncharge.length; i++) {
if (contactIncharge[i].innerText.includes('Adhihariharan')) {
contactIncharge[i].style.backgroundColor = '#2191FB';
} else if (contactIncharge[i].innerText.includes('Anuja')) {
contactIncharge[i].style.backgroundColor = '#994636';
} else if (contactIncharge[i].innerText.includes('Dhivya')) {
contactIncharge[i].style.backgroundColor = '#005b96';
} else if (contactIncharge[i].innerText.includes('Govind')) {
contactIncharge[i].style.backgroundColor = '#FFAD05';
} else if (contactIncharge[i].innerText.includes('Joann')) {
contactIncharge[i].style.backgroundColor = '#CE6D8B';
} else {
contactIncharge[i].style.backgroundColor = '#35C4C8';
}
const edName = contactIncharge[i].innerText.split(' /')[0];
contactIncharge[i].style.backgroundColor = edColors[edName] ?? '#35C4C8';
}

// Change chevron direction
Expand All @@ -63,6 +52,22 @@ for (let i = 0; i < chevron.length; i++) {
});
}

// Hide address input and label if contact choose ownTransport
const ownTransport = document.querySelectorAll("input[name='ownTransport']");
const address = document.querySelectorAll("textarea[name='address']");

for (let i = 0; i < ownTransport.length; i++) {
ownTransport[i].addEventListener('change', function () {
if (ownTransport[i].checked) {
address[i].classList.add('d-none');
address[i].previousElementSibling.classList.add('d-none');
} else {
address[i].classList.remove('d-none');
address[i].previousElementSibling.classList.remove('d-none');
}
});
}

// Populate edit modal with data
const editBtns = document.getElementsByClassName('edit-contact');

Expand All @@ -88,18 +93,17 @@ for (let i = 0; i < editBtns.length; i++) {
}
}

const ownTransport = editForm['ownTransport'];
const isOwnTransport = this.getAttribute('data-ownTransport');

// Hide address field if the contact choose ownTransport
// Hide address field if the contact chooses ownTransport
if (isOwnTransport == 'true') {
ownTransport.checked = true;
editForm['ownTransport'].checked = true;
// Hide address input
editForm['address'].classList.add('d-none');
// Hide address label
editForm['address'].previousElementSibling.classList.add('d-none');
} else {
ownTransport.checked = false;
editForm['ownTransport'].checked = false;
editForm['address'].value = this.getAttribute('data-address') ?? '';
// Show address input
editForm['address'].classList.remove('d-none');
Expand Down
1 change: 1 addition & 0 deletions views/error.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<p><%= err.stack %></p>
<% } %>
</div>
<button class="btn btn-primary" type="button" onclick="window.history.back()">Go Back</button>
</div>
</div>
18 changes: 0 additions & 18 deletions views/layouts/boilerplate.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,5 @@

<!-- Custom JS -->
<script src="/js/script.js"></script>

<!-- JavaScript to accept address input only if contact is not using own transport -->
<script>
const ownTransport = document.querySelectorAll("input[name='ownTransport']");
const address = document.querySelectorAll("textarea[name='address']");
for (let i = 0; i < ownTransport.length; i++) {
ownTransport[i].addEventListener('change', function () {
if (ownTransport[i].checked) {
address[i].classList.add('d-none');
address[i].previousElementSibling.classList.add('d-none');
} else {
address[i].classList.remove('d-none');
address[i].previousElementSibling.classList.remove('d-none');
}
});
}
</script>
</body>
</html>

0 comments on commit bd9a889

Please sign in to comment.