From b6e181efb13f03008ca421fb389bb21a46f549a8 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 11:24:18 +0100 Subject: [PATCH 01/10] excess whitespace --- ext/notes/main.php | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/notes/main.php b/ext/notes/main.php index 39743226..b1706c03 100644 --- a/ext/notes/main.php +++ b/ext/notes/main.php @@ -1,4 +1,3 @@ - Date: Sat, 18 Jun 2016 11:47:04 +0100 Subject: [PATCH 02/10] search button can sometimes be on same line as input --- ext/autocomplete/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/autocomplete/style.css b/ext/autocomplete/style.css index 582af002..019bb7fd 100644 --- a/ext/autocomplete/style.css +++ b/ext/autocomplete/style.css @@ -2,7 +2,7 @@ .tagit { background: white !important; border: 1px solid grey !important; cursor: text; } .tagit-choice { cursor: initial; } -input[name=search] ~ input[type=submit] { display: block !important; } +input[name=search] ~ input[type=submit] { display: inline-block !important; } .tag-negative { background: #ff8080 !important; } .tag-positive { background: #40bf40 !important; } \ No newline at end of file From 559a4c7e4000693d65a7715a0af4064c81ce9c29 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 11:58:41 +0100 Subject: [PATCH 03/10] move autocomplete js to script.js so it's cached --- ext/autocomplete/script.js | 58 +++++++++++++++++++++++++++++++++++ ext/autocomplete/theme.php | 63 +------------------------------------- 2 files changed, 59 insertions(+), 62 deletions(-) create mode 100644 ext/autocomplete/script.js diff --git a/ext/autocomplete/script.js b/ext/autocomplete/script.js new file mode 100644 index 00000000..b2f26384 --- /dev/null +++ b/ext/autocomplete/script.js @@ -0,0 +1,58 @@ +$(function(){ + $('[name=search]').tagit({ + singleFieldDelimiter: ' ', + beforeTagAdded: function(event, ui) { + // give special class to negative tags + if(ui.tagLabel[0] === '-') { + ui.tag.addClass('tag-negative'); + }else{ + ui.tag.addClass('tag-positive'); + } + }, + autocomplete : ({ + source: function (request, response) { + var isNegative = (request.term[0] === '-'); + $.ajax({ + url: base_href + '/api/internal/autocomplete', + data: {'s': (isNegative ? request.term.substring(1) : request.term)}, + dataType : 'json', + type : 'GET', + success : function (data) { + response($.map(data, function (item) { + item = (isNegative ? '-'+item : item); + return { + label : item, + value : item + } + })); + }, + error : function (request, status, error) { + alert(error); + } + }); + }, + minLength: 1 + }) + }); + + $('.ui-autocomplete-input').keydown(function(e) { + var keyCode = e.keyCode || e.which; + + //Stop tags containing space. + if(keyCode == 32) { + e.preventDefault(); + + $('[name=search]').tagit('createTag', $(this).val()); + $(this).autocomplete('close'); + } else if (keyCode == 9) { + e.preventDefault(); + + var tag = $('.tagit-autocomplete[style*=\"display: block\"] > li:first').text(); + if(tag){ + $('[name=search]').tagit('createTag', tag); + $('.ui-autocomplete-input').autocomplete('close'); + $('.ui-autocomplete-input').val(''); //If tag already exists, make sure to remove duplicate. + } + } + }); +}); \ No newline at end of file diff --git a/ext/autocomplete/theme.php b/ext/autocomplete/theme.php index 3b5a4af5..462d2bfd 100644 --- a/ext/autocomplete/theme.php +++ b/ext/autocomplete/theme.php @@ -7,68 +7,7 @@ class AutoCompleteTheme extends Themelet { $page->add_html_header(""); $page->add_html_header(""); - $page->add_html_header(''); + $page->add_html_header(''); $page->add_html_header(""); - - $page->add_html_header(""); } } From 2a747c8f2b729a8dadc6df49370c97ce8f6e620d Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 12:10:37 +0100 Subject: [PATCH 04/10] move home css to style.css --- ext/home/style.css | 9 +++++++++ ext/home/theme.php | 11 ----------- 2 files changed, 9 insertions(+), 11 deletions(-) create mode 100644 ext/home/style.css diff --git a/ext/home/style.css b/ext/home/style.css new file mode 100644 index 00000000..fbf1bcf3 --- /dev/null +++ b/ext/home/style.css @@ -0,0 +1,9 @@ +div#front-page h1 {font-size: 4em; margin-top: 2em; margin-bottom: 0px; text-align: center; border: none; background: none; box-shadow: none; -webkit-box-shadow: none; -moz-box-shadow: none;} +div#front-page {text-align:center;} +.space {margin-bottom: 1em;} +div#front-page div#links a {margin: 0 0.5em;} +div#front-page li {list-style-type: none; margin: 0;} +@media (max-width: 800px) { + div#front-page h1 {font-size: 3em; margin-top: 0.5em; margin-bottom: 0.5em;} + #counter {display: none;} +} \ No newline at end of file diff --git a/ext/home/theme.php b/ext/home/theme.php index 6c51c73d..91e8ea5c 100644 --- a/ext/home/theme.php +++ b/ext/home/theme.php @@ -14,17 +14,6 @@ class HomeTheme extends Themelet { $hh - $body From 6b6e4f04b637687bbd8b0f75be671189acf60ad9 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 12:25:22 +0100 Subject: [PATCH 05/10] html_headers should be properly sorted --- ext/home/theme.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/home/theme.php b/ext/home/theme.php index 91e8ea5c..a833e962 100644 --- a/ext/home/theme.php +++ b/ext/home/theme.php @@ -5,6 +5,7 @@ class HomeTheme extends Themelet { $page->set_mode("data"); $hh = ""; $page->add_auto_html_headers(); + ksort($page->html_headers); foreach($page->html_headers as $h) {$hh .= $h;} $page->set_data(<< From 4bd9ee1c7fb2d50e7b6b97d1cfedca38deeb1eaa Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 12:25:39 +0100 Subject: [PATCH 06/10] fix autocomplete search not looking correct on home page --- ext/home/style.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/home/style.css b/ext/home/style.css index fbf1bcf3..dba7e859 100644 --- a/ext/home/style.css +++ b/ext/home/style.css @@ -6,4 +6,8 @@ div#front-page li {list-style-type: none; margin: 0;} @media (max-width: 800px) { div#front-page h1 {font-size: 3em; margin-top: 0.5em; margin-bottom: 0.5em;} #counter {display: none;} -} \ No newline at end of file +} + +div#front-page > #search > form { margin: 0 auto; } +div#front-page > #search > form > ul { width: 225px; vertical-align: middle; display: inline-block; } +div#front-page > #search > form > input[type=submit]{ padding: 4px 6px; } From 2546621c59d62a6c3147e879eee4b70e7a114524 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 13:18:59 +0100 Subject: [PATCH 07/10] sort autocomplete by score + show score --- ext/autocomplete/main.php | 10 ++++++++-- ext/autocomplete/script.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index cd373c63..1dfb81f4 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -20,8 +20,14 @@ class AutoComplete extends Extension { $SQLarr['limit'] = $_GET["limit"]; } - $res = $database->get_col( - "SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 $limitSQL", $SQLarr); + $res = $database->get_pairs(" + SELECT tag, count + FROM tags + WHERE tag LIKE :search + AND count > 0 + ORDER BY count DESC + $limitSQL", $SQLarr + ); $page->set_mode("data"); $page->set_type("application/json"); diff --git a/ext/autocomplete/script.js b/ext/autocomplete/script.js index b2f26384..87ccbf93 100644 --- a/ext/autocomplete/script.js +++ b/ext/autocomplete/script.js @@ -18,10 +18,10 @@ $(function(){ dataType : 'json', type : 'GET', success : function (data) { - response($.map(data, function (item) { + response($.map(data, function (count, item) { item = (isNegative ? '-'+item : item); return { - label : item, + label : item + ' ('+count+')', value : item } })); From 56e5348470a2ec660749ad97879df50097771c9c Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 13:19:25 +0100 Subject: [PATCH 08/10] autocomplete caching see 7dce8da850d2b266ffc196a9e9c0aa9ee9314fe3 --- ext/autocomplete/main.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index 1dfb81f4..6854f3e4 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -13,21 +13,28 @@ class AutoComplete extends Extension { if(!isset($_GET["s"])) return; //$limit = 0; + $cache_key = "autocomplete-" . strtolower($_GET["s"]); $limitSQL = ""; $SQLarr = array("search"=>$_GET["s"]."%"); if(isset($_GET["limit"]) && $_GET["limit"] !== 0){ $limitSQL = "LIMIT :limit"; $SQLarr['limit'] = $_GET["limit"]; + $cache_key .= "-" . $_GET["limit"]; } - $res = $database->get_pairs(" - SELECT tag, count - FROM tags - WHERE tag LIKE :search - AND count > 0 - ORDER BY count DESC - $limitSQL", $SQLarr - ); + $res = null; + $database->cache->get($cache_key); + if(!$res) { + $res = $database->get_pairs(" + SELECT tag, count + FROM tags + WHERE tag LIKE :search + AND count > 0 + ORDER BY count DESC + $limitSQL", $SQLarr + ); + $database->cache->set($cache_key, $res, 600); + } $page->set_mode("data"); $page->set_type("application/json"); From 5d5b1d70599dedb4b7ac99b28e99c0d2cb1953f1 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 13:56:18 +0100 Subject: [PATCH 09/10] this should be set to $res --- ext/autocomplete/main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index 6854f3e4..d6656bcd 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -23,7 +23,7 @@ class AutoComplete extends Extension { } $res = null; - $database->cache->get($cache_key); + $res = $database->cache->get($cache_key); if(!$res) { $res = $database->get_pairs(" SELECT tag, count From b5d56214cdb5863a493e545629e46e9c0d0576d0 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 14:45:21 +0100 Subject: [PATCH 10/10] fix case-insensitive autocomplete on postgres --- ext/autocomplete/main.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index d6656bcd..918796a4 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -22,16 +22,15 @@ class AutoComplete extends Extension { $cache_key .= "-" . $_GET["limit"]; } - $res = null; $res = $database->cache->get($cache_key); if(!$res) { - $res = $database->get_pairs(" + $res = $database->get_pairs($database->scoreql_to_sql(" SELECT tag, count FROM tags - WHERE tag LIKE :search + WHERE SCORE_STRNORM(tag) LIKE SCORE_STRNORM(:search) AND count > 0 ORDER BY count DESC - $limitSQL", $SQLarr + $limitSQL"), $SQLarr ); $database->cache->set($cache_key, $res, 600); }