Skip to content

Commit 08e6c1b

Browse files
authored
Added question picker (#57)
1 parent a769082 commit 08e6c1b

20 files changed

+593
-127
lines changed

package-lock.json

Lines changed: 130 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sfdx-quiz",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"private": true,
55
"description": "Lightning Web Component Quiz App on a Salesforce Org",
66
"engines": {
@@ -21,11 +21,11 @@
2121
"@salesforce/eslint-config-lwc": "^0.5.0",
2222
"@salesforce/sfdx-lwc-jest": "^0.7.1",
2323
"eslint": "^6.8.0",
24-
"husky": "^4.2.3",
25-
"lint-staged": "^10.0.8",
26-
"prettier": "^1.19.1",
27-
"prettier-plugin-apex": "^1.2.0",
28-
"semver": "^7.1.3",
24+
"husky": "^4.2.5",
25+
"lint-staged": "^10.1.3",
26+
"prettier": "^2.0.4",
27+
"prettier-plugin-apex": "^1.3.0",
28+
"semver": "^7.2.1",
2929
"replace-in-file": "^5.0.2"
3030
},
3131
"husky": {

src/main/default/classes/QuizController.cls

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ public with sharing class QuizController {
4444
if (sessionId == null) {
4545
throw new AuraHandledException('Missing session Id.');
4646
}
47-
return sessionService.getCurrentQuestion(sessionId);
47+
Quiz_Question__c question = sessionService.getCurrentQuestion(
48+
sessionId
49+
);
50+
if (question == null) {
51+
throw new AuraHandledException(
52+
'Missing current question for session.'
53+
);
54+
}
55+
return question;
4856
}
4957

5058
@AuraEnabled
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
public with sharing class QuizEditorController {
2+
private static final QuizQuestionService questionService = new QuizQuestionService();
3+
private static final QuizSessionService sessionService = new QuizSessionService();
4+
5+
@AuraEnabled(cacheable=true)
6+
public static List<Quiz_Question__c> getAllQuestions() {
7+
return questionService.getQuestions();
8+
}
9+
10+
@AuraEnabled
11+
public static void setSessionQuestions(Id sessionId, List<Id> questionIds) {
12+
if (sessionId == null) {
13+
throw new AuraHandledException('Missing session Id.');
14+
}
15+
if (questionIds == null) {
16+
throw new AuraHandledException('Missing questions Ids.');
17+
}
18+
sessionService.setSessionQuestions(sessionId, questionIds);
19+
}
20+
21+
@AuraEnabled(cacheable=true)
22+
public static List<Quiz_Question__c> getSessionQuestions(Id sessionId) {
23+
if (sessionId == null) {
24+
throw new AuraHandledException('Missing session Id.');
25+
}
26+
return sessionService.getSessionQuestions(sessionId);
27+
}
28+
}
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+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class QuizQuestionService extends QuizAbstractDataService {
2+
public List<Quiz_Question__c> getQuestions() {
3+
return [SELECT Id, Label__c FROM Quiz_Question__c];
4+
}
5+
}
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+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>48.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

src/main/default/classes/QuizSessionService.cls

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,33 @@ public class QuizSessionService extends QuizAbstractDataService {
5454
}
5555
return questions;
5656
}
57+
58+
public void setSessionQuestions(Id sessionId, List<Id> questionIds) {
59+
// Get session
60+
Quiz_Session__c session = [
61+
SELECT Current_Question__c
62+
FROM Quiz_Session__c
63+
WHERE Id = :sessionId
64+
];
65+
// Overwrite session questions
66+
delete [
67+
SELECT Id
68+
FROM Quiz_Session_Question__c
69+
WHERE Session__c = :sessionId
70+
];
71+
List<Quiz_Session_Question__c> questions = new List<Quiz_Session_Question__c>();
72+
for (Integer i = 0; i < questionIds.size(); i++) {
73+
questions.add(
74+
new Quiz_Session_Question__c(
75+
Question__c = questionIds[i],
76+
Question_Index__c = i,
77+
Session__c = sessionId
78+
)
79+
);
80+
}
81+
insert questions;
82+
// Replace current question
83+
session.Current_Question__c = questionIds[0];
84+
update session;
85+
}
5786
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FlexiPage xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<flexiPageRegions>
4+
<componentInstances>
5+
<componentInstanceProperties>
6+
<name>collapsed</name>
7+
<value>false</value>
8+
</componentInstanceProperties>
9+
<componentInstanceProperties>
10+
<name>hideChatterActions</name>
11+
<value>false</value>
12+
</componentInstanceProperties>
13+
<componentInstanceProperties>
14+
<name>numVisibleActions</name>
15+
<value>3</value>
16+
</componentInstanceProperties>
17+
<componentName>force:highlightsPanel</componentName>
18+
</componentInstances>
19+
<name>header</name>
20+
<type>Region</type>
21+
</flexiPageRegions>
22+
<flexiPageRegions>
23+
<componentInstances>
24+
<componentName>questionPicker</componentName>
25+
</componentInstances>
26+
<name>leftcol</name>
27+
<type>Region</type>
28+
</flexiPageRegions>
29+
<flexiPageRegions>
30+
<componentInstances>
31+
<componentName>force:detailPanel</componentName>
32+
</componentInstances>
33+
<name>rightcol</name>
34+
<type>Region</type>
35+
</flexiPageRegions>
36+
<masterLabel>Quiz Session Record Page</masterLabel>
37+
<sobjectType>Quiz_Session__c</sobjectType>
38+
<template>
39+
<name>flexipage:recordHomeTwoColEqualHeaderTemplateDesktop</name>
40+
</template>
41+
<type>RecordPage</type>
42+
</FlexiPage>

src/main/default/layouts/Quiz_Session__c-Quiz Session Layout.layout-meta.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</layoutColumns>
1515
<layoutColumns>
1616
<layoutItems>
17-
<behavior>Required</behavior>
17+
<behavior>Edit</behavior>
1818
<field>Current_Question__c</field>
1919
</layoutItems>
2020
</layoutColumns>
@@ -57,6 +57,24 @@
5757
<layoutColumns/>
5858
<style>CustomLinks</style>
5959
</layoutSections>
60+
<platformActionList>
61+
<actionListContext>Record</actionListContext>
62+
<platformActionListItems>
63+
<actionName>Delete</actionName>
64+
<actionType>StandardButton</actionType>
65+
<sortOrder>0</sortOrder>
66+
</platformActionListItems>
67+
<platformActionListItems>
68+
<actionName>Edit</actionName>
69+
<actionType>StandardButton</actionType>
70+
<sortOrder>1</sortOrder>
71+
</platformActionListItems>
72+
<platformActionListItems>
73+
<actionName>Clone</actionName>
74+
<actionType>StandardButton</actionType>
75+
<sortOrder>2</sortOrder>
76+
</platformActionListItems>
77+
</platformActionList>
6078
<relatedLists>
6179
<fields>NAME</fields>
6280
<fields>Quiz_Question__c.NAME</fields>
@@ -72,7 +90,7 @@
7290
<showRunAssignmentRulesCheckbox>false</showRunAssignmentRulesCheckbox>
7391
<showSubmitAndAttachButton>false</showSubmitAndAttachButton>
7492
<summaryLayout>
75-
<masterLabel>00h1g000000MR8k</masterLabel>
93+
<masterLabel>00h1j000000sXjK</masterLabel>
7694
<sizeX>4</sizeX>
7795
<sizeY>0</sizeY>
7896
<summaryLayoutStyle>Default</summaryLayoutStyle>

0 commit comments

Comments
 (0)