From 369ba567c932d336ba7bcafeeb216b465c6911b1 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 29 Jul 2013 16:50:27 -0700 Subject: [PATCH] Better search fail state (fixes #1655) --- css/app.css | 1 + data/core.yaml | 5 +++-- dist/locales/en.json | 5 +++-- js/id/ui/feature_list.js | 47 ++++++++++++++++++++++++++-------------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/css/app.css b/css/app.css index d162c63f2..8fd47702e 100644 --- a/css/app.css +++ b/css/app.css @@ -765,6 +765,7 @@ a:hover .icon.out-link { background-position: -500px -14px;} width:100%; } +.no-results-item, .geocode-item, .feature-list-item { width: 100%; diff --git a/data/core.yaml b/data/core.yaml index a530e3f57..58715b25d 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -164,8 +164,9 @@ en: list: "Edits by {users}" truncated_list: "Edits by {users} and {count} others" geocoder: - search: Continue search on server... - no_results: No results found + search: Search worldwide... + no_results_visible: No results in visible map area + no_results_worldwide: No results found geolocate: title: Show My Location inspector: diff --git a/dist/locales/en.json b/dist/locales/en.json index 5c2f41949..ce22652de 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -205,8 +205,9 @@ "truncated_list": "Edits by {users} and {count} others" }, "geocoder": { - "search": "Continue search on server...", - "no_results": "No results found" + "search": "Search worldwide...", + "no_results_visible": "No results in visible map area", + "no_results_worldwide": "No results found" }, "geolocate": { "title": "Show My Location" diff --git a/js/id/ui/feature_list.js b/js/id/ui/feature_list.js index b4c22c2f4..fc3ab761b 100644 --- a/js/id/ui/feature_list.js +++ b/js/id/ui/feature_list.js @@ -98,32 +98,47 @@ iD.ui.FeatureList = function(context) { } function drawList() { - var value = search.property('value'); + var value = search.property('value'), + results = features(); list.classed('filtered', value.length); - var geocodeButton = list.selectAll('.geocode-item') + var noResultsWorldwide = geocodeResults && geocodeResults.length === 0; + + var resultsIndicator = list.selectAll('.no-results-item') + .data([0]) + .enter().append('button') + .property('disabled', true) + .attr('class', 'no-results-item'); + + resultsIndicator.append('span') + .attr('class', 'icon alert'); + + resultsIndicator.append('span') + .attr('class', 'entity-name'); + + list.selectAll('.no-results-item .entity-name') + .text(noResultsWorldwide ? t('geocoder.no_results_worldwide') : t('geocoder.no_results_visible')); + + list.selectAll('.geocode-item') .data([0]) .enter().append('button') .attr('class', 'geocode-item') - .on('click', geocode); + .on('click', geocode) + .append('div') + .attr('class', 'label') + .append('span') + .attr('class', 'entity-name') + .text(t('geocoder.search')); - var label = geocodeButton.append('div') - .attr('class', 'label'); - - label.append('span') - .attr('class', 'entity-name'); - - var noResults = geocodeResults && geocodeResults.length === 0; + list.selectAll('.no-results-item') + .style('display', (value.length && !results.length) ? 'block' : 'none'); list.selectAll('.geocode-item') - .style('display', noResults || (value && geocodeResults === undefined) ? 'block' : 'none') - .property('disabled', noResults) - .selectAll('.entity-name') - .text(noResults ? t('geocoder.no_results') : t('geocoder.search')); + .style('display', (value && geocodeResults === undefined) ? 'block' : 'none'); var items = list.selectAll('.feature-list-item') - .data(features(), function(d) { return d.id; }); + .data(results, function(d) { return d.id; }); var enter = items.enter().insert('button', '.geocode-item') .attr('class', 'feature-list-item') @@ -131,7 +146,7 @@ iD.ui.FeatureList = function(context) { .on('mouseout', mouseout) .on('click', click); - label = enter.append('div') + var label = enter.append('div') .attr('class', 'label'); label.append('span')