Skip to content

Commit

Permalink
Move keywords from ajax load to jinja load + ...
Browse files Browse the repository at this point in the history
... include the changes in api.py that are necessary
for the previous commit.
  • Loading branch information
jdejoode committed Jul 1, 2015
1 parent d1360d5 commit 6c53462
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
8 changes: 5 additions & 3 deletions clic/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ def concordances():
def fetchKeywords(args):
keyworder = Keywords()
args = processArgs(args, 'keywords')
keywords = keyworder.list_keywords(args[0], args[1], args[2], args[3], args[4])
return {'keywords' : keywords}
keywordlist = keyworder.list_keywords(args[0], args[1], args[2], args[3], args[4])
return keywordlist
# return {'keywords' : keywords}

@cache.cache('clusters')
def fetchClusters(args):
cluster = Clusters()
args = processArgs(args, 'clusters')
clusterlist = cluster.list_clusters(args[0], args[1])
return {'clusters' : clusterlist}
return clusterlist
# return {'clusters' : clusterlist}

@cache.cache('concordances')
def fetchConcordance(args):
Expand Down
12 changes: 8 additions & 4 deletions clic/web/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import ## help python find modules within clic package (see John H email 09.04.2014)
from flask import Flask, render_template, url_for, redirect, request

from clic.web.api import api, fetchClusters
from clic.web.api import api, fetchClusters, fetchKeywords
from clic.chapter_repository import ChapterRepository

app = Flask(__name__, static_url_path='')
Expand Down Expand Up @@ -59,11 +59,15 @@ def keywords():
testIdxMod = request.args.get('testIdxMod')
selectWords = "whole"

args = request.args
keywords_result = fetchKeywords(args)

return render_template("keywords-results.html",
IdxGroup=IdxGroup,
testCollection=testCollection,
testIdxMod=testIdxMod,
selectWords=selectWords)
selectWords=selectWords,
keywords=keywords_result)

else:
return render_template("keywords-form.html")
Expand Down Expand Up @@ -113,5 +117,5 @@ def chapterView(number, book, word_index = None, search_term = None):
return render_template("chapter-view.html", content=chapter, book_title=book_title)

# TODO delete?
# if __name__ == '__main__':
# app.run()
#if __name__ == '__main__':
# app.run()
64 changes: 33 additions & 31 deletions clic/web/templates/keywords-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,43 @@
{% endblock %}

{% block title %}
Keywords Search {{ super() }}
Keywords {{ super() }}
{% endblock %}

{% block body %}
<h2 class="without-pills">Keywords Results</h2>

<div id="resultsWrap">
<div id="tableContainer"></div>
<div id="tableContainer">
<table style="width: 0px; cursor:pointer;" aria-describedby="dataTableKeywords_info" class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableKeywords">
<thead>
<tr role="row">
<th aria-label="No" style="width: 0px;" colspan="1" rowspan="1" class="sorting_asc">No</th>
<th aria-label="n-gram: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">n-gram</th>
<th aria-label="Test Freq: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">Test Freq</th>
<th aria-label="%: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">%</th>
<th aria-label="Ref Freq: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="nowrap sorting">Ref Freq</th>
<th aria-label="%: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">%</th>
<th aria-label="K: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">K</th>
<th aria-label="P: activate to sort column ascending" style="width: 0px;" colspan="1" rowspan="1" aria-controls="dataTableKeywords" tabindex="0" class="sorting">P</th>
</tr>
</thead>
<tbody>
{% for keyword in keywords %}
<tr class="{{ loop.cycle('odd', 'even') }}">
<td class="sorting_1">{{ loop.index }}</td>
<td>{{ keyword[1] }}</td>
<td>{{ keyword[2] }}</td>
<td>{{ keyword[3] }}</td>
<td>{{ keyword[4] }}</td>
<td>{{ keyword[5] }}</td>
<td>{{ keyword[6] }}</td>
<td>{{ keyword[7] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endblock %}

Expand All @@ -33,36 +62,9 @@ <h2 class="without-pills">Keywords Results</h2>

<script>
$(function () {
$('#resultsWrap').hide();

// Get URL params
var params = location.search;
var host = window.location.hostname;

jsonUrl = '/api/keywords/' + params; // from the app

$('#tableContainer').html('<table class="table table-striped table-hover dataTable no-footer uonDatatable" id="dataTableKeywords"></table>');
var oTable = $('#dataTableKeywords').dataTable({

"ajax": {
"url": jsonUrl,
"dataSrc": "keywords",
"error": function (xhr, error, thrown) {
alert( 'Sorry. Failed to load data. Please try again.' );
}
},

"fnDrawCallback": function ( oSettings ) {
/* Need to redo the counters if filtered or sorted */
if ( oSettings.bSorted || oSettings.bFiltered )
{
for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
{
$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
}
}
},

"fnInitComplete": function () {
$('#resultsWrap').show();
Pace.stop();
Expand Down Expand Up @@ -120,7 +122,7 @@ <h2 class="without-pills">Keywords Results</h2>
var slug = slugify(term)
window.location.href = '/concordances/?terms=' + slug + "&testCollection={{testCollection}}&testIdxMod={{testIdxMod}}&selectWords={{selectWords}}";
});

});
});
</script>

{% endblock %}

0 comments on commit 6c53462

Please sign in to comment.