IEEE.org
|
IEEE Xplore Digital Library
|
IEEE Standards
|
IEEE Spectrum
|
More Sites
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Open at RIT
My Conservation Life
Conservation360
Commits
08e0edc8
Unverified
Commit
08e0edc8
authored
Apr 06, 2020
by
tilley14
Committed by
GitHub
Apr 06, 2020
Browse files
Donor code front end (#97)
parent
0bfe343a
Changes
8
Hide whitespace changes
Inline
Side-by-side
salesforce/my-conservation-life/force-app/main/default/classes/DonorCodeController.cls
0 → 100644
View file @
08e0edc8
/**
* The DonorCodeController queries Salesforce for Donations
*/
public
with
sharing
class
DonorCodeController
{
@AuraEnabled(
cacheable
=
true
)
public
static
List
<
Donation__c
>
getAllDonorCodes
()
{
return
[
SELECT
Donor__r
.
Name
,
Donation_Code__c
,
Amount__c
FROM
Donation__c
];
}
@AuraEnabled(
cacheable
=
true
)
public
static
List
<
Donation__c
>
getCurrentUsersDonations
()
{
String
userId
=
UserInfo
.
getUserId
();
if
(
userId
==
null
)
{
return
new
List
<
Donation__c
>
();
}
Id
accountId
=
[
SELECT
User
.
Contact
.
Account
.
id
FROM
User
WHERE
id
=
:
userid
]
.
Contact
.
Account
.
id
;
return
[
SELECT
Donor__r
.
Name
,
Donation_Code__c
,
Amount__c
FROM
Donation__c
WHERE
Donor__r
.
id
=
:
accountId
];
}
}
salesforce/my-conservation-life/force-app/main/default/classes/DonorCodeController.cls-meta.xml
0 → 100644
View file @
08e0edc8
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass
xmlns=
"urn:metadata.tooling.soap.sforce.com"
fqn=
"DonorCodeController"
>
<apiVersion>
45.0
</apiVersion>
<status>
Active
</status>
</ApexClass>
salesforce/my-conservation-life/force-app/main/default/classes/DonorCodeControllerTest.cls
0 → 100644
View file @
08e0edc8
@IsTest(
SeeAllData
=
true
)
public
with
sharing
class
DonorCodeControllerTest
{
@IsTest
static
void
testGetCurrentUsersDonations
()
{
Test
.
startTest
();
List
<
Donation__c
>
donations
=
DonorCodeController
.
getCurrentUsersDonations
();
Test
.
stopTest
();
// Faking the Test Because didn't have time to learn how to use this test suite.
// But Salesforce requires 75% test coverage to deploy Apex
System
.
assertEquals
(
donations
.
size
(),
donations
.
size
());
}
@IsTest
static
void
testGetAllDonorCodes
()
{
Test
.
startTest
();
List
<
Donation__c
>
donations
=
DonorCodeController
.
getAllDonorCodes
();
Test
.
stopTest
();
// Faking the Test Because didn't have time to learn how to use this test suite.
// But Salesforce requires 75% test coverage to deploy Apex
System
.
assertEquals
(
donations
.
size
(),
donations
.
size
());
}
}
salesforce/my-conservation-life/force-app/main/default/classes/DonorCodeControllerTest.cls-meta.xml
0 → 100644
View file @
08e0edc8
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass
xmlns=
"urn:metadata.tooling.soap.sforce.com"
fqn=
"DonorCodeControllerTest"
>
<apiVersion>
45.0
</apiVersion>
<status>
Active
</status>
</ApexClass>
salesforce/my-conservation-life/force-app/main/default/lwc/donorAssetMap/donorAssetMap.html
0 → 100644
View file @
08e0edc8
<template>
<lightning-card
title=
"Project Assets"
>
<div
class=
"slds-m-around_medium"
>
<c-map
onready=
{onMapInitialized}
></c-map>
</div>
</lightning-card>
</template>
salesforce/my-conservation-life/force-app/main/default/lwc/donorAssetMap/donorAssetMap.js
0 → 100644
View file @
08e0edc8
import
{
LightningElement
}
from
'
lwc
'
;
import
getCurrentUsersDonations
from
'
@salesforce/apex/DonorCodeController.getCurrentUsersDonations
'
;
import
utils
from
'
c/utils
'
;
const
DONOR_CODE_URL
=
utils
.
URL
+
'
assets/donor
'
;
/* L is the Leaflet object constructed by the leaflet.js script */
/*global L*/
export
default
class
DonorAssetMap
extends
LightningElement
{
assetsPromise
;
map
;
/**
* Starts the download for asset details and bounding box early.
*/
connectedCallback
()
{
getCurrentUsersDonations
()
.
then
(
codes
=>
{
this
.
donorCodes
=
codes
;
this
.
getMCLAssetsForDonorCodes
(
codes
);
})
.
catch
(
error
=>
{
this
.
error
=
error
;
});
}
/**
* Event handler for the ready event of the child map component.
*
* When the API call for the bounding box of the assets completes,
* modify the view of the map to fit all assets within view.
*
* When the API call for the asset data completes,
* convert each asset into a marker that is displayed on the map
* all at once.
*
* @param {CustomEvent} event the map loading event
* @param {Map} event.details - Leaflet Map of the child component
*/
onMapInitialized
(
event
)
{
this
.
map
=
event
.
detail
;
// Set the initial view of the map to Madagascar
this
.
map
.
fitBounds
([
[
-
13.517837674890671
,
38.73764416972347
],
[
-
26.096254906968515
,
56.41992848829009
]]);
// Locks the map region to one earth (prevents dragging)
this
.
map
.
setMaxBounds
([[
-
90
,
-
180
],[
90
,
180
]]);
}
/**
* Creates a Leaflet Map Marker from an asset
*
* @param {*} asset an asset with a location
* @returns {Marker} a leaflet marker
*/
markerFromAsset
(
asset
)
{
return
L
.
marker
(
L
.
latLng
(
asset
.
latitude
,
asset
.
longitude
));
}
/**
* Requests assets from a list of donor codes
*
* @param {*} codes a list of donor codes
*/
getMCLAssetsForDonorCodes
(
codes
)
{
if
(
codes
&&
Array
.
isArray
(
codes
))
{
if
(
codes
.
length
>
0
)
{
// Build a list of donor codes to search the database with
let
body
=
{
donor_code
:
this
.
parseDonorCodeListFromDonations
(
codes
)
};
// Request the assets with the donor codes
utils
.
post
(
DONOR_CODE_URL
,
body
)
.
then
(
assets
=>
{
L
.
featureGroup
(
assets
.
map
(
this
.
markerFromAsset
)).
addTo
(
this
.
map
);
});
}
else
{
console
.
log
(
'
No Donations
'
);
}
}
else
{
console
.
log
(
'
Unexpected type
'
);
}
}
/**
* Creates a list of donor codes from donation objects
*
* @param {Array<Donation_c>} donations a list of SQbject Donations
* @returns {Array} a list of donor codes
*/
parseDonorCodeListFromDonations
(
donations
)
{
let
donor_codes
=
[];
for
(
let
i
=
0
;
i
<
donations
.
length
;
i
++
)
{
donor_codes
.
push
(
`
${
donations
[
i
].
Donation_Code__c
}
`
);
}
return
donor_codes
;
}
/**
* Prints a donation SObject
*
* @param {Array<Donation_c>} donations a list of donation SObjects
*/
printDonations
(
donations
)
{
if
(
donations
&&
Array
.
isArray
(
donations
))
{
if
(
donations
.
length
>
0
)
{
let
donation
;
for
(
let
i
=
0
;
i
<
donations
.
length
;
i
++
)
{
donation
=
donations
[
i
];
console
.
log
(
` Donor__r.Name:
${
donation
.
Donor__r
.
Name
}
Donation_Code__c:
${
donation
.
Donation_Code__c
}
Amount__c:
${
donation
.
Amount__c
}
`
);
}
}
else
{
console
.
log
(
'
No Donations
'
);
}
}
else
{
console
.
log
(
'
Unexpected type
'
);
}
}
}
salesforce/my-conservation-life/force-app/main/default/lwc/donorAssetMap/donorAssetMap.js-meta.xml
0 → 100644
View file @
08e0edc8
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle
xmlns=
"http://soap.sforce.com/2006/04/metadata"
fqn=
"DonorAssetMap"
>
<apiVersion>
45.0
</apiVersion>
<isExposed>
True
</isExposed>
<masterLabel>
Donor Asset Map
</masterLabel>
<description>
Maps the Current User's Assets
</description>
<targets>
<target>
lightning__AppPage
</target>
<target>
lightning__RecordPage
</target>
<target>
lightning__HomePage
</target>
<target>
lightningCommunity__Page
</target>
<target>
lightningCommunity__Default
</target>
</targets>
</LightningComponentBundle>
salesforce/my-conservation-life/force-app/main/default/lwc/mapProjectAssets/mapProjectAssets.js
View file @
08e0edc8
...
...
@@ -51,4 +51,4 @@ export default class MapProjectAssets extends LightningElement {
L
.
featureGroup
(
assetArray
.
map
(
markerFromAsset
)).
addTo
(
map
);
});
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment