Advertisement
kstoyanov

07. * Bug Tracker

Oct 13th, 2020 (edited)
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.10 KB | None | 0 0
  1. function bugTracker() {
  2.     let bugReports = [];
  3.     let bugId = 0;
  4.     let selector = undefined;
  5.  
  6.     function report(author, description, reproducible, severity) {
  7.         let report = {
  8.             ID: bugId++,
  9.             author: author,
  10.             description: description,
  11.             reproducible: reproducible,
  12.             severity: severity,
  13.             status: 'Open'
  14.         };
  15.         bugReports.push(report);
  16.         updateHTML();
  17.     }
  18.  
  19.     function setStatus(id, newStatus) {
  20.         bugReports.filter(x => x.ID == id)[0].status = newStatus;
  21.         console.log(bugReports);
  22.         updateHTML();
  23.     }
  24.  
  25.     function remove(id) {
  26.         bugReports = bugReports.filter(x => x.ID != id);
  27.         updateHTML();
  28.     }
  29.  
  30.     function sort(method) {
  31.         switch (method) {
  32.             case 'author':
  33.                 bugReports = bugReports.sort((a, b) => a.author.localeCompare(b.author));
  34.                 break;
  35.             case 'severity':
  36.                 bugReports = bugReports.sort((a, b) => a.severity - b.severity);
  37.                 break;
  38.             default:
  39.                 bugReports = bugReports.sort((a, b) => a.ID - b.ID);
  40.                 break;
  41.         }
  42.         updateHTML();
  43.     }
  44.  
  45.     function output(sel) {
  46.         selector = sel;
  47.     }
  48.  
  49.     function updateHTML() {
  50.         if (selector) {
  51.             let container = $(selector).html('');
  52.             for (let report of bugReports) {
  53.                 let reportHTML =
  54.                     $('<div>').attr('id', 'report_' + report.ID).addClass('report')
  55.                         .append($('<div>').addClass('body').append($('<p>').text(report.description)))
  56.                         .append($('<div>')
  57.                             .addClass('title')
  58.                             .append($('<span>').addClass('author').text('Submitted by: ' + report.author))
  59.                             .append($('<span>').addClass('status').text(report.status + ' | ' + report.severity)));
  60.                 container.append(reportHTML);
  61.             }
  62.         }
  63.     }
  64.  
  65.     return {report, setStatus, remove, sort, output};
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement