Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bugTracker() {
- let obj = (() => {
- let id = 0;
- let bugs = [];
- let selector = undefined;
- let report = function (author, description, reproducible, severity) {
- bugs[id] = {
- ID: id,
- author: author,
- description: description,
- reproducible: reproducible,
- severity: severity,
- status: 'Open'
- };
- id++;
- thereIsSelector(selector);
- }
- let setStatus = function (id, newStatus) {
- bugs.forEach(bug => {
- if (bug.ID === id) {
- bug.status = newStatus
- }
- });
- thereIsSelector(selector);
- };
- let remove = function (id) {
- let index = bugs.findIndex(el => el.ID === Number(id));
- if (index !== -1) {
- bugs.splice(index, 1);
- thereIsSelector(selector);
- }
- };
- let sort = function (method) {
- (method === 'ID' || method === 'severity')
- ? bugs.sort((a, b) => a[method] - b[method])
- : bugs.sort((a, b) => a[method].localeCompare(b[method]))
- if (selector) {
- draw();
- }
- };
- let output = function (select) {
- selector = select;
- };
- let draw = function () {
- let parentElem = document.querySelector(`${selector}`);
- parentElem.innerHTML = '';
- bugs.forEach(bug => {
- parentElem.innerHTML += `<div id="report_${bug.ID}" class="report">
- <div class="body">
- <p>${bug.description}</p></div>
- <div class="title">
- <span class="author">Submitted by: ${bug.author}</span>
- <span class="status">${bug.status} | ${bug.severity}</span></div></div>`
- })
- };
- function thereIsSelector(selector) {
- if (selector) {
- sort('ID');
- draw();
- }
- }
- return { report, setStatus, remove, sort, output }
- })();
- return obj
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement