({ scriptsLoaded: function(component, event, helper){ }, doInit : function(component, event, helper) { component.set("v.isLoading",true); component.set("v.addfilter",false); var getusertimezoneaction = component.get("c.getusertimezone"); getusertimezoneaction.setCallback(this,function(res){ if( res.getState() == 'SUCCESS' && res.getReturnValue() && res.getReturnValue() != null){ var usertimezonevalue = res.getReturnValue(); if(usertimezonevalue){ component.set("v.usertimezonevalue",usertimezonevalue); } var action = component.get("c.getListofLogs"); action.setCallback(this,function(Response){ var state = Response.getState(); var value = Response.getReturnValue(); // var value = JSON.parse('[{ "Id": "a0H2v00000jKuvzEAC", "Name": "Account", "CreatedDate": "2019-01-01T07:37:01.000Z", "LastModifiedDate": "2019-02-02T07:37:01.000Z", "HIC_ShopifySync__Shopify_Id__c": "Business 3004654256267", "HIC_ShopifySync__Error_id__c": "Business3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvkEAC", "Name": "Product2", "CreatedDate": "2019-02-01T07:36:35.000Z", "LastModifiedDate": "2019-03-01T07:36:35.000Z", "HIC_ShopifySync__Shopify_Id__c": "4416902398091", "HIC_ShopifySync__Error_id__c": "Business300465425626da7", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvlEAC", "Name": "HIC_ShopifySync__Variant__c", "CreatedDate": "2019-02-02T07:36:35.000Z", "LastModifiedDate": "2019-02-02T07:36:35.000Z", "HIC_ShopifySync__Shopify_Id__c": "31651809394827", "HIC_ShopifySync__Error_id__c": "Busiasdaness3004adad654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwoEAC", "Name": "OrderItem", "CreatedDate": "2020-01-01T07:37:48.000Z", "LastModifiedDate": "2020-02-03T07:37:48.000Z", "HIC_ShopifySync__Shopify_Id__c": "523105009803316518093948274416902398091", "HIC_ShopifySync__Error_id__c": "Business3004654256adasd267", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvvEAC", "Name": "Contact", "CreatedDate": "2021-01-03T07:36:59.000Z", "LastModifiedDate": "2021-04-03T07:36:59.000Z", "HIC_ShopifySync__Shopify_Id__c": "3008468058251", "HIC_ShopifySync__Error_id__c": "Business3004654256267sadah", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwiEAC", "Name": "Order", "CreatedDate": "2020-01-03T07:37:43.000Z", "LastModifiedDate": "2020-01-03T07:37:43.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731", "HIC_ShopifySync__Error_id__c": "Busineadsasss3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwjEAC", "Name": "OrderItem", "CreatedDate": "2020-01-03T07:37:45.000Z", "LastModifiedDate": "2020-01-03T07:37:45.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731316518037587314416899022987", "HIC_ShopifySync__Error_id__c": "Business300465425sda6267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwkEAC", "Name": "OrderItem", "CreatedDate": "2020-01-03T07:37:45.000Z", "LastModifiedDate": "2020-01-03T07:37:45.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731316518036931954416899022987", "HIC_ShopifySync__Error_id__c": "Business3004654256267", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwsEAC", "Name": "Opportunity", "CreatedDate": "2020-01-03T07:37:49.000Z", "LastModifiedDate": "2020-01-03T07:37:49.000Z", "HIC_ShopifySync__Shopify_Id__c": "523105140875", "HIC_ShopifySync__Error_id__c": "Businasdaess3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }]'); var objects = []; if(state == 'SUCCESS'){ if(value != null && value !== undefined && value.length> 0){ var today = $A.localizationService.formatDate(new Date(), "YYYY-MM-DD"); // var today= helper.getDatetimeasusertimezone((new Date()).toLocaleString(),usertimezonevalue) component.set('v.startdate',today ); for(var item in value ){ if(value[item]['HIC_ShopifySync__Error_id__c'] && value[item]['HIC_ShopifySync__Error_id__c'] != null ){ if( value[item]['HIC_ShopifySync__Error_id__c'].toString().includes("Delete")){ value[item]['HIC_ShopifySync__Error_id__c'] = true; }else{ value[item]['HIC_ShopifySync__Error_id__c'] = false; } } value[item]["HIC_ShopifySync__Info__c"] = value[item]["HIC_ShopifySync__Info__c"] + value[item]["HIC_ShopifySync__Second_Info__c"] + value[item]["HIC_ShopifySync__Third_Info__c"]; objects.push(value[item]['Name']); //value[item]["CreatedDate"] = helper.getDatetimeasusertimezone(component,value[item]["CreatedDate"],usertimezonevalue) //value[item]["LastModifiedDate"] = helper.getDatetimeasusertimezone(component,value[item]["LastModifiedDate"],usertimezonevalue); } component.set("v.lisoflogs",value); component.set("v.disablecsv",false); component.set("v.filteredData",value); component.set("v.searchdatalist",value); var setforobj = new Set(objects); var newobjects = Array.from(setforobj); component.set("v.listofobjects",newobjects); // component.set("v.isLoading",false); component.set('v.listofdata',value); var dataset = []; var innerlist = []; for(var inneritem in value){ innerlist = []; innerlist.push(value[inneritem]["Id"]); if(value[inneritem]["HIC_ShopifySync__Store__c"] && value[inneritem]["HIC_ShopifySync__Store__c"] != null && value[inneritem]["HIC_ShopifySync__Store__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Store__c"].toString()); }else{ innerlist.push('N/A'); } innerlist.push(value[inneritem]["Name"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Shopify_Id__c"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Is_Webhook__c"].toString()); if(value[inneritem]["HIC_ShopifySync__Info__c"] && value[inneritem]["HIC_ShopifySync__Info__c"] != null && value[inneritem]["HIC_ShopifySync__Info__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Info__c"].toString()); }else{ innerlist.push('NO JSON'); } var updatedcreatedate = helper.getDatetimeasusertimezone(component,value[inneritem]["CreatedDate"],usertimezonevalue); innerlist.push(updatedcreatedate); var updatedmodifieddate = helper.getDatetimeasusertimezone(component,value[inneritem]["LastModifiedDate"],usertimezonevalue); innerlist.push(updatedmodifieddate); value[inneritem]["CreatedDate"] = updatedcreatedate; value[inneritem]["LastModifiedDate"] = updatedmodifieddate; //innerlist.push($A.localizationService.formatDate(value[inneritem]["LastModifiedDate"], "MMM dd yyyy, hh:mm:ss a").toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Error_id__c"].toString()); dataset.push(innerlist); console.log("dataset"); console.log(dataset); } setTimeout(function(){ $('#tableId').DataTable({ "scrollX": true, "pageLength": 10, data: dataset, columns: [ { title: "Id" }, { title: "Store" }, { title: "Name" }, { title: "External Id" , render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Is Webhook", render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center" }, { title: "JSON", render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Created at" }, { title: "Modified at" }, { title: "Is Deleted" , render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center"}, { title: "View" } ], "columnDefs": [ { targets: 4, "searchable": false, "orderable": false, //render: $.fn.dataTable.render.ellipsis( 30, true ) },{ "targets": -1, "data": null, "defaultContent": "" }, { targets: 0, visible:false, "searchable": false, "orderable": false, render: $.fn.dataTable.render.ellipsis( 11, true ) } ], }); $('#tableId tbody').on( 'click', 'button', function () { var data = $('#tableId').DataTable().row( $(this).parents('tr') ).data(); window.open('/'+data[0],'_blank'); } ); // add lightning class to search filter field with some bottom margin.. $('div.dataTables_filter input').addClass('slds-input'); $('div.dataTables_filter input').css("marginBottom", "10px"); component.set("v.isLoading",false); }, 500); }else{ component.set("v.data",false); component.set("v.disablecsv",true); component.set("v.isLoading",false); } }else if (state === "INCOMPLETE") { console.log('in complete'); }else if (state === "ERROR") { var errors = Response.getError(); if (errors) { if (errors[0] && errors[0].message) { console.log("Error message: " + errors[0].message); } } else { console.log("Unknown error"); } } }); $A.enqueueAction(action); } }); $A.enqueueAction(getusertimezoneaction); }, refreshlist: function(component, event, helper){ //return; component.set("v.addfilter",false); component.set("v.isLoading",true); var table = $('#tableId').DataTable(); table.clear().draw(); table.destroy(); var action = component.get('c.doInit'); $A.enqueueAction(action); }, refreshlistold: function(component, event, helper){ component.set("v.addfilter",false); // component.set("v.filteredData",null); var action = component.get("c.getListofLogs"); component.set("v.isLoading",true); action.setCallback(this,function(Response){ var value = Response.getReturnValue(); //value = JSON.parse('[{ "Id": "a0H2v00000jKuvzEAC", "Name": "Account", "CreatedDate": "2019-01-01T07:37:01.000Z", "LastModifiedDate": "2019-02-02T07:37:01.000Z", "HIC_ShopifySync__Shopify_Id__c": "Business 3004654256267", "HIC_ShopifySync__Error_id__c": "Business3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvkEAC", "Name": "Product2", "CreatedDate": "2019-02-01T07:36:35.000Z", "LastModifiedDate": "2019-03-01T07:36:35.000Z", "HIC_ShopifySync__Shopify_Id__c": "4416902398091", "HIC_ShopifySync__Error_id__c": "Business300465425626da7", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvlEAC", "Name": "HIC_ShopifySync__Variant__c", "CreatedDate": "2019-02-02T07:36:35.000Z", "LastModifiedDate": "2019-02-02T07:36:35.000Z", "HIC_ShopifySync__Shopify_Id__c": "31651809394827", "HIC_ShopifySync__Error_id__c": "Busiasdaness3004adad654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwoEAC", "Name": "OrderItem", "CreatedDate": "2020-01-01T07:37:48.000Z", "LastModifiedDate": "2020-02-03T07:37:48.000Z", "HIC_ShopifySync__Shopify_Id__c": "523105009803316518093948274416902398091", "HIC_ShopifySync__Error_id__c": "Business3004654256adasd267", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuvvEAC", "Name": "Contact", "CreatedDate": "2021-01-03T07:36:59.000Z", "LastModifiedDate": "2021-04-03T07:36:59.000Z", "HIC_ShopifySync__Shopify_Id__c": "3008468058251", "HIC_ShopifySync__Error_id__c": "Business3004654256267sadah", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwiEAC", "Name": "Order", "CreatedDate": "2020-01-03T07:37:43.000Z", "LastModifiedDate": "2020-01-03T07:37:43.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731", "HIC_ShopifySync__Error_id__c": "Busineadsasss3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwjEAC", "Name": "OrderItem", "CreatedDate": "2020-01-03T07:37:45.000Z", "LastModifiedDate": "2020-01-03T07:37:45.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731316518037587314416899022987", "HIC_ShopifySync__Error_id__c": "Business300465425sda6267-Delete", "HIC_ShopifySync__Is_Webhook__c": false, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwkEAC", "Name": "OrderItem", "CreatedDate": "2020-01-03T07:37:45.000Z", "LastModifiedDate": "2020-01-03T07:37:45.000Z", "HIC_ShopifySync__Shopify_Id__c": "523104878731316518036931954416899022987", "HIC_ShopifySync__Error_id__c": "Business3004654256267", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }, { "Id": "a0H2v00000jKuwsEAC", "Name": "Opportunity", "CreatedDate": "2020-01-03T07:37:49.000Z", "LastModifiedDate": "2020-01-03T07:37:49.000Z", "HIC_ShopifySync__Shopify_Id__c": "523105140875", "HIC_ShopifySync__Error_id__c": "Businasdaess3004654256267-Delete", "HIC_ShopifySync__Is_Webhook__c": true, "HIC_ShopifySync__Info__c": "JSONBODY" }]'); var objects = []; if(Response.getState() == 'SUCCESS'){ if(value != null && value !== undefined && value.length> 0){ for(var item in value ){ if( value[item]['HIC_ShopifySync__Error_id__c'].toString().includes("Delete")){ value[item]['HIC_ShopifySync__Error_id__c'] = true; }else{ value[item]['HIC_ShopifySync__Error_id__c'] = false; } objects.push(value[item]['Name']); } component.set("v.lisoflogs",value); component.set("v.disablecsv",false); component.set("v.filteredData",value); component.set("v.searchdatalist",value); var setforobj = new Set(objects); var newobjects = Array.from(setforobj); component.set("v.listofobjects",newobjects); component.set("v.addfilter",false); var table = $('#tableId').DataTable(); table.clear().draw(); table.destroy(); setTimeout(function(){ $('#tableId').DataTable({ "scrollX": true, "pageLength": 10, data: value, columns: [ { title: "Id" }, { title: "Store" }, { title: "Name" }, { title: "Shopify id" }, { title: "Is Webhook" }, { title: "JSON" }, { title: "Created at" }, { title: "Modified at" }, { title: "View" } ], }); // add lightning class to search filter field with some bottom margin.. $('div.dataTables_filter input').addClass('slds-input'); $('div.dataTables_filter input').css("marginBottom", "10px"); component.set("v.isLoading",false); }, 500); }else{ component.set("v.data",false); component.set("v.disablecsv",true); } } }); $A.enqueueAction(action); }, downloadCsv : function(component, event, helper) { try{ component.set("v.OpenModel",true); // get the Records [contact] list from 'ListOfContact' attribute var stockData = component.get("v.filteredData"); setTimeout(function(){ // call the helper function which "return" the CSV data as a String var csv = helper.convertArrayOfObjectsToCSV(component,stockData); if (csv == null || csv == undefined || csv == '' ){return;} /* var hiddenElement = document.createElement('a'); hiddenElement.setAttribute('id','csvid'); hiddenElement.setAttribute( 'href', 'data:text/csv;charset=utf-8,' + encodeURI(csv) ); hiddenElement.setAttribute('target','_blank'); hiddenElement.setAttribute('download', 'ExportData.csv'); document.body.appendChild(hiddenElement); hiddenElement.click();*/ var link = document.createElement('a'); var blob = new Blob(["\ufeff", csv]); var url = URL.createObjectURL(blob); // link.href = url; link.setAttribute( 'href', url ); link.setAttribute('download', 'Shopifymadeeasylogs.csv'); link.click(); component.set("v.OpenModel",false); },5000); }catch(e){ console.log('error'); console.log(e); } }, handleRowAction: function(component, event, helper) { /* console.log(event.getSource().get("v.value")); window.open('/'+event.getSource().get("v.value"),'_blank');*/ }, updateColumnSorting: function (component , event, helper) { var fieldName = event.getParam('fieldName'); var sortDirection = event.getParam('sortDirection'); // assign the latest attribute with the sorted column fieldName and sorted direction component .set("v.sortedBy", fieldName); component .set("v.sortedDirection", sortDirection); helper.sortData(component , fieldName, sortDirection); }, SercherFunction : function(component ,event,helper){ component.set("v.isLoading",true); var searchFilter = event.getSource().get("v.value").toUpperCase().trim(); /*if(searchFilter === undefined || searchFilter == null || searchFilter == '' ) { var action = component .get("c.handlefiter"); console.log('action '+action); $A.enqueueAction(action); return; }*/ /* var searchFilter = event.getSource().get("v.value"); searchFilter = searchFilter.toUpperCase(); var allRecords = component .get("v.filteredData"); var i; var tempArray = []; for(i=0; i < allRecords.length; i++){ if((allRecords[i].HIC_ShopifySync__Shopify_Id__c && allRecords[i].HIC_ShopifySync__Shopify_Id__c.toUpperCase().indexOf(searchFilter) != -1) || (allRecords[i].Name && allRecords[i].Name.toUpperCase().indexOf(searchFilter) != -1 ) ) { tempArray.push(allRecords[i]); } } console.log('tempArray '+tempArray); if(tempArray && tempArray.length > 0){ component .set("v.data",true); component .set("v.filteredData",tempArray); }else{ component .set("v.data",false); }*/ var allRecords = component .get("v.searchdatalist"); var tempArray = []; var i; for(i=0; i < allRecords.length; i++){ if((allRecords[i].HIC_ShopifySync__Shopify_Id__c && allRecords[i].HIC_ShopifySync__Shopify_Id__c.toUpperCase().indexOf(searchFilter) != -1) || (allRecords[i].Name && allRecords[i].Name.toUpperCase().indexOf(searchFilter) != -1 ) ) { tempArray.push(allRecords[i]); } } if(tempArray && tempArray.length > 0){ component .set("v.data",true); component .set("v.filteredData",tempArray); component .set("v.disablecsv",false); }else{ component .set("v.data",false); component .set("v.disablecsv",true); } //} }, handleaddfilter : function(component,event,helper){ try{ component.set("v.isLoading",true); if( component.get("v.lisoflogs") == undefined || component.get("v.lisoflogs") == null || component.get("v.lisoflogs") == '' || !component.get("v.lisoflogs").length > 0 ){ component.set("v.addfilter",false); component.set("v.isLoading",false); return; } var addfiler = event.getSource().get("v.checked"); if(addfiler){ var action = component.get("c.handlefiter"); $A.enqueueAction(action); }else{ var value = component.get("v.lisoflogs"); if(value !== undefined && value !== null && value.length > 0 ){ component.set("v.disablecsv",false); } component.set("v.filteredData",value); component.set("v.searchdatalist",value); component.set("v.data",true); var table = $('#tableId').DataTable(); table.clear().draw(); table.destroy(); var dataset = []; var innerlist = []; var usertimezonevalue = component.get("v.usertimezonevalue"); for(var inneritem in value){ innerlist = []; innerlist.push(value[inneritem]["Id"]); if(value[inneritem]["HIC_ShopifySync__Store__c"] && value[inneritem]["HIC_ShopifySync__Store__c"] != null && value[inneritem]["HIC_ShopifySync__Store__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Store__c"].toString()); }else{ innerlist.push('N/A'); } innerlist.push(value[inneritem]["Name"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Shopify_Id__c"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Is_Webhook__c"].toString()); if(value[inneritem]["HIC_ShopifySync__Info__c"] && value[inneritem]["HIC_ShopifySync__Info__c"] != null && value[inneritem]["HIC_ShopifySync__Info__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Info__c"].toString()); }else{ innerlist.push('NO JSON'); } /* var updatedcreatedate = helper.getDatetimeasusertimezone(component,value[inneritem]["CreatedDate"],usertimezonevalue); innerlist.push(updatedcreatedate); var updatedmodifieddate = helper.getDatetimeasusertimezone(component,value[inneritem]["LastModifiedDate"],usertimezonevalue); innerlist.push(updatedmodifieddate); value[inneritem]["CreatedDate"] = updatedcreatedate; value[inneritem]["LastModifiedDate"] = updatedmodifieddate; */ innerlist.push(value[inneritem]["CreatedDate"]); innerlist.push(value[inneritem]["LastModifiedDate"]); innerlist.push(value[inneritem]["HIC_ShopifySync__Error_id__c"].toString()); dataset.push(innerlist); } setTimeout(function(){ $('#tableId').DataTable({ "scrollX": true, "pageLength": 10, data: dataset, columns: [ { title: "Id" }, { title: "Store" }, { title: "Name" }, { title: "External Id" , render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Is Webhook", render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center" }, { title: "JSON", render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Created at" }, { title: "Modified at" }, { title: "Is Deleted" , render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center"}, { title: "View" } ], "columnDefs": [ { targets: 4, "searchable": false, "orderable": false, //render: $.fn.dataTable.render.ellipsis( 30, true ) },{ "targets": -1, "data": null, "defaultContent": "" }, { targets: 0, visible:false, "searchable": false, "orderable": false, render: $.fn.dataTable.render.ellipsis( 11, true ) } ], }); $('#tableId tbody').on( 'click', 'button', function () { var data = $('#tableId').DataTable().row( $(this).parents('tr') ).data(); window.open('/'+data[0],'_blank'); } ); // add lightning class to search filter field with some bottom margin.. $('div.dataTables_filter input').addClass('slds-input'); $('div.dataTables_filter input').css("marginBottom", "10px"); component.set("v.isLoading",false); }, 500); } // component.find("SearchBox").set("v.value",""); }catch(e){ console.log(e); } }, handlefiter : function(component ,event,helper) { component .set("v.isLoading",true) var searchFilter; var labelvalue; var allRecords = component .get("v.lisoflogs"); try{ searchFilter = event.getSource().get("v.value"); labelvalue = event.getSource().get("v.label"); }catch(e){ } if(labelvalue !== undefined && labelvalue != null & labelvalue != '' && labelvalue == 'Type'){ allRecords = component .get("v.lisoflogs"); } var tempArray = []; var i; var firstfilter = []; var Secondfilterlist =[]; var thirdfilter; var selectedobject = component .get("v.selectedobject").toUpperCase(); var store = component.get("v.isstore"); var selectedtype = component .get("v.iswebhook").toUpperCase(); var startdate = component.get("v.startdate"); var Iscreateddate = component .get("v.Iscreateddate"); if(startdate === undefined || startdate == null || startdate == ''){ component .find('startdate').showHelpMessageIfInvalid(); return; } if(selectedobject == 'ALL' && selectedtype == 'ALL'){ //tempArray = allRecords; for(i=0; i < allRecords.length; i++){ if(Iscreateddate == 'true' || Iscreateddate == true){ if( $A.localizationService.formatDate(allRecords[i].CreatedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( $A.localizationService.formatDate(allRecords[i].LastModifiedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } } } } if(selectedobject !== 'ALL' && selectedtype !== 'ALL'){ var valboth = (selectedtype === "TRUE"); for(i=0; i < allRecords.length; i++){ if((allRecords[i].Name && allRecords[i].Name.toUpperCase().indexOf(selectedobject) != -1 && allRecords[i].Name.toUpperCase() == selectedobject.toUpperCase()) && ((allRecords[i].HIC_ShopifySync__Is_Webhook__c === valboth && selectedtype != 'DELETE') || (selectedtype == 'DELETE' && (allRecords[i].HIC_ShopifySync__Error_id__c))) ) { if(Iscreateddate == 'true' || Iscreateddate == true){ if(allRecords[i].CreatedDate && $A.localizationService.formatDate(allRecords[i].CreatedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( allRecords[i].LastModifiedDate && $A.localizationService.formatDate(allRecords[i].LastModifiedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } } /* if(allRecords[i].HIC_ShopifySync__Is_Webhook__c === valboth && selectedtype != 'DELETE'){ if(Iscreateddate == 'true' || Iscreateddate == true){ if(allRecords[i].CreatedDate && allRecords[i].CreatedDate >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( allRecords[i].LastModifiedDate && allRecords[i].LastModifiedDate >= startdate ){ tempArray.push(allRecords[i]); } } }else if(selectedtype == 'DELETE' && (allRecords[i].HIC_ShopifySync__Error_id__c && allRecords[i].HIC_ShopifySync__Error_id__c.toUpperCase().indexOf(selectedtype) != -1)){ if(Iscreateddate == 'true' || Iscreateddate == true){ if(allRecords[i].CreatedDate && allRecords[i].CreatedDate >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( allRecords[i].LastModifiedDate && allRecords[i].LastModifiedDate >= startdate ){ tempArray.push(allRecords[i]); } } }*/ } } } if(selectedobject == 'ALL' && selectedtype !== 'ALL'){ var val = (selectedtype == "TRUE"); for(i=0; i < allRecords.length; i++){ if(((allRecords[i].HIC_ShopifySync__Is_Webhook__c === val && selectedtype != 'DELETE') || (selectedtype == 'DELETE' && (allRecords[i].HIC_ShopifySync__Error_id__c))) ) { // tempArray.push(allRecords[i]); if(Iscreateddate == 'true' || Iscreateddate == true){ if(allRecords[i].CreatedDate && $A.localizationService.formatDate(allRecords[i].CreatedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( allRecords[i].LastModifiedDate && $A.localizationService.formatDate(allRecords[i].LastModifiedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } } } } } if(selectedobject !== 'ALL' && selectedtype == 'ALL'){ for(i=0; i < allRecords.length; i++){ if((allRecords[i].Name && allRecords[i].Name.toUpperCase().indexOf(selectedobject) != -1) && allRecords[i].Name.toUpperCase() == selectedobject.toUpperCase() ) { // tempArray.push(allRecords[i]); if(Iscreateddate == 'true' || Iscreateddate == true){ if(allRecords[i].CreatedDate && $A.localizationService.formatDate(allRecords[i].CreatedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } }else{ if( allRecords[i].LastModifiedDate && $A.localizationService.formatDate(allRecords[i].LastModifiedDate, "YYYY-MM-DD") >= startdate ){ tempArray.push(allRecords[i]); } } } } } if(tempArray && tempArray.length > 0){ component .set("v.data",true); component .set("v.filteredData",tempArray); component .set("v.searchdatalist",tempArray); component .set("v.disablecsv",false); var table = $('#tableId').DataTable(); table.clear().draw(); table.destroy(); var value = tempArray; var dataset = []; var innerlist = []; var usertimezonevalue = component.get("v.usertimezonevalue"); for(var inneritem in value){ innerlist = []; innerlist.push(value[inneritem]["Id"]); if(value[inneritem]["HIC_ShopifySync__Store__c"] && value[inneritem]["HIC_ShopifySync__Store__c"] != null && value[inneritem]["HIC_ShopifySync__Store__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Store__c"].toString()); }else{ innerlist.push('N/A'); } innerlist.push(value[inneritem]["Name"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Shopify_Id__c"].toString()); innerlist.push(value[inneritem]["HIC_ShopifySync__Is_Webhook__c"].toString()); if(value[inneritem]["HIC_ShopifySync__Info__c"] && value[inneritem]["HIC_ShopifySync__Info__c"] != null && value[inneritem]["HIC_ShopifySync__Info__c"] != '' ) { innerlist.push(value[inneritem]["HIC_ShopifySync__Info__c"].toString()); }else{ innerlist.push('NO JSON'); } //innerlist.push($A.localizationService.formatDate(value[inneritem]["CreatedDate"], "MMM dd yyyy, hh:mm:ss a").toString()); /* var updatedcreatedate = helper.getDatetimeasusertimezone(component,value[inneritem]["CreatedDate"],usertimezonevalue); innerlist.push(updatedcreatedate); var updatedmodifieddate = helper.getDatetimeasusertimezone(component,value[inneritem]["LastModifiedDate"],usertimezonevalue); innerlist.push(updatedmodifieddate); value[inneritem]["CreatedDate"] = updatedcreatedate; value[inneritem]["LastModifiedDate"] = updatedmodifieddate;*/ innerlist.push(value[inneritem]["CreatedDate"]); innerlist.push(value[inneritem]["LastModifiedDate"]); innerlist.push(value[inneritem]["HIC_ShopifySync__Error_id__c"].toString()); dataset.push(innerlist); } setTimeout(function(){ $('#tableId').DataTable({ "scrollX": true, "pageLength": 10, data: dataset, columns: [ { title: "Id" }, { title: "Store" }, { title: "Name" }, { title: "External Id" , render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Is Webhook", render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center" }, { title: "JSON", render: function ( data, type, row ) { return '

'+data+'

'; }, }, { title: "Created at" }, { title: "Modified at" }, { title: "Is Deleted" , render: function ( data, type, row ) { if(data == 'true'){ return ''; }else{ return ''; } }, className: "dt-body-center"}, { title: "View" } ], "columnDefs": [ { targets: 4, "searchable": false, "orderable": false, //render: $.fn.dataTable.render.ellipsis( 30, true ) },{ "targets": -1, "data": null, "defaultContent": "" }, { targets: 0, visible:false, "searchable": false, "orderable": false, render: $.fn.dataTable.render.ellipsis( 11, true ) } ], }); $('#tableId tbody').on( 'click', 'button', function () { var data = $('#tableId').DataTable().row( $(this).parents('tr') ).data(); window.open('/'+data[0],'_blank'); } ); // add lightning class to search filter field with some bottom margin.. $('div.dataTables_filter input').addClass('slds-input'); $('div.dataTables_filter input').css("marginBottom", "10px"); component.set("v.isLoading",false); }, 500); }else{ component .set("v.isLoading",false) component .set("v.data",false); component .set("v.disablecsv",true); } } })