From bd9a889b62fdfa5206117b2b1b36b00d41bbbeb7 Mon Sep 17 00:00:00 2001 From: Nilesh D Date: Fri, 1 Jan 2021 19:31:33 +0530 Subject: [PATCH] refactor: Code improvements --- models/Contact.js | 2 - models/User.js | 1 - public/js/script.js | 72 ++++++++++++++++++----------------- views/error.ejs | 1 + views/layouts/boilerplate.ejs | 18 --------- 5 files changed, 39 insertions(+), 55 deletions(-) diff --git a/models/Contact.js b/models/Contact.js index d44546c..0eb0434 100644 --- a/models/Contact.js +++ b/models/Contact.js @@ -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'); diff --git a/models/User.js b/models/User.js index d570fd0..84a566c 100644 --- a/models/User.js +++ b/models/User.js @@ -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: { diff --git a/public/js/script.js b/public/js/script.js index df302be..343cc18 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -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 @@ -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'); @@ -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'); diff --git a/views/error.ejs b/views/error.ejs index 3d3e495..8a73b22 100644 --- a/views/error.ejs +++ b/views/error.ejs @@ -8,5 +8,6 @@

<%= err.stack %>

<% } %> + diff --git a/views/layouts/boilerplate.ejs b/views/layouts/boilerplate.ejs index 0d64111..ad2a342 100644 --- a/views/layouts/boilerplate.ejs +++ b/views/layouts/boilerplate.ejs @@ -68,23 +68,5 @@ - - -