Advertisement
GeorgiLukanov87

02. Sprint Planning - exam

Apr 8th, 2023
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 02. Sprint Planning
  2.  
  3. window.addEventListener('load', solve);
  4.  
  5. function solve() {
  6.     const totalPointsElement = document.getElementById('total-sprint-points');
  7.     const taskIdHiddenElement = document.getElementById('task-id');
  8.     const titleElement = document.getElementById('title');
  9.     const descriptionElement = document.getElementById('description');
  10.     const labelElement = document.getElementById('label');
  11.     const pointsElement = document.getElementById('points');
  12.     const assigneeElement = document.getElementById('assignee');
  13.  
  14.     const taskBtn = document.getElementById('create-task-btn');
  15.     const deleteBtn = document.getElementById('delete-task-btn');
  16.     taskBtn.addEventListener('click', taskHandler);
  17.  
  18.     const taskSectionElement = document.getElementById('tasks-section');
  19.     console.log(taskSectionElement)
  20.     let data = {};
  21.     let idConter = 0;
  22.     let pointsCounter = 0;
  23.     let iconsMapper = {
  24.         feature: '&#8865',
  25.         low: '&#9737',
  26.         high: '&#9888',
  27.     }
  28.  
  29.     let additionClassMapper = {
  30.         feature: "feature",
  31.         low: "low-priority",
  32.         high: "high-priority",
  33.     }
  34.  
  35.     function taskHandler(e) {
  36.         e.preventDefault();
  37.         console.log(e.target)
  38.         data = {
  39.             title: titleElement.value,
  40.             description: descriptionElement.value,
  41.             label: labelElement.value,
  42.             points: pointsElement.value,
  43.             assignee: assigneeElement.value,
  44.         }
  45.         if (!data.title || !data.description || !data.label || !data.points || !data.assignee) {
  46.             alert('wrong data');
  47.             return
  48.         }
  49.  
  50.         idConter++;
  51.         let article = document.createElement('article');
  52.         article.id = `task-${idConter}`;
  53.         taskIdHiddenElement.value = article.id;
  54.         article.classList.add('task-card');
  55.  
  56.         let iconToAdd = '';
  57.         let classToAdd = '';
  58.         if (data.label === 'Feature') {
  59.             iconToAdd += iconsMapper['feature']
  60.             classToAdd += additionClassMapper['feature']
  61.  
  62.         } else if (data.label === 'Low Priority Bug') {
  63.             iconToAdd += iconsMapper['low']
  64.             classToAdd += additionClassMapper['low']
  65.  
  66.         } else if (data.label === 'High Priority Bug') {
  67.             iconToAdd += iconsMapper['high']
  68.             classToAdd += additionClassMapper['high']
  69.         }
  70.  
  71.         let label = cunstomHtml('div', 'task-card-label', data.label, article);
  72.         label.innerHTML += " " + iconToAdd;
  73.         label.classList.add(classToAdd)
  74.  
  75.         label.classList.add('feature')
  76.         let title = cunstomHtml('h3', 'task-card-title', data.title, article);
  77.         let description = cunstomHtml('p', 'task-card-description', data.description, article);
  78.         let points = cunstomHtml('div', 'task-card-points', `Estimated at ${data.points} pts`, article);
  79.         let assignee = cunstomHtml('div', 'task-card-assignee', `Assigned to: ${data.assignee}`, article);
  80.         let divBtnContainer = cunstomHtml('div', 'task-card-actions', '', article)
  81.  
  82.         let delBtn = document.createElement('button');
  83.         delBtn.textContent = 'Delete';
  84.         delBtn.addEventListener('click', deleteHandler);
  85.         divBtnContainer.appendChild(delBtn);
  86.         taskSectionElement.appendChild(article)
  87.  
  88.         titleElement.value = '';
  89.         descriptionElement.value = '';
  90.         labelElement.value = '';
  91.         pointsElement.value = '';
  92.         assigneeElement.value = '';
  93.         pointsCounter += Number(data.points);
  94.         totalPointsElement.textContent = `Total Points ${pointsCounter}pts`
  95.     }
  96.  
  97.     function deleteHandler(e) {
  98.         let task = e.target.parentNode.parentNode;
  99.         let label = task.children[0].textContent;
  100.         if (label.includes('Feature')) {
  101.             labelElement.value = 'Feature'
  102.  
  103.         } else if (label.includes('Low')) {
  104.             labelElement.value = "Low Priority Bug";
  105.         } else if (label.includes('High')) {
  106.             labelElement.value = "High Priority Bug";
  107.         }
  108.  
  109.         let title = task.children[1].textContent;
  110.         let description = task.children[2].textContent;
  111.         let points = task.children[3].textContent.split(' ')[2];
  112.         let assignee = task.children[4].textContent.split(': ')[1];
  113.  
  114.         titleElement.value = title;
  115.         descriptionElement.value = description;
  116.         pointsElement.value = points;
  117.         assigneeElement.value = assignee;
  118.  
  119.         taskBtn.disabled = true;
  120.         deleteBtn.disabled = false;
  121.  
  122.         labelElement.disabled = true;
  123.         titleElement.disabled = true;
  124.         descriptionElement.disabled = true;
  125.         pointsElement.disabled = true;
  126.         assigneeElement.disabled = true;
  127.  
  128.         deleteBtn.addEventListener('click', function deleteTask() {
  129.             console.log(e.target.parentNode.parentNode)
  130.             e.target.parentNode.parentNode.remove();
  131.             taskBtn.disabled = false;
  132.             deleteBtn.disabled = true;
  133.  
  134.             labelElement.disabled = false;
  135.             titleElement.disabled = false;
  136.             descriptionElement.disabled = false;
  137.             pointsElement.disabled = false;
  138.             assigneeElement.disabled = false;
  139.  
  140.             titleElement.value = '';
  141.             descriptionElement.value = '';
  142.             labelElement.value = '';
  143.             pointsElement.value = '';
  144.             assigneeElement.value = '';
  145.  
  146.             pointsCounter -= Number(points);
  147.             totalPointsElement.textContent = `Total Points ${pointsCounter}pts`
  148.         });
  149.  
  150.     }
  151.  
  152.  
  153.     function cunstomHtml(type, className, text, parent) {
  154.         let newElement = document.createElement(type);
  155.         newElement.classList.add(className);
  156.         newElement.textContent = text;
  157.         if (parent) {
  158.             parent.appendChild(newElement);
  159.         }
  160.         return newElement
  161.     }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement