Challenge tags now work

This commit is contained in:
CodeKevin
2016-02-05 23:18:36 -05:00
parent a4b39a1eb5
commit 3841322e2d
4 changed files with 32 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
from flask import current_app as app, render_template, request, redirect, abort, jsonify, json as json_mod, url_for, session, Blueprint
from CTFd.utils import ctftime, view_after_ctf, authed, unix_time, get_kpm, can_view_challenges, is_admin, get_config
from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys
from CTFd.models import db, Challenges, Files, Solves, WrongKeys, Keys, Tags
import time
import re
@@ -38,8 +38,9 @@ def chals():
json = {'game':[]}
for x in chals:
tags = [tag.tag for tag in Tags.query.add_columns('tag').filter_by(chal=x[1]).all()]
files = [ str(f.location) for f in Files.query.filter_by(chal=x.id).all() ]
json['game'].append({'id':x[1], 'name':x[2], 'value':x[3], 'description':x[4], 'category':x[5], 'files':files})
json['game'].append({'id':x[1], 'name':x[2], 'value':x[3], 'description':x[4], 'category':x[5], 'files':files, 'tags':tags})
db.session.close()
return jsonify(json)

View File

@@ -227,6 +227,10 @@ table{
border-radius: 0px;
}
.chal-tag {
margin: 0 5px 0 5px;
}
.alert {
border-radius: 0px;
}

View File

@@ -45,22 +45,31 @@ function loadchalbyname(chalname) {
}
function updateChalWindow(obj) {
window.location.hash = obj.name
$('#chal-window').find('.chal-name').text(obj.name)
$('#chal-window').find('.chal-desc').html(marked(obj.description, {'gfm':true, 'breaks':true}))
$('#chal-window').find('.chal-files').empty();
window.location.hash = obj.name;
var chal = $('#chal-window');
chal.find('.chal-name').text(obj.name);
chal.find('.chal-desc').html(marked(obj.description, {'gfm':true, 'breaks':true}));
chal.find('.chal-files').empty();
for (var i = 0; i < obj.files.length; i++) {
filename = obj.files[i].split('/')
filename = filename[filename.length - 1]
filename = obj.files[i].split('/');
filename = filename[filename.length - 1];
$('#chal-window').find('.chal-files').append("<div class='col-md-3 file-button-wrapper'><a class='file-button' href='"+obj.files[i]+"'><label class='challenge-wrapper file-wrapper hide-text'>"+filename+"</label></a></div>")
};
}
$('#chal-window').find('.chal-value').text(obj.value)
$('#chal-window').find('.chal-category').text(obj.category)
$('#chal-window').find('#chal-id').val(obj.id)
var tags = chal.find('.chal-tags');
tags.empty();
var tag = "<span class='label label-primary chal-tag'>{0}</span>";
for (var i = 0; i < obj.tags.length; i++){
var data = tag.format(obj.tags[i]);
tags.append($(data));
}
chal.find('.chal-value').text(obj.value);
chal.find('.chal-category').text(obj.category);
chal.find('#chal-id').val(obj.id);
var solves = obj.solves == 1 ? " Solve" : " Solves";
$('#chal-window').find('.chal-solves').text(obj.solves + solves)
$('#answer').val("")
chal.find('.chal-solves').text(obj.solves + solves);
$('#answer').val("");
$('pre code').each(function(i, block) {
hljs.highlightBlock(block);
@@ -168,7 +177,7 @@ function getsolves(id){
function loadchals() {
$.get("/chals", function (data) {
categories = [];
var categories = [];
challenges = $.parseJSON(JSON.stringify(data));
$('#challenges-board').html("");
@@ -188,8 +197,8 @@ function loadchals() {
};
for (var i = 0; i <= challenges['game'].length - 1; i++) {
chalinfo = challenges['game'][i];
challenge = chalinfo.category.replace(/ /g,"-").hashCode();
var chalinfo = challenges['game'][i];
var challenge = chalinfo.category.replace(/ /g,"-").hashCode();
var chalid = chalinfo.name.replace(/ /g,"-").hashCode();
var catid = chalinfo.category.replace(/ /g,"-").hashCode();
var chalwrap = $("<div id='{0}' class='challenge-wrapper col-md-2'></div>".format(chalid));

View File

@@ -107,6 +107,7 @@
<div role="tabpanel" class="tab-pane active" id="challenge">
<h3 class='chal-name'></h3>
<h4 class="chal-value"></h4>
<div class="chal-tags"></div>
<p class="chal-desc"></p>
<div class="chal-files file-row row">
</div>