Advertisement
Guest User

RDM 4 - Easy / script.js

a guest
Feb 14th, 2022
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Simple reference solution to RDM-4 Easy
  2. // Utilizing PapaParse and JQuery
  3. function processTickets(ticketsJson){
  4.     ticketsList = {};
  5.     for (ticketInd in ticketsJson) {
  6.       ticket = ticketsJson[ticketInd];
  7.       if(ticket === null || ticket.length === 0) continue;
  8.       var author = ticket['Author Username'];
  9.       if(author === '' || author === null) continue;
  10.       if (author in ticketsList) {
  11.         var newTicket = {};
  12.         newTicket['Issue ID'] = ticket['Issue ID'];
  13.         newTicket['URL'] = ticket['URL'];
  14.         newTicket['Title'] = ticket['Title'];
  15.         newTicket['Description'] = ticket['Description'];
  16.         newTicket['Created At (UTC)'] = ticket['Created At (UTC)'];
  17.         newTicket['Updated At (UTC)'] = ticket['Updated At (UTC)'];
  18.         newTicket['Labels'] = ticket['Labels'];
  19.         ticketsList[author].push(newTicket);
  20.      
  21.       } else if (ticket['Issue ID']){
  22.         var newTicket = {};
  23.         newTicket['Issue ID'] = ticket['Issue ID'];
  24.         newTicket['URL'] = ticket['URL'];
  25.         newTicket['Title'] = ticket['Title'];
  26.         newTicket['Description'] = ticket['Description'];
  27.         newTicket['Created At (UTC)'] = ticket['Created At (UTC)'];
  28.         newTicket['Updated At (UTC)'] = ticket['Updated At (UTC)'];
  29.         newTicket['Labels'] = ticket['Labels'];
  30.         ticketsList[author] = [newTicket];
  31.       }
  32.     }
  33.     var resArr = Object.keys(ticketsList).map(function(key) {
  34.       return [key, ticketsList[key]];
  35.     });
  36.     resArr.sort(function(f,s){
  37.       return s[0] < f[0];
  38.     });
  39.     return resArr;
  40. }
  41.  
  42. function writeTable(results){
  43.     var tbl = $('#results');
  44.     tbl.css('display','inline-block');
  45.     var n = results.length;
  46.     for(var i = 0;i<n;++i){
  47.         var authorDiv = '<div id="' +results[i][0] + '">';
  48.         var lbl = '<label id="' + results[i][0]  +'-name">' + results[i][0] + '</label>';
  49.         authorDiv += lbl;
  50.         var tbl = '<table id="' + results[i][0] + '-results">';
  51.         var header = '<thead>';
  52.         var headerRow = '<tr>'
  53.         headerRow += '<th>'+"Issue ID"+'</th>';
  54.         headerRow += '<th>'+"URL"+'</th>';
  55.         headerRow += '<th>'+"Title"+'</th>';
  56.         headerRow += '<th>'+"Description"+'</th>';
  57.         headerRow += '<th>'+"Created At (UTC)"+'</th>';
  58.         headerRow += '<th>'+"Updated At (UTC)"+'</th>';
  59.         headerRow += '<th>'+"Labels"+'</th>';
  60.         headerRow += '</tr>';
  61.         header += headerRow;
  62.         header += '</thead>';
  63.         tbl += header;
  64.         tbd = '<tbody>';
  65.         var nTickets = results[i][1].length;
  66.         for(var j = 0; j < nTickets; j++){
  67.             var row ='<tr>';
  68.             row+='<td>'+results[i][1][j]['Issue ID']+'</td>';
  69.             row+='<td>'+results[i][1][j]['URL']+'</td>';
  70.             row+='<td>'+results[i][1][j]['Title']+'</td>';
  71.             row+='<td>'+results[i][1][j]['Description']+'</td>';
  72.             row+='<td>'+results[i][1][j]['Created At (UTC)']+'</td>';
  73.             row+='<td>'+results[i][1][j]['Updated At (UTC)']+'</td>';
  74.             row+='<td>'+results[i][1][j]['Labels']+'</td>';
  75.             row+='</tr>';
  76.             tbd+=row;
  77.         }
  78.         tbd+='</tbody>';
  79.         tbl += tbd;
  80.         tbl += '</table>';
  81.         authorDiv += tbl;
  82.         authorDiv += '</div> </br>';
  83.         $('#results').append(authorDiv);
  84.     }
  85. }
  86.  
  87. function readFile(){
  88.     var csv = $("#ticketFile").prop('files')[0];
  89.     if (!csv) alert('insert a file');
  90.     var inputData;
  91.     resJson=[];
  92.     Papa.parse(csv ,{
  93.      header:true,
  94.       dynamicTyping: false,
  95.       complete: function(results) {
  96.             inputData = results.data;
  97.         writeTable(processTickets(inputData));
  98.       }
  99.     });
  100. };
  101.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement