Skip to content

Commit

Permalink
[UI] Allow teachers to customize adventure ordering (hedyorg#3854)
Browse files Browse the repository at this point in the history
**Description**

This is the WIP towards hedyorg#3541

Things to do:
* [x] Fix the customization page to allow teachers to reorder the adventures.
* [x] Change the Database design to save the change
 

**Fixes hedyorg#3541**

**How to test**

* If this is a UI change: _describe how to run your code to see it in action. See this hedyorg#880 (comment) for an example_
* If this is a language change: _add a few tests showing the difference_

**Checklist**
Done? Check if you have it all in place using this list:*
  
- [ ] Contains one of the PR categories in the name
- [ ] Describes changes in the format above
- [ ] Links to an existing issue or discussion 
- [ ] Has a "How to test" section

If you're unsure about any of these, don't hesitate to ask. We're here to help!
  • Loading branch information
jpelay authored Jan 19, 2023
1 parent f8cdb41 commit c826b5a
Show file tree
Hide file tree
Showing 60 changed files with 3,294 additions and 2,743 deletions.
52 changes: 35 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ def load_adventures_per_level(level, keyword_lang):
for short_name, adventure in adventures.items():
if level not in adventure['levels']:
continue
# end adventure is the quiz
# if quizzes are not enabled, do not load it
# Todo TB -> Is this still relevant? Teachers can simply "disable"
# adventures in customizations!
if short_name == 'end' and not config['quiz-enabled']:
continue
current_adventure = {
'short_name': short_name,
'name': adventure['name'],
Expand Down Expand Up @@ -995,16 +989,38 @@ def index(level, program_id):

teacher_adventures = []
# Todo: TB It would be nice to improve this by using level as a sort key
for adventure in customizations.get('teacher_adventures', []):
current_adventure = DATABASE.get_adventure(adventure)
if current_adventure.get('level') == str(level):
try:
current_adventure['content'] = safe_format(current_adventure['content'],
**hedy_content.KEYWORDS.get(g.keyword_lang))
except BaseException:
# We don't want teacher being able to break the student UI -> pass this adventure
pass
teacher_adventures.append(current_adventure)
if 'sorted_adventures' in customizations:
sorted_adventures = customizations['sorted_adventures']
adventures_level = sorted_adventures.get(str(level), [])
for adventure in adventures_level:
if adventure['from_teacher']:
current_adventure = DATABASE.get_adventure(adventure['name'])
try:
current_adventure['content'] = safe_format(current_adventure['content'],
**hedy_content.KEYWORDS.get(g.keyword_lang))
except BaseException:
# We don't want teacher being able to break the student UI -> pass this adventure
pass
teacher_adventures.append(current_adventure)

elif 'teacher_adventures' in customizations:
for adventure in customizations.get('teacher_adventures', []):
current_adventure = DATABASE.get_adventure(adventure)
if current_adventure.get('level') == str(level):
try:
current_adventure['content'] = safe_format(current_adventure['content'],
**hedy_content.KEYWORDS.get(g.keyword_lang))
except BaseException:
# We don't want teacher being able to break the student UI -> pass this adventure
pass
teacher_adventures.append(current_adventure)
adventures_names = {}
for adventure in adventures:
adventures_names[adventure['short_name']] = adventure['name']
for adventure in teacher_adventures:
adventures_names[adventure['id']] = adventure['name']

adventures_per_level = hedy_content.ADVENTURE_ORDER_PER_LEVEL[int(level)]

enforce_developers_mode = False
if 'other_settings' in customizations and 'developers_mode' in customizations['other_settings']:
Expand Down Expand Up @@ -1049,7 +1065,9 @@ def index(level, program_id):
enforce_developers_mode=enforce_developers_mode,
teacher_adventures=teacher_adventures,
loaded_program=loaded_program,
adventure_name=adventure_name)
adventure_name=adventure_name,
adventures_names=adventures_names,
adventures_per_level=adventures_per_level)


@app.route('/hedy/<id>/view', methods=['GET'])
Expand Down
17 changes: 17 additions & 0 deletions build-tools/heroku/tailwind/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -695,3 +695,20 @@ input:checked ~ .toggle-path {
0% {bottom:15px; font-size: 1em; opacity: 1}
100% {bottom:100%; font-size: 4em; opacity: 0}
}

.drop-adventures-hint {
@apply bg-blue-100 border-blue-300;
}

.drop-adventures-active {
@apply bg-yellow-100 border-yellow-300;
}

.adventures-tab {
@apply flex flex-row w-auto overflow-x-auto overflow-y-hidden;
display :none;
}

.adventures-tab[style*='display: block'] {
display: flex !important;
}
Loading

0 comments on commit c826b5a

Please sign in to comment.