Skip to content

Commit

Permalink
Merge pull request #44 from AbRa734/PI-016
Browse files Browse the repository at this point in the history
Pi 016
  • Loading branch information
dyemm21 authored Jun 19, 2024
2 parents 8b0a530 + 14dadc4 commit ecd7fe7
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 73 deletions.
56 changes: 18 additions & 38 deletions force-app/main/default/classes/AnimalClass.cls
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,7 @@ public class AnimalClass {

if (!String.isBlank(ageFilter))
{
String ageCondition;
if (ageFilter == 'do 5 lat')
{
ageCondition = 'Age__c <= 5';
}
else if (ageFilter == 'do 10 lat')
{
ageCondition = 'Age__c <= 10';
}
else
{
ageCondition = 'Age__c > 10';
}
filters.add(ageCondition);
filters.add(ageFilter);
}

if (!String.isBlank(sexFilter))
Expand All @@ -46,37 +33,30 @@ public class AnimalClass {
}

@AuraEnabled
public static List<String> getBreeds()
public static List<Map<String, String>> getBreeds()
{
Set<String> breedSet = new Set<String>();
for (Animal__c animal : [SELECT Breed__c FROM Animal__c])
{
if (!String.isBlank(animal.Breed__c))
{
breedSet.add(animal.Breed__c);
}
List<Map<String, String>> breeds = new List<Map<String, String>>();
Schema.DescribeFieldResult field = Animal__c.Breed__c.getDescribe();
List<Schema.PicklistEntry> pickListVal = field.getPicklistValues();
for (Schema.PicklistEntry picklist : pickListVal)
{
breeds.add(new Map<String, String>{
'label' => picklist.getLabel(),
'value' => picklist.getValue()
});
}
return new List<String>(breedSet);
return breeds;
}

@AuraEnabled(cacheable=true)
public static List<Map<String, String>> getShelters() {
List<Map<String, String>> shelters = new List<Map<String, String>>();
Set<Id> shelterIds = new Set<Id>();

for (Animal__c animal : [SELECT Shelter__c FROM Animal__c WHERE Shelter__c != NULL])
{
shelterIds.add(animal.Shelter__c);
}

for (Shelter__c shelter : [SELECT Id, Name FROM Shelter__c WHERE Id IN :shelterIds])
public static List<Object> getShelters()
{
List<Object> shelters = new List<Object>();
for (AggregateResult ar : [SELECT Shelter__r.Name shelterName FROM Animal__c WHERE Shelter__r.Name != null GROUP BY Shelter__r.Name])
{
shelters.add(new Map<String, String>{
'label' => shelter.Name,
'value' => shelter.Name
});
String shelterName = (String)ar.get('shelterName');
shelters.add(new Map<String, String>{'label' => shelterName, 'value' => shelterName});
}

return shelters;
}
}
13 changes: 8 additions & 5 deletions force-app/main/default/lwc/animalCardList/animalCardList.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<template>
<lightning-card title="Animals" icon-name="utility:animal_and_nature">
<div class="filters">
<lightning-combobox
name="breeds"
label="Breed"
value={breedFilter}
<lightning-combobox
name="breeds"
label="Breed"
value={breedFilter}
placeholder="Select a Breed"
options={breeds}
options={breeds}
class="combobox-custom"
onchange={handleBreedChange}>
</lightning-combobox>
Expand Down Expand Up @@ -44,6 +44,9 @@
<lightning-button variant="neutral" label="Reset Filters" title="Reset Filters" onclick={resetFilters} class="reset-button"></lightning-button>

</div>
<template if:true={isLoading}>
<lightning-spinner alternative-text="Loading..." variant="brand"></lightning-spinner>
</template>

<template if:true={animals}>
<template if:false={isSearchNotAvailable}>
Expand Down
59 changes: 39 additions & 20 deletions force-app/main/default/lwc/animalCardList/animalCardList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import getAnimals from '@salesforce/apex/AnimalClass.getAnimals';
import getBreeds from '@salesforce/apex/AnimalClass.getBreeds';
import getShelters from '@salesforce/apex/AnimalClass.getShelters';

export default class AnimalCardList extends LightningElement
{
export default class AnimalCardList extends LightningElement {
@track animals;
@track breeds = [];
@track ages = [
{ label: 'do 5 lat', value: 'do 5 lat' },
{ label: 'do 10 lat', value: 'do 10 lat' },
{ label: 'powyżej 10 lat', value: 'powyżej 10 lat' }
{ label: 'Up to 5 years', value: 'Age__c <= 5' },
{ label: 'Up to 10 years', value: 'Age__c <= 10' },
{ label: 'Over 10 years', value: 'Age__c > 10' }
];
@track sexes = [
{ label: 'Male', value: 'Male' },
Expand All @@ -23,12 +22,21 @@ export default class AnimalCardList extends LightningElement
@track sexFilter = '';
@track shelterFilter = '';
@track isSearchNotAvailable = false;
@track isLoading = false;
connectedCallback()
{
this.loadBreeds();
this.loadShelters();
this.loadAnimals();
connectedCallback() {
this.isLoading = true;
Promise.all([
this.loadBreeds(),
this.loadShelters(),
this.loadAnimals()
])
.catch(error => {
this.error = error;
})
.finally(() => {
this.isLoading = false;
});
}
handleBreedChange(event)
Expand All @@ -49,53 +57,64 @@ export default class AnimalCardList extends LightningElement
this.loadAnimals();
}
handleShelterChange(event)
handleShelterChange(event)
{
this.shelterFilter = event.target.value;
this.loadAnimals();
}
loadAnimals() {
loadAnimals()
{
this.isLoading = true;
getAnimals({ breedFilter: this.breedFilter, ageFilter: this.ageFilter, sexFilter: this.sexFilter, shelterFilter: this.shelterFilter })
.then(result => {
this.animals = result;
if (this.animals.length > 0) {
if (this.animals.length > 0)
{
this.isSearchNotAvailable = false;
} else {
} else
{
this.isSearchNotAvailable = true;
}
})
.catch(error => {
this.isSearchNotAvailable = false;
this.error = error;
})
.finally(() => {
this.isLoading = false;
});
}
loadBreeds() {
getBreeds()
return getBreeds()
.then(result => {
this.breeds = result.map(breed => ({ label: breed, value: breed }));
this.breeds = result;
})
.catch(error => {
this.error = error;
});
}
loadShelters() {
getShelters()
return getShelters()
.then(result => {
this.shelters = result;
})
.catch(error => {
this.error = error;
});
}
resetFilters() {
this.isLoading = true;
this.breedFilter = '';
this.ageFilter = '';
this.sexFilter = '';
this.shelterFilter = '';
this.loadAnimals();
this.loadAnimals()
.finally(() => {
this.isLoading = false;
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,57 @@
<fullName>Breed__c</fullName>
<externalId>false</externalId>
<label>Breed</label>
<length>50</length>
<required>false</required>
<required>true</required>
<trackTrending>false</trackTrending>
<type>Text</type>
<unique>false</unique>
<type>Picklist</type>
<valueSet>
<valueSetDefinition>
<sorted>false</sorted>
<value>
<fullName>Labrador Retriever</fullName>
<default>false</default>
<label>Labrador Retriever</label>
</value>
<value>
<fullName>German Shepherd</fullName>
<default>false</default>
<label>German Shepherd</label>
</value>
<value>
<fullName>Golden Retriever</fullName>
<default>false</default>
<label>Golden Retriever</label>
</value>
<value>
<fullName>Bulldog</fullName>
<default>false</default>
<label>Bulldog</label>
</value>
<value>
<fullName>Beagle</fullName>
<default>false</default>
<label>Beagle</label>
</value>
<value>
<fullName>Siamese</fullName>
<default>false</default>
<label>Siamese</label>
</value>
<value>
<fullName>Maine Coon</fullName>
<default>false</default>
<label>Maine Coon</label>
</value>
<value>
<fullName>Persian</fullName>
<default>false</default>
<label>Persian</label>
</value>
<value>
<fullName>Bengal</fullName>
<default>false</default>
<label>Bengal</label>
</value>
</valueSetDefinition>
</valueSet>
</CustomField>
5 changes: 0 additions & 5 deletions force-app/main/default/profiles/Admin.profile-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@
<field>Animal__c.Age__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>true</editable>
<field>Animal__c.Breed__c</field>
<readable>true</readable>
</fieldPermissions>
<fieldPermissions>
<editable>false</editable>
<field>Animal__c.Date_of_admission__c</field>
Expand Down
1 change: 0 additions & 1 deletion manifest/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<members>Adoption__c.Amount__c</members>
<members>Adoption__c.Contact__c</members>
<members>Animal__c.Age__c</members>
<members>Animal__c.Breed__c</members>
<members>Animal__c.Date_of_admission__c</members>
<members>Animal__c.Description__c</members>
<members>Animal__c.Dislikes__c</members>
Expand Down

0 comments on commit ecd7fe7

Please sign in to comment.