diff --git a/db.sqlite3 b/db.sqlite3 index 77bfa1d..8748547 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/hr_module/__pycache__/urls.cpython-38.pyc b/hr_module/__pycache__/urls.cpython-38.pyc index 9af6a64..424aa27 100644 Binary files a/hr_module/__pycache__/urls.cpython-38.pyc and b/hr_module/__pycache__/urls.cpython-38.pyc differ diff --git a/hr_module/__pycache__/views.cpython-38.pyc b/hr_module/__pycache__/views.cpython-38.pyc index 2ec1e81..3145c3f 100644 Binary files a/hr_module/__pycache__/views.cpython-38.pyc and b/hr_module/__pycache__/views.cpython-38.pyc differ diff --git a/hr_module/handling_functions/__pycache__/misc.cpython-38.pyc b/hr_module/handling_functions/__pycache__/misc.cpython-38.pyc new file mode 100644 index 0000000..3cbdcbf Binary files /dev/null and b/hr_module/handling_functions/__pycache__/misc.cpython-38.pyc differ diff --git a/hr_module/handling_functions/misc.py b/hr_module/handling_functions/misc.py new file mode 100644 index 0000000..58416f6 --- /dev/null +++ b/hr_module/handling_functions/misc.py @@ -0,0 +1,8 @@ + +def dictfetchall(cursor): + "Return all rows from a cursor as a dict" + columns = [col[0] for col in cursor.description] + return [ + dict(zip(columns, row)) + for row in cursor.fetchall() + ] \ No newline at end of file diff --git a/hr_module/static/css/calendar.css b/hr_module/static/css/calendar.css index a52a24f..94c8174 100644 --- a/hr_module/static/css/calendar.css +++ b/hr_module/static/css/calendar.css @@ -1,7 +1,4 @@ -html, body { - font-family: sans-serif; -} div.month_container table, div.month_container th, diff --git a/hr_module/static/css/hr_module_change_employee_data.css b/hr_module/static/css/hr_module_change_employee_data.css new file mode 100644 index 0000000..6d5a939 --- /dev/null +++ b/hr_module/static/css/hr_module_change_employee_data.css @@ -0,0 +1,25 @@ + +#search_results { + margin-top: 20px; +} + +div#search_results label { + text-transform: capitalize; + clear: both; + width: 200px; + margin-right: 10px; +} + +.field_container { + width: 400px; + margin-top: 10px; + display: flex; + height: 30px; + border: thin; + border-bottom: 1px solid lightgray; +} + +.database_field { + text-align: center; +} + diff --git a/hr_module/static/css/hr_module_schedule.css b/hr_module/static/css/hr_module_create_schedule.css similarity index 100% rename from hr_module/static/css/hr_module_schedule.css rename to hr_module/static/css/hr_module_create_schedule.css diff --git a/hr_module/static/css/hr_module_import.css b/hr_module/static/css/hr_module_import.css index 89a94db..292d736 100644 --- a/hr_module/static/css/hr_module_import.css +++ b/hr_module/static/css/hr_module_import.css @@ -25,7 +25,6 @@ table, th, td { } - .form_element, .import_text { height: 30px; } diff --git a/hr_module/static/css/hr_module_show_schedule.css b/hr_module/static/css/hr_module_show_schedule.css index 1024981..780d86d 100644 --- a/hr_module/static/css/hr_module_show_schedule.css +++ b/hr_module/static/css/hr_module_show_schedule.css @@ -1,21 +1,35 @@ -input { - border: solid thin black; -} - input[readonly] { color: black; background-color: lightgray; } -table { +table#detailed_plan_records { width: 100%; + font-size: 15px; + vertical-align:middle; + font-weight: lighter; } -input { - width: 100%; - display: block; +table#detailed_plan_records th { height: 25px; + font-weight: lighter; + padding: 0px; +} + +table#detailed_plan_records td { + text-align: center; + padding: 0px; +} + +tr:nth-child(even) { + background-color: #6DDCBD; +} + +div#detailed_plan_records input { + width: 97%; + display: block; + border: solid thin black; } .detailed_plan_records { @@ -23,4 +37,8 @@ input { border-collapse: collapse; border-width: thin; font-weight: lighter; +} + +.begin_time, .end_time { + display: block; } \ No newline at end of file diff --git a/hr_module/static/js/csrf_token.js b/hr_module/static/js/csrf_token.js new file mode 100644 index 0000000..d75d2b2 --- /dev/null +++ b/hr_module/static/js/csrf_token.js @@ -0,0 +1,17 @@ +const csrftoken = getCookie('csrftoken'); + +function getCookie(name) { + let cookieValue = null; + if (document.cookie && document.cookie !== '') { + let cookies = document.cookie.split(';'); + for (let i = 0; i < cookies.length; i++) { + let cookie = cookies[i].trim(); + + if (cookie.substring(0, name.length + 1) === (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; +} \ No newline at end of file diff --git a/hr_module/static/js/hr_module_change_employee_data.js b/hr_module/static/js/hr_module_change_employee_data.js new file mode 100644 index 0000000..3d2be1e --- /dev/null +++ b/hr_module/static/js/hr_module_change_employee_data.js @@ -0,0 +1,61 @@ + +var searchEmployeeButton = document.getElementById('load_employee_data_button') +searchEmployeeButton.addEventListener('click', function(){ + fetchSearchEmployeeData() +}) + +function fetchSearchEmployeeData() { + var host = 'http://' + window.location.host; + var fetch_url = host + '/hr_module/change_employee_data_api' + var username = document.getElementById('username_input').value + + fetch(fetch_url, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'X-CSRFToken': csrftoken + }, + body: JSON.stringify({ + "username": username + }), + }).then((response) => { + return response.json(); + }).then((data) => { + console.log(data); + loadValuesIntoPage(data) + }); +} + +function loadValuesIntoPage(data){ + var order = ['username', 'first_name', 'last_name', 'email', 'department', 'manager_username', 'time_model_id', 'manager_flag', 'is_active', 'is_staff', 'is_superuser'] + + var informationContainer = document.getElementById('search_results') + + for (var i = 0; i < order.length; i++){ + var field = order[i] + var value = data[field] + + var fieldContainer = document.createElement('div') + fieldContainer.className = 'field_container' + + if (typeof(value) === 'boolean'){ + var httpfield = document.createElement('input') + httpfield.type = 'checkbox' + httpfield.checked = value + httpfield.setAttribute('disabled', 'disabled') + } else { + var httpfield = document.createElement('div') + httpfield.innerHTML = value + } + var label = document.createElement('label') + label.setAttribute('for', field) + label.innerText = field.replace('_', ' ') + httpfield.id = field + httpfield.className = 'database_field' + + fieldContainer.appendChild(label) + fieldContainer.appendChild(httpfield) + informationContainer.appendChild(fieldContainer) + } +} \ No newline at end of file diff --git a/hr_module/static/js/hr_module_schedule.js b/hr_module/static/js/hr_module_create_schedule.js similarity index 93% rename from hr_module/static/js/hr_module_schedule.js rename to hr_module/static/js/hr_module_create_schedule.js index 6f07153..f800718 100644 --- a/hr_module/static/js/hr_module_schedule.js +++ b/hr_module/static/js/hr_module_create_schedule.js @@ -1,4 +1,3 @@ -const csrftoken = getCookie('csrftoken'); var searchInput = document.getElementById('searched_string'); searchInput.addEventListener("click", fetchSearchOptions); @@ -11,7 +10,7 @@ submitToDb.addEventListener('click', postPlanToDb); function fetchSearchOptions() { var host = 'http://' + window.location.host; - var fetch_url = host + '/hr_module/search' + var fetch_url = host + '/hr_module/search_api' var searched_field = document.getElementById('schedule_filter_category').value var searched_string = document.getElementById('searched_string').value @@ -235,24 +234,6 @@ function postPlanToDb(){ } - -function getCookie(name) { - let cookieValue = null; - if (document.cookie && document.cookie !== '') { - let cookies = document.cookie.split(';'); - for (let i = 0; i < cookies.length; i++) { - let cookie = cookies[i].trim(); - - if (cookie.substring(0, name.length + 1) === (name + '=')) { - cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); - break; - } - } - } - return cookieValue; -} - - function showPopup(){ document.getElementById("popup_content").addEventListener("click", function(e) { e.stopPropagation(); diff --git a/hr_module/static/js/hr_module_show_schedule.js b/hr_module/static/js/hr_module_show_schedule.js index 5fb287e..9f67999 100644 --- a/hr_module/static/js/hr_module_show_schedule.js +++ b/hr_module/static/js/hr_module_show_schedule.js @@ -1,4 +1,3 @@ -const csrftoken = getCookie('csrftoken'); var parent = document.getElementById('calendar_box') document.onload = parent.appendChild(addCalendar(monthsAhead=3)) @@ -86,34 +85,26 @@ function createDetailedCalendarRecords(data){ row.setAttribute('database_username', username) var cell = row.insertCell(0) - var dateInput = document.createElement('input') - dateInput.type = 'date' - dateInput.readOnly = true - dateInput.value = processedDate + var dateInput = document.createElement('div') + dateInput.innerText = processedDate dateInput.name = 'date' cell.appendChild(dateInput) var cell = row.insertCell(1) - var timeInput = document.createElement('input') - timeInput.type = 'time' - timeInput.readOnly = true - timeInput.value = processedBeginTime - timeInput.name = 'begin_time' + var timeInput = document.createElement('div') + timeInput.innerText = processedBeginTime + timeInput.className = 'begin_time' cell.appendChild(timeInput) var cell = row.insertCell(2) - var timeInput = document.createElement('input') - timeInput.type = 'time' - timeInput.readOnly = true - timeInput.value = processedEndTime - timeInput.name = 'end_time' + var timeInput = document.createElement('div') + timeInput.innerText = processedEndTime + timeInput.className = 'end_time' cell.appendChild(timeInput) var cell = row.insertCell(3) - var textInput = document.createElement('input') - textInput.type = 'text' - textInput.readOnly = true - textInput.value = processedActivityType + var textInput = document.createElement('div') + textInput.innerText = processedActivityType textInput.name = 'activity_type' cell.appendChild(textInput) @@ -144,10 +135,18 @@ function unlockRecordsForEditing(event){ var databaseId = event.target.value var parent = event.target.parentElement var row = document.getElementById('database_id_' + databaseId.toString()) - var children = row.getElementsByTagName('input') + var children = row.getElementsByTagName('div') for (var i = 0; i < children.length; i++){ - if (children[i].getAttribute('type') == 'time') { - children[i].readOnly = false; + console.log(children[i].className ) + if (['begin_time', 'end_time'].includes(children[i].className)) { + var value = children[i].innerText + var name = children[i].className + var input = document.createElement('input') + input.name = name + input.value = value + input.type = 'time' + children[i].innerHTML = '' + children[i].appendChild(input) } } @@ -229,6 +228,8 @@ function unhideCheckboxes(databaseId){ checkboxes[i].firstChild.checked = 'true' } } + var header_copy_over = document.getElementById('header_copy_over') + header_copy_over.style.display = 'table-cell' } function removeEditButtons(id){ @@ -277,13 +278,19 @@ function addCancelButton(databaseId){ function createDetailedHeaders(){ var table = document.createElement('table') let headerRow = document.createElement('tr') - let columns = ['Date', 'Start time', 'End time', 'Activity type', '', ''] + let columns = ['Date', 'Start time', 'End time', 'Activity type', 'Action', 'Copy over'] for (let i = 0; i < columns.length; i++){ var headerCell = document.createElement('th') var headerText = document.createElement('div') headerText.innerText = columns[i] headerCell.appendChild(headerText) + if (i == columns.length -1){ + headerCell.style.display = 'none' + headerCell.id = 'header_copy_over' + } + headerRow.appendChild(headerCell) + } table.appendChild(headerRow) table.id = 'detailed_plan_records' diff --git a/hr_module/static/js/tmp.js b/hr_module/static/js/tmp.js deleted file mode 100644 index da9db02..0000000 --- a/hr_module/static/js/tmp.js +++ /dev/null @@ -1,42 +0,0 @@ -var container = document.createElement('div') - container.id = 'calendar_container' - - var monthsBlock = document.createElement('div') - monthsBlock.id = 'months_block' - - renderCalendarFor(monthsBlock, currentYear, currentMonth, monthsAhead, 1) - - var buttonBack = createButton('calendar_button_back', 'calendar_button', '<') - buttonBack.addEventListener('click', function(){ - if (currentMonth == 1){ - currentMonth = 11 - currentYear = currentYear - 1 - } - renderCalendarFor(monthsBlock, currentYear, currentMonth, monthsAhead, 1) - }) - - - container.appendChild(buttonBack) - container.appendChild(monthsBlock) - - var buttonForward = createButton('calendar_button_forwards', 'calendar_button', '>') - buttonForward.addEventListener('click', function(){ - if (currentMonth == 12){ - currentMonth = 0 - currentYear = currentYear + 1 - } - renderCalendarFor(monthsBlock, currentYear, currentMonth, monthsAhead, 1) - }) - - container.appendChild(buttonForward) - - - - var buttonGoToDate = document.getElementById('button_load_selected_months') - buttonGoToDate.addEventListener('click', function(){ - var currentYear = parseInt(document.getElementById('year_selector').value) - var currentMonth = parseInt(document.getElementById('month_selector').value) - addCalendar(container, monthsAhead, currentMonth + 1, currentYear) - }) - - formatCalendarContainerSize() \ No newline at end of file diff --git a/hr_module/templates/hr_module_base.html b/hr_module/templates/hr_module_base.html index 8ca9e34..9ad7294 100644 --- a/hr_module/templates/hr_module_base.html +++ b/hr_module/templates/hr_module_base.html @@ -10,17 +10,31 @@ {% block core_content %}