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

[PR Review] Manage Logo image feature #38

Merged
merged 2 commits into from
Dec 19, 2023
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
64 changes: 55 additions & 9 deletions force-app/main/default/classes/GGW_ApplicationCtrl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public without sharing class GGW_ApplicationCtrl {
GGW_GrantApplicationWrapper app = new GGW_GrantApplicationWrapper();
if(!appItems.isEmpty()){
app.recordid = grant.Id;
app.logostate = grant.Include_Logo__c;
app.logodisplayurl = getValidLogoURL(grant);
app.name = appItems[0].Application_Name__c;
app.status = appItems[0].Grant_Application__r.Status__c;
Expand All @@ -32,7 +33,52 @@ public without sharing class GGW_ApplicationCtrl {
}
return app;
}
// Delete logo file from grant
@AuraEnabled
public static String deleteLogo(String recordId){
GGW_Grant_Application__c app = new GGW_Grant_Application__c();
app.Id = recordId;
app.DistributionPublicUrl__c = null; // Logo public URL
app.Logo_Download_Url__c = null; // Logo display URL
app.Include_Logo__c = false;
// Check object CRUD
if(Schema.sObjectType.GGW_Grant_Application__c.isUpdateable()){
update app;
}
// Find and delete content file and related records
deleteImageLogo(recordId);
return 'Logo image deleted';
}
// Include or exclude logo image into grant application
@AuraEnabled
public static String includeLogo(String recordId, Boolean state){
GGW_Grant_Application__c app = new GGW_Grant_Application__c();
app.Id = recordId;
app.Include_Logo__c = state;
if(Schema.sObjectType.GGW_Grant_Application__c.isUpdateable()){
update app;
}
return 'Application logo updated';
}

private static void deleteImageLogo(String recordId){
ContentDocumentLink cdl = [SELECT Id, LinkedEntityId, ContentDocumentId, IsDeleted, Visibility, ShareType
FROM ContentDocumentLink
WHERE LinkedEntityId =: recordId WITH SECURITY_ENFORCED];

ContentDistribution cntdistr = [SELECT Id, Name, ContentVersionId, ContentDocumentId, RelatedRecordId, ContentDownloadUrl
FROM ContentDistribution
WHERE ContentDocumentId =: cdl.ContentDocumentId WITH SECURITY_ENFORCED];

ContentDocument cd = new ContentDocument();
cd.Id = cdl.ContentDocumentId;
if(Schema.sObjectType.ContentDistribution.isDeletable()){
delete cntdistr;
}
if(Schema.sObjectType.ContentDocument.isDeletable()){
delete cd;
}
}
private static String getValidLogoURL(GGW_Grant_Application__c grant){
String logourl = null;
if(grant != null && grant.Logo_Download_Url__c != null){
Expand Down Expand Up @@ -286,15 +332,6 @@ public without sharing class GGW_ApplicationCtrl {
}
*/

// Utility selector method
public static List<GGW_Selected_Item__c> querySelectedItemsByGrant(String appId){
List<GGW_Selected_Item__c> appItems = [SELECT Id, Application_Name__c, Grant_Application__c, GGW_Section__c,
Section_Name__c,Selected_Block__c, Sort_Order__c, Grant_Application__r.Status__c,
Selected_Block__r.Description__c, Text_Block__c, Language__c
FROM GGW_Selected_Item__c
WHERE Grant_Application__c =: appId WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return appItems;
}
/**
* Method to create a new ContentBlock add to section as part a library to later reuse
* on other Grant applications.
Expand Down Expand Up @@ -518,6 +555,15 @@ public without sharing class GGW_ApplicationCtrl {
}

///--- BASIC SELECTOR METHODS
public static List<GGW_Selected_Item__c> querySelectedItemsByGrant(String appId){
List<GGW_Selected_Item__c> appItems = [SELECT Id, Application_Name__c, Grant_Application__c, GGW_Section__c,
Section_Name__c,Selected_Block__c, Sort_Order__c, Grant_Application__r.Status__c,
Selected_Block__r.Description__c, Text_Block__c, Language__c
FROM GGW_Selected_Item__c
WHERE Grant_Application__c =: appId WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return appItems;
}

private static List<GGW_Section__c> querySectionsByLanguage(String lang){
List<GGW_Section__c> sectionList = [SELECT Id, Name, CreatedDate, Recommended__c, Suggested__c,
Sort_Order__c, Language__c
Expand Down
117 changes: 117 additions & 0 deletions force-app/main/default/classes/GGW_ApplicationCtrlTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,123 @@ public class GGW_ApplicationCtrlTest {
GGW_TestDataFactory.createGrantContentTestData();
}

@isTest
static void includeLogoTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}

GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('MyTest Grant', sections);

Test.startTest();
String msg = GGW_ApplicationCtrl.includeLogo(app.Id, true);
Test.stopTest();

System.assertEquals('Application logo updated', msg, 'Invalid message returnd for Logo include into Grant');
GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id);
System.assertEquals(app.Id, grant.recordid, 'Invalid grant application Id');
System.assertEquals(true, grant.logostate, 'Logo include state is not valid');
}
static void excludeLogoTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}

GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('MyTest Grant', sections);

Test.startTest();
String msg = GGW_ApplicationCtrl.includeLogo(app.Id, false);
Test.stopTest();

System.assertEquals('Application logo updated', msg, 'Invalid message returnd for Logo include into Grant');
GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id);
System.assertEquals(app.Id, grant.recordid, 'Invalid grant application Id');
System.assertEquals(false, grant.logostate, 'Logo exclude state is not valid');
}

@isTest
static void deleteLogoTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant Logo delete Test', sections);

//ContentDocument cdoc = new ContentDocument();
//cdoc.Title = 'Grant test logo';
//insert cdoc;

ContentVersion cvo = new Contentversion();
//cvo.ContentDocumentId = cdoc.Id;
cvo.Title = 'Test Content file';
cvo.PathOnClient = 'test';
cvo.VersionData = EncodingUtil.base64Decode('Unit Test Attachment Body');
//List<ContentVersion> cvl = new List<ContentVersion>();
//cvl.add(cvo);
insert cvo;

ContentVersion cvtmp = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id =: cvo.Id];
// Create content document Link
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.LinkedEntityId = app.Id;
cdl.ContentDocumentId = cvtmp.ContentDocumentId;
insert cdl;

String downloadURL = GGW_ApplicationCtrl.createContentDistribution(app.Id, cvo.Id);

Test.startTest();
String result = GGW_ApplicationCtrl.deleteLogo(app.Id);

Test.stopTest();
System.assertEquals('Logo image deleted', result, 'Logo delete is not valid');

}
@isTest
static void createContentDistributionTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Content Distribution Test', sections);
ContentVersion cvo = new Contentversion();
cvo.Title = 'Test Content file';
cvo.PathOnClient = 'test';
cvo.VersionData = EncodingUtil.base64Decode('Unit Test Attachment Body');
insert cvo;
ContentVersion cvtmp = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id =: cvo.Id];
// Create content document Link
ContentDocumentLink cdl = new ContentDocumentLink();
cdl.LinkedEntityId = app.Id;
cdl.ContentDocumentId = cvtmp.ContentDocumentId;
insert cdl;

Test.startTest();
String downloadURL = GGW_ApplicationCtrl.createContentDistribution(app.Id, cvo.Id);
Test.stopTest();

System.assertNotEquals(null, downloadURL, 'Contenet distribution is invalid');
GGW_GrantApplicationWrapper grant = GGW_ApplicationCtrl.getApplication(app.Id);
System.assertEquals(downloadURL, grant.logodisplayurl, 'Logo download URL is not valid');

}
@isTest
static void testNewGrant(){
// Query all suggested sections
Expand Down
5 changes: 5 additions & 0 deletions force-app/main/default/classes/GGW_ExportCtrl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ public without sharing class GGW_ExportCtrl {
public String recordId {get; set;}
public String appName {get;set;}
public String logoURL {get; set;}
public Boolean isDisplayLogo {get; set;}
public List<GGW_Selected_Item__c> items {get; set;}
private final GGW_Grant_Application__c app;

public GGW_ExportCtrl(ApexPages.StandardController stdController) {
this.isDisplayLogo = false;
this.app = (GGW_Grant_Application__c)stdController.getRecord();
if(this.app != null && this.app.Id != null){
this.recordId = this.app.Id;
Expand All @@ -36,6 +38,9 @@ public without sharing class GGW_ExportCtrl {
GGW_Grant_Application__c app = GGW_Util.queryGrantApp(this.recordId.escapeHtml4());
if(app != null && app.Logo_Download_Url__c != null){
this.logoURL = app.Logo_Download_Url__c;
if(app.Include_Logo__c == true){
this.isDisplayLogo = true;
}
}

this.items = GGW_Util.getSelectedItems(this.recordId.escapeHtml4());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class GGW_GrantApplicationWrapper {
@AuraEnabled public String name;
@AuraEnabled public String status;
@AuraEnabled public String logodisplayurl;
@AuraEnabled public Boolean logostate;
@AuraEnabled public String language;
@AuraEnabled public List<GGW_SectionWrapper> unselectSectionList; // Used to add new sections to Grant
@AuraEnabled public List<GGW_ContentBlockWrapper> selectedContentBlock; // Include Section and Text block
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/classes/GGW_Util.cls
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public without sharing class GGW_Util {
}
public static GGW_Grant_Application__c queryGrantApp(String appId){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c, Language__c
DistributionPublicUrl__c, Status__c, Description__c, Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WHERE Id =: appId WITH SECURITY_ENFORCED LIMIT 1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Logo_Download_Url__c</field>
<field>Language__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>DistributionPublicUrl__c</field>
<field>OwnerId</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>Language__c</field>
<field>Include_Logo__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
<behavior>Edit</behavior>
<field>OwnerId</field>
<field>Logo_Download_Url__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>DistributionPublicUrl__c</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsTopToBottom</style>
Expand Down Expand Up @@ -107,7 +111,7 @@
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
<summaryLayout>
<masterLabel>00h0R000008ilih</masterLabel>
<masterLabel>00h01000002bd1h</masterLabel>
<sizeX>4</sizeX>
<sizeY>0</sizeY>
<summaryLayoutStyle>Default</summaryLayoutStyle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,32 @@ <h3 slot="title" >
</template>
</div>
</div>
</lightning-layout-item>
</lightning-layout-item>
<template if:true={showLogoButtons}>
<lightning-layout-item padding="around-small">
<div class="header-column slds-p-top_x-large">
<lightning-button-stateful
label-when-off="Include Logo"
label-when-on="Logo Included"
label-when-hover="Exclude Logo"
icon-name-when-off="utility:add"
icon-name-when-on="utility:check"
icon-name-when-hover="utility:close"
selected={logoState}
onclick={handleLogoSelectorClick}>
</lightning-button-stateful>

<lightning-button-icon
icon-name="utility:delete"
variant="border-filled"
alternative-text="Delete"
class="slds-m-left_xx-small"
title="Delete"
onclick={handleLogoDelete}>
</lightning-button-icon>
</div>
</lightning-layout-item>
</template>
</lightning-layout>
</div>
</template>
Expand All @@ -76,7 +101,7 @@ <h3 slot="title" >
selected-item-id={sec.selecteditem}
sectioncount={sec.sectioncount}
sortorder={sec.sortorder}
onselectedtext={hanldeSelectedTextChange}
onselectedtext={handleSelectedTextChange}
ondeletesection={handleDeleteSection}
key={sec.value}
></c-ggw-section>
Expand Down
Loading