# HG changeset patch # User veltr # Date 1349962958 -7200 # Node ID 7c3f54ce68afac8566a209fc163e9474cfe012c5 # Parent 91bc8521e3cbd41e878be449858acf3303411556 Merged Completion List back into Facettes diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/static/hdalab/css/facettes.css --- a/web/hdalab/static/hdalab/css/facettes.css Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/static/hdalab/css/facettes.css Thu Oct 11 15:42:38 2012 +0200 @@ -430,4 +430,57 @@ position: absolute; width: 10px; height: 10px; background: #000000; border-radius: 5px; display: none; } +/* COMPLETION */ +#tagsearch { + width: 100%; font-size: 16px; font-weight: bold; border-style: none; border-bottom: 1px solid #000; +} + +#tagsearch.waiting { + background: url(../img/small-loader.gif) no-repeat right; +} + +ul.ui-autocomplete { + font-family: "Open Sans"; max-width: 230px; + max-height: 400px; overflow-y: auto; overflow-x: hidden; +} + +.wpinfo { + margin-left: 240px; +} + +.ui-menu-item:hover .acwp { + display: block; +} + +.acnb { + float: right; font-size: 12px; margin: 2px 0 0 2px; +} + +.actitle { + font-size: 13px; +} + +.wptitle { + font-size: 13px; font-weight: bold; +} + +.wpimg { + max-width: 80px; max-height: 60px; float: left; margin: 5px 2px 2px 0; border: none; +} + +.wpabstract { + font-size: 11px; +} + +.wpsource { + font-size: 10px; font-style: bold; +} + +.clear { + clear: both; +} + +.actitle strong, .wptitle strong { + color: #c000c0; +} diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/static/hdalab/js/completion.js --- a/web/hdalab/static/hdalab/js/completion.js Thu Oct 04 12:25:12 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -var gomNs = { - languageCode: 'fr' -} - -function showResults(data) { - $("#contentcount").html(''+data.count+' ' + ngettext('notice', 'notices', data.count)); - var contentdata = data.contents; - if (contentdata && contentdata.length) { - var _htmlCl = ''; - $("#contents").html(_htmlCl).scrollTop(0); - } - else { - $("#contents").html(""); - } -} - -function getContents(label) { - $.getJSON( - gomNs.urls['contentsbytag'], - { - label: label - }, - showResults - ); -} - -function ellipse(_text, _length) { - var _rgxp = new RegExp('(^.{0,' + _length + '})([\s]|$)(.*)') - return _text.replace(/(\n|\r|\r\n)/mg,' ').trim().replace(_rgxp,'$1…') -} - -function highlightText(_text, _search) { - var _rgxp = new RegExp('(' + _search.replace(/(\W)/g, '\\$1') + ')','gi'); - return _text.replace(_rgxp, '$1'); -} - -function wikipediaUrl(_text) { - return "http://" + gomNs.languageCode + ".wikipedia.org/wiki/" + encodeURI(_text.replace(/ /g,'_')) -} - -wpTemplate = _.template( - '

<% print(highlightText(item.label, inputvalue)); %>

<% if (item.thumbnail) { %><% };' - + ' if (item.abstract) { %>

<% print(ellipse(item.abstract,250))%>

<% print(gettext("Source : Wikipédia")) %>

<% }; %>
' -); - -acTemplate = _.template( - '<%- item.nb %>

<% print(highlightText(item.label, inputvalue)); %>

' -) - -$(document).ready(function() { - $(" #tagform ").submit(function() { - return false; - }); - var cache = {}, /*CACHE => http://jqueryui.com/demos/autocomplete/#remote-with-cache */ - lastXhr; - $( "#tagsearch" ).autocomplete({ - source: function( request, response ) { - var term = request.term; - if ( term in cache ) { - $("#tagsearch").removeClass("waiting"); - response( cache[ term ] ); - return; - } - $("#tagsearch").addClass("waiting"); - lastXhr = $.getJSON( gomNs.urls['tag_search'], request, function( data, status, xhr ) { - cache[ term ] = data; - if ( xhr === lastXhr ) { - response( data ); - $("#tagsearch").removeClass("waiting"); - } - }); - }, - minLength: ( gomNs.languageCode == 'ja' ? 1 : 2 ), - focus: function( event, ui ) { - $(".wpinfo").html(wpTemplate({ - item: ui.item, - inputvalue: $("#tagsearch").val() - })); - }, - select: function( event, ui ) { - getContents(ui.item.label); - } - }) - .data("autocomplete")._renderItem = function(ul, item) { - var _contents = acTemplate({ - item: item, - inputvalue: $("#tagsearch").val() - }); - return $( "
  • " ) - .data( "item.autocomplete", item ) - .html( _contents ) - .appendTo( ul ); - }; -}); diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/static/hdalab/js/gomina.js --- a/web/hdalab/static/hdalab/js/gomina.js Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/static/hdalab/js/gomina.js Thu Oct 11 15:42:38 2012 +0200 @@ -407,7 +407,7 @@ + _(data.tags).map(function(_d) { return '
  • ' + _disc.map(function(_d) { var _col = getGradient(_d.score / _max); - return '
  • ' + _d.translated_label @@ -645,6 +645,28 @@ function animStop() { $("#waiting").empty().fadeOut(); } +function ellipse(_text, _length) { + var _rgxp = new RegExp('(^.{0,' + _length + '})([\s]|$)(.*)') + return _text.replace(/(\n|\r|\r\n)/mg,' ').trim().replace(_rgxp,'$1…') +} + +function highlightText(_text, _search) { + var _rgxp = new RegExp('(' + _search.replace(/(\W)/g, '\\$1') + ')','gi'); + return _text.replace(_rgxp, '$1'); +} + +function wikipediaUrl(_text) { + return "http://" + gomNs.languageCode + ".wikipedia.org/wiki/" + encodeURI(_text.replace(/ /g,'_')) +} + +wpTemplate = _.template( + '

    <% print(highlightText(item.label, inputvalue)); %>

    <% if (item.thumbnail) { %><% };' + + ' if (item.abstract) { %>

    <% print(ellipse(item.abstract,250))%>

    <% print(gettext("Source : Wikipédia")) %>

    <% }; %>
    ' +); + +acTemplate = _.template( + '<%- item.nb %>

    <% print(highlightText(item.label, inputvalue)); %>

    ' +); $(document).ready(function() { switch(gomNs.mappingLibrary) { @@ -832,4 +854,47 @@ } return false; }); + $(" #tagform ").submit(function() { + return false; + }); + var cache = {}, /*CACHE => http://jqueryui.com/demos/autocomplete/#remote-with-cache */ + lastXhr; + $( "#tagsearch" ).autocomplete({ + source: function( request, response ) { + var term = request.term; + if ( term in cache ) { + $("#tagsearch").removeClass("waiting"); + response( cache[ term ] ); + return; + } + $("#tagsearch").addClass("waiting"); + lastXhr = $.getJSON( gomNs.urls['tag_search'], request, function( data, status, xhr ) { + cache[ term ] = data; + if ( xhr === lastXhr ) { + response( data ); + $("#tagsearch").removeClass("waiting"); + } + }); + }, + minLength: ( gomNs.languageCode == 'ja' ? 1 : 2 ), + focus: function( event, ui ) { + $(".wpinfo").html(wpTemplate({ + item: ui.item, + inputvalue: $("#tagsearch").val() + })); + }, + select: function( event, ui ) { + addFilter('tag', ui.item.original_label); + } + }) + .data("autocomplete")._renderItem = function(ul, item) { + var _contents = acTemplate({ + item: item, + inputvalue: $("#tagsearch").val() + }); + return $( "
  • " ) + .data( "item.autocomplete", item ) + .html( _contents ) + .appendTo( ul ); + }; }); diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/templates/base.html --- a/web/hdalab/templates/base.html Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/templates/base.html Thu Oct 11 15:42:38 2012 +0200 @@ -28,7 +28,6 @@
  • Recherche par facettes
  • diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/templates/completion.html --- a/web/hdalab/templates/completion.html Thu Oct 04 12:25:12 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -{% extends "base.html" %} - -{% load i18n %} - -{% block title %}{{block.super}} > {% trans "Recherche par liste de completion" %}{% endblock %} - -{% block css_import %} -{{block.super}} - - - -{% endblock %} - -{% block js_import %} -{{block.super}} - - - - - - - - -{% endblock %} - -{% block completion_actif %}actif{% endblock %} - -{% block main_content %} -
    -
    -

    {% trans "Recherche par liste de completion" %} 

    -
    -
    -
    -
    - {% csrf_token %} - - {% get_language_info_list for LANGUAGES as languages %} - {% for language in languages %} - - {% endfor %} -
    -
    -
    -
    -
    -
    -
    -
    -

    {% trans "Rechercher un tag" %}

    -
    -
    -
    - -
    -
    - -
    -
    -
    -
    - {% trans "translation_info" %} -
    -
    -
    -
    -
    -

    {% trans "Resultats de recherche" %}

    -
    -
    -
    -
    -
    -
    -
    -
    - - -{% endblock %} diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/templates/facettes.html --- a/web/hdalab/templates/facettes.html Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/templates/facettes.html Thu Oct 11 15:42:38 2012 +0200 @@ -28,6 +28,7 @@ 'filter': "{% url filter %}", 'session_info': "{% url session_info %}", 'countries': "{{STATIC_URL}}hdalab/lib/countries.geo.json", + 'tag_search': "{% url tag_search %}" }; ZeroClipboard.setMoviePath('{{STATIC_URL}}hdalab/lib/ZeroClipboard.swf'); @@ -118,6 +119,19 @@
    +
    +
    +

    {% trans "Rechercher un tag" %}

    +
    +
    +
    + +
    +
    + +
    +
    +
    {% trans "translation_info" %}
    diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/urls.py --- a/web/hdalab/urls.py Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/urls.py Thu Oct 11 15:42:38 2012 +0200 @@ -25,7 +25,6 @@ url(r'^facettes/', TemplateView.as_view(template_name="facettes.html"), name='facettes'), url(r'^categories/', TemplateView.as_view(template_name="categories.html"), name='categories'), - url(r'^completion/', TemplateView.as_view(template_name="completion.html"), name='completion'), url(r'^$', TemplateView.as_view(template_name="index.html"), name='home'), ) @@ -37,5 +36,4 @@ (r'^a/catsearch$', 'catsearch', {}, 'cat_search'), (r'^a/cattree$', 'cattree', {}, 'cat_tree'), (r'^a/filltree$', 'filltree', {}, 'fill_tree'), - (r'^a/contentsbytag$', 'contentsbytag', {}, 'contentsbytag'), ) diff -r 91bc8521e3cb -r 7c3f54ce68af web/hdalab/views/ajax.py --- a/web/hdalab/views/ajax.py Thu Oct 04 12:25:12 2012 +0200 +++ b/web/hdalab/views/ajax.py Thu Oct 11 15:42:38 2012 +0200 @@ -423,72 +423,14 @@ return HttpResponse(content=outputstr, mimetype='application/json') -def contentsbytag(request): - - lang = request.GET.get('lang',request.LANGUAGE_CODE) - label = request.GET.get('label', None).strip().lower() - max_tag_order = int(request.GET.get('mto', '30')) - content_count = int(request.GET.get('contentcount', '30')) - - cache_key = fix_cache_key("contentsbytag-%s"%unicode(label).encode("utf-8")) - - outputstr = cache.get(cache_key) - - if outputstr is None: - - matchtagids = [] - - contentqs = Datasheet.objects.filter(validated=True) - - no_translate_langs = [ 'fr' ] - if lang in no_translate_langs: - tagsqs = Tag.objects.filter( label__iexact = label ) - else: - tagsqs = Tag.objects.select_related('dbpedia_fields').filter(dbpedia_fields__translations__label__iexact = label, dbpedia_fields__translations__language_code=lang) - - contentqs = contentqs.select_related('taggedsheet__tag').filter(taggedsheet__tag__in=tagsqs).distinct() - - cont_count = contentqs.count() - - contenus = dict([(content.id, {'score' : 0, 'tags' : [], 'id':content.id, 'title': content.title, 'description': content.description, 'url': content.url}) for content in contentqs[0:content_count]]) - contentids = contenus.keys() - - qs = DatasheetExtras.objects.select_related('insee').filter(datasheet__in = contentids) - for dse in qs: - contenus[dse.datasheet_id]['coords'] = {'city_name': dse.insee.city_name, 'latitude': dse.insee.latitude, 'longitude': dse.insee.longitude} - - qs = list(TaggedSheet.objects.select_related('tag', 'tag__dbpedia_fields').filter(datasheet__in = contentids).order_by('order')) - - if lang in no_translate_langs: - translations = {} - else: - transqs = DbpediaFieldsTranslation.objects.filter(master__in = [ts.tag.dbpedia_fields for ts in qs], language_code = lang) - translations = dict([(trans.master_id,trans.label) for trans in transqs]) - - for ts in qs: - translated_label = translations.get(ts.tag.dbpedia_fields.id, ts.tag.label) if ts.tag.dbpedia_fields is not None else ts.tag.label - match_tag = ( label == translated_label.lower() ) - contenus[ts.datasheet_id]['tags'].append({'id': ts.tag.id, 'label':ts.tag.label, 'order':ts.order, 'match': match_tag , 'translated_label': translated_label}) - - if match_tag: - contenus[ts.datasheet_id]['score'] += 2*max_tag_order - ts.order - - contenus = sorted(contenus.values(),key=lambda e: -e['score']) - - output = {'count': cont_count, 'contents': contenus} - outputstr = json.dumps(output) - cache.set(cache_key, outputstr) - - return HttpResponse(content=outputstr, mimetype='application/json') - def subtree(tree): - MAX_TAG_ORDER = 8 + MAX_TAG_ORDER = 16 label = tree['label'] sub = tree.get('contents',[]) datasheets = Datasheet.objects.filter(validated = True, taggedsheet__tag__label__iexact = label, taggedsheet__order__lte = MAX_TAG_ORDER).annotate(tagorder=Min('taggedsheet__order')).select_related('organisation').distinct() - contents = [{ 'description': ds.description, 'title': ds.title, 'url': ds.url, 'score': MAX_TAG_ORDER - ds.tagorder, 'id': ds.id, 'hda_id': ds.hda_id, 'organization': ds.organisation.name } for ds in datasheets] + contents = [{ 'description': ds.description, 'title': ds.title, 'url': ds.url, 'score': int((MAX_TAG_ORDER - ds.tagorder)/2), 'id': ds.id, 'hda_id': ds.hda_id, 'organization': ds.organisation.name } for ds in datasheets] contents = sorted(contents, key=lambda e: -e['score'])