diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2013-03-20 12:04:54 +0000 |
---|---|---|
committer | Paul Eggleton <paul.eggleton@linux.intel.com> | 2013-03-20 17:04:56 +0000 |
commit | 342ff28648d01e783aed4013f9c20fa016c99833 (patch) | |
tree | c210a08dd99609135027979b8315f6d286cce362 | |
parent | 42d710b640b421f5a66922755d0ddc8d73a0ab03 (diff) | |
download | openembedded-core-contrib-342ff28648d01e783aed4013f9c20fa016c99833.tar.gz |
De-emphasise recipes where there is a more preferred version available
If another recipe exists with the same name in a different layer and
that other layer is "older" (by layer ID) and is a software or base
layer then lighten the recipe entry in the search results as it may
not be the preferred version (e.g. recipes in BSP or distro layers may
have been customised specifically for the machine or distro).
This has had a performance impact on the recipes list; as a result
showing all recipes by default has been disabled. If the user really
wants to see all recipes they can just leave the search box blank and
hit the search button.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | layerindex/static/css/additional.css | 4 | ||||
-rw-r--r-- | layerindex/views.py | 27 | ||||
-rw-r--r-- | templates/layerindex/recipes.html | 13 |
4 files changed, 41 insertions, 4 deletions
@@ -10,7 +10,6 @@ Later: * Add link to the all layers and all recipes tables from the layer details page? * Display no-results found message when search does not return any results (all tables) * Change behaviour of filter menus to stay open so that you can check / uncheck multiple items -* Show recipes from non-software/base layers differently in recipes list * Show layer type in layer detail? * Usage links in list page? * Avoid page content changing size depending on whether scrollbar is there or not? diff --git a/layerindex/static/css/additional.css b/layerindex/static/css/additional.css index cd99fdd82f..1e2e7b3eb5 100644 --- a/layerindex/static/css/additional.css +++ b/layerindex/static/css/additional.css @@ -156,3 +156,7 @@ padding: 8px; background-color: white; height: 100%; } + +.muted a { + color: #66B8E0; +} diff --git a/layerindex/views.py b/layerindex/views.py index 9e613176fd..89822ba798 100644 --- a/layerindex/views.py +++ b/layerindex/views.py @@ -247,9 +247,32 @@ class RecipeSearchView(ListView): init_qs = Recipe.objects.filter(layerbranch__branch__name=self.request.session.get('branch', 'master')) if query_string.strip(): entry_query = simplesearch.get_query(query_string, ['pn', 'summary', 'description', 'filename']) - return init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer') + qs = init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer') else: - return init_qs.order_by('pn', 'layerbranch__layer') + if 'q' in self.request.GET: + qs = init_qs.order_by('pn', 'layerbranch__layer') + else: + # It's a bit too slow to return all records by default, and most people + # won't actually want that (if they do they can just hit the search button + # with no query string) + return Recipe.objects.none() + + # Add extra column so we can show "duplicate" recipes from other layers de-emphasised + # (it's a bit crude having to do this using SQL but I couldn't find a better way...) + return qs.extra( + select={ + 'preferred_count': """SELECT COUNT(1) +FROM layerindex_recipe AS recipe2 +, layerindex_layerbranch as branch2 +, layerindex_layeritem as layer2 +WHERE branch2.id = recipe2.layerbranch_id +AND layer2.id = branch2.layer_id +AND layer2.layer_type in ('S', 'A') +AND recipe2.pn = layerindex_recipe.pn +AND recipe2.layerbranch_id < layerindex_recipe.layerbranch_id +""" + }, + ) def get_context_data(self, **kwargs): context = super(RecipeSearchView, self).get_context_data(**kwargs) diff --git a/templates/layerindex/recipes.html b/templates/layerindex/recipes.html index 36749de38e..f400442467 100644 --- a/templates/layerindex/recipes.html +++ b/templates/layerindex/recipes.html @@ -50,7 +50,7 @@ <tbody> {% for recipe in recipe_list %} - <tr> + <tr {% if recipe.preferred_count > 0 %}class="muted"{% endif %}> <td><a href="{% url recipe recipe.id %}">{{ recipe.name }}</a></td> <td>{{ recipe.pv }}</td> <td>{{ recipe.short_desc }}</td> @@ -77,3 +77,14 @@ {% endautoescape %} {% endblock %} + + +{% block scripts %} +<script> + $(document).ready(function() { + firstfield = $("#filter-form input:text").first() + if( ! firstfield.val() ) + firstfield.focus() + }); +</script> +{% endblock %} |