challenge update modal is now replaceable (#236)

* challenge update modal is now replaceable

By defining
* [type]-challenge-update.hbs
* [type]-challenge-modals.hbs
* [type]-challenge-update.js

in the /static/admin/js/templates/challenges/[type] folder the
challenge update modal will be defined for any challenges of
the given type. This allows for essentially full customizability
of how you will edit custom challenge types in the admin UI.

The reason for having two files, *update.hbs and *modals.hbs, is
that *update.hbs defines the body for the main challenge update
modal, while *modals.hbs defines any additional modals which will be
used within the main modal

There is one function which is required in *update.js is
`openchal(id)` which will be passed the id of the challenge to be
edited and should open the modal as well as load any needed data

* fixed multi-modal issues

Issues were coming from two sources:
* I had placed the modals in an indirect relationship in the DOM
  tree. They need to be siblings I now see
* There was double counting of modals within multi-modal.js. This
  only started to appear with the dynamically loaded modals. I
  fixed the script to accurately count modals each time
This commit is contained in:
Victor "Nate" Graf
2017-04-08 00:20:22 -05:00
committed by Kevin Chung
parent b027703f80
commit fd22ef98dc
10 changed files with 871 additions and 714 deletions

View File

@@ -25,7 +25,7 @@ def admin_chal_types():
@admins_only
def admin_chals():
if request.method == 'POST':
chals = Challenges.query.add_columns('id', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all()
chals = Challenges.query.add_columns('id', 'type', 'name', 'value', 'description', 'category', 'hidden', 'max_attempts').order_by(Challenges.value).all()
teams_with_points = db.session.query(Solves.teamid).join(Teams).filter(
Teams.banned == False).group_by(Solves.teamid).count()
@@ -39,6 +39,9 @@ def admin_chals():
else:
percentage = 0.0
type_class = CHALLENGE_CLASSES.get(x.type)
type_name = type_class.name if type_class else None
json_data['game'].append({
'id': x.id,
'name': x.name,
@@ -47,6 +50,8 @@ def admin_chals():
'category': x.category,
'hidden': x.hidden,
'max_attempts': x.max_attempts,
'type': x.type,
'type_name': type_name,
'percentage_solved': percentage
})
@@ -286,4 +291,4 @@ def admin_update_chal():
db.session.add(challenge)
db.session.commit()
db.session.close()
return redirect(url_for('admin_challenges.admin_chals'))
return redirect(url_for('admin_challenges.admin_chals'))