Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updates #7

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"**/bower_components": true,
"**/.sfdx": true
}
}
}
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,3 @@ this.event('eventmouseenter', info)
```





10 changes: 5 additions & 5 deletions config/project-scratch-def.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"features": [],
"settings": {
"lightningExperienceSettings": {
"enableS1DesktopEnabled": true
"enableS1DesktopEnabled": true
},
"securitySettings": {
"passwordPolicies": {
"enableSetPasswordInApi": true
}
"passwordPolicies": {
"enableSetPasswordInApi": true
}
},
"mobileSettings": {
"enableS1EncryptedStoragePref2": false
"enableS1EncryptedStoragePref2": false
}
}
}
34 changes: 34 additions & 0 deletions force-app/main/default/classes/CustomCalendarHelper.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public with sharing class CustomCalendarHelper {

@AuraEnabled
public static List<sObject> getEvents(
String recordId,
String childObject,
String parentFieldName,
String startDatetimeField,
String endDatetimeField,
Date startDate,
Date endDate) {

if (
recordId == null ||
childObject == null ||
parentFieldName == null ||
startDatetimeField == null ||
endDatetimeField == null
) {
throw new AuraHandledException('Missing Config');
}

DateTime startDateTime = DateTime.newInstance(startDate.year(), startDate.month(), startDate.day());
DateTime endDateTime = DateTime.newInstance(endDate.year(), endDate.month(), endDate.day());

String query = 'SELECT Id, Name, ' + startDatetimeField + ', ' + endDatetimeField;
query += ' FROM ' + childObject;
query += ' WHERE ' + parentFieldName + ' = ' + '\'' + recordId +'\'';
query += ' AND ' + startDatetimeField + ' >= : startDateTime';
query += ' AND ' + endDatetimeField + ' <= : endDateTime';
system.debug(query);
return Database.query(query);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<status>Active</status>
</ApexClass>
37 changes: 37 additions & 0 deletions force-app/main/default/classes/CustomPicklist.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
global with sharing class CustomPicklist extends VisualEditor.DynamicPickList {

global override VisualEditor.DataRow getDefaultValue(){
VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('Account', 'Account');
return defaultValue;
}

global override VisualEditor.DynamicPickListRows getValues() {
VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows();

for (Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values()) {
String apiName = objTyp.getDescribe().getName();
String label = objTyp.getDescribe().getLabel();

//Exclude all the unwanted Sobjects e.g. History, Share etc
if (apiName.toLowerCase().right(3) == '__c') {
VisualEditor.DataRow val = new VisualEditor.DataRow(label, apiName);
myValues.addRow(val);

System.debug( 'label : ' + label);
System.debug( 'apiName : ' + apiName);

continue;
}
if (!apiName.containsignorecase('history') &&
!apiName.containsignorecase('tag') &&
!apiName.containsignorecase('share') &&
!apiName.containsignorecase('feed')) {

VisualEditor.DataRow val = new VisualEditor.DataRow(label, apiName);
myValues.addRow(val);
}

}
return myValues;
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/CustomPicklist.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<status>Active</status>
</ApexClass>
10 changes: 10 additions & 0 deletions force-app/main/default/classes/CustomPicklistTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@isTest
public with sharing class CustomPicklistTest {

@isTest
private static void picklistTest() {
CustomPicklist cp = new CustomPicklist();
cp.getDefaultValue();
cp.getValues();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>55.0</apiVersion>
<status>Active</status>
</ApexClass>
24 changes: 9 additions & 15 deletions force-app/main/default/lwc/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { api, LightningElement } from 'lwc';
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import fullCalendar from "@salesforce/resourceUrl/fullCalendar";
import { loadStyle, loadScript } from "lightning/platformResourceLoader";
import { formatShifts, jsToApexDate, invertColor, msToHMS} from './utils'
import { jsToApexDate, invertColor, msToHMS} from './utils'
export default class Calendar extends LightningElement {

calendarLabel = ''
Expand Down Expand Up @@ -42,7 +42,7 @@ export default class Calendar extends LightningElement {
])

//create calendar and render
await this.init()
this.init()

} catch (error) {

Expand Down Expand Up @@ -75,6 +75,7 @@ export default class Calendar extends LightningElement {
initialView: 'dayGridMonth',
header: false,
events: [],
editable: true,
eventRendering : 'list-item',
// eventOrder: function(a, b) {
// if (a.slotSort < b.slotSort) {
Expand All @@ -83,15 +84,11 @@ export default class Calendar extends LightningElement {
// return 1
// }
// },
eventClick: info => {
this.event('fceventclick', info)
},
eventMouseEnter: info => {
this.event('eventmouseenter', info)
},
dateClick: info => {
this.event('fcdateclick', info)
},

eventDrop: info => { console.log('event drag start', info) },
eventClick: info => { this.event('fceventclick', info) },
eventMouseEnter: info => {console.log("mouse enter", info) },
dateClick: info => { this.event('fcdateclick', info) },
});

console.log(this.calendar)
Expand All @@ -103,8 +100,6 @@ export default class Calendar extends LightningElement {
let endDate = jsToApexDate(this.calendar.view.activeEnd)

this.event('datechange', { startDate, endDate })
// this.calenderRendered = true
// this.handleDates(this.calendar)
}

refresh() {
Expand All @@ -116,8 +111,7 @@ export default class Calendar extends LightningElement {
const postedEvents = this.calendar.getEvents()
postedEvents.forEach(event => event.remove())

const formattedEvents = formatShifts(events)
formattedEvents.forEach(event => this.calendar.addEvent(event))
events.forEach(event => this.calendar.addEvent(event))
}

setDates() {
Expand Down
111 changes: 56 additions & 55 deletions force-app/main/default/lwc/calendar/utils.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,62 @@
const formatShifts = (shifts) => {
const invertColor = (hex = "#FFFFFF", bw) => {
if (hex.indexOf("#") === 0) {
hex = hex.slice(1);
}
// convert 3-digit hex to 6-digits.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
if (hex.length !== 6) {
throw new Error("Invalid HEX color.");
}
let r = parseInt(hex.slice(0, 2), 16),
g = parseInt(hex.slice(2, 4), 16),
b = parseInt(hex.slice(4, 6), 16);
if (bw) {
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? "#000000" : "#FFFFFF";
}
// invert color components
r = (255 - r).toString(16);
g = (255 - g).toString(16);
b = (255 - b).toString(16);
// pad each with zeros and return
return "#" + padZero(r) + padZero(g) + padZero(b);
};

const invertColor = (hex = '#FFFFFF', bw) => {
if (hex.indexOf('#') === 0) {
hex = hex.slice(1);
}
// convert 3-digit hex to 6-digits.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
if (hex.length !== 6) {
throw new Error('Invalid HEX color.');
}
let r = parseInt(hex.slice(0, 2), 16),
g = parseInt(hex.slice(2, 4), 16),
b = parseInt(hex.slice(4, 6), 16);
if (bw) {
return (r * 0.299 + g * 0.587 + b * 0.114) > 186 ? '#000000' : '#FFFFFF';
}
// invert color components
r = (255 - r).toString(16);
g = (255 - g).toString(16);
b = (255 - b).toString(16);
// pad each with zeros and return
return "#" + padZero(r) + padZero(g) + padZero(b);
}

const msToHMS = (duration) => {
let seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);

hours = (hours < 10) ? "0" + hours : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

return hours + ":" + minutes + ":" + seconds ;
}
const msToHMS = (duration) => {
let seconds = Math.floor((duration / 1000) % 60),
minutes = Math.floor((duration / (1000 * 60)) % 60),
hours = Math.floor((duration / (1000 * 60 * 60)) % 24);

return shifts.map(shift => {
shift.id = shift.Id
shift.status = shift.Shift_Status__c
shift.title = `${shift.Facility_1__r?.Name || ''}-${shift?.Name}`
shift.start = `${shift.Date__c}T${msToHMS(shift.Scheduled_Start__c)}`
shift.end = `${shift.Date__c}T${msToHMS(shift.Scheduled_End__c)}`
shift.textColor = invertColor(shift?.Color__c, true)
shift.borderColor = shift.Color__c
shift.backgroundColor = shift.Color__c
return shift
})
}
hours = hours < 10 ? "0" + hours : hours;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

const jsToApexDate = (date) => {
const year = date.getFullYear()
const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
return `${year}-${month}-${day}`
}
return hours + ":" + minutes + ":" + seconds;
};

return shifts.map((shift) => {
shift.id = shift.Id;
shift.status = shift.Shift_Status__c;
shift.title = `${shift.Facility_1__r?.Name || ""}-${shift?.Name}`;
shift.start = `${shift.Date__c}T${msToHMS(shift.Scheduled_Start__c)}`;
shift.end = `${shift.Date__c}T${msToHMS(shift.Scheduled_End__c)}`;
shift.textColor = invertColor(shift?.Color__c, true);
shift.borderColor = shift.Color__c;
shift.backgroundColor = shift.Color__c;
return shift;
});
};

const jsToApexDate = (date) => {
const year = date.getFullYear();
const month =
date.getMonth() + 1 < 10
? "0" + (date.getMonth() + 1)
: date.getMonth() + 1;
const day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return `${year}-${month}-${day}`;
};

export { formatShifts, jsToApexDate }
export { formatShifts, jsToApexDate };
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createElement } from "lwc";
import CustomCalendar from "c/customCalendar";

describe("c-custom-calendar", () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it("TODO: test case generated by CLI command, please fill in test logic", () => {
// Arrange
const element = createElement("c-custom-calendar", {
is: CustomCalendar
});

// Act
document.body.appendChild(element);

// Assert
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});
11 changes: 11 additions & 0 deletions force-app/main/default/lwc/customCalendar/customCalendar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
recordId {recordId} <br />
childObject {childObject} <br />
parentFieldName {parentFieldName} <br />
startDatetimeField {startDatetimeField} <br />
endDatetimeField {endDatetimeField} <br />

<c-calendar
ondatechange={handleDateChange}
></c-calendar>
</template>
Loading