diff options
-rw-r--r-- | equations/models.py | 2 | ||||
-rw-r--r-- | equations/templates/equations/variable_detail.html | 2 | ||||
-rw-r--r-- | equations/views.py | 16 | ||||
-rw-r--r-- | templates/go.html | 171 | ||||
-rw-r--r-- | urls.py | 5 |
5 files changed, 174 insertions, 22 deletions
diff --git a/equations/models.py b/equations/models.py index b34a93c..e644a37 100644 --- a/equations/models.py +++ b/equations/models.py @@ -33,6 +33,8 @@ class Symbol(models.Model): self.render = self.renderdir + "%s.png" % self.id super(Symbol, self).save() +dispatcher.connect(update_render, signal=signals.pre_save, sender=Symbol) + def update_generic_variable(sender, instance, signal, *args, **kwargs): """Checks if there is a generic variable associated with this symbol; create one if there isn't""" diff --git a/equations/templates/equations/variable_detail.html b/equations/templates/equations/variable_detail.html index ceec48c..63ca233 100644 --- a/equations/templates/equations/variable_detail.html +++ b/equations/templates/equations/variable_detail.html @@ -14,7 +14,7 @@ <tr><td><b>Reference:</b></td><td> <a href="{{ object.reference }}">{{ object.reference }}</a></td></tr> {% endif %} - <tr><td><b>Raw LaTeX:</b></td><td><pre>{{ object.latex }}</pre></td></tr> + <tr><td width="25%"><b>Raw LaTeX:</b></td><td><pre>{{ object.latex }}</pre></td></tr> {% if object.unicode %} <tr><td><b>Unicode:</b></td><td>{{ object.unicode }}</td></tr> {% endif %} diff --git a/equations/views.py b/equations/views.py index 9ef1081..41309c1 100644 --- a/equations/views.py +++ b/equations/views.py @@ -2,11 +2,11 @@ from django.core import serializers from models import Equation, Variable, Symbol from django.http import HttpResponse -def all_vars(request): +def all_variables(request): data = serializers.serialize("json", Variable.objects.all()) return HttpResponse(data, mimetype="text/javascript") -def all_symbs(request): +def all_symbols(request): data = serializers.serialize("json", Symbol.objects.all()) return HttpResponse(data, mimetype="text/javascript") @@ -27,3 +27,15 @@ def equs_by_vars(request, whichvars): data = serializers.serialize("json", returnables) return HttpResponse(data, mimetype="text/javascript") + + +def vars_by_symbs(request, which_symbols): + vars = which_symbols.split(',') + if len(vars) < 1 or which_symbols == '': + return HttpResponse('[]', mimetype="text/javascript") + if vars[-1] == '/' or vars[-1] == '': + vars = vars[:-1] + returnables = Variable.objects.filter(symbol=vars[0]) + + data = serializers.serialize("json", returnables) + return HttpResponse(data, mimetype="text/javascript") diff --git a/templates/go.html b/templates/go.html index 98a2ddb..2617037 100644 --- a/templates/go.html +++ b/templates/go.html @@ -5,32 +5,157 @@ </script> <script type="text/javascript"> var variables = [] +var symbols = [] var equations = [] var equationsTMP = [] +var lock = false; +function get_symbols() { + //$('status_bin').innerHTML= "Fetching..." + lock = true; + var initialSymbolssRequest = new Ajax.Request( + "/json/all_symbols/", + { method: 'get', + onSuccess: handle_symbols}); +} function get_variables() { //$('status_bin').innerHTML= "Fetching..." + lock = true; var initialVariablesRequest = new Ajax.Request( - "/json/all_vars/", + "/json/all_variables/", { method: 'get', - onSuccess: handle_variables }); + onSuccess: handle_variables}); } -function handle_variables(transport) { +function handle_symbols(transport) { + lock = false; json = transport.responseText.evalJSON(); //$('status_bin').innerHTML = "Recieved: \n" + json; - $('variables_bin').innerHTML = ''; + $('symbols_bin').innerHTML = ''; for(i=0; i<json.length; i++) { - variables[i] = json[i].fields; - $('variables_bin').innerHTML += '<img src="/static/' + - variables[i].render + + symbols[i] = json[i].fields; + symbols[i].pk = json[i].pk; + $('symbols_bin').innerHTML += '<img src="/static/' + + symbols[i].render + '" style="padding:2px; border: 2px solid white; margin: 4px;" ' + - 'id="variable'+i+'" ' + - 'alt="'+variables[i].name+'" onClick="toggle_variable('+i+');">'; - variables[i].isselected = false; + 'id="symbol'+i+'" ' + + 'alt="'+symbols[i].name+'" onClick="toggle_symbol('+i+');">'; + symbols[i].isselected = false; } } +function handle_variables(transport) { + lock = false; + json = transport.responseText.evalJSON(); + //$('status_bin').innerHTML = "Recieved: \n" + json; + if(! $('variables_bin').started) { + $('variables_bin').started = true + $('variables_bin').innerHTML = ''; + } + if(json.length < 1) { + $('variables_bin').innerHTML = '<br />'; + $('variables_bin').started = false; + } + + var symbol = -1; + for(i = 0; i<symbols.length; i++) { + for(j=0; j<json.length; j++) { + if(symbols[i].pk == json[j].fields.symbol) { + symbol = i; + break; + } + } + } + if(symbol == -1) { return; } + + if(!($('set_symbol'+symbol))){ + $('variables_bin').innerHTML += '<span id="set_symbol' + + symbol + '"></span>'; + } + $('set_symbol'+symbol).innerHTML = + '<img src="/static/' + symbols[symbol].render + '" />: ' + + '<span class="clickable" onClick="toggle_allvars(' + symbol + + ');" id="all_vars'+symbol+'">(all)</a>'; + + var prevars = variables.length; + for(i=0; i<json.length; i++) { + variables[i+prevars] = json[i].fields; + variables[i+prevars].pk = json[i].pk; + //if(! variables[i+prevars].isgeneric) { + $('set_symbol'+symbol).innerHTML += ' ' + + '<span class="clickable" id="variable'+(i+prevars)+'"' + + 'onClick="toggle_variable('+(i+prevars)+');">'+ + variables[i+prevars].name + '</span> '; + variables[i+prevars].isselected = false; + //} + } + $('set_symbol'+symbol).innerHTML += '<br />'; + toggle_allvars(symbol); +} + +function toggle_allvars(snum) { + if(lock) return; + symbols[snum].isall = true; + $('all_vars'+snum).style["border"] = "2px solid green"; + for(i=0;i<variables.length;i++) { + if(variables[i].symbol = snum) { + variables[i].isselected = true; + if(! variables[i].isgeneric) { + $('variable'+i).style["border"] = "2px solid white"; + } + } + } + var whichvars = '' + for(i=0; i<variables.length; i++){ + if(variables[i].isselected == true){ + whichvars += variables[i].pk + "," + } + } + + //$('status_bin').innerHTML = "Requested: \n" + + "/json/equs_by_vars/" + whichvars + "/" + "<br />"; + lock = true; + var freshEquationsRequest = new Ajax.Request( + "/json/equs_by_vars/" + whichvars + "/", + { method: 'get', + onSuccess: handle_equations}); +} + +function toggle_symbol(snum) { + if(lock) return; + if(symbols[snum].isselected == false) { + symbols[snum].isselected = true; + $('symbol'+snum).style["border"] = "2px solid green"; + } else { + symbols[snum].isselected = false; + $('symbol'+snum).style["border"] = "2px solid white"; + if($('set_symbol'+snum)) { + $('set_symbol'+snum).innerHTML = ''; + } + } + var whichsymbols = '' + for(i=0; i<symbols.length; i++){ + if(symbols[i].isselected == true){ + whichsymbols += symbols[i].pk + ","; + } + } + lock = true; + var freshVariablesRequest = new Ajax.Request( + "/json/vars_by_symbs/" + whichsymbols + "/", + { method: 'get', + onSuccess: handle_variables}); +} function toggle_variable(vnum) { + if(lock) return; + var symbol = variables[vnum].symbol + if(symbols[symbol].isall) { + $('all_vars'+symbol).style["border"] = "2px solid white" + for(i=0;i<variables.length;i++) { + if(variables[i].symbol == symbol) { + variables[i].isselected = false; + } + } + symbols[symbol].isall = false; + } if(variables[vnum].isselected == false) { variables[vnum].isselected = true; $('variable'+vnum).style["border"] = "2px solid green" @@ -41,32 +166,38 @@ function toggle_variable(vnum) { var whichvars = '' for(i=0; i<variables.length; i++){ if(variables[i].isselected == true){ - whichvars += (i+1) + "," + whichvars += variables[i].pk + "," } } //$('status_bin').innerHTML = "Requested: \n" + "/json/equs_by_vars/" + whichvars + "/" + "<br />"; + lock = true; var freshEquationsRequest = new Ajax.Request( "/json/equs_by_vars/" + whichvars + "/", { method: 'get', onSuccess: handle_equations}); } function handle_equations(transport) { + lock = false; //$('status_bin').innerHTML += "Recieved: \n" + transport.responseText; json = transport.responseText.evalJSON(); //$('status_bin').innerHTML += "<br />Recieved: \n" + json; - $('equations_bin').innerHTML = '<br />'; + $('equations_bin').innerHTML = ''; + if(json.length < 1) + $('equations_bin').innerHTML = '<br />'; for(i=0; i<json.length; i++) { equations[json[i].pk-1] = json[i].fields; + equations[json[i].pk-1] = json[i].pk; equationsTMP[i] = json[i].fields; + equationsTMP[i].pk = json[i].pk; $('equations_bin').innerHTML += '<a style="text-decoration:none;' + 'border:none;" href="/equation/'+json[i].pk+'/">' + '<img src="/static/' + json[i].fields.render + '" style="padding:2px; border: 2px solid white; margin: 4px;" ' + 'id="variable'+i+'" ' + - 'alt="'+json[i].fields.name+'"></a>'; + 'alt="'+json[i].fields.name+'"></a> '; } } @@ -76,21 +207,27 @@ function handle_equations(transport) { {% block title %}<span style="color: orange;">YAY!</span>{% endblock %} {% block content %} -<b>Variables<!-- <span onClick="get_variables();">(fetch)</span>-->: </b> -<div id="variables_bin" style="border: 2px solid black; width: 100%;"> +<b>Symbols<!-- <span onClick="get_variables();">(fetch)</span>-->: </b> +<div id="symbols_bin" style="border: 2px solid black; width: 100%;"> (none yet!) </div> <br /> +<b>Variables<!-- <span onClick="get_variables();">(fetch)</span>-->: </b> +<div id="variables_bin" style="border: 2px solid black; width: 100%; + padding: 3px;"> +(none yet, choose some symbols!) +</div> +<br /> <b>Matching Equations: </b> <div id="equations_bin" style="border: 2px solid black; width: 100%;"> (none yet, choose some variables!) </div> -<span style="visibility: hidden; width=1px, height=1px;"> +<!--<span style="visibility: hidden; width=1px, height=1px;">--> <b>Status: </b> <div id="status_bin" style="border: 2px solid black; width: 100%;"> (nothing...)</div> </span> <script type="text/javascript"> -window.onLoad = get_variables(); +window.onLoad = get_symbols(); </script> {% endblock %} @@ -29,6 +29,7 @@ urlpatterns += patterns('django.views.generic.list_detail', ) urlpatterns += patterns('equator.equations.views', (r'^json/equs_by_vars/(?P<whichvars>[\d\,]*)/?$', 'equs_by_vars'), - (r'^json/all_vars/$', 'all_vars'), - (r'^json/all_symbs/$', 'all_symbs'), + (r'^json/vars_by_symbs/(?P<which_symbols>[\d\,]*)/?$', 'vars_by_symbs'), + (r'^json/all_variables/$', 'all_variables'), + (r'^json/all_symbols/$', 'all_symbols'), ) |