--- a/src/hdalab/static/hdalab/js/hdalab-renkan-bins.js Fri Aug 29 16:19:31 2014 +0200
+++ b/src/hdalab/static/hdalab/js/hdalab-renkan-bins.js Tue Sep 02 12:14:38 2014 +0200
@@ -59,7 +59,6 @@
_this = this,
count = 0;
Rkns._(this.data.results).each(function(_result) {
- console.log(_result);
var title = _result.title,
url = _result.url,
full_description = _result.description,
@@ -95,11 +94,9 @@
Rkns.HdaNotices.Bin.prototype.refresh = function() {
var _this = this;
- console.log("refresh");
Rkns.$.ajax({
url: this.url + "?q=" + encodeURIComponent(this.search) + "&format=json&limit=50",
success: function(_data) {
- console.log("ntm");
_this.data = _data;
_this.render();
}
@@ -108,7 +105,7 @@
/* Rkns.HdaTags bin definition : search form and result rendering */
-/*
+
Rkns.HdaTags = {
};
@@ -116,7 +113,7 @@
this.renkan = _renkan;
this.lang = _opts.lang || "fr";
this.image = _opts.image;
- console.log("2",this.image);
+ this.url = _opts.url;
};
Rkns.HdaTags.Search.prototype.getBgClass = function() {
@@ -131,6 +128,7 @@
this.renkan.tabs.push(
new Rkns.HdaTags.Bin(this.renkan, {
lang: this.lang,
+ url: this.url,
image: this.image,
search: _q
})
@@ -141,8 +139,8 @@
Rkns.HdaTags.Bin.prototype.resultTemplate = Rkns._.template(
'<li class="Rk-Wikipedia-Result Rk-Bin-Item" draggable="true" data-uri="<%-url%>" ' +
- 'data-title="Wikipedia: <%-title%>" data-description="<%-description%>" data-image="<%- Rkns.Utils.getFullURL( static_url + \'img/wikipedia.png\' ) %>">' +
- '<img class="Rk-Wikipedia-Icon" src="<%-image%>"></div><h4 class="Rk-Wikipedia-Title">HDA TAGS : <a href="<%-url%>" target="_blank"><%=htitle%></a></h4>' +
+ 'data-title="<%-title%>" data-description="<%-full_description%>" data-image="<%-image%>">' +
+ '<img class="Rk-Wikipedia-Icon" src="<%-image%>"></div><h4 class="Rk-Wikipedia-Title"><a href="<%-url%>" target="_blank"><%=htitle%></a></h4>' +
'<p class="Rk-Wikipedia-Snippet"><%=hdescription%></p></li>'
);
@@ -150,10 +148,10 @@
this.renkan = _renkan;
this.search = _opts.search;
this.lang = _opts.lang || "fr";
+ this.url = _opts.url;
this.image = _opts.image;
- console.log("1",this.image,_opts);
- this.title_icon_$.addClass('Rk-Wikipedia-Title-Icon');
- this.title_$.html(this.search).addClass("Rk-Wikipedia-Title");
+ this.title_icon_$.addClass('Rk-HdaTags-Title-Icon');
+ this.title_$.html(this.search).addClass("Rk-HdaTags-Title");
this.refresh();
};
@@ -166,10 +164,12 @@
var _html = "",
_this = this,
count = 0;
- Rkns._(this.data.query.search).each(function(_result) {
- var title = _result.title,
- url = "http://" + _this.lang + ".wikipedia.org/wiki/" + encodeURI(title.replace(/ /g,"_")),
- description = Rkns.$('<div>').html(_result.snippet).text();
+ Rkns._(this.data).each(function(_result) {
+ var title = _result.value,
+ url = _result.url,
+ full_description = _result.abstract ? _result.abstract : "",
+ description = ( (full_description.indexOf(" ", 170) < 0 ) ? full_description : (full_description.substr(0, full_description.indexOf(" ", 170)) + "...") ),
+ image = _result.thumbnail;
if (!search.isempty && !search.test(title) && !search.test(description)) {
return;
}
@@ -178,10 +178,10 @@
url: url,
title: title,
htitle: highlight(title),
+ full_description: full_description,
description: description,
hdescription: highlight(description),
- static_url: _this.renkan.options.static_url,
- image: _this.image
+ image: image
});
});
_this.main_$.html(_html);
@@ -190,9 +190,9 @@
} else {
this.count_$.hide();
}
- if (!search.isempty && !count) {
+ if (!search.isempty && !count) {
this.$.hide();
- } else {
+ } else {
this.$.show();
}
this.renkan.resizeBins();
@@ -201,12 +201,10 @@
Rkns.HdaTags.Bin.prototype.refresh = function() {
var _this = this;
Rkns.$.ajax({
- url: "http://" + _this.lang + ".wikipedia.org/w/api.php?action=query&list=search&srsearch=" + encodeURIComponent(this.search) + "&format=json",
- dataType: "jsonp",
+ url: this.url + "?term=" + encodeURIComponent(this.search) + "&format=json&count=50&count_notices=0",
success: function(_data) {
_this.data = _data;
_this.render();
}
});
-};
-*/
\ No newline at end of file
+};
\ No newline at end of file
--- a/src/hdalab/templates/renkan_edit.html Fri Aug 29 16:19:31 2014 +0200
+++ b/src/hdalab/templates/renkan_edit.html Tue Sep 02 12:14:38 2014 +0200
@@ -35,6 +35,12 @@
static_url : "{% static 'renkanmanager/lib/renkan/' %}",
search: [
{
+ type: "HdaTags",
+ lang: "{{LANGUAGE_CODE}}",
+ image: "http://dbpedia.org/statics/dbpedia_logo.png",
+ url: "{% url 'tag_search' %}"
+ },
+ {
type: "HdaNotices",
lang: "{{LANGUAGE_CODE}}",
image: "http://digital-impulse.com/wp-content/plugins/smilies-themer/digicons/IronMan.png",
--- a/src/hdalab/views/ajax.py Fri Aug 29 16:19:31 2014 +0200
+++ b/src/hdalab/views/ajax.py Tue Sep 02 12:14:38 2014 +0200
@@ -98,12 +98,8 @@
master_category = WpCategory.objects.filter(label__iexact=label)[0:1]
if len(master_category):
resobj = subcat(master_category[0], globtags, 1, MAX_LEVEL )
-
-# tag_list = [k for k in globtags]
-
-# if len(tag_list):
- contents = []
-# datasheets = Datasheet.objects.filter(validated = True, taggedsheet__tag__label__in = tag_list, taggedsheet__order__lte = MAX_TAG_ORDER).distinct()
+
+ #datasheets = Datasheet.objects.filter(validated = True, taggedsheet__tag__label__in = tag_list, taggedsheet__order__lte = MAX_TAG_ORDER).distinct()
datasheets = Datasheet.objects.filter(validated = True, taggedsheet__tag__label__iexact = label, taggedsheet__order__lte = ROOT_MAX_TAG_ORDER).select_related('organisation').distinct()
for datasheet in datasheets:
# Calculating where we add the datasheet in the tree
@@ -133,8 +129,6 @@
'score': max(dsscore, rootscore)
})
cleantags(resobj)
-
-# resobj['contents'] = [{'id': d.id, 'title': d.title, 'tags': [t.label for t in d.tags.filter(taggedsheet__order__lte=5)]} for d in datasheets]
return HttpResponse(content=json.dumps(resobj), mimetype='application/json')
@@ -184,6 +178,10 @@
q = request.GET.get('term',None)
maxcount = int(request.GET.get('count','40'))
lang = request.GET.get('lang',request.LANGUAGE_CODE)
+ count_notices_str = request.REQUEST.get("count_notices")
+ count_notices_bool = True
+ if count_notices_str:
+ count_notices_bool = {'true': True, 'false': False, "0": False, "1": True}.get(count_notices_str.lower())
stemming_langs = [ 'fr', 'en', 'de', 'it' ]
# For Japanese, there are no word boundaries, we should not use the regexp in that case
@@ -205,8 +203,11 @@
qs = qs.filter(dbpedia_fields__translations__label__icontains=q, dbpedia_fields__translations__language_code=lang, dbpedia_fields__translations__is_label_translated = True)
else:
qs = Tag.objects.filter(~Q(dbpedia_uri = None))
-
- qs = qs.annotate(nb=Count('datasheet',distinct=True)).order_by('-nb')[:maxcount]
+
+ if count_notices_bool:
+ qs = qs.annotate(nb=Count('datasheet',distinct=True)).order_by('-nb')[:maxcount]
+ else:
+ qs = qs.distinct()[:maxcount]
qslist = list(qs)
@@ -221,7 +222,9 @@
for t in qslist:
if hasattr(t, 'dbpedia_fields'):
dbfields = t.dbpedia_fields
- resobj = {'original_label':t.label,'nb':t.nb}
+ resobj = {'original_label':t.label, 'url':t.dbpedia_uri}
+ if count_notices_bool:
+ resobj['nb'] = t.nb
resobj['thumbnail'] = dbfields.thumbnail if dbfields is not None else None
if t.id in translations: