add searchpath UI extension

This commit is contained in:
Baris Ayaz 2020-07-08 16:53:38 +02:00
parent 8d6579c624
commit 4140862328
7 changed files with 107 additions and 0 deletions

View file

@ -320,6 +320,7 @@ labels.profile.placeholder_confirm_new_password=Neues Passwort (bestätigen)
labels.top.search=Suche
labels.index_title=Fess
labels.index_form_search_btn=Suche
labels.index_form_searchpath_btn=Pfad
labels.index_osdd_title=Suche
labels.index_form_option_btn=Optionen
labels.index_help=Hilfe

View file

@ -364,6 +364,7 @@ labels.profile.placeholder_confirm_new_password=Confirm New Password
labels.top.search=Search
labels.index_title=Fess
labels.index_form_search_btn=Search
labels.index_form_searchpath_btn=Path
labels.index_osdd_title=Search
labels.index_form_option_btn=Options
labels.index_help=Help

View file

@ -21,6 +21,14 @@
class="btn btn-primary">
<em class="fa fa-search"></em>
</button>
<button type="button" class="btn btn-light"
data-toggle="control-search-path" data-target="#searchPath"
id="searchPathButton">
<i class="far fa-folder"></i>
<span class="sr-only">
<la:message key="labels.index_form_searchpath_btn" />
</span>
</button>
<button type="button" class="btn btn-light"
data-toggle="control-options" data-target="#searchOptions"
id="searchOptionsButton">
@ -94,4 +102,22 @@
</div>
</div>
</div>
<div id="searchPath" class="control-search-path">
<div class="container">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="far fa-folder"></i></span>
</div>
<input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="search path"
id="searchPathField" name="searchPath" value="${f:h(fe:join(searchPath))}">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="searchPathFieldClear">
<i class="fa fa-times-circle"></i>
</button>
</div>
</div>
</div>
</div>
</la:form>

View file

@ -118,6 +118,22 @@
autocomplete="off" />
</div>
</div>
<div id="searchPath" class="control-search-path mx-auto col-10 col-sm-8 col-md-8 col-lg-6" style="margin-top:10px;">
<div class="container">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="far fa-folder"></i></span>
</div>
<input type="text" class="form-control" placeholder="" aria-label="" aria-describedby="search path"
id="searchPathField" name="searchPath" value="${f:h(fe:join(searchPath))}">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="searchPathFieldClear">
<i class="fa fa-times-circle"></i>
</button>
</div>
</div>
</div>
</div>
<c:if test="${!empty popularWords}">
<div class="clearfix">
<p class="text-truncate">
@ -141,6 +157,11 @@
<em class="fa fa-search"></em>
<la:message key="labels.index_form_search_btn" />
</button>
<button type="button" class="btn btn-outline-secondary"
data-toggle="control-search-path" data-target="#searchPath" id="searchPathButton">
<i class="far fa-folder"></i>
<la:message key="labels.index_form_searchpath_btn" />
</button>
<button type="button" class="btn btn-outline-secondary"
data-toggle="control-options" data-target="#searchOptions"
id="searchOptionsButton">
@ -160,5 +181,6 @@
<script type="text/javascript" src="${fe:url('/js/bootstrap.min.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/suggestor.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/index.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/searchpath.js')}"></script>
</body>
</html>

View file

@ -153,5 +153,6 @@
<script type="text/javascript" src="${fe:url('/js/bootstrap.min.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/suggestor.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/search.js')}"></script>
<script type="text/javascript" src="${fe:url('/js/searchpath.js')}"></script>
</body>
</html>

View file

@ -160,3 +160,7 @@ legend{
white-space: nowrap;
}
}
/* searchPath extension */
#searchPath {display: none;}
#searchPath.active {display: block;}

View file

@ -0,0 +1,52 @@
// Search Path extension
$("[data-toggle='control-search-path']").click(function (e) {
e.preventDefault();
var target = $(this).attr("data-target") || $(this).attr("href");
if (target) {
$(target).toggleClass("active");
}
});
$('#searchPathFieldClear').click(function (e) {
$('#searchPathField').val('');
});
$(function () {
var query = (location.search.split('q' + '=')[1] || '').split('&')[0];
var searchPathTerms = [];
if (query.indexOf("inurl") > 0) {
var inurlEncodedMatches = query.match(/inurl%3A%22(.*?)%22/g) || [""];
inurlEncodedMatches.forEach(function (item, idx) {
var inurl = decodeURIComponent(item)
// console.log("In URL: " + inurl);
var searchPathTerm = (inurl.match("\\inurl:\"(.*?)\\\"") || [""])[1];
// console.log("Search Path Term: " + searchPathTerm);
//Replace inurl in query
$('#query').val($('#query').val().replace('inurl:\"' + searchPathTerm + '\"', '').trim())
searchPathTerms.push(searchPathTerm);
});
//Activate search path field
$('#searchPath').toggleClass("active", true);
$('#searchPathField').val(searchPathTerms.join(" "));
}
});
$('#searchForm').submit(function () {
var searchPath = $('#searchPathField').val();
if (searchPath != "") {
$('#query').css('color', 'white');
$('#contentQuery').css('color', 'white');
$('#searchPathField').css('color', 'white');
var searchPathTerms = searchPath.split(" ");
searchPathTerms.forEach(function (item, idx) {
$('#query').val($('#query').val() + " inurl:\"" + item + "\"");
$('#contentQuery').val($('#contentQuery').val() + " inurl:\"" + item + "\"");
})
}
});