Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
d7b05e48
Commit
d7b05e48
authored
Jan 07, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add insertion of problem types.
parent
75b97409
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
7 deletions
+117
-7
common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
+48
-0
common/lib/xmodule/xmodule/js/src/problem/edit.coffee
+69
-7
No files found.
common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee
View file @
d7b05e48
describe
'MarkdownEditingDescriptor'
,
->
describe
'MarkdownEditingDescriptor'
,
->
describe
'insertMultipleChoice'
,
->
it
'inserts the template if selection is empty'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertMultipleChoice
(
''
)
expect
(
revisedSelection
).
toEqual
(
MarkdownEditingDescriptor
.
multipleChoiceTemplate
)
it
'wraps existing text'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertMultipleChoice
(
'foo
\n
bar'
)
expect
(
revisedSelection
).
toEqual
(
'( ) foo
\n
( ) bar
\n
'
)
it
'recognizes x as a selection if there is non-whitespace after x'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertMultipleChoice
(
'a
\n
x b
\n
c
\n
x
\n
d
\n
x e'
)
expect
(
revisedSelection
).
toEqual
(
'( ) a
\n
(x) b
\n
( ) c
\n
( ) x
\n
( ) d
\n
(x) e
\n
'
)
it
'removes multiple newlines'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertMultipleChoice
(
'a
\n
x b
\n\n\n
c'
)
expect
(
revisedSelection
).
toEqual
(
'( ) a
\n
(x) b
\n
( ) c
\n
'
)
describe
'insertCheckboxChoice'
,
->
# Note, shares code with insertMultipleChoice. Therefore only doing smoke test.
it
'inserts the template if selection is empty'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertCheckboxChoice
(
''
)
expect
(
revisedSelection
).
toEqual
(
MarkdownEditingDescriptor
.
checkboxChoiceTemplate
)
it
'wraps existing text'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertCheckboxChoice
(
'foo
\n
bar'
)
expect
(
revisedSelection
).
toEqual
(
'[ ] foo
\n
[ ] bar
\n
'
)
describe
'insertStringInput'
,
->
it
'inserts the template if selection is empty'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertStringInput
(
''
)
expect
(
revisedSelection
).
toEqual
(
MarkdownEditingDescriptor
.
stringInputTemplate
)
it
'wraps existing text'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertStringInput
(
'my text'
)
expect
(
revisedSelection
).
toEqual
(
'= my text'
)
describe
'insertNumberInput'
,
->
it
'inserts the template if selection is empty'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertNumberInput
(
''
)
expect
(
revisedSelection
).
toEqual
(
MarkdownEditingDescriptor
.
numberInputTemplate
)
it
'wraps existing text'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertNumberInput
(
'my text'
)
expect
(
revisedSelection
).
toEqual
(
'= my text'
)
describe
'insertSelect'
,
->
it
'inserts the template if selection is empty'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertSelect
(
''
)
expect
(
revisedSelection
).
toEqual
(
MarkdownEditingDescriptor
.
selectTemplate
)
it
'wraps existing text'
,
->
revisedSelection
=
MarkdownEditingDescriptor
.
insertSelect
(
'my text'
)
expect
(
revisedSelection
).
toEqual
(
'[[my text]]'
)
describe
'markdownToXml'
,
->
describe
'markdownToXml'
,
->
it
'converts raw text to paragraph'
,
->
it
'converts raw text to paragraph'
,
->
data
=
MarkdownEditingDescriptor
.
markdownToXml
(
'foo'
)
data
=
MarkdownEditingDescriptor
.
markdownToXml
(
'foo'
)
...
...
common/lib/xmodule/xmodule/js/src/problem/edit.coffee
View file @
d7b05e48
class
@
MarkdownEditingDescriptor
extends
XModule
.
Descriptor
class
@
MarkdownEditingDescriptor
extends
XModule
.
Descriptor
@
multipleChoiceTemplate
:
"( ) incorrect
\n
( ) incorrect
\n
(x) correct
\n
"
@
checkboxChoiceTemplate
:
"[x] correct
\n
[ ] incorrect
\n
[x] correct
\n
"
@
stringInputTemplate
:
"= answer
\n
"
@
numberInputTemplate
:
"= answer +- x%
\n
"
@
selectTemplate
:
"[[incorrect, (correct), incorrect]]
\n
"
constructor
:
(
element
)
->
constructor
:
(
element
)
->
$body
.
on
(
'click'
,
'.editor-tabs .tab'
,
@
changeEditor
)
$body
.
on
(
'click'
,
'.editor-tabs .tab'
,
@
changeEditor
)
$body
.
on
(
'click'
,
'.editor-bar a'
,
@
onToolbarButton
);
$body
.
on
(
'click'
,
'.editor-bar a'
,
@
onToolbarButton
);
...
@@ -19,24 +25,32 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
...
@@ -19,24 +25,32 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
changeEditor
:
(
e
)
=>
changeEditor
:
(
e
)
=>
e
.
preventDefault
();
e
.
preventDefault
();
if
not
$
(
e
.
currentTarget
).
hasClass
(
'current'
)
$
(
'.editor-tabs .current'
).
removeClass
(
'current'
)
$
(
'.editor-tabs .current'
).
removeClass
(
'current'
)
$
(
e
.
currentTarget
).
addClass
(
'current'
)
$
(
e
.
currentTarget
).
addClass
(
'current'
)
if
(
@
current_editor
==
@
xml_editor
)
if
(
@
current_editor
==
@
xml_editor
)
@
setCurrentEditor
(
@
markdown_editor
)
@
setCurrentEditor
(
@
markdown_editor
)
# onMarkdownEditorUpdate();
else
else
@
setCurrentEditor
(
@
xml_editor
)
@
setCurrentEditor
(
@
xml_editor
)
@
xml_editor
.
setValue
(
MarkdownEditingDescriptor
.
markdownToXml
(
@
markdown_editor
.
getValue
()))
@
xml_editor
.
setValue
(
MarkdownEditingDescriptor
.
markdownToXml
(
@
markdown_editor
.
getValue
()))
onToolbarButton
:
(
e
)
=>
onToolbarButton
:
(
e
)
=>
e
.
preventDefault
();
e
.
preventDefault
();
selection
=
@
markdown_editor
.
getSelection
()
revisedSelection
=
null
switch
$
(
e
.
currentTarget
).
attr
(
'class'
)
switch
$
(
e
.
currentTarget
).
attr
(
'class'
)
when
"multiple-choice-button"
then
console
.
log
(
"multiple choice"
)
when
"multiple-choice-button"
then
revisedSelection
=
MarkdownEditingDescriptor
.
insertMultipleChoice
(
selection
)
when
"string-button"
then
console
.
log
(
"string-button"
)
when
"string-button"
then
revisedSelection
=
MarkdownEditingDescriptor
.
insertStringInput
(
selection
)
when
"number-button"
then
console
.
log
(
"number-button"
)
when
"number-button"
then
revisedSelection
=
MarkdownEditingDescriptor
.
insertNumberInput
(
selection
)
when
"checks-button"
then
console
.
log
(
"checks-button"
)
when
"checks-button"
then
revisedSelection
=
MarkdownEditingDescriptor
.
insertCheckboxChoice
(
selection
)
when
"dropdown-button"
then
console
.
log
(
"dropdown-button"
)
when
"dropdown-button"
then
revisedSelection
=
MarkdownEditingDescriptor
.
insertSelect
(
selection
)
else
console
.
log
(
"unknown option"
)
else
# do nothing
if
revisedSelection
!=
null
@
markdown_editor
.
replaceSelection
(
revisedSelection
)
@
markdown_editor
.
focus
()
setCurrentEditor
:
(
editor
)
->
setCurrentEditor
:
(
editor
)
->
$
(
@
current_editor
.
getWrapperElement
()).
hide
()
$
(
@
current_editor
.
getWrapperElement
()).
hide
()
...
@@ -49,6 +63,54 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
...
@@ -49,6 +63,54 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
$body
.
off
(
'click'
,
'.editor-bar a'
,
@
onToolbarButton
);
$body
.
off
(
'click'
,
'.editor-bar a'
,
@
onToolbarButton
);
data
:
@
xml_editor
.
getValue
()
data
:
@
xml_editor
.
getValue
()
@
insertMultipleChoice
:
(
selectedText
)
->
return
MarkdownEditingDescriptor
.
insertGenericChoice
(
selectedText
,
'('
,
')'
,
MarkdownEditingDescriptor
.
multipleChoiceTemplate
)
@
insertCheckboxChoice
:
(
selectedText
)
->
return
MarkdownEditingDescriptor
.
insertGenericChoice
(
selectedText
,
'['
,
']'
,
MarkdownEditingDescriptor
.
checkboxChoiceTemplate
)
@
insertGenericChoice
:
(
selectedText
,
choiceStart
,
choiceEnd
,
template
)
->
if
selectedText
.
length
>
0
# Replace adjacent newlines with a single newline
cleanSelectedText
=
selectedText
.
replace
(
/\n+/g
,
'
\n
'
)
lines
=
cleanSelectedText
.
split
(
'
\n
'
)
revisedLines
=
''
for
line
in
lines
revisedLines
+=
choiceStart
# This is looking for a x before text to mark as selected.
if
/x\s/i
.
test
(
line
)
# Remove the x and any initial whitespace
lineWithoutX
=
line
.
replace
(
/^(\s+)?x/i
,
''
)
# Check if any non-whitespace chars remain on the line
if
not
/^\s+$/
.
test
(
lineWithoutX
)
# Remove initial whitespace, x, and space immediately after
line
=
line
.
replace
(
/^(\s+)?x\s/i
,
''
)
revisedLines
+=
'x'
else
revisedLines
+=
' '
else
revisedLines
+=
' '
revisedLines
+=
choiceEnd
+
' '
+
line
+
'
\n
'
return
revisedLines
else
return
template
@
insertStringInput
:
(
selectedText
)
->
return
MarkdownEditingDescriptor
.
insertGenericInput
(
selectedText
,
'= '
,
''
,
MarkdownEditingDescriptor
.
stringInputTemplate
)
@
insertNumberInput
:
(
selectedText
)
->
return
MarkdownEditingDescriptor
.
insertGenericInput
(
selectedText
,
'= '
,
''
,
MarkdownEditingDescriptor
.
numberInputTemplate
)
@
insertSelect
:
(
selectedText
)
->
return
MarkdownEditingDescriptor
.
insertGenericInput
(
selectedText
,
'[['
,
']]'
,
MarkdownEditingDescriptor
.
selectTemplate
)
@
insertGenericInput
:
(
selectedText
,
lineStart
,
lineEnd
,
template
)
->
if
selectedText
.
length
>
0
# TODO: should this insert a newline afterwards?
return
lineStart
+
selectedText
+
lineEnd
else
return
template
@
markdownToXml
:
(
markdown
)
->
@
markdownToXml
:
(
markdown
)
->
toXml
=
`
function
(
markdown
)
{
toXml
=
`
function
(
markdown
)
{
var
xml
=
markdown
;
var
xml
=
markdown
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment