Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crowdsourcehinter
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
OpenEdx
crowdsourcehinter
Commits
7b6ee71b
Commit
7b6ee71b
authored
Apr 05, 2015
by
solashirai
Committed by
Piotr Mitros
Oct 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small improvements
parent
6a50de30
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
82 deletions
+45
-82
crowdsourcehinter/.#crowdsourcehinter.py
+0
-2
crowdsourcehinter/crowdsourcehinter.py
+11
-29
crowdsourcehinter/static/html/crowdsourcehinter.html
+1
-1
crowdsourcehinter/static/js/src/crowdsourcehinter.js
+33
-50
No files found.
crowdsourcehinter/.#crowdsourcehinter.py
deleted
120000 → 0
View file @
6a50de30
user
@olduser
-
VPCEB3NFX
.
4809
:
1424514334
\ No newline at end of file
crowdsourcehinter/crowdsourcehinter.py
View file @
7b6ee71b
...
...
@@ -63,19 +63,6 @@ class CrowdsourceHinter(XBlock):
# Setting the element in the XML file is critical for the hinter to work.
Element
=
String
(
default
=
""
,
scope
=
Scope
.
content
)
def
student_view
(
self
,
context
=
None
):
"""
This view renders the hint view to the students. The HTML has the hints templated
in, and most of the remaining functionality is in the JavaScript.
"""
html
=
self
.
resource_string
(
"static/html/crowdsourcehinter.html"
)
frag
=
Fragment
(
html
)
frag
.
add_javascript_url
(
'//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js'
)
frag
.
add_css
(
self
.
resource_string
(
"static/css/crowdsourcehinter.css"
))
frag
.
add_javascript
(
self
.
resource_string
(
"static/js/src/crowdsourcehinter.js"
))
frag
.
initialize_js
(
'CrowdsourceHinter'
,
{
'hinting_element'
:
self
.
Element
})
return
frag
def
studio_view
(
self
,
context
=
None
):
"""
This function defines a view for editing the XBlock when embedding it in a course. It will allow
...
...
@@ -105,15 +92,18 @@ class CrowdsourceHinter(XBlock):
"""
return
self
.
xmodule_runtime
.
user_is_staff
@XBlock.json_handler
def
is_user_staff
(
self
,
_data
,
_suffix
=
''
):
def
student_view
(
self
,
context
=
None
):
"""
Return whether the user is staff.
Returns:
is_user_staff: indicator for whether the user is staff
This view renders the hint view to the students. The HTML has the hints templated
in, and most of the remaining functionality is in the JavaScript.
"""
result
=
{
'is_user_staff'
:
self
.
get_user_is_staff
()}
return
result
html
=
self
.
resource_string
(
"static/html/crowdsourcehinter.html"
)
frag
=
Fragment
(
html
)
frag
.
add_javascript_url
(
'//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js'
)
frag
.
add_css
(
self
.
resource_string
(
"static/css/crowdsourcehinter.css"
))
frag
.
add_javascript
(
self
.
resource_string
(
"static/js/src/crowdsourcehinter.js"
))
frag
.
initialize_js
(
'CrowdsourceHinter'
,
{
'hinting_element'
:
self
.
Element
,
'isStaff'
:
self
.
Element
})
return
frag
@XBlock.json_handler
def
get_hint
(
self
,
data
,
suffix
=
''
):
...
...
@@ -226,7 +216,7 @@ class CrowdsourceHinter(XBlock):
# that were not used. The keys are the used hints, the values are the
# corresponding incorrect answer
feedback_data
=
{}
if
data
[
'isStaff'
]
==
'true'
:
if
self
.
get_user_is_staff
()
:
if
len
(
self
.
Reported
)
!=
0
:
for
answer_keys
in
self
.
hint_database
:
if
str
(
len
(
self
.
hint_database
[
str
(
answer_keys
)]))
!=
str
(
0
):
...
...
@@ -255,14 +245,6 @@ class CrowdsourceHinter(XBlock):
self
.
Used
=
[]
return
feedback_data
def
no_hints
(
self
,
index
):
"""
This function is used when no hints exist for an answer. The feedback_data within
get_feedback is set to "there are no hints for" + " " + str(self.WrongAnswers[index])
"""
self
.
WrongAnswers
.
append
(
str
(
self
.
WrongAnswers
[
index
]))
self
.
Used
.
append
(
str
(
"There are no hints for"
+
" "
+
str
(
self
.
WrongAnswers
[
index
])))
@XBlock.json_handler
def
get_ratings
(
self
,
data
,
suffix
=
''
):
"""
...
...
crowdsourcehinter/static/html/crowdsourcehinter.html
View file @
7b6ee71b
...
...
@@ -4,7 +4,7 @@
<
div
class
=
"csh_hint"
><
b
>
{{
hint
}}
<
/b></
div
>
<
/div
>
<
div
class
=
'csh_rating_data'
>
<
div
role
=
"button"
class
=
"csh_rate_hint"
data
-
rate
=
"upvote"
data
-
icon
=
"arrow-u"
>
<
div
role
=
"button"
class
=
"csh_rate_hint"
data
-
rate
=
"upvote"
>
<
b
>
Rate
as
Helpful
<
/b
>
<
/div
>
<
div
role
=
"button"
class
=
"csh_rate_hint"
data
-
rate
=
"downvote"
>
...
...
crowdsourcehinter/static/js/src/crowdsourcehinter.js
View file @
7b6ee71b
function
CrowdsourceHinter
(
runtime
,
element
,
data
){
//executeHinter is used to disable the hinter after switching units in an edX course
//If the code is not made to stop running, the hinter will act up after switching from and back to
//a certain unit.
//switching units back to a previous question will make a second hinter start up.
//executeHinter is used to disable the hinter after switching units in an edX course.
var
executeHinter
=
true
;
$
(
".crowdsourcehinter_block"
,
element
).
hide
();
if
(
executeHinter
){
var
isShowingHintFeedback
=
false
;
var
hinting_element
;
var
isStaff
=
false
;
var
isStaff
;
var
voted
=
false
;
$
(
".csh_HintsToUse"
,
element
).
text
(
""
);
function
stopScript
(){
...
...
@@ -45,26 +44,9 @@ function CrowdsourceHinter(runtime, element, data){
//send empty data for ajax call because not having a data field causes error
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'
is_user_staff
'
),
url
:
runtime
.
handlerUrl
(
element
,
'
get_feedback
'
),
data
:
JSON
.
stringify
({}),
success
:
function
(
result
)
{
if
(
result
[
'is_user_staff'
])
{
isStaff
=
true
;
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'get_feedback'
),
data
:
JSON
.
stringify
({
"isStaff"
:
"true"
}),
success
:
getFeedback
});
}
else
{
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'get_feedback'
),
data
:
JSON
.
stringify
({
"isStaff"
:
"false"
}),
success
:
getFeedback
});
}
}
success
:
getFeedback
});
}
}
...
...
@@ -114,8 +96,9 @@ function CrowdsourceHinter(runtime, element, data){
}
function
setStudentAnswers
(
student_answers
){
//Append divs for each answer the student submitted before correctly answering the question.
//showHintFeedback appends new hints into these divs.
//Append new divisions into html for each answer the student submitted before correctly
//answering the question. showHintFeedback appends new hints into these divs.
//When the hinter is set to show best, only one div will be created
var
html
=
""
;
var
template
=
$
(
'#show_answer_feedback'
).
html
();
var
data
=
{
...
...
@@ -128,7 +111,7 @@ function CrowdsourceHinter(runtime, element, data){
function
getFeedback
(
result
){
//Set up the student feedback stage. Each student answer and all answer-specific hints for that answer are shown
//to the student, as well as an option to create a new hint for an answer.
if
(
isStaff
){
if
(
data
.
isStaff
){
$
(
'.crowdsourcehinter_block'
,
element
).
attr
(
'class'
,
'crowdsourcehinter_block_is_staff'
);
$
.
each
(
result
,
function
(
index
,
value
)
{
if
(
value
==
"Reported"
)
{
...
...
@@ -169,9 +152,9 @@ function CrowdsourceHinter(runtime, element, data){
isShowingHintFeedback
=
true
;
}
}
$
(
element
).
on
(
'click'
,
'.csh_student_hint_creation'
,
function
(){
//
Click event for the creation of a new hint. This button will bring up the text input.
//
create text input area for contributing a new hint
$
(
'.csh_student_hint_creation'
,
element
).
each
(
function
(){
$
(
this
).
show
();
});
...
...
@@ -193,24 +176,16 @@ function CrowdsourceHinter(runtime, element, data){
})
$
(
element
).
on
(
'click'
,
'.csh_submit_new'
,
function
(){
//
Click event to submit a new hint for an answer.
//
add the newly created hint to the hinter's pool of hints
if
(
$
(
this
).
parent
().
parent
().
find
(
'.csh_student_text_input'
).
val
().
length
>
0
){
var
answerdata
=
unescape
(
$
(
this
).
attr
(
'answer'
));
var
newhint
=
unescape
(
$
(
'.csh_student_text_input'
).
val
());
Logger
.
log
(
'crowd_hinter.submit_new.click.event'
,
{
"student_answer"
:
answerdata
,
"new_hint_submission"
:
newhint
});
$
(
'.csh_submitbutton'
,
element
).
show
();
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'add_new_hint'
),
data
:
JSON
.
stringify
({
"submission"
:
newhint
,
"answer"
:
answerdata
}),
success
:
function
(
result
){
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'get_ratings'
),
data
:
JSON
.
stringify
({
"student_answer"
:
answerdata
,
"hint"
:
newhint
}),
success
:
showHintFeedback
(
newhint
,
answerdata
)
});
}
success
:
Logger
.
log
(
'crowd_hinter.submit_new.click.event'
,
{
"student_answer"
:
answerdata
,
"new_hint_submission"
:
newhint
})
});
$
(
this
).
parent
().
parent
().
find
(
'.csh_student_text_input'
).
remove
();
$
(
this
).
remove
();
...
...
@@ -218,22 +193,35 @@ function CrowdsourceHinter(runtime, element, data){
})
$
(
element
).
on
(
'click'
,
'.csh_rate_hint'
,
function
(){
//send info to hinter indicating whether the hint was upvoted, downvoted, or reported
if
(
!
voted
||
$
(
this
).
attr
(
'data-rate'
)
==
"report"
){
if
(
$
(
this
).
attr
(
'data-rate'
)
==
"report"
){
alert
(
"This hint has been reported for review."
);
}
hint
=
$
(
'.csh_HintsToUse'
,
element
).
attr
(
'hint_received'
);
student_answer
=
$
(
'.csh_HintsToUse'
,
element
).
attr
(
'student_answer'
);
Logger
.
log
(
'crowd_hinter.rate_hint.click.event'
,
{
"hint"
:
hint
,
"student_answer"
:
student_answer
,
"rating"
:
$
(
this
).
attr
(
'data-rate'
)});
$
.
ajax
({
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'rate_hint'
),
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"hint"
:
hint
,
"student_answer"
:
student_answer
})
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"hint"
:
hint
,
"student_answer"
:
student_answer
}),
success
:
Logger
.
log
(
'crowd_hinter.rate_hint.click.event'
,
{
"hint"
:
hint
,
"student_answer"
:
student_answer
,
"rating"
:
$
(
this
).
attr
(
'data-rate'
)})
});
voted
=
true
;
}
});
function
removeFeedback
(){
//remove a hint from the staff feedback area after a staff member has
//returned the hint to the hint pool or removed it permanently
$
(
'.csh_hint_value'
,
element
).
each
(
function
(){
if
(
$
(
this
).
attr
(
'value'
)
==
hint
){
$
(
this
).
remove
();
}
});
}
$
(
element
).
on
(
'click'
,
'.csh_staff_rate'
,
function
(){
//Staff ratings are the removal or unreporting of reported hints from the database. The attribute 'data-rate' is used
//to determine whether to unreport or delete the hint.
//Staff "rating" removes or returns a reported hint from/to the hinter's pool of hints
hint
=
$
(
this
).
parent
().
find
(
".csh_hint"
).
text
();
student_answer
=
"Reported"
;
Logger
.
log
(
'crowd_hinter.staff_rate_hint.click.event'
,
{
"hint"
:
hint
,
"student_answer"
:
student_answer
,
"rating"
:
$
(
this
).
attr
(
'data-rate'
)});
...
...
@@ -241,13 +229,8 @@ function CrowdsourceHinter(runtime, element, data){
type
:
"POST"
,
url
:
runtime
.
handlerUrl
(
element
,
'rate_hint'
),
data
:
JSON
.
stringify
({
"student_rating"
:
$
(
this
).
attr
(
'data-rate'
),
"hint"
:
hint
,
"student_answer"
:
student_answer
}),
success
:
function
(
result
){
$
(
'.csh_hint_value'
,
element
).
each
(
function
(){
if
(
$
(
this
).
attr
(
'value'
)
==
hint
){
$
(
this
).
remove
();
}
});
}
success
:
removeFeedback
()
});
})
}}
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