Using only one form in linklist.html + adding untaggedonly filter - fix #885

This commit is contained in:
Lucas Cimon 2017-06-01 17:55:26 +02:00
parent d5d22a6d07
commit f210d94f71
9 changed files with 113 additions and 104 deletions

View file

@ -417,21 +417,22 @@ public function filterDay($request) {
* - searchterm: term search * - searchterm: term search
* @param bool $casesensitive Optional: Perform case sensitive filter * @param bool $casesensitive Optional: Perform case sensitive filter
* @param string $visibility return only all/private/public links * @param string $visibility return only all/private/public links
* @param string $untaggedonly return only untagged links
* *
* @return array filtered links, all links if no suitable filter was provided. * @return array filtered links, all links if no suitable filter was provided.
*/ */
public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all') public function filterSearch($filterRequest = array(), $casesensitive = false, $visibility = 'all', $untaggedonly = false)
{ {
// Filter link database according to parameters. // Filter link database according to parameters.
$searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : ''; $searchtags = isset($filterRequest['searchtags']) ? escape($filterRequest['searchtags']) : '';
$searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : ''; $searchterm = isset($filterRequest['searchterm']) ? escape($filterRequest['searchterm']) : '';
// Search tags + fullsearch - blank string parameter will return all links. // Search tags + fullsearch - blank string parameter will return all links.
$type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; $type = LinkFilter::$FILTER_TAG | LinkFilter::$FILTER_TEXT; // == "vuotext"
$request = [$searchtags, $searchterm]; $request = [$searchtags, $searchterm];
$linkFilter = new LinkFilter($this); $linkFilter = new LinkFilter($this);
return $linkFilter->filter($type, $request, $casesensitive, $visibility); return $linkFilter->filter($type, $request, $casesensitive, $visibility, $untaggedonly);
} }
/** /**

View file

@ -52,10 +52,11 @@ public function __construct($links)
* @param mixed $request Filter content. * @param mixed $request Filter content.
* @param bool $casesensitive Optional: Perform case sensitive filter if true. * @param bool $casesensitive Optional: Perform case sensitive filter if true.
* @param string $visibility Optional: return only all/private/public links * @param string $visibility Optional: return only all/private/public links
* @param string $untaggedonly Optional: return only untagged links. Applies only if $type includes FILTER_TAG
* *
* @return array filtered link list. * @return array filtered link list.
*/ */
public function filter($type, $request, $casesensitive = false, $visibility = 'all') public function filter($type, $request, $casesensitive = false, $visibility = 'all', $untaggedonly = false)
{ {
if (! in_array($visibility, ['all', 'public', 'private'])) { if (! in_array($visibility, ['all', 'public', 'private'])) {
$visibility = 'all'; $visibility = 'all';
@ -64,23 +65,34 @@ public function filter($type, $request, $casesensitive = false, $visibility = 'a
switch($type) { switch($type) {
case self::$FILTER_HASH: case self::$FILTER_HASH:
return $this->filterSmallHash($request); return $this->filterSmallHash($request);
case self::$FILTER_TAG | self::$FILTER_TEXT: case self::$FILTER_TAG | self::$FILTER_TEXT: // == "vuotext"
if (!empty($request)) { $noRequest = empty($request) || (empty($request[0]) && empty($request[1]));
$filtered = $this->links; if ($noRequest) {
if (isset($request[0])) { if ($untaggedonly) {
$filtered = $this->filterTags($request[0], $casesensitive, $visibility); return $this->filterUntagged($visibility);
} }
if (isset($request[1])) { return $this->noFilter($visibility);
$lf = new LinkFilter($filtered);
$filtered = $lf->filterFulltext($request[1], $visibility);
}
return $filtered;
} }
return $this->noFilter($visibility); if ($untaggedonly) {
$filtered = $this->filterUntagged($visibility);
} else {
$filtered = $this->links;
}
if (!empty($request[0])) {
$filtered = (new LinkFilter($filtered))->filterTags($request[0], $casesensitive, $visibility);
}
if (!empty($request[1])) {
$filtered = (new LinkFilter($filtered))->filterFulltext($request[1], $visibility);
}
return $filtered;
case self::$FILTER_TEXT: case self::$FILTER_TEXT:
return $this->filterFulltext($request, $visibility); return $this->filterFulltext($request, $visibility);
case self::$FILTER_TAG: case self::$FILTER_TAG:
return $this->filterTags($request, $casesensitive, $visibility); if ($untaggedonly) {
return $this->filterUntagged($visibility);
} else {
return $this->filterTags($request, $casesensitive, $visibility);
}
case self::$FILTER_DAY: case self::$FILTER_DAY:
return $this->filterDay($request); return $this->filterDay($request);
default: default:
@ -253,9 +265,6 @@ public function filterTags($tags, $casesensitive = false, $visibility = 'all')
{ {
// Implode if array for clean up. // Implode if array for clean up.
$tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags; $tags = is_array($tags) ? trim(implode(' ', $tags)) : $tags;
if ($tags === false) {
return $this->filterUntagged($visibility);
}
if (empty($tags)) { if (empty($tags)) {
return $this->noFilter($visibility); return $this->noFilter($visibility);
} }

View file

@ -78,6 +78,7 @@ private function initialize()
$this->tpl->assign('version', shaarli_version); $this->tpl->assign('version', shaarli_version);
$this->tpl->assign('scripturl', index_url($_SERVER)); $this->tpl->assign('scripturl', index_url($_SERVER));
$this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
$this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly']));
$this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli')); $this->tpl->assign('pagetitle', $this->conf->get('general.title', 'Shaarli'));
if ($this->conf->exists('general.header_link')) { if ($this->conf->exists('general.header_link')) {
$this->tpl->assign('titleLink', $this->conf->get('general.header_link')); $this->tpl->assign('titleLink', $this->conf->get('general.header_link'));

View file

@ -287,6 +287,7 @@ function logout() {
unset($_SESSION['ip']); unset($_SESSION['ip']);
unset($_SESSION['username']); unset($_SESSION['username']);
unset($_SESSION['privateonly']); unset($_SESSION['privateonly']);
unset($_SESSION['untaggedonly']);
} }
setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH);
} }
@ -1017,6 +1018,19 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history)
exit; exit;
} }
// -------- User wants to see only untagged links (toggle)
if (isset($_GET['untaggedonly'])) {
$_SESSION['untaggedonly'] = !$_SESSION['untaggedonly'];
if (! empty($_SERVER['HTTP_REFERER'])) {
$location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('untaggedonly'));
} else {
$location = '?';
}
header('Location: '. $location);
exit;
}
// -------- Handle other actions allowed for non-logged in users: // -------- Handle other actions allowed for non-logged in users:
if (!isLoggedIn()) if (!isLoggedIn())
{ {
@ -1651,7 +1665,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
'searchtags' => $searchtags, 'searchtags' => $searchtags,
'searchterm' => $searchterm, 'searchterm' => $searchterm,
]; ];
$linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility); $linksToDisplay = $LINKSDB->filterSearch($request, false, $visibility, !empty($_SESSION['untaggedonly']));
} }
// ---- Handle paging. // ---- Handle paging.

View file

@ -63,10 +63,9 @@ public function testFilter()
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, '')) count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, ''))
); );
// Untagged only
$this->assertEquals( $this->assertEquals(
self::$refDB->countUntaggedLinks(), self::$refDB->countUntaggedLinks(),
count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, false)) count(self::$linkFilter->filter(LinkFilter::$FILTER_TAG, /*$request=*/'', /*$casesensitive=*/false, /*$visibility=*/'all', /*$untaggedonly=*/true))
); );
$this->assertEquals( $this->assertEquals(

View file

@ -226,6 +226,12 @@ body, .pure-g [class*="pure-u"] {
border-radius: 2px; border-radius: 2px;
color: #252525; color: #252525;
} }
@media screen and (max-width: 64em) {
.searchform {
max-width: 260px;
margin: 0 auto;
}
}
/* because chrome */ /* because chrome */
#search input[type="text"]::-webkit-input-placeholder, #search input[type="text"]::-webkit-input-placeholder,
@ -236,43 +242,37 @@ body, .pure-g [class*="pure-u"] {
#search button, #search button,
#search-tagcloud button, #search-tagcloud button,
#search-linklist button { #search-linklist button {
background: transparent; padding: 4px 8px 6px 8px;
border: none; background-color: #1B926C;
}
#search button {
color: #f5f5f5; color: #f5f5f5;
border: none;
border-radius: 2px;
} }
#search-linklist button { #search-tagcloud button {
color: #252525; width: 90%;
}
@media screen and (max-width: 64em) {
#search-linklist button {
width: 100%;
}
#search-linklist .awesomplete {
margin: 5px 0;
}
} }
#search button:hover, #search button:hover,
#search-linklist button:hover { #search-linklist button:hover,
color: #fff;
}
#search-tagcloud button:hover { #search-tagcloud button:hover {
color: #d0d0d0; color: #d0d0d0;
} }
#search,
#search-linklist { #search-linklist {
padding: 5px 0; padding: 6px 0;
} }
@media screen and (min-width: 64em) {
#search .searchform,
#search-linklist .searchform {
margin-right: 25px;
text-align: right;
}
#search .tagfilter,
#search-linklist .tagfilter {
margin-left: 25px;
text-align: left;
}
}
@media screen and (max-width: 64em) { @media screen and (max-width: 64em) {
#search, #search * { #search, #search * {
visibility: hidden; visibility: hidden;
@ -321,7 +321,6 @@ body, .pure-g [class*="pure-u"] {
} }
.subheader-form input[type="text"], .subheader-form input[type="password"], .subheader-form .remember-me { .subheader-form input[type="text"], .subheader-form input[type="password"], .subheader-form .remember-me {
margin: 0 0 5px 0;
padding: 5px 5px 3px 15px; padding: 5px 5px 3px 15px;
height: 20px; height: 20px;
width: 20%; width: 20%;

View file

@ -19,30 +19,21 @@
<div id="search-linklist"> <div id="search-linklist">
<div class="pure-g"> <form method="GET" class="pure-form searchform" name="searchform">
<div class="pure-u-1 pure-u-lg-1-2"> <input type="text" tabindex="1" name="searchterm" class="searchterm" placeholder="{'Search text'|t}"
<form method="GET" class="searchform" name="searchform"> {if="!empty($search_term)"}
<input type="text" tabindex="1" name="searchterm" placeholder="{'Search text'|t}" value="{$search_term}"
{if="!empty($search_term)"} {/if}
value="{$search_term}" >
{/if} <input type="text" tabindex="2" name="searchtags" class="searchtags" placeholder="{'Filter by tag'|t}"
> {if="!empty($search_tags)"}
<button type="submit" class="search-button"><i class="fa fa-search"></i></button> value="{$search_tags}"
</form> {/if}
</div> autocomplete="off" data-multiple data-autofirst data-minChars="1"
<div class="pure-u-1 pure-u-lg-1-2"> data-list="{loop="$tags"}{$key}, {/loop}"
<form method="GET" class="tagfilter" name="tagfilter"> >
<input type="text" tabindex="2" name="searchtags" placeholder="{'Filter by tag'|t}" <button type="submit" class="search-button"><i class="fa fa-search"></i></button>
{if="!empty($search_tags)"} </form>
value="{$search_tags}"
{/if}
autocomplete="off" data-multiple data-autofirst data-minChars="1"
data-list="{loop="$tags"}{$key}, {/loop}"
>
<button type="submit" class="search-button"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
</div> </div>
{loop="$plugins_header.fields_toolbar"} {loop="$plugins_header.fields_toolbar"}
@ -91,7 +82,7 @@
<div id="searchcriteria">{'Nothing found.'|t}</div> <div id="searchcriteria">{'Nothing found.'|t}</div>
</div> </div>
</div> </div>
{elseif="!empty($search_term) or $search_tags !== '' or !empty($visibility)"} {elseif="!empty($search_term) or $search_tags !== '' or !empty($visibility) or $untaggedonly"}
<div class="pure-g pure-alert pure-alert-success search-result"> <div class="pure-g pure-alert pure-alert-success search-result">
<div class="pure-u-2-24"></div> <div class="pure-u-2-24"></div>
<div class="pure-u-20-24"> <div class="pure-u-20-24">
@ -107,10 +98,6 @@
<a href="?removetag={function="urlencode($value)"}">{$value}<span class="remove"><i class="fa fa-times"></i></span></a> <a href="?removetag={function="urlencode($value)"}">{$value}<span class="remove"><i class="fa fa-times"></i></span></a>
</span> </span>
{/loop} {/loop}
{elseif="$search_tags === false"}
<span class="label label-tag" title="{'Remove tag'|t}">
<a href="?">{'untagged'|t}<span class="remove"><i class="fa fa-times"></i></span></a>
</span>
{/if} {/if}
{if="!empty($visibility)"} {if="!empty($visibility)"}
{'with status'|t} {'with status'|t}
@ -118,6 +105,11 @@
{$visibility|t} {$visibility|t}
</span> </span>
{/if} {/if}
{if="$untaggedonly"}
<span class="label label-private">
{'without any tag'|t}
</span>
{/if}
</div> </div>
</div> </div>
{/if} {/if}

View file

@ -6,10 +6,13 @@
{'Filters'|t} {'Filters'|t}
</span> </span>
{if="isLoggedIn()"} {if="isLoggedIn()"}
<a href="?privateonly" title="{'Filter private links'|t}" <a href="?privateonly" title="{'Filter private links'|t}"
class={if="$privateonly"}"filter-on"{else}"filter-off"{/if} class={if="$privateonly"}"filter-on"{else}"filter-off"{/if}
><i class="fa fa-key"></i></a> ><i class="fa fa-key"></i></a>
{/if} {/if}
<a href="?untaggedonly" title="{'Filter untagged links'|t}"
class={if="$untaggedonly"}"filter-on"{else}"filter-off"{/if}
><i class="fa fa-tag"></i></a>
<a href="#" class="filter-off fold-all pure-u-lg-0" title="Fold all"> <a href="#" class="filter-off fold-all pure-u-lg-0" title="Fold all">
<i class="fa fa-chevron-up"></i> <i class="fa fa-chevron-up"></i>
</a> </a>

View file

@ -97,30 +97,21 @@
<div id="content"> <div id="content">
<div id="search" class="subheader-form"> <div id="search" class="subheader-form">
<div class="pure-g"> <form method="GET" class="pure-form searchform" name="searchform">
<div class="pure-u-1 pure-u-lg-1-2"> <input type="text" tabindex="1" id="searchform_value" name="searchterm" placeholder="{'Search text'|t}"
<form method="GET" class="searchform" name="searchform"> {if="!empty($search_term)"}
<input type="text" tabindex="1" id="searchform_value" name="searchterm" placeholder="{'Search text'|t}" value="{$search_term}"
{if="!empty($search_term)"} {/if}
value="{$search_term}" >
{/if} <input type="text" tabindex="2" name="searchtags" id="tagfilter_value" placeholder="{'Filter by tag'|t}"
> {if="!empty($search_tags)"}
<button type="submit" class="search-button"><i class="fa fa-search"></i></button> value="{$search_tags}"
</form> {/if}
</div> autocomplete="off" data-multiple data-autofirst data-minChars="1"
<div class="pure-u-1 pure-u-lg-1-2"> data-list="{loop="$tags"}{$key}, {/loop}"
<form method="GET" class="tagfilter" name="tagfilter"> >
<input type="text" tabindex="2" name="searchtags" id="tagfilter_value" placeholder="{'Filter by tag'|t}" <button type="submit" class="search-button"><i class="fa fa-search"></i></button>
{if="!empty($search_tags)"} </form>
value="{$search_tags}"
{/if}
autocomplete="off" data-multiple data-autofirst data-minChars="1"
data-list="{loop="$tags"}{$key}, {/loop}"
>
<button type="submit" class="search-button"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
</div> </div>
<div id="actions" class="subheader-form"> <div id="actions" class="subheader-form">
<div class="pure-g"> <div class="pure-g">