Skip to content

Commit a9c88e5

Browse files
rrtheonlyoneremo5000
authored andcommitted
Tone Matrix Side Content Addition - Quest 5B (#361)
* Added mockup tab to add in Tone Matrix * Fix formatting for GradingEditor * Updated code and added ToneMatrix script * Changed predicate to check external lib for tone matrix function * update formatting * Added test case for Tone Matrix * Updated formatting * Fixed wording in solution template
1 parent f5dd172 commit a9c88e5

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/components/assessment/AssessmentWorkspace.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Markdown from '../commons/Markdown'
1010
import Workspace, { WorkspaceProps } from '../workspace'
1111
import { ControlBarProps } from '../workspace/ControlBar'
1212
import { SideContentProps } from '../workspace/side-content'
13+
import ToneMatrix from '../workspace/side-content/ToneMatrix'
1314
import {
1415
IAssessment,
1516
IMCQQuestion,
@@ -228,6 +229,15 @@ class AssessmentWorkspace extends React.Component<
228229
body: <Markdown content={comment} />
229230
})
230231
}
232+
233+
const functionsAttached = props.assessment!.questions[questionId].library.external.symbols
234+
if (functionsAttached.includes('get_matrix')) {
235+
tabs.push({
236+
label: `Tone Matrix`,
237+
icon: IconNames.GRID_VIEW,
238+
body: <ToneMatrix />
239+
})
240+
}
231241
return {
232242
activeTab: props.activeTab,
233243
handleChangeActiveTab: props.handleChangeActiveTab,
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Button } from '@blueprintjs/core'
2+
import * as React from 'react'
3+
4+
class ToneMatrix extends React.Component<{}, {}> {
5+
private $container: HTMLElement | null
6+
7+
public shouldComponentUpdate() {
8+
return false
9+
}
10+
11+
public componentDidMount() {
12+
if ((window as any).ToneMatrix) {
13+
;(window as any).ToneMatrix.initialise_matrix(this.$container!)
14+
}
15+
}
16+
17+
public handleClear() {
18+
;(window as any).ToneMatrix.clear_matrix()
19+
}
20+
21+
public handleRandomise() {
22+
;(window as any).ToneMatrix.randomise_matrix()
23+
}
24+
25+
public render() {
26+
return (
27+
<div className="sa-tone-matrix">
28+
<div className="row">
29+
<div className="controls col-xs-12 pt-dark pt-button-group">
30+
<Button id="clear-matrix" onClick={this.handleClear}>
31+
Clear
32+
</Button>
33+
<Button id="randomise-matrix" onClick={this.handleRandomise}>
34+
Randomise
35+
</Button>
36+
</div>
37+
</div>
38+
<div className="row">
39+
<div className="col-xs-12" ref={r => (this.$container = r)} />
40+
</div>
41+
</div>
42+
)
43+
}
44+
}
45+
46+
export default ToneMatrix

src/mocks/assessmentAPI.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ const mockCurveLibrary: Library = {
180180
globals: mockGlobals
181181
}
182182

183+
const mockToneMatrixLibrary: Library = {
184+
chapter: 1,
185+
external: {
186+
name: ExternalLibraryNames.SOUND,
187+
symbols: ['get_matrix']
188+
},
189+
globals: mockGlobals
190+
}
191+
183192
export const mockAssessmentQuestions: Array<IProgrammingQuestion | IMCQQuestion> = [
184193
{
185194
answer: 'display("answer1");',
@@ -260,6 +269,15 @@ What's your favourite dinner food?
260269
library: mockCurveLibrary,
261270
type: 'mcq',
262271
solution: null
272+
},
273+
{
274+
answer: null,
275+
comment: 'Wow you have come far! `Steady`',
276+
content: 'You have reached the last question! Have some fun with the tone matrix...',
277+
id: 1,
278+
library: mockToneMatrixLibrary,
279+
solutionTemplate: '5th question mock solution template',
280+
type: 'programming'
263281
}
264282
]
265283

0 commit comments

Comments
 (0)