Created
March 18, 2021 09:16
-
-
Save swapnilshrikhande/7e62559e6a866354eae38d97bc75d1be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SurveyData { | |
public class Survey { | |
public List<Question> rows; | |
//index must map with the isApplicable array | |
public List<String> allProducts; | |
{ | |
rows = new List<Question>(); | |
allProducts = new List<String>(); | |
} | |
} | |
public class Question { | |
public String id; | |
public String team; | |
public String question; | |
List<Boolean> isApplicableForProduct; | |
Question(String theTeam,String theQuestion, List<Boolean> isApplicable){ | |
this.team = theTeam; | |
this.question = theQuestion; | |
isApplicableForProduct = isApplicable; | |
id = (team+'-'+question).replaceAll(' ', '-').toLowerCase(); | |
} | |
} | |
@AuraEnabled | |
public static String fetchSurveyData(){ | |
try { | |
Survey survey = new Survey(); | |
survey.allProducts = new List<String>{'Product 1','Product 2','Product 3'}; | |
survey.rows.add( | |
new Question( | |
'Team 1' | |
, 'Question 1' | |
, new List<Boolean>{ true, false, true} | |
) | |
); | |
survey.rows.add( | |
new Question( | |
'Team 1' | |
, 'Question 2' | |
, new List<Boolean>{ true, true, true} | |
) | |
); | |
survey.rows.add( | |
new Question( | |
'Team 2' | |
, 'Question 1' | |
, new List<Boolean>{ true, false, true} | |
) | |
); | |
survey.rows.add( | |
new Question( | |
'Team 2' | |
, 'Question 2' | |
, new List<Boolean>{ true, false, true} | |
) | |
); | |
return JSON.serializePretty(survey); | |
} catch (Exception e) { | |
throw new AuraHandledException(e.getMessage()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<template for:each={products} for:item="product"> | |
{product} | |
</template> | |
<template for:each={surveyData} for:item="row"> | |
<div key={row.id}> | |
{row.team} | |
{row.question} | |
<template for:each={row.isApplicableForProduct} for:item="isApplicable"> | |
<template if:true={isApplicable}> | |
<span key={row.id}> | |
<lightning-input type="checkbox" label="" name="input1" ></lightning-input> | |
</span> | |
</template> | |
<template if:false={isApplicable}> | |
<span key={row.id}> | |
NA | |
</span> | |
</template> | |
</template> | |
</div> | |
</template> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement,track } from 'lwc'; | |
import submitPSVRequest from '@salesforce/apex/SurveyData.fetchSurveyData'; | |
export default class SurveyData extends LightningElement { | |
@track | |
surveyData = []; | |
@track | |
products = []; | |
connectedCallback(){ | |
this.fetchSurveyData(); | |
} | |
fetchSurveyData(){ | |
submitPSVRequest().then((responseDataString) => { | |
if( responseDataString ) { | |
let data = JSON.parse(responseDataString); | |
this.surveyData = data.rows; | |
this.products = data.allProducts; | |
} | |
}).catch((error) => { | |
console.error(error); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment