Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 90c645a

Browse files
authored
Added SimpleMetadata library for metadata classes, created new components
Created several new components that are built on top of SimpleMetadata library (included in this repo) * simpleAdmin.cmp * currentUser.cmp * environmentMetadata.cmp * fieldSetMetadata.cmp * listviewMetadata.cmp * queueMetadata.cmp * recordTypeMetadata.cmp
1 parent 26a5b28 commit 90c645a

File tree

82 files changed

+2663
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2663
-418
lines changed

.codeclimate.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

README.md

Lines changed: 37 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,43 @@
1-
# Lightning Components
2-
A library of lightweight Salesforce Lightning components that streamline developing by automatically applying sobject-level security, field-level security, field types and more.
1+
# Simple Lightning Components
2+
A library of lightweight Salesforce Lightning components that simplify developing in Lightning by automatically:
3+
* Honoring SObject-level security & field-level security for displaying fields & allowing fields to be edited
4+
* Displaying the correct input field type based on the field's metadata, including lookup fields & support for polymorphic fields like Task.WhoId & Task.WhatId
5+
* Translating SObject labels, field labels and picklist options
36

47
<a href="https://githubsfdeploy.herokuapp.com" target="_blank">
5-
<img alt="Deploy to Salesforce"
6-
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">
8+
<img alt="Deploy to Salesforce" src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">
79
</a>
810

9-
## sobjectMetadata.cmp
10-
* An extensible, markup-less component that returns an instance of LightningMetadataController.SObjectMetadata for the specified SObject
11-
12-
`<c:sobjectMetadata sobjectName="Account" aura:id="accountMetadataService" />`
13-
14-
## fieldMetadata.cmp
15-
* An extensible, markup-less component that returns an instance of LightningMetadataController.FieldMetadata for the specified field
16-
17-
`<c:fieldMetadata sobjectName="Account" fieldName="Type" aura:id="accountTypeMetadataService" />`
18-
19-
## inputField.cmp
20-
* Provides a simple way to display an SObject's field as an input (editable) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
21-
22-
`<c:inputField sobjectName="Account" fieldName="Type" record="{!v.myAccount}" />`
23-
24-
## lookup.cmp
25-
* Provides lookup functionality that Salesforce does not provide for developers in LEX. This component is used by inputField.cmp for lookup fields.
26-
27-
Users can search for the record or choose one of the recently viewed records automatically displayed on focus
28-
`<c:lookup sobjectName="Contact" fieldName="AccountId" record="{!v.myContact}" />`
29-
30-
Polymorphic fields, like Task.WhoId, automatically display an SObject Switcher.
31-
SObject-level permissions are automatically applied - only objects that the user has permission to view are displayed in the SObject Switcher.
32-
`<c:lookup sobjectName="Task" fieldName="WhoId" record="{!v.myTask}" />`
33-
![lookup-task-whoid](https://user-images.githubusercontent.com/1267157/34769563-6f5b8374-f5fe-11e7-88c7-98e6fbb0ec75.gif)
34-
35-
36-
## outputField.cmp
37-
* Provides a simple way to display an SObject's field as an output (read-only) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
38-
39-
`<c:inputField sobjectName="Account" fieldName="Type" record="{!v.myAccount}" />`
40-
41-
## sobjectLabel.cmp
42-
* Displays the localized version of the provided SObject's label
43-
44-
`<c:sobjectLabel sobjectName="Account" />`
45-
46-
* Feature: Show the SObject's plural label
47-
48-
`<c:sobjectLabel sobjectName="Account" variant="labelPlural" />`
49-
50-
## fieldLabel.cmp
51-
* Displays the localized version of the provided field's label
52-
53-
`<c:fieldLabel sobjectName="Account" fieldName="Type" />`
54-
55-
* Feature: Show the field's inline help text
56-
57-
`<c:fieldLabel sobjectName="Account" fieldName="Type" showHelpText="true" />`
58-
59-
## modal.cmp
60-
* Generates a modal window and displays your contents inside
61-
```
62-
<c:modal title="My Modal" isOpen="{!v.showModal}">
63-
<aura:set attribute="body">
64-
<p>This paragraph will be shown inside the modal</p>
65-
</aura:set>
66-
</c:modal>
67-
```
68-
69-
## objectPropertyValue.cmp
70-
* Displays the specified property of any javascript object - this is helpful since Lightning does not allow you to dynamically get a property value by name (like 'myObject[someProperty]')
71-
72-
`<c:objectPropertyValue object="{!v.my.complex.nested.object}" propertyName="someProperty" />`
73-
74-
# Apex Classes
75-
76-
## LightningMetadataController.cls
11+
## Simple Admin component
12+
* simpleAdmin.cmp - this is a demo component that provides examples of how to use the other components. It's also a handy admin tool to quickly get information about your org.
13+
14+
## Metadata Components
15+
Several no-markup components are included. These can be used to dynamically access metadata about your org in Lightning components
16+
* **currentUser.cmp**: return info about the current user. Additional user fields can be returned by setting currentUser.additionalFieldApiNames
17+
* **environmentMetadata.cmp**: returns an instance of EnvironmentMetadata for the specified SObjectenvironmentMetadata.cmp
18+
* **fieldMetadata.cmp**: returns an instance of FieldMetadata for the specified SObjectfieldMetadata.cmp
19+
* **fieldSetMetadata.cmp**: returns an instance of FieldSetMetadata for the specified SObjectfieldSetMetadata.cmp
20+
* **listviewMetadata.cmp**: returns an instance of ListviewMetadata for the specified SObjectlistviewMetadata.cmp
21+
* **queueMetadata.cmp**: returns an instance of QueueMetadata for the specified SObjectqueueMetadata.cmp
22+
* **recordTypeMetadata.cmp**: returns an instance of RecordTypeMetadata for the specified SObjectrecordTypeMetadata.cmp
23+
* **sobjectMetadata.cmp**: returns an instance of SObjectMetadata for the specified SObjectsobjectMetadata.cmp
24+
25+
## UI Components
26+
These components are used to build UIs in Lightning - several of these leverage the metadata service components
27+
* **fieldLabel.cmp**: Displays the localized version of the provided field's label
28+
* **inputField.cmp**: Provides a simple way to display an SObject's field as an input (editable) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
29+
* **lookup.cmp**: Provides lookup functionality that Salesforce does not provide for developers in LEX. This component is used by inputField.cmp for lookup fields.
30+
* **modal.cmp**: Generates a modal window and displays your contents inside
31+
* **objectPropertyValue.cmp**: Displays the specified property of any javascript object - this is helpful since Lightning does not allow you to dynamically get a property value by name (like 'myObject[someProperty]')
32+
* **outputField.cmp**: Provides a simple way to display an SObject's field as an output (read-only) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
33+
* **sobjectLabel.cmp**: Displays the localized version of the provided SObject's label
34+
35+
## Apex Classes
36+
37+
### LightningMetadataController.cls
7738
Contains methods for describing your orgs metadata and returning the info as aura-friendly objects that can be consumed by Lightning Components
7839
* getSObjectMetadata(String sobjectName) - returns an instance of LightningMetadataController.SObjectMetadata
79-
* getFieldMetadata(String sobjectName, String fieldName) - returns an instance of LightningMetadataController.FieldMetadata
40+
* getFieldMetadata(String sobjectName, String fieldName) - returns an instance of LightningMetadataController.FieldMetadata
41+
42+
### SimpleMetadata classes
43+
The remaining metadata classes (SObjectMetadata.cls, FieldMetadata.cls, etc) are part of the [SimpleMetadata](https://github.com/jongpie/SimpleMetadata) project - any bugs or enhancements for those classes are maintained in that project, and the latest version is used in this repo.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
This file is part of the Simple Lightning Components project, released under the MIT License.
3+
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
4+
-->
5+
<aura:component extensible="true" controller="LightningMetadataController">
6+
7+
<!-- Public Attributes -->
8+
<aura:attribute name="additionalFieldApiNames" type="String[]" description="(Optional) Additional field API names to return for the current user" />
9+
<aura:attribute name="currentUser" type="User" description="The current user" />
10+
11+
<!-- Public Functions -->
12+
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the current user">
13+
<aura:attribute name="callback" type="function"/>
14+
</aura:method>
15+
16+
<!-- Handlers -->
17+
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
18+
<aura:handler name="change" value="{!v.additionalFieldApiNames}" action="{!c.doInit}" />
19+
20+
<!-- Markup -->
21+
{!v.body}
22+
23+
</aura:component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>41.0</apiVersion>
4+
<description>currentUser</description>
5+
</AuraDefinitionBundle>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
({
22
doInit : function(component, event, helper) {
3-
helper.fetchSObjectMetadata(component, event);
3+
helper.fetchCurrentUser(component, event);
44
}
55
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
({
2+
fetchCurrentUser : function(component, event) {
3+
var params = event.getParam('arguments');
4+
5+
var action = component.get('c.getCurrentUser');
6+
action.setParams({
7+
'additionalFieldApiNames': component.get('v.additionalFieldApiNames')
8+
});
9+
action.setStorable();
10+
action.setCallback(this, function(response) {
11+
if(response.getState() === 'SUCCESS') {
12+
var currentUser = response.getReturnValue();
13+
component.set('v.currentUser', currentUser);
14+
15+
if(params) params.callback(null, currentUser);
16+
} else if(response.getState() === 'ERROR') {
17+
this.processCallbackErrors(response);
18+
}
19+
});
20+
$A.enqueueAction(action);
21+
},
22+
processCallbackErrors : function(response) {
23+
console.log('ERROR');
24+
for(var i=0; i < response.getError().length; i++) {
25+
console.log(response.getError()[i]);
26+
}
27+
}
28+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--
2+
This file is part of the Simple Lightning Components project, released under the MIT License.
3+
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
4+
-->
5+
<aura:component extensible="true" controller="LightningMetadataController">
6+
7+
<!-- Public Attributes -->
8+
<aura:attribute name="environmentMetadata" type="EnvironmentMetadata" description="The Environment metadata object returned from the controller" />
9+
10+
<!-- Public Functions -->
11+
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the metadata">
12+
<aura:attribute name="callback" type="function"/>
13+
</aura:method>
14+
15+
<!-- Handlers -->
16+
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
17+
18+
<!-- Markup -->
19+
{!v.body}
20+
21+
</aura:component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>41.0</apiVersion>
4+
<description>environmentMetadata</description>
5+
</AuraDefinitionBundle>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
({
2+
doInit : function(component, event, helper) {
3+
helper.fetchEnvironmentMetadata(component, event);
4+
}
5+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
({
2+
fetchEnvironmentMetadata : function(component, event) {
3+
var params = event.getParam('arguments');
4+
5+
var action = component.get('c.getEnvironmentMetadata');
6+
action.setStorable();
7+
action.setCallback(this, function(response) {
8+
if(response.getState() === 'SUCCESS') {
9+
var environmentMetadata = response.getReturnValue();
10+
component.set('v.environmentMetadata', environmentMetadata);
11+
12+
if(params) params.callback(null, environmentMetadata);
13+
} else if(response.getState() === 'ERROR') {
14+
this.processCallbackErrors(response);
15+
}
16+
});
17+
$A.enqueueAction(action);
18+
},
19+
processCallbackErrors : function(response) {
20+
console.log('ERROR');
21+
for(var i=0; i < response.getError().length; i++) {
22+
console.log(response.getError()[i]);
23+
}
24+
}
25+
})

0 commit comments

Comments
 (0)