Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nutmeg release bug fixes #15

Open
wants to merge 4 commits into
base: develop/nutmeg.master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions keyterms/keyterms.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ def update_keyterm_html(self, list, course_id):
"""
This handler updates the html to be displayed to the user.
"""
# make sure keyterms are in alphabetical order
list.sort()

self.keytermhtml = ""
for keyterm in list:
div_parent_id = "#allKeytermsList"
keyterm_card_header_id = pydash.camel_case("heading" + keyterm)
keyterm_data_target = pydash.camel_case("collapse" + keyterm)
# remove all non alphanumeric characters and capitalize each word in keyterm. This matches what is being done in keyterms.js
clean_keyterm = ''.join(char for char in keyterm.title() if char.isalnum())
keyterm_card_header_id = "heading" + clean_keyterm
keyterm_data_target = "collapse" + clean_keyterm
keyterm_data_target_hashed = f'#{keyterm_data_target}'
keyterm_show = ("show" if list[0] == keyterm else "")
cardItem = '<div class="card">\n'
Expand All @@ -158,8 +163,8 @@ def update_keyterm_html(self, list, course_id):
cardItem += ' </h5>\n'
cardItem += ' </div>\n'
cardItem += ' <div id="{keyterm_data_target}" class="collapse {keyterm_show}" aria-labelledby="{keyterm_card_header_id}" data-parent="{div_parent_id}">\n'
cardItem += ' <div class="card-body">\n'
cardItem += ' Example Content.\n'
cardItem += ' <div class="{keyterm_data_target} card-body">\n'
cardItem += ' Error loading content.\n'
cardItem += ' </div>\n'
cardItem += ' </div>\n'
cardItem += '</div>\n'
Expand Down
2 changes: 1 addition & 1 deletion keyterms/static/css/collapse.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ tbody.collapse.in {
.collapse-btn {
display: block;
font-weight: 400;
text-align: center;
text-align: left;
white-space: nowrap;
-webkit-user-select: none;
-moz-user-select: none;
Expand Down
26 changes: 23 additions & 3 deletions keyterms/static/js/src/keyterms.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
function camelize(str) {
return str.toLowerCase()
// Replaces any - or _ characters with a space
.replace(/[-_]+/g, ' ')
.replace(/[-_/]+/g, ' ')
// Removes any non alphanumeric characters
.replace(/[^\w\s]/g, '')
// Ensure there are no double spaces after removing characters
.replace(/ /g, ' ')
// Uppercases the first character in each group immediately following a space
// (delimited by spaces)
.replace(/ (.)/g, function($1) { return $1.toUpperCase(); })
Expand Down Expand Up @@ -238,6 +240,17 @@ function KeytermsXBlock(runtime, element, initData) {
function(data, err) {
// Store list of all keyterms
keytermsJson = data;
// Sorts the keyterms into alphabetical order
keytermsJson.sort((a, b) => {
if (a.key_name < b.key_name) {
return -1;
}
if (a.key_name > b.key_name) {
return 1;
}
return 0;
});
allKeytermsSet.clear();
keytermsJson.forEach(keyterm => allKeytermsSet.add(keyterm["key_name"]));
}).then(data => {
// Was adding code to style the accordian card header when clicked.
Expand All @@ -252,7 +265,14 @@ function KeytermsXBlock(runtime, element, initData) {

// Definitions
if (keytermInformation["definitions"].length > 0) {
formattedContent += `<div class="flex-col"><b>Definitions</b><ul class="bullets">`;
formattedContent += `<div class="flex-col">`
if (keytermInformation["definitions"].length > 1) {
formattedContent += `<b>Definitions</b>`
}
else {
formattedContent += `<b>Definition</b>`
}
formattedContent += `<ul class="bullets">`;
keytermInformation["definitions"].forEach(definition => {
formattedContent += `<li>${definition["description"]}</li>`
})
Expand Down Expand Up @@ -310,7 +330,7 @@ function KeytermsXBlock(runtime, element, initData) {
*/
});

var data = { course_id: courseid };
var data = { keyterms: allKeytermsSet, course_id: courseid };
$.ajax({
type: "POST",
url: getincludedkeytermshandlerUrl,
Expand Down