Skip to content

Commit 4fc1ad0

Browse files
committed
Fix #721: Allow sorting columns in search results (#727)
* Fix #721: Allow sorting columns in search results * clean up our code to always define additional css and js files in the dispatcher * make tables in all views sortable except a couple were it didn't make sense (like a 3 rows table) * update the select_column.js and its associated html to not conflict with sorttable.js on the click event * fix naming of variables for consistency
1 parent dbf3ce6 commit 4fc1ad0

21 files changed

Lines changed: 77 additions & 78 deletions

app/classes/Transvision/ShowResults.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public static function resultsTable($search_object, $search_results, $page)
259259
$extra_column_header = "<th>{$locale3}</th>";
260260
}
261261

262-
$table = "<table class='collapsable results_table'>
262+
$table = "<table class='collapsable results_table sortable'>
263263
<thead>
264264
<tr class='column_headers'>
265265
<th>Entity</th>

app/classes/Transvision/Utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static function highlightString($str)
151151
* @param array $arr2 Optional. A second column of data
152152
* @param array $titles Column titles, by default 4 columns
153153
* @param string $cssclass optional css class to apply to the table
154-
* @return string and html table
154+
* @return void
155155
*/
156156
public static function printSimpleTable(
157157
$arr,
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22
require_once INC . 'l10n-init.php';
33

4-
// Include JS lib after $javascript_include gets reset in l10n-init.php.
5-
$javascript_include = ['/js/select_column.js'];
6-
74
include MODELS . 'channelcomparison.php';
85
include VIEWS . 'channelcomparison.php';

app/controllers/health_status.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
namespace Transvision;
33

44
$locales_list = [];
5-
$javascript_include = ['/js/show_hide_tabs.js'];
65

76
foreach (Project::getRepositories() as $repo) {
87
$locales_list = array_merge($locales_list, Project::getRepositoryLocales($repo));

app/controllers/showrepos.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?php
22
require_once INC . 'l10n-init.php';
33

4-
// Include JS lib after $javascript_include gets reset in l10n-init.php.
5-
$javascript_include = ['/js/sorttable.js'];
6-
74
include MODELS . 'showrepos.php';
85
include VIEWS . 'showrepos.php';

app/controllers/tmx_downloads.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
include MODELS . 'tmx_downloading.php';
2020
include VIEWS . 'tmx_downloading.php';
2121
} else {
22-
$javascript_include = ['/js/select_all.js'];
2322
$l10n = new \tinyl10n\ChooseLocale($locales_list);
2423
$locale = $l10n->getCompatibleLocale();
2524
include VIEWS . 'tmx_downloads.php';

app/controllers/unlocalized_words.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// Get requested repo and locale.
55
require_once INC . 'l10n-init.php';
66

7-
// Include JS lib after $javascript_include gets reset in l10n-init.php.
8-
$javascript_include = ['/js/sorttable.js'];
9-
107
include MODELS . 'unlocalized_words.php';
118

129
switch ($page) {

app/inc/dispatcher.php

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,83 +11,99 @@
1111
$extra = null;
1212
$experimental = false;
1313
$show_title = true;
14+
$css_files = ['transvision.css'];
15+
$js_files = ['/js/base.js'];
1416

1517
switch ($url['path']) {
1618
case '/':
1719
$controller = 'mainsearch';
1820
$show_title = false;
21+
$js_files[] = '/js/component_filter.js';
22+
$js_files[] = '/js/main_search.js';
23+
$js_files[] = '/js/sorttable.js';
24+
$js_files[] = '/assets/jQuery-Autocomplete/dist/jquery.autocomplete.min.js';
1925
break;
2026
case '3locales':
2127
$controller = 'mainsearch';
2228
$show_title = true;
2329
$page_title = '3 locales search';
2430
$page_descr = 'One source locale, get search results for two target locales';
31+
$js_files[] = '/js/component_filter.js';
32+
$js_files[] = '/js/main_search.js';
33+
$js_files[] = '/js/sorttable.js';
34+
$js_files[] = '/assets/jQuery-Autocomplete/dist/jquery.autocomplete.min.js';
2535
break;
2636
case 'accesskeys':
27-
$view = 'accesskeys';
37+
$view = 'accesskeys';
2838
$page_title = 'Access Keys';
2939
$page_descr = 'Check your access keys.';
40+
$js_files[] = '/js/sorttable.js';
3041
break;
3142
case Strings::StartsWith($url['path'], 'api'):
3243
$controller = 'api';
3344
$page_title = 'API response';
3445
$page_descr = '';
35-
$template = false;
46+
$template = false;
3647
break;
3748
case 'channelcomparison':
3849
$controller = 'channelcomparison';
3950
$page_title = 'Channel Comparison';
4051
$page_descr = 'Compare strings from channel to channel.';
52+
$js_files[] = '/js/select_column.js';
53+
$js_files[] = '/js/sorttable.js';
4154
break;
4255
case 'consistency':
4356
$experimental = true;
44-
$controller = 'consistency';
45-
$page_title = 'Translation Consistency';
46-
$page_descr = 'Analyze translation consistency across repositories.';
57+
$controller = 'consistency';
58+
$page_title = 'Translation Consistency';
59+
$page_descr = 'Analyze translation consistency across repositories.';
4760
break;
4861
case 'credits':
49-
$view = 'credits';
62+
$view = 'credits';
5063
$page_title = 'Credits';
5164
$page_descr = '';
5265
break;
5366
case 'downloads':
54-
$controller = 'tmx_downloads';
55-
$page_title = 'TMX Download';
56-
$page_descr = 'Create and download your own <abbr title="Translation Memory eXchange">TMX</abbr> file containing the strings you need.';
57-
$css_include = ['tmx.css'];
67+
$controller = 'tmx_downloads';
68+
$page_title = 'TMX Download';
69+
$page_descr = 'Create and download your own <abbr title="Translation Memory eXchange">TMX</abbr> file containing the strings you need.';
70+
$css_files[] = 'tmx.css';
71+
$js_files[] = '/js/select_all.js';
5872
break;
5973
case 'gaia':
60-
$view = 'gaia';
74+
$view = 'gaia';
6175
$page_title = 'Gaia Comparison';
6276
$page_descr = 'Check the Status of your GAIA strings across repositories.';
6377
break;
6478
case 'news':
65-
$controller = 'changelog';
66-
$page_title = 'Transvision News and Release Notes';
67-
$page_descr = '';
68-
$css_include = ['changelog.css'];
79+
$controller = 'changelog';
80+
$page_title = 'Transvision News and Release Notes';
81+
$page_descr = '';
82+
$css_files[] = 'changelog.css';
6983
break;
7084
case 'productization':
71-
$view = 'productization';
72-
$page_title = 'Productization Overview';
73-
$page_descr = 'Show productization aspects for this locale.';
74-
$css_include = ['productization.css'];
85+
$view = 'productization';
86+
$page_title = 'Productization Overview';
87+
$page_descr = 'Show productization aspects for this locale.';
88+
$css_files[] = 'productization.css';
7589
break;
7690
case 'rss':
7791
$controller = 'changelog';
78-
$template = false;
92+
$template = false;
7993
break;
8094
case 'showrepos':
8195
$experimental = true;
82-
$controller = 'health_status';
83-
$page_title = 'Health status';
84-
$page_descr = 'Check the health status of locales.';
85-
$css_include = ['health.css'];
96+
$controller = 'health_status';
97+
$page_title = 'Health status';
98+
$page_descr = 'Check the health status of locales.';
99+
$css_files[] = 'health.css';
100+
$js_files[] = '/js/show_hide_tabs.js';
86101
break;
87102
case 'stats':
88103
$controller = 'showrepos';
89104
$page_title = 'Status Overview';
90105
$page_descr = 'Repository status overview.';
106+
$js_files[] = '/js/sorttable.js';
91107
break;
92108
case 'string':
93109
$controller = 'onestring';
@@ -98,12 +114,15 @@
98114
$controller = 'unchanged_strings';
99115
$page_title = 'Unchanged Strings';
100116
$page_descr = 'Display a list of strings identical to English';
117+
$js_files[] = '/js/component_filter.js';
118+
$js_files[] = '/js/sorttable.js';
101119
break;
102120
case 'unlocalized':
103121
$experimental = true;
104122
$controller = 'unlocalized_words';
105123
$page_title = 'Commonly Unlocalized Words';
106124
$page_descr = 'Display the list of the most common untranslated words. Click on the table headers to sort results.';
125+
$js_files[] = '/js/sorttable.js';
107126
break;
108127
case 'unlocalized-json':
109128
$controller = 'unlocalized_words';
@@ -113,9 +132,11 @@
113132
$controller = 'check_variables';
114133
$page_title = 'Variables Overview';
115134
$page_descr = 'Show potential errors related to missing or mispelled variables in your strings.';
135+
$js_files[] = '/js/component_filter.js';
136+
$js_files[] = '/js/sorttable.js';
116137
break;
117138
default:
118-
$view = '404';
139+
$view = '404';
119140
$page_title = '404: Page Not Found';
120141
$page_descr = '';
121142
break;
@@ -148,12 +169,18 @@
148169
$content = ob_get_contents();
149170
ob_end_clean();
150171
}
172+
151173
ob_start();
174+
152175
// Log script performance in the HTTP headers sent to the browser
153176
Utils::addPerformancesHTTPHeader();
154177
$perf_header = ob_get_contents();
178+
155179
// Log script performance in PHP integrated developement server console
156180
Utils::logScriptPerformances();
181+
157182
ob_end_clean();
183+
158184
print $perf_header . $content;
185+
159186
die;

app/inc/l10n-init.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,3 @@
6565
// Get RTL attribute for source and target locales
6666
$locale_dir = $l10n->getDirection($locale);
6767
$source_locale_dir = $l10n->getDirection($source_locale);
68-
69-
// Initialize list of JavaScript files to include
70-
$javascript_include = [];

app/models/check_variables.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
// Add component filter
3232
if (in_array($repo, $desktop_repos)) {
3333
// Build logic to filter components
34-
$javascript_include = ['/js/component_filter.js'];
3534
$components = Project::getComponents(array_flip($var_errors));
3635
$filter_block = '';
3736
foreach ($components as $value) {

0 commit comments

Comments
 (0)