Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Simple reference solution to RDM-4 Easy
- // Utilizing PapaParse and JQuery
- function processTickets(ticketsJson){
- ticketsList = {};
- for (ticketInd in ticketsJson) {
- ticket = ticketsJson[ticketInd];
- if(ticket === null || ticket.length === 0) continue;
- var author = ticket['Author Username'];
- if(author === '' || author === null) continue;
- if (author in ticketsList) {
- var newTicket = {};
- newTicket['Issue ID'] = ticket['Issue ID'];
- newTicket['URL'] = ticket['URL'];
- newTicket['Title'] = ticket['Title'];
- newTicket['Description'] = ticket['Description'];
- newTicket['Created At (UTC)'] = ticket['Created At (UTC)'];
- newTicket['Updated At (UTC)'] = ticket['Updated At (UTC)'];
- newTicket['Labels'] = ticket['Labels'];
- ticketsList[author].push(newTicket);
- } else if (ticket['Issue ID']){
- var newTicket = {};
- newTicket['Issue ID'] = ticket['Issue ID'];
- newTicket['URL'] = ticket['URL'];
- newTicket['Title'] = ticket['Title'];
- newTicket['Description'] = ticket['Description'];
- newTicket['Created At (UTC)'] = ticket['Created At (UTC)'];
- newTicket['Updated At (UTC)'] = ticket['Updated At (UTC)'];
- newTicket['Labels'] = ticket['Labels'];
- ticketsList[author] = [newTicket];
- }
- }
- var resArr = Object.keys(ticketsList).map(function(key) {
- return [key, ticketsList[key]];
- });
- resArr.sort(function(f,s){
- return s[0] < f[0];
- });
- return resArr;
- }
- function writeTable(results){
- var tbl = $('#results');
- tbl.css('display','inline-block');
- var n = results.length;
- for(var i = 0;i<n;++i){
- var authorDiv = '<div id="' +results[i][0] + '">';
- var lbl = '<label id="' + results[i][0] +'-name">' + results[i][0] + '</label>';
- authorDiv += lbl;
- var tbl = '<table id="' + results[i][0] + '-results">';
- var header = '<thead>';
- var headerRow = '<tr>'
- headerRow += '<th>'+"Issue ID"+'</th>';
- headerRow += '<th>'+"URL"+'</th>';
- headerRow += '<th>'+"Title"+'</th>';
- headerRow += '<th>'+"Description"+'</th>';
- headerRow += '<th>'+"Created At (UTC)"+'</th>';
- headerRow += '<th>'+"Updated At (UTC)"+'</th>';
- headerRow += '<th>'+"Labels"+'</th>';
- headerRow += '</tr>';
- header += headerRow;
- header += '</thead>';
- tbl += header;
- tbd = '<tbody>';
- var nTickets = results[i][1].length;
- for(var j = 0; j < nTickets; j++){
- var row ='<tr>';
- row+='<td>'+results[i][1][j]['Issue ID']+'</td>';
- row+='<td>'+results[i][1][j]['URL']+'</td>';
- row+='<td>'+results[i][1][j]['Title']+'</td>';
- row+='<td>'+results[i][1][j]['Description']+'</td>';
- row+='<td>'+results[i][1][j]['Created At (UTC)']+'</td>';
- row+='<td>'+results[i][1][j]['Updated At (UTC)']+'</td>';
- row+='<td>'+results[i][1][j]['Labels']+'</td>';
- row+='</tr>';
- tbd+=row;
- }
- tbd+='</tbody>';
- tbl += tbd;
- tbl += '</table>';
- authorDiv += tbl;
- authorDiv += '</div> </br>';
- $('#results').append(authorDiv);
- }
- }
- function readFile(){
- var csv = $("#ticketFile").prop('files')[0];
- if (!csv) alert('insert a file');
- var inputData;
- resJson=[];
- Papa.parse(csv ,{
- header:true,
- dynamicTyping: false,
- complete: function(results) {
- inputData = results.data;
- writeTable(processTickets(inputData));
- }
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement