Skip to content

Commit

Permalink
#76 enhancement POC for merge fields in content block
Browse files Browse the repository at this point in the history
  • Loading branch information
iandrosov committed Nov 3, 2022
1 parent 3e29dfb commit 49b83b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
42 changes: 36 additions & 6 deletions force-app/main/default/classes/GGW_ApplicationCtrl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public without sharing class GGW_ApplicationCtrl {
@AuraEnabled public String sectionid;
@AuraEnabled public String sectionname;
@AuraEnabled public String title; // Display title map to Name
@AuraEnabled public String displaytext; // map to Description__c
@AuraEnabled public String displaytext; // map to Description__c raw daat text
@AuraEnabled public String displaytextformat; // map data preprocess merge text
@AuraEnabled public Integer wordcount; // Derived from Rich tect field in APEX count words
@AuraEnabled public String displaybadge; // DEPRECATE Tag to display on the badge (Winner etc)
@AuraEnabled public List<String> badgeList; // Tags to display on the badge (Winner etc) from Topics
Expand All @@ -60,16 +61,16 @@ public without sharing class GGW_ApplicationCtrl {
@AuraEnabled public String selecteditemid; // Id of selecetd item on application
@AuraEnabled public Integer sortorder;
public GGW_ContentBlockWrapper(){

}
//. Construct and map Block fields
// Construct and map Block fields
public GGW_ContentBlockWrapper(GGW_Content_Block__c block, Integer cnt){
this.isselected = false;
this.recordid = block.Id;
this.sectionid = block.Section__c;
this.sectionname = block.Section__r.Name;
this.title = block.Name;
this.displaytext = block.Description__c; // Rich text
this.displaytextformat = ''; //this.getMergeFieldsText(block, block.Description__c);
// Count words in rich text with APEX methods
integer words = block.Description__c.normalizeSpace().stripHtmlTags().replaceAll('\\S','').length() ;
this.wordcount = words;
Expand All @@ -79,6 +80,20 @@ public without sharing class GGW_ApplicationCtrl {
this.totalblocks = cnt;
this.badgeList = new List<String>(); // init empty list fill in later
}
/**
public String getMergeFieldsText(GGW_Content_Block__c block, String txt){
String str = txt;
String result = txt;
if(txt != null && block != null){
String mrgFld = txt.substringBetween('{!','}');
if(mrgFld != null && mrgFld.length() > 0){
String fldData = (String)block.get(mrgFld);
// Set new text with replaced text data field
result = str.replace('{!'+mrgFld+'}', fldData);
}
}
return result;
}*/
}

// Return Grant Aplication Wrapper object
Expand All @@ -94,7 +109,7 @@ public without sharing class GGW_ApplicationCtrl {

List<GGW_Selected_Item__c> appItems = querySelectedItemsByGrant(tempId);
GGW_Grant_Application__c grant = GGW_Util.queryGrantApp(tempId);
// Save state
// Save state user selected application record
GGW_Util.saveGrantState(tempId);
//List<GGW_SectionWrapper> unselectedSections = getLeftoverSections(appItems);
GGW_GrantApplicationWrapper app = new GGW_GrantApplicationWrapper();
Expand All @@ -115,6 +130,7 @@ public without sharing class GGW_ApplicationCtrl {
cbw.sectionname = item.Section_Name__c;
cbw.totalblocks = 1; // Alway only 1 per section in Grant
cbw.displaytext = item.Text_Block__c; //Selected_Block__r.Description__c;
cbw.displaytextformat = getItemMergeFieldsText(item, item.Text_Block__c);
cbw.isselected = true;
cbw.sortorder = item.Sort_Order__c.intValue(); // APEX SOQL return NUmber decimal need convert to Int Illegal assignment from Decimal to Integer
contentList.add(cbw);
Expand All @@ -123,14 +139,28 @@ public without sharing class GGW_ApplicationCtrl {
}
return app;
}
private static String getItemMergeFieldsText(GGW_Selected_Item__c item, String txt){
String str = txt;
String result = txt;
if(txt != null && item != null){
String mrgFld = txt.substringBetween('{!','}');
if(mrgFld != null && mrgFld.length() > 0){
String fldData = (String)item.get(mrgFld);
// Set new text with replaced text data field
result = str.replace('{!'+mrgFld+'}', fldData);
}
}
return result;
}

/**
* Creating ContentDistribution record
* parameter: contentVersionId
* response return URL image
* response return URL to image distribution
*
* SELECT Id, LinkedEntityId, ContentDocumentId, ShareType, Visibility FROM ContentDocumentLink WHERE LinkedEntityId = 'a010R00000FYjbAQAT'
SELECT Id, ContentDocumentId, Title FROM ContentVersion WHERE ContentDocumentId = '0690R000001qBEgQAM'
SELECT Id, ContentDocumentId, Title FROM ContentVersion WHERE ContentDocumentId = '0690R000001qBEgQAM'
*/
@AuraEnabled
public static String createConetentDistribution(String grantId, String cvid){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
section-title={sec.label}
display-title={sec.displaytitle}
text-block={sec.textblock}
text-block-formated={sec.textblockformat}
section-id={sec.value}
section-has-blocks={sec.hasblocks}
application-id={sec.appid}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ export default class GgwGrantApplication extends NavigationMixin(LightningElemen
for(var i=0; i<data.selectedContentBlock.length; i++) {
var item = data.selectedContentBlock[i];
var tmpText = item.displaytext ? item.displaytext : 'Text placeholder'; // Set text value condition for null
var tmpTextFormated = item.displaytextformat ? item.displaytextformat : 'Text placeholder';
this.sections = [...this.sections ,{label: item.sectionname,
displaytitle: '['+item.sortorder+'] ' + item.sectionname,
value: item.sectionid, // sfid for Section record
Expand All @@ -214,7 +215,9 @@ export default class GgwGrantApplication extends NavigationMixin(LightningElemen
sortorder: item.sortorder,
selecteditem: item.selecteditemid,
blockid: item.recordid, // sfid for Content Block record
textblock: tmpText} ];
textblock: tmpText,
textblockformat: tmpTextFormated
} ];

console.log('Text: '+item.displaytext);
}
Expand Down
3 changes: 2 additions & 1 deletion force-app/main/default/lwc/ggwSection/ggwSection.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<div class="slds-box slds-box_xx-small slds-m-left_x-small slds-m-right_x-small slds-m-bottom_xx-small">
<template if:false={enableEdit}>
<lightning-formatted-rich-text
value={textBlock}

value={textBlockFormated}
></lightning-formatted-rich-text>
</template>
<template if:true={enableEdit}>
Expand Down
3 changes: 2 additions & 1 deletion force-app/main/default/lwc/ggwSection/ggwSection.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import deleteSection from '@salesforce/apex/GGW_ApplicationCtrl.deleteSection';
export default class GgwSection extends LightningElement {
@api sectionTitle = 'Default Section';
@api textBlock = 'Text placeholder';
@api textBlockFormated = 'Text placeholder';
@api sectionId;
@api sectionHasBlocks; // Boolean value if section has block allow to save
@api applicationId;
Expand Down Expand Up @@ -47,7 +48,7 @@ export default class GgwSection extends LightningElement {
this.textBlock = this.saveSelectedText; // Restore initial text
}
handleEnableEdit(){
this.enableEdit = true;
this.enableEdit = !this.enableEdit;
}
// Save set selected section text and close modal
saveCloseModal() {
Expand Down

0 comments on commit 49b83b6

Please sign in to comment.