Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created March 18, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swapnilshrikhande/7e62559e6a866354eae38d97bc75d1be to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/7e62559e6a866354eae38d97bc75d1be to your computer and use it in GitHub Desktop.
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());
}
}
}
<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>
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