Skip to content

Commit

Permalink
Fix export to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
MJ12358 committed Jun 2, 2022
1 parent b4e8fde commit 6f2de09
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
8 changes: 0 additions & 8 deletions force-app/main/default/aura/.eslintrc.json

This file was deleted.

7 changes: 4 additions & 3 deletions force-app/main/default/classes/ResourceCalendarController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public with sharing class ResourceCalendarController {
List<ServiceResourceWrapper> results = new List<ServiceResourceWrapper>();

for (ServiceResource sr : [
SELECT Id, Name, FSL__GanttLabel__c, ResourceType,
SELECT Id, Name, FSL__GanttLabel__c, FSL__Picture_Link__c, ResourceType,
RelatedRecord.SmallPhotoUrl, RelatedRecord.Title
FROM ServiceResource
WHERE IsActive = true
Expand Down Expand Up @@ -126,6 +126,7 @@ public with sharing class ResourceCalendarController {

@RemoteAction
public static String exportToCsv(String json) {
// deserialize ourselves because remote action will utilize strict mode (we have props that dont exist in our class)
List<ServiceAppointmentWrapper> data = (List<ServiceAppointmentWrapper>)System.JSON.deserialize(json, List<ServiceAppointmentWrapper>.class);
CsvBuilder builder = new CsvBuilder();
for (ServiceAppointmentWrapper sa : data) {
Expand Down Expand Up @@ -199,10 +200,10 @@ public with sharing class ResourceCalendarController {
public ServiceResourceWrapper(ServiceResource sr) {
this.Id = sr.Id;
this.Name = sr.Name.normalizeSpace();
this.Photo = sr.RelatedRecord?.SmallPhotoUrl;
this.Photo = sr.FSL__Picture_Link__c != null ? sr.FSL__Picture_Link__c : sr.RelatedRecord?.SmallPhotoUrl;
this.Label = sr.FSL__GanttLabel__c != null
? sr.FSL__GanttLabel__c.normalizeSpace()
: (sr.RelatedRecord.Title != null ? sr.RelatedRecord.Title.normalizeSpace() : sr.ResourceType);
: (sr.RelatedRecord?.Title != null ? sr.RelatedRecord.Title.normalizeSpace() : sr.ResourceType);
}

public ServiceResourceWrapper(AssignedResource ar) {
Expand Down
12 changes: 9 additions & 3 deletions force-app/main/default/staticresources/ResourceCalendar/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
} else {
onFailure(event);
}
}
}, { escape: false }
);
},
failure: function(event) {
Expand Down Expand Up @@ -302,7 +302,7 @@
}

function onExportToCsv() {
let arr = CALENDAR.getEvents()
let data = CALENDAR.getEvents()
.filter(v => v.source.id === 'appointments')
.reduce((a, c) => {
// SF dosent like relationships sent back to it without proper formatting so just filter them out
Expand All @@ -311,10 +311,16 @@
return (typeof value === 'string' || typeof value === 'number');
})
);
// VF remoting cannot deserialize long to datetime
for (let [key, value] of Object.entries(r)) {
if (key.includes('Time')) {
r[key] = new Date(value).toISOString();
}
}
a.push(r);
return a;
}, []);
ResourceCalendarController.exportToCsv(JSON.stringify(arr), (result, event) => {
ResourceCalendarController.exportToCsv(JSON.stringify(data), (result, event) => {
if (event.status) {
let a = document.createElement('a');
// this does not work for lengthly csv's
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f2de09

Please sign in to comment.