Members

1

Trips

1
var currentPage = 1; var pageLimit = 30; var ridesGrid = $('#ridesTable'); ridesGrid.text('Please wait...'); var csvRidesDownload; var rideColumnTitles = []; var options = { enableCellNavigation: true, enableTextSelectionOnCells: true, autoEdit: false, }; var pluginOptions = { readOnlyMode: false, includeHeaderWhenCopying: false, }; function getRides() { $('.btn-rides-prev').prop('disabled', true); $('.btn-rides-next').prop('disabled', true); $.get(`${serverDomain}/rides?partnerId=${partnerId}&fields=createdAt,firstName,lastName,distance,duration,status,startLocation,endLocation,driverName,car,gogoCost,customerCost,customerCredits,partnerCost,partnerCredits&limit=${pageLimit}&offset=${(currentPage - 1) * pageLimit}`) .done(function(rides){ var ride = rides[0]; rideColumnTitles = [] //Column Titles rideColumnTitles.push({ id: "selector", name: "Num", //first column is numbering field: "num", width: 30 }); var num = 0; for (var key in ride) { num++; rideColumnTitles.push({ id: num, name: key, field: key, }); //copy names for headers in csv } //Custom Column Names const columnSettings = [ {field: 'createdAt', name: 'Trip Date', width: 300}, {field: 'phoneNumber', name: 'Phone Number'}, {field: 'startLocation', name: 'Start Location', width: 300}, {field: 'endLocation', name: 'End Location', width: 300}, {field: 'riderPhone', name: 'Ride Phone Number'}, {field: 'vendor', name: 'Ride Vendor'}, {field: 'dummyId', name: 'Corp Account Id'}, {field: 'eta', name: 'ETA'}, {field: 'timeStamp', name: 'Date and Time (UTC)', width: 175}, {field: 'totalFare', name: 'Vendor Total Fare'}, {field: 'gogoRevenue', name: 'GoGoGrandparent Concierge Fee'}, {field: 'gogoCost', name: 'Total Fare'}, ]; // First Column = numbering for (var i = 0; i < rides.length; i++) { rides[i]["num"] = (currentPage - 1) * pageLimit + i + 1; } var headers = {}; rideColumnTitles.forEach(function(columnTitle) { var columnSetting = columnSettings.find(function(ele){ return ele.field === columnTitle.field; }); // Custom Name var customName = columnSetting && columnSetting.name; var columnName = customName ? customName : _.startCase(columnTitle.name); //Use custom name or title case columnTitle.name = columnName; // Custom Width var columnWidth = columnSetting && columnSetting.width; if (columnWidth) { columnTitle.width = columnWidth; } headers[columnTitle.field] = columnName; // for csv download, title row }); // Setup Grid var grid = new Slick.Grid("#ridesTable", rides, rideColumnTitles, options); grid.setSelectionModel(new Slick.CellSelectionModel()); // Set keyboard focus on the grid grid.getCanvasNode().focus(); grid.registerPlugin(new Slick.CellExternalCopyManager(pluginOptions)); // CSV download csvRidesDownload = JSON.parse(JSON.stringify(rides)); //clone json csvRidesDownload.unshift(headers); //add headers $('.btn-rides-prev').prop('disabled', false); $('.btn-rides-next').prop('disabled', false); if (currentPage === 1) { $('.btn-rides-prev').prop('disabled', true); } if (rides.length < pageLimit) { $('.btn-rides-next').prop('disabled', true); } }) .fail(function(xhr, status, errorThrown ) { console.log('Error: ' + errorThrown); console.log('Status: ' + status); console.dir(xhr); var res = xhr && xhr.responseJSON; var code = res && res.code || 'error'; var message = res && res.message || 'error'; ridesGrid.text(res.code + ': ' + res.message); $('.btn-rides-prev').prop('disabled', false); $('.btn-rides-next').prop('disabled', false); if (currentPage === 1) { $('.btn-rides-prev').prop('disabled', true); } if (rides.length < pageLimit) { $('.btn-rides-next').prop('disabled', true); } }); } function DownloadRidesJSON2CSV(){ var objArray = csvRidesDownload; var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray; var str = ''; for (var i = 0; i < array.length; i++) { var line = ''; for (var j = 0; j < rideColumnTitles.length; j++) { // need to use rideColumnTitles because: ex. homeNote = '', that field is not even retrieved and so it's not even in array[i] var index = rideColumnTitles[j].field; var prop = array[i][index]; if (line !== '') { // this is for so we don't create an empty first column line += ','; } line += '"' + prop + '"'; // wrap everything in quotations to specify it together (takes into account commas) } str += line + '\r\n'; } if (navigator.appName != 'Microsoft Internet Explorer'){ window.open('data:text/csv;charset=utf-8,' + escape(str)); } else { var popup = window.open('','csv',''); popup.document.body.innerHTML = '
' + str + '
'; } } function prevRidesPage() { currentPage--; $(".ride-page-number").text(currentPage); this.getRides(); } function nextRidesPage() { currentPage++; $(".ride-page-number").text(currentPage); this.getRides(); } this.getRides();
1