Skip to content

Commit

Permalink
Make search results more visible (#853)
Browse files Browse the repository at this point in the history
* Move API promotion at the bottom of results
* Jump to filters to highlight search results
* Add component filters to entity results
* Don't focus search input when there's a hash
  • Loading branch information
flodolo authored Feb 4, 2017
1 parent 7dcbfc0 commit 332472f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
7 changes: 4 additions & 3 deletions app/views/onestring.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

// We have no error, display results
$page_descr = $entity;

// Promote API view
include VIEWS . 'templates/api_promotion.php';
?>

<table>
Expand Down Expand Up @@ -44,3 +41,7 @@
}
?>
</table>

<?php
// Promote API view
include VIEWS . 'templates/api_promotion.php';
30 changes: 26 additions & 4 deletions app/views/results_entities.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
namespace Transvision;

// Promote API view
include VIEWS . 'templates/api_promotion.php';

$table = "
<table class='collapsable'>
<thead>
Expand All @@ -19,8 +16,11 @@
$current_repo = $search->getRepository();
$extra_locale = $url['path'] == '3locales';

$components = [];
// Display results
foreach ($entities as $entity) {
$component = explode('/', $entity)[0];
$components[] = $component;
if (in_array($current_repo, ['firefox_ios', 'mozilla_org'])) {
$path_locale1 = VersionControl::gitPath($source_locale, $current_repo, $entity);
$path_locale2 = VersionControl::gitPath($locale, $current_repo, $entity);
Expand Down Expand Up @@ -164,7 +164,7 @@
}

$table .= "
<tr>
<tr class='{$component}'>
<td>
<span class='celltitle'>Entity</span>
<a class='resultpermalink tag' id='{$anchor_name}' href='#{$anchor_name}' title='Permalink to this result'>#</a>
Expand Down Expand Up @@ -198,7 +198,29 @@
</tr>\n";
}

// Remove duplicated components
$components = array_unique($components);
if (Project::isDesktopRepository($search->getRepository())) {
// Build logic to filter components
$filter_block = '';
foreach ($components as $value) {
$filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>";
}
}
if (isset($filter_block)):
?>
<div id="filters">
<h4>Filter by folder:</h4>
<a href="#showall" id="showall" class="filter">Show all results</a>
<?=$filter_block;?>
</div>
<?php
endif;

$table .= "</tbody>\n</table>\n\n";
if ($entities) {
print $table;
}

// Promote API view
include VIEWS . 'templates/api_promotion.php';
6 changes: 3 additions & 3 deletions app/views/results_strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<?php
endif;

// Promote API view
include VIEWS . 'templates/api_promotion.php';

foreach ($output as $results_table) {
print $results_table;
}

// Promote API view
include VIEWS . 'templates/api_promotion.php';
4 changes: 3 additions & 1 deletion web/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ $(document).ready(function() {
}

// Focus on the main search field.
$('#recherche').focus();
if (window.location.hash === '') {
$('#recherche').focus();
}
});
10 changes: 10 additions & 0 deletions web/js/main_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,14 @@ $(document).ready(function() {
$(this).remove();
});
});

/*
Jump to filters if there's not an hash already defined, e.g. to
jump to a specific row.
*/
if (window.location.hash === '' && $('#filters').length) {
$('body,html').animate({
scrollTop: $('#filters').offset().top
}, 500);
}
});

0 comments on commit 332472f

Please sign in to comment.