From af0ad888fc7f11f5746f3d60d8fc86da6006ae18 Mon Sep 17 00:00:00 2001 From: ivinayakg Date: Sat, 22 Jul 2023 18:50:42 +0530 Subject: [PATCH 1/6] feat: overdue tasks --- .vscode/settings.json | 3 + constants.js | 1 + extension-requests/script.js | 1 + extension-requests/style.css | 2 +- index.html | 7 + overdue-tasks/constants.js | 19 +++ overdue-tasks/index.html | 96 +++++++++++++ overdue-tasks/local-utils.js | 115 ++++++++++++++++ overdue-tasks/script.js | 173 ++++++++++++++++++++++++ overdue-tasks/style.css | 254 +++++++++++++++++++++++++++++++++++ script.js | 9 +- style.css | 20 +++ 12 files changed, 697 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 overdue-tasks/constants.js create mode 100644 overdue-tasks/index.html create mode 100644 overdue-tasks/local-utils.js create mode 100644 overdue-tasks/script.js create mode 100644 overdue-tasks/style.css diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..e2e4cf2c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5500 +} diff --git a/constants.js b/constants.js index 7a88a01b..795ed76b 100644 --- a/constants.js +++ b/constants.js @@ -1,6 +1,7 @@ const API_BASE_URL = 'https://api.realdevsquad.com'; const USER_MANAGEMENT_LINK = 'user-management-link'; const EXTENSION_REQUESTS_LINK = 'extension-requests-link'; +const OVERDUE_TASKS_LINK = 'overdue-tasks-link'; const dummyPicture = 'https://dashboard.realdevsquad.com/users/images/avatar.png'; const USER_MANAGEMENT_URL = diff --git a/extension-requests/script.js b/extension-requests/script.js index b4ca3c4b..a172a09f 100644 --- a/extension-requests/script.js +++ b/extension-requests/script.js @@ -190,6 +190,7 @@ function fillUpdateForm() { ) .toISOString() .replace('Z', ''); + modalUpdateForm.querySelector('.extensionOldEndsOn').value = new Date( oldEndsOn * 1000, ) diff --git a/extension-requests/style.css b/extension-requests/style.css index 5f05634e..c6bec397 100644 --- a/extension-requests/style.css +++ b/extension-requests/style.css @@ -187,7 +187,7 @@ body { .extension-requests { display: grid; - grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + grid-template-columns: 2fr; flex-wrap: wrap; } diff --git a/index.html b/index.html index b711afb7..7ad5fe75 100644 --- a/index.html +++ b/index.html @@ -42,6 +42,13 @@ > Extension Requests + + Overdue Tasks + Online Members diff --git a/overdue-tasks/constants.js b/overdue-tasks/constants.js new file mode 100644 index 00000000..08b4c70f --- /dev/null +++ b/overdue-tasks/constants.js @@ -0,0 +1,19 @@ +const taskInfoModelHeadings = [ + { title: 'Title' }, + { title: 'Overdue From', key: 'endsOn', time: true }, + { title: 'Purpose' }, + { title: 'Assignee' }, + { title: 'Created By', key: 'createdBy' }, + { title: 'Is Noteworthy', key: 'isNoteworthy' }, +]; + +const extensionRequestCardHeadings = [ + { title: 'Title' }, + { title: 'Reason' }, + { title: 'Old Ends On', key: 'oldEndsOn', time: true }, + { title: 'New Ends On', key: 'newEndsOn', time: true }, + { title: 'Status', bold: true }, + { title: 'Assignee' }, + { title: 'Created At', key: 'timestamp', time: true }, + { title: 'Task', key: 'taskId' }, +]; diff --git a/overdue-tasks/index.html b/overdue-tasks/index.html new file mode 100644 index 00000000..a9005fbb --- /dev/null +++ b/overdue-tasks/index.html @@ -0,0 +1,96 @@ + + + + + + + Overdue Tasks + + + +
+
+

Prompt Heading

+ + +
+
+

Create Extension Request

+ + + + + + + + + + + + + + + + +
+
+
+

Overdue Tasks

+
+
+
+
+

+ + + + + + + diff --git a/overdue-tasks/local-utils.js b/overdue-tasks/local-utils.js new file mode 100644 index 00000000..1189dcab --- /dev/null +++ b/overdue-tasks/local-utils.js @@ -0,0 +1,115 @@ +async function getCurrentOverdueTasks(query = {}) { + const url = new URL(`${API_BASE_URL}/tasks/overdue/current`); + + const res = await fetch(url, { + credentials: 'include', + method: 'GET', + headers: { + 'Content-type': 'application/json', + }, + }); + return await res.json(); +} + +async function getExtensionRequests(query = {}) { + const url = new URL(`${API_BASE_URL}/extension-requests`); + + queryParams = ['assignee', 'status', 'taskId']; + queryParams.forEach( + (key) => query[key] && url.searchParams.set(key, query[key]), + ); + + const res = await fetch(url, { + credentials: 'include', + method: 'GET', + headers: { + 'Content-type': 'application/json', + }, + }); + return await res.json(); +} + +async function createExtensionRequest(extensionObject) { + const url = `${API_BASE_URL}/extension-requests/admin/`; + const res = await fetch(url, { + credentials: 'include', + method: 'POST', + body: JSON.stringify(extensionObject), + headers: { + 'Content-type': 'application/json', + }, + }); + return await res.json(); +} + +async function getTaskDetails(taskId) { + if (!taskId) return; + const url = `${API_BASE_URL}/tasks/${taskId}/details`; + const res = await fetch(url, { + credentials: 'include', + method: 'GET', + headers: { + 'Content-type': 'application/json', + }, + }); + return await res.json(); +} + +async function unassignTask(taskId) { + if (!taskId) return; + const url = `${API_BASE_URL}/tasks/${taskId}/`; + const res = await fetch(url, { + credentials: 'include', + method: 'PATCH', + headers: { + 'Content-type': 'application/json', + }, + body: JSON.stringify({ assignee: null, status: 'AVAILABLE', endsOn: 0 }), + }); + return res.status === 204; +} + +function getTimeFromTimestamp(timestamp) { + return new Date(timestamp * 1000).toLocaleString(); +} + +function createTable(headings, data, className = '') { + const table = createElement({ + type: 'table', + attributes: { + class: className, + }, + }); + const tableBody = createElement({ type: 'tbody' }); + headings.forEach(({ title, key, time, bold }) => { + let row = createElement({ type: 'tr' }); + let rowHeading = createElement({ type: 'th', innerText: title }); + + let contentText = ''; + if (time) contentText = getTimeFromTimestamp(data[key]); + else contentText = key ? data[key] : data[title.toLowerCase()]; + + let tableData = createElement({ + type: 'td', + innerText: contentText, + attributes: { + class: bold ? 'bold' : '', + }, + }); + row.appendChild(rowHeading); + row.appendChild(tableData); + tableBody.appendChild(row); + }); + + table.appendChild(tableBody); + return table; +} + +function formDataToObject(formData) { + if (!formData) return; + const result = {}; + for (const [key, value] of formData.entries()) { + result[key] = value; + } + return result; +} diff --git a/overdue-tasks/script.js b/overdue-tasks/script.js new file mode 100644 index 00000000..7d7fb1e0 --- /dev/null +++ b/overdue-tasks/script.js @@ -0,0 +1,173 @@ +const container = document.querySelector('.container'); +const overdueTasksContainer = document.querySelector('.overdue-tasks'); + +const errorHeading = document.querySelector('h2#error'); +const modalParent = document.querySelector('.overdue-tasks-modal-parent'); +const closeModal = document.querySelectorAll('#close-modal'); + +//modal containers +const modalShowPrompt = document.querySelector('.overdue-tasks-prompt'); +const modalCreateForm = document.querySelector('.extension-requests-form'); + +//pathname +const url = window.location.href; + +const state = { + task: null, + dev: new URL(url).searchParams.get('dev'), +}; + +const render = async () => { + try { + addLoader(container); + const overdueTasks = await getCurrentOverdueTasks(); + const alloverdueTasks = overdueTasks.overdueTasks; + alloverdueTasks.forEach((data) => { + overdueTasksContainer.appendChild( + createOverdueTasksCard(data, taskInfoModelHeadings), + ); + }); + checkTaskExtensionDetails(alloverdueTasks); + } catch (error) { + errorHeading.textContent = 'Something went wrong'; + errorHeading.classList.add('error-visible'); + reload(); + } finally { + removeLoader('loader'); + } +}; + +// to check if there are already extension requests created for this +// async function checkTaskExtensionDetails(tasks){ +// await Promise.all( +// tasks.map(async (task) => { +// let extensionRequestResponse = await getExtensionRequests({taskId: task.id, status: "PENDING"}) +// let extensionRequests = extensionRequestResponse.allExtensionRequests + +// if (extensionRequests.length){ +// task_extensionRequest_button = document.querySelector(`.create-extension-btn-${task.id}`) +// task_extensionRequest_button.disabled = true +// task_extensionRequest_button.innerText = "Extension Requests Exists" +// } +// }) +// ); +// } + +function createOverdueTasksCard(data, dataHeadings) { + if (!data) return; + + const unassignBtn = createElement({ + type: 'button', + attributes: { class: 'unassign-task-btn' }, + innerText: 'Unassign Task', + }); + const createExtensionBtn = createElement({ + type: 'button', + attributes: { + class: `create-extension-btn create-extension-btn-${data.id}`, + }, + innerText: 'Create Extension For this', + }); + unassignBtn.addEventListener('click', () => { + showModal(); + state.task = data; + unassignTaskTrigger(); + }); + createExtensionBtn.addEventListener('click', () => { + state.task = data; + fillCreateForm(); + showModal('form'); + }); + + const main = createTable(dataHeadings, data, 'overdue-task-container'); + + main.appendChild(unassignBtn); + main.appendChild(createExtensionBtn); + return main; +} +render(); + +//PATCH requests functions +async function onCreateFormSubmit(e) { + e.preventDefault(); + try { + addLoader(container); + let formData = formDataToObject(new FormData(e.target)); + formData['oldEndsOn'] = new Date(formData['oldEndsOn']).getTime() / 1000; + formData['newEndsOn'] = new Date(formData['newEndsOn']).getTime() / 1000; + await createExtensionRequest(formData); + // reload(); + } catch (error) { + errorHeading.textContent = 'Something went wrong'; + errorHeading.classList.add('error-visible'); + // reload(); + } finally { + removeLoader('loader'); + } +} +modalCreateForm.addEventListener('submit', onCreateFormSubmit); + +modalParent.addEventListener('click', hideModal); +closeModal.forEach((node) => node.addEventListener('click', () => hideModal())); + +function showModal(state = 'prompt') { + modalParent.classList.add('visible'); + modalParent.setAttribute('state', state); +} +function hideModal(e) { + if (!e) { + modalParent.classList.remove('visible'); + return; + } + e.stopPropagation(); + if (e.target === modalParent) { + modalParent.classList.remove('visible'); + } +} + +function reload() { + if (state.dev) return; + setTimeout(() => window.history.go(0), 2000); +} + +function fillCreateForm() { + modalCreateForm.querySelector('.extensionId').value = state.task.id; + modalCreateForm.querySelector('.extensionTitle').value = state.task.title; + modalCreateForm.querySelector('.extensionAssignee').value = + state.task.assignee; + modalCreateForm.querySelector('.extensionStatus').value = 'PENDING'; + modalCreateForm.querySelector('.extensionOldEndsOn').value = new Date( + state.task.endsOn * 1000, + ) + .toISOString() + .replace('Z', ''); +} + +function unassignTaskTrigger() { + let success_btn = modalShowPrompt.querySelector('.prompt_success'); + let failure_btn = modalShowPrompt.querySelector('.prompt_failure'); + + if (state.task.assignee) { + modalShowPrompt.querySelector( + 'h2', + ).innerHTML = `Unassign ${state.task.assignee} of ${state.task.title} task`; + } else { + modalShowPrompt.querySelector( + 'h2', + ).innerHTML = `Make this task AVAILABLE`; + } + + success_btn.addEventListener('click', async function () { + addLoader(modalShowPrompt); + unassignSuccess = await unassignTask(state.task.id); + removeLoader('overdue-tasks-prompt'); + if (unassignSuccess) { + hideModal(); + reload(); + } + }); + + failure_btn.onclick = async function () { + hideModal(); + }; +} diff --git a/overdue-tasks/style.css b/overdue-tasks/style.css new file mode 100644 index 00000000..9d68ecc0 --- /dev/null +++ b/overdue-tasks/style.css @@ -0,0 +1,254 @@ +:root { + --dark-blue: #1b1378; + --light-aqua: #d4f9f2; + --scandal: #e5fcf5; + --white: #ffffff; + --black-transparent: #000000a8; + --black: #181717; + --light-gray: #d9d9d9; + --razzmatazz: #df0057; + --gray: #808080; + --button-proceed: #008000; + --modal-color: #00000048; + --red: rgb(255, 40, 40); +} + +*, +::after, +::before { + box-sizing: border-box; +} + +button { + cursor: pointer; +} + +.bold { + font-weight: bolder; +} + +body { + font-family: 'Roboto', sans-serif; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + min-height: 100vh; + user-select: none; + max-width: 100vw; +} + +.container { + width: 100%; + text-align: center; + padding: 10px; +} + +.header { + background-color: var(--dark-blue); + text-align: center; + color: var(--white); +} + +.overdue-tasks { + display: grid; + grid-template-columns: 1fr 1fr; + flex-wrap: wrap; +} + +.overdue-task-container { + text-align: left; + border: 2px solid var(--black-transparent); + padding: 1.25rem; + margin: 10px; + color: var(--black); + border-radius: 5px; + display: flex; + flex-wrap: wrap; +} + +.overdue-task-container tbody { + flex-basis: 100%; +} + +.overdue-task-container tr th { + width: 50%; +} + +.overdue-task-container .create-extension-btn, +.overdue-task-container .unassign-task-btn { + background-color: var(--button-proceed); + border: none; + color: var(--white); + padding: 0.5rem 1rem; + font-size: medium; + font-weight: bold; + border-radius: 5px; + margin: 10px 10px 0px 0px; +} + +/* Loader Container */ +.loader-text { + text-align: center; + font-size: 2rem; +} +.loader { + margin: auto auto; +} + +.loader p { + font-weight: 800; + font-size: 3em; +} + +/* Error Heading */ +.error { + display: none; +} +.error-visible { + display: block; +} + +/* modal */ +.overdue-tasks-modal-parent { + display: none; +} + +.overdue-tasks-modal-parent.visible { + z-index: 1; + position: fixed; + top: 0; + left: 0; + display: flex; + justify-content: center; + align-items: center; + min-width: 100vw; + min-height: 100vh; + background-color: var(--modal-color); + overflow-y: scroll; + padding-bottom: 1rem; +} + +.overdue-tasks-modal-parent[state='prompt'] .overdue-tasks-prompt { + display: flex; +} + +.overdue-tasks-modal-parent .overdue-tasks-prompt { + position: fixed; + top: 40%; + bottom: 40%; + width: 30%; + background-color: var(--white); + padding: 1.25rem; + border-radius: 5px; + display: none; + flex-wrap: wrap; + justify-content: center; + align-items: center; + height: min-content; +} + +.overdue-tasks-prompt > h2 { + flex-basis: 100%; + text-align: center; + margin: 0; + margin-bottom: 10px; +} + +.overdue-tasks-prompt > h2 > i { + font-weight: normal; + font-size: 80%; +} + +.overdue-tasks-prompt .prompt_success { + background-color: var(--button-proceed); + border: none; + color: var(--white); + padding: 0.5rem 1rem; + font-size: medium; + font-weight: bold; + border-radius: 5px; + margin: 10px 10px 0px 0px; +} + +.overdue-tasks-prompt .prompt_failure { + background-color: var(--red); + border: none; + color: var(--white); + padding: 0.5rem 1rem; + font-size: medium; + font-weight: bold; + border-radius: 5px; + margin: 10px 10px 0px 0px; +} + +/* create extension form */ +/* update form */ +.overdue-tasks-modal-parent[state='form'] .extension-requests-form { + display: flex; +} + +.extension-requests-form { + position: absolute; + left: 30%; + right: 30%; + overflow-y: scroll; + top: 5%; + bottom: 5%; + display: none; + flex-direction: column; + justify-content: center; + align-items: flex-start; + background-color: var(--white); + padding: 1.25rem; + padding-top: 2rem; + border-radius: 5px; +} + +.extension-requests-form input, +.extension-requests-form select { + margin: 5px 0px 15px 0px; + padding: 5px; + width: 100%; + border: none; + border-bottom: 1px solid var(--gray); +} +.extension-requests-form input:focus { + outline: none; + border-bottom: 1px solid var(--gray); +} +.extension-requests-form button { + background-color: var(--button-proceed); + border: none; + color: var(--white); + padding: 0.5rem 1rem; + font-size: medium; + font-weight: bold; + border-radius: 5px; + margin: 10px; +} + +#close-modal { + background-color: var(--red); +} + +@media screen and (max-width: 900px) { + .overdue-tasks-modal-parent .extension-requests-form { + left: 20%; + right: 20%; + } +} + +@media screen and (max-width: 600px) { + .overdue-tasks { + grid-template-columns: 1fr; + } + + .overdue-tasks-modal-parent .overdue-tasks-prompt { + width: 75%; + } + .overdue-tasks-modal-parent .extension-requests-form { + left: 10%; + right: 10%; + } +} diff --git a/script.js b/script.js index b5316022..f7235f46 100644 --- a/script.js +++ b/script.js @@ -1,5 +1,6 @@ const userManagementLink = document.getElementById(USER_MANAGEMENT_LINK); const extensionRequestsLink = document.getElementById(EXTENSION_REQUESTS_LINK); +const overdueTasksLink = document.getElementById(OVERDUE_TASKS_LINK); export async function showSuperUserOptions(...privateBtns) { try { @@ -20,7 +21,11 @@ export async function showSuperUserOptions(...privateBtns) { * Then get the node from the DOM into a variable and pass that variable in the * function below. */ -showSuperUserOptions(userManagementLink, extensionRequestsLink); +showSuperUserOptions( + userManagementLink, + extensionRequestsLink, + overdueTasksLink, +); const createGoalButton = document.getElementById('create-goal'); const params = new URLSearchParams(window.location.search); @@ -28,4 +33,4 @@ if (params.get('dev') === 'true') { createGoalButton.classList.remove('element-display-remove'); } -showUserManagementButton(); +// showUserManagementButton(); diff --git a/style.css b/style.css index 36181d15..7aa0b875 100644 --- a/style.css +++ b/style.css @@ -127,6 +127,26 @@ button { border-color: transparent; } +/* Overdue Tasks */ +#overdue-tasks-link { + color: black; + font-weight: 500; + font-size: larger; + background-color: var(--white-color); + border: 2px solid var(--black-color); + border-radius: 5px; + padding: 10px 50px; + cursor: pointer; + transition: all 0.5s ease; + width: max-content; + text-decoration: none; +} +#overdue-tasks-link:hover { + color: var(--white-color); + background-color: var(--blue-color); + border-color: transparent; +} + /* Online-members */ .online-members-link { color: black; From ddcc77fb8317fcda8615f494d774a9d279fb8292 Mon Sep 17 00:00:00 2001 From: Vinayak Goyal <73058928+ivinayakg@users.noreply.github.com> Date: Tue, 22 Aug 2023 00:04:32 +0530 Subject: [PATCH 2/6] fix: bug fixes due to new overdue api --- overdue-tasks/local-utils.js | 4 ++-- overdue-tasks/script.js | 39 ++++++++++++++++++++---------------- script.js | 2 -- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/overdue-tasks/local-utils.js b/overdue-tasks/local-utils.js index 1189dcab..fc55abd6 100644 --- a/overdue-tasks/local-utils.js +++ b/overdue-tasks/local-utils.js @@ -1,5 +1,5 @@ async function getCurrentOverdueTasks(query = {}) { - const url = new URL(`${API_BASE_URL}/tasks/overdue/current`); + const url = new URL(`${API_BASE_URL}/tasks?dev=true&status=overdue`); const res = await fetch(url, { credentials: 'include', @@ -30,7 +30,7 @@ async function getExtensionRequests(query = {}) { } async function createExtensionRequest(extensionObject) { - const url = `${API_BASE_URL}/extension-requests/admin/`; + const url = `${API_BASE_URL}/extension-requests/`; const res = await fetch(url, { credentials: 'include', method: 'POST', diff --git a/overdue-tasks/script.js b/overdue-tasks/script.js index 7d7fb1e0..8f66ee75 100644 --- a/overdue-tasks/script.js +++ b/overdue-tasks/script.js @@ -21,7 +21,7 @@ const render = async () => { try { addLoader(container); const overdueTasks = await getCurrentOverdueTasks(); - const alloverdueTasks = overdueTasks.overdueTasks; + const alloverdueTasks = overdueTasks.tasks; alloverdueTasks.forEach((data) => { overdueTasksContainer.appendChild( createOverdueTasksCard(data, taskInfoModelHeadings), @@ -38,20 +38,25 @@ const render = async () => { }; // to check if there are already extension requests created for this -// async function checkTaskExtensionDetails(tasks){ -// await Promise.all( -// tasks.map(async (task) => { -// let extensionRequestResponse = await getExtensionRequests({taskId: task.id, status: "PENDING"}) -// let extensionRequests = extensionRequestResponse.allExtensionRequests - -// if (extensionRequests.length){ -// task_extensionRequest_button = document.querySelector(`.create-extension-btn-${task.id}`) -// task_extensionRequest_button.disabled = true -// task_extensionRequest_button.innerText = "Extension Requests Exists" -// } -// }) -// ); -// } +async function checkTaskExtensionDetails(tasks) { + await Promise.all( + tasks.map(async (task) => { + let extensionRequestResponse = await getExtensionRequests({ + taskId: task.id, + status: 'PENDING', + }); + let extensionRequests = extensionRequestResponse.allExtensionRequests; + + if (extensionRequests.length) { + task_extensionRequest_button = document.querySelector( + `.create-extension-btn-${task.id}`, + ); + task_extensionRequest_button.disabled = true; + task_extensionRequest_button.innerText = 'Extension Requests Exists'; + } + }), + ); +} function createOverdueTasksCard(data, dataHeadings) { if (!data) return; @@ -96,11 +101,11 @@ async function onCreateFormSubmit(e) { formData['oldEndsOn'] = new Date(formData['oldEndsOn']).getTime() / 1000; formData['newEndsOn'] = new Date(formData['newEndsOn']).getTime() / 1000; await createExtensionRequest(formData); - // reload(); + reload(); } catch (error) { errorHeading.textContent = 'Something went wrong'; errorHeading.classList.add('error-visible'); - // reload(); + reload(); } finally { removeLoader('loader'); } diff --git a/script.js b/script.js index 536664c1..cdb1b4c1 100644 --- a/script.js +++ b/script.js @@ -21,7 +21,6 @@ function getCurrentTimestamp() { return new Date().toLocaleString(); } - export async function showSuperUserOptions(...privateBtns) { try { const isSuperUser = await checkUserIsSuperUser(); @@ -66,7 +65,6 @@ if (params.get('dev') === 'true') { createGoalButton.classList.remove('element-display-remove'); } - // showUserManagementButton(); function addClickEventListener( From 9e98e94ee7789775712bf4d140a8c4d6a6753c8a Mon Sep 17 00:00:00 2001 From: Vinayak Goyal <73058928+ivinayakg@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:09:21 +0530 Subject: [PATCH 3/6] fix: removed vscode settings file --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e2e4cf2c..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "liveServer.settings.port": 5500 -} From adff52c451bfcb6d09a3092db1f4f982f52aa27c Mon Sep 17 00:00:00 2001 From: Vinayak Goyal <73058928+ivinayakg@users.noreply.github.com> Date: Tue, 5 Sep 2023 18:11:02 +0530 Subject: [PATCH 4/6] updated: added .vscode in gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 642271f5..bb43d965 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ -coverage/ \ No newline at end of file +coverage/ +.vscode \ No newline at end of file From 723f64b02b572b1ba422e132c45cb6dbb0fb6e65 Mon Sep 17 00:00:00 2001 From: Vinayak Goyal <73058928+ivinayakg@users.noreply.github.com> Date: Tue, 5 Sep 2023 19:21:15 +0530 Subject: [PATCH 5/6] refact: added feature flag for overdue tasks --- overdue-tasks/script.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/overdue-tasks/script.js b/overdue-tasks/script.js index 8f66ee75..68797c07 100644 --- a/overdue-tasks/script.js +++ b/overdue-tasks/script.js @@ -11,6 +11,7 @@ const modalCreateForm = document.querySelector('.extension-requests-form'); //pathname const url = window.location.href; +const queryParams = new URLSearchParams(window.location.search); const state = { task: null, @@ -18,6 +19,13 @@ const state = { }; const render = async () => { + if (!devActive()) { + setTimeout(() => { + window.history.go(-1); + }, 2000); + return; + } + try { addLoader(container); const overdueTasks = await getCurrentOverdueTasks(); @@ -176,3 +184,9 @@ function unassignTaskTrigger() { hideModal(); }; } + +function devActive() { + let dev = queryParams.get('dev'); + dev = JSON.parse(dev); + return dev; +} From 9735f52de200be7d0206421226a5e828ef9d46be Mon Sep 17 00:00:00 2001 From: Pratiyush Kumar Date: Sun, 1 Oct 2023 17:04:22 +0530 Subject: [PATCH 6/6] removing code that got merged in merge conflict --- extension-requests/script.js | 165 ----------------------------------- 1 file changed, 165 deletions(-) diff --git a/extension-requests/script.js b/extension-requests/script.js index 5c76f76e..82760703 100644 --- a/extension-requests/script.js +++ b/extension-requests/script.js @@ -317,171 +317,6 @@ const toggleSortIcon = () => { } }; -const showTaskDetails = async (taskId, approved) => { - if (!taskId) return; - try { - modalShowInfo.innerHTML = '

Task Details

'; - addLoader(modalShowInfo); - const taskDetails = await getTaskDetails(taskId); - const taskData = taskDetails.taskData; - modalShowInfo.append( - createTaskInfoModal(taskData, approved, taskInfoModelHeadings), - ); - } catch (error) { - addErrorElement(extensionRequestsContainer); - reload(); - } finally { - removeLoader('loader'); - } -}; -function createTaskInfoModal(data, approved, dataHeadings) { - if (!data) return; - - const updateStatus = createElement({ - type: 'button', - attributes: { class: 'status-form' }, - innerText: 'Update Status', - }); - const closeModal = createElement({ - type: 'button', - attributes: { id: 'close-modal' }, - innerText: 'Cancel', - }); - updateStatus.addEventListener('click', () => { - showModal('status-form'); - fillStatusForm(); - }); - closeModal.addEventListener('click', () => hideModal()); - - const main = createTable(dataHeadings, data); - - if (!approved) main.appendChild(updateStatus); - main.appendChild(closeModal); - return main; -} -function createExtensionRequestCard(data, dataHeadings) { - if (!data) return; - - const updateRequestBtn = createElement({ - type: 'button', - attributes: { class: 'update_request' }, - innerText: 'Update Request', - }); - const moreInfoBtn = createElement({ - type: 'button', - attributes: { class: 'more' }, - innerText: 'More', - }); - updateRequestBtn.addEventListener('click', () => { - showModal('update-form'); - state.currentExtensionRequest = data; - fillUpdateForm(); - }); - moreInfoBtn.addEventListener('click', () => { - showModal('info'); - showTaskDetails(data.taskId, data.status === 'APPROVED'); - state.currentExtensionRequest = data; - }); - - const main = createTable(dataHeadings, data, 'extension-request'); - - const wrapperDiv = createElement({ type: 'div' }); - - wrapperDiv.appendChild(moreInfoBtn); - wrapperDiv.appendChild(updateRequestBtn); - - main.appendChild(wrapperDiv); - return main; -} - -//PATCH requests functions -async function onStatusFormSubmit(e) { - e.preventDefault(); - try { - addLoader(container); - let formData = formDataToObject(new FormData(e.target)); - await updateExtensionRequestStatus({ - id: state.currentExtensionRequest.id, - body: formData, - }); - reload(); - } catch (error) { - addErrorElement(extensionRequestsContainer); - reload(); - } finally { - removeLoader('loader'); - } -} -async function onUpdateFormSubmit(e) { - e.preventDefault(); - try { - addLoader(container); - let formData = formDataToObject(new FormData(e.target)); - formData['newEndsOn'] = new Date(formData['newEndsOn']).getTime() / 1000; - await updateExtensionRequest({ - id: state.currentExtensionRequest.id, - body: formData, - }); - addErrorElement(extensionRequestsContainer); - reload(); - } finally { - removeLoader('loader'); - } -} - -modalUpdateForm.addEventListener('submit', onUpdateFormSubmit); -modalStatusForm.addEventListener('submit', onStatusFormSubmit); - -modalParent.addEventListener('click', hideModal); -closeModal.forEach((node) => node.addEventListener('click', () => hideModal())); - -function showModal(show = 'form') { - modalParent.classList.add('visible'); - modalParent.setAttribute('show', show); -} -function hideModal(e) { - if (!e) { - modalParent.classList.remove('visible'); - return; - } - e.stopPropagation(); - if (e.target === modalParent) { - modalParent.classList.remove('visible'); - } -} -function reload() { - setTimeout(() => window.history.go(0), 2000); -} -function fillStatusForm() { - modalStatusForm.querySelector('.extensionId').value = - state.currentExtensionRequest.id; - modalStatusForm.querySelector('.extensionTitle').value = - state.currentExtensionRequest.title; - modalStatusForm.querySelector('.extensionAssignee').value = - state.currentExtensionRequest.assignee; -} -function fillUpdateForm() { - const { newEndsOn, oldEndsOn, status, id, title, assignee, reason } = - state.currentExtensionRequest; - - modalUpdateForm.querySelector('.extensionNewEndsOn').value = new Date( - newEndsOn * 1000, - ) - .toISOString() - .replace('Z', ''); - - modalUpdateForm.querySelector('.extensionOldEndsOn').value = new Date( - oldEndsOn * 1000, - ) - .toISOString() - .replace('Z', ''); - - modalUpdateForm.querySelector('.extensionStatus').value = status; - modalUpdateForm.querySelector('.extensionId').value = id; - modalUpdateForm.querySelector('.extensionTitle').value = title; - modalUpdateForm.querySelector('.extensionAssignee').value = assignee; - modalUpdateForm.querySelector('.extensionReason').value = reason; -} filterButton.addEventListener('click', (event) => { event.stopPropagation(); filterModal.classList.toggle('hidden');