Skip to content

TagSpaces is an offline, open source, document manager with tagging support

adding new search ui

uggrock96d050388e4c
diff --git a/data/assets/general.css b/data/assets/general.css
index c70782b6f..b0cdd3360 100644
--- a/data/assets/general.css
+++ b/data/assets/general.css
@@ -226,6 +226,10 @@ li hr {
width: 100%;
}
+.searchFormElements {
+ font-size: 14px !important;
+}
+
#tagsContainer {
width: 100%;
min-height: 40px;
diff --git a/data/index.html b/data/index.html
index 523f1eb69..1ef4f80f0 100644
--- a/data/index.html
+++ b/data/index.html
@@ -222,7 +222,7 @@
<div class="flexMaxWidth"></div>
<div id="searchToolbar">
<div class="flexLayout">
- <button class="btn btn-link" data-i18n="[title]ns.common:showSearchOptions" id="showSearchOptionsButton">
+ <button class="btn btn-link" data-i18n="[title]ns.common:showAdvancedSearch" id="showSearchOptionsButton">
<i class="fa fa-lg fa-angle-double-down"></i>
</button>
<input class="flexMaxWidth" id="searchBox" data-i18n="[placeholder]ns.common:searchPlaceholder" type="text">
@@ -857,69 +857,53 @@
</ul>
</div>
-<div id="searchOptions" class="dropdown clearfix" style="position: absolute; top: 45px; right: 0px; width: 400px;">
- <div class="dropdown-menu" style="display:block;position:static;">
+<div id="searchOptions" class="dropdown clearfix" style="position: absolute; top: 80px; right: 2px; width: 300px;">
+ <div class="dropdown-menu" style="display:block; position:static; width:100%;">
<li class="dropdown-header">
<button class="close">&times;</button>
<span data-i18n="ns.common:searchAdvanced">Advanced Search</span>
</li>
<div style="padding: 10px;">
- <form class="form-horizontal">
+ <form>
<div class="form-group">
- <label for="inputEmail3" class="col-sm-2 control-label">Query</label>
- <div class="col-sm-10">
- <input type="email" class="form-control" id="inputEmail3">
- </div>
+ <label for="searchTerms">Search words</label>
+ <input type="text" class="form-control searchFormElements" id="searchTerms" placeholder="Search words separated by space">
</div>
<div class="form-group">
- <label for="inputEmail3" class="col-sm-2 control-label">Tags</label>
- <div class="col-sm-10">
- <input type="email" class="form-control" id="inputEmail3">
- </div>
+ <label for="searchTags">Tags</label>
+ <input type="text" class="form-control searchFormElements" id="searchTags" placeholder="Tags separated by spaces">
</div>
<div class="form-group">
- <label for="searchFileType" class="col-sm-2 control-label">Type</label>
- <div id="searchFileType" class="col-sm-10">
- <select id="searchFileType" class="form-control">
- <option>Specify file type</option>
- <option value="type:pictures">Pictures (JPG,PNG,GIF,...)</option>
- <option value="type:docs">Documents (PDF,ODF,DOCX,EXL,...)</option>
- <option value="type:audio">Audio (OGG,MP3,...)</option>
- <option value="type:video">Video files (WEBM,OGV,MP4,...)</option>
- <option value="type:archive">Archives (ZIP,RAR,TGZ,...)</option>
- </select>
- </div>
+ <label for="searchFileType">Type</label>
+ <select id="searchFileType" class="form-control searchFormElements">
+ <option value="">Specify file type</option>
+ <option value="t:pictures">Pictures (JPG,PNG,GIF,...)</option>
+ <option value="t:docs">Documents (PDF,ODF,DOCX,EXL,...)</option>
+ <option value="t:audio">Audio (OGG,MP3,...)</option>
+ <option value="t:video">Video files (WEBM,OGV,MP4,...)</option>
+ <option value="t:archives">Archives (ZIP,RAR,TGZ,...)</option>
+ </select>
</div>
<!-- div class="form-group">
<label for="searchFileType" class="col-sm-2 control-label">History</label>
- <div id="searchFileType" class="col-sm-10">
- <select id="" class="form-control">
- <option>of your last 15 searches</option>
- <option value="t:pictures +topsy">t:pictures +topsy</option>
- <option value="t:pictures +danny">t:pictures +danny</option>
- <option value="t:docs +work">t:docs +work</option>
- <option value="t:archives +client1">t:archives +client1</option>
- <option value="t:audio u2">t:audio u2</option>
- <option value="type:pictures +topsy">Clear all</option>
- </select>
- </div>
+ <select id="" class="form-control">
+ <option>of your last 15 searches</option>
+ <option value="t:pictures +topsy">t:pictures +topsy</option>
+ <option value="t:pictures +danny">t:pictures +danny</option>
+ <option value="t:docs +work">t:docs +work</option>
+ <option value="t:archives +client1">t:archives +client1</option>
+ <option value="t:audio u2">t:audio u2</option>
+ <option value="type:pictures +topsy">Clear all</option>
+ </select>
</div -->
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <div class="checkbox">
- <label>
- <input type="checkbox" checked>&nbsp;<span>Search in subfolders</span>
- </label>
- </div>
- </div>
+ <div class="checkbox">
+ <label>
+ <input type="checkbox" id="searchRecursive" checked>&nbsp;<span>Search in subfolders</span>
+ </label>
</div>
- <div class="form-group" style="margin-bottom: 0px;">
- <div class="col-sm-12">
- <span class="pull-right">
- <button class="btn btn-default btn-sm" aria-hidden="true"><i class="fa fa-eraser fa-lg"></i>&nbsp;<span>Reset</span></button>
- <button class="btn btn-primary btn-sm" aria-hidden="true"><i class="fa fa-search fa-lg"></i>&nbsp;<span>Search</span></button>
- </span>
- </div>
+ <div class="form-group" style="margin-bottom: 5px;">
+ <button class="btn btn-default btn-sm" aria-hidden="true" id="cancelSearchButton"><i class="fa fa-eraser fa-lg"></i>&nbsp;<span>Cancel</span></button>
+ <button class="btn btn-primary btn-sm pull-right" aria-hidden="true" id="startSearchButton"><i class="fa fa-search fa-lg"></i>&nbsp;<span>Search</span></button>
</div>
</form>
diff --git a/data/js/core.ui.js b/data/js/core.ui.js
index e822e9e1c..bc66de4b9 100644
--- a/data/js/core.ui.js
+++ b/data/js/core.ui.js
@@ -643,49 +643,6 @@ define(function(require, exports, module) {
// Hide the tagGroupsContent or locationContent by default
$('#locationContent').hide();
- // Search UI
- $('#searchOptions').on('click', '.close', function() {
- $('#searchOptions').hide();
- });
-
- $('#searchBox')
- .keyup(function(e) {
- if (e.keyCode === 13) { // Start the search on ENTER
- startSearch();
- //$('#searchButton').focus();
- } else if (e.keyCode == 27) { // Hide search on ESC
- cancelSearch();
- } else {
- TSCORE.Search.nextQuery = this.value;
- }
- if (this.value.length === 0) {
- TSCORE.Search.nextQuery = this.value;
- TSCORE.PerspectiveManager.redrawCurrentPerspective();
- }
- })
- /*.blur(function() {
- if (this.value.length < 1) {
- cancelSearch();
- }
- })*/;
-
- $('#showSearchButton').on('click', function() {
- // Showing the expanded search area
- TSCORE.showSearchArea();
- });
-
- $('#searchButton').on("click", function(e) {
- e.preventDefault();
- startSearch();
- });
-
- $('#showSearchOptionsButton').on("click", function(e) {
- e.preventDefault();
- TSCORE.showSearchArea();
- $("#searchOptions").show();
- });
- // Search UI END
-
$('#perspectiveSwitcherButton').prop('disabled', true);
var $contactUsContent = $('#contactUsContent');
$contactUsContent.on('click', '#openHints', showWelcomeDialog);
@@ -738,12 +695,125 @@ define(function(require, exports, module) {
openLinkExternally($(this).attr('href'));
});
+ // Search UI
+ $('#searchBox')
+ .keyup(function(e) {
+ if (e.keyCode === 13) { // Start the search on ENTER
+ startSearch();
+ } else if (e.keyCode == 27) { // Hide search on ESC
+ cancelSearch();
+ } else {
+ TSCORE.Search.nextQuery = this.value;
+ }
+ if (this.value.length === 0) {
+ TSCORE.Search.nextQuery = this.value;
+ TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ }
+ })
+ .focus(function(e) {
+ $("#searchOptions").hide();
+ });
+
+ $('#showSearchButton').on('click', function() {
+ // Showing the expanded search area
+ TSCORE.showSearchArea();
+ });
+
+ $('#searchButton').on("click", function(e) {
+ startSearch();
+ });
+
+ $('#startSearchButton').on("click", function(e) {
+ e.preventDefault();
+ startSearch();
+ });
+
+ $('#showSearchOptionsButton').on("click", function() {
+ showSearchOptions();
+ });
+
+ $('#searchOptions').on('click', '.close', function() {
+ $('#searchOptions').hide();
+ cancelSearch();
+ });
+
+ $('#cancelSearchButton').on('click', function(e) {
+ e.preventDefault();
+ $('#searchOptions').hide();
+ cancelSearch();
+ });
+
+ $('#searchRecursive').on('click', function(e) {
+ updateQuery();
+ });
+
+ $('#searchTerms').on('blur', function(e) {
+ updateQuery();
+ });
+
+ $('#searchTags').on('blur', function(e) {
+ updateQuery();
+ });
+
+ $('#searchFileType').on('change', function(e) {
+ updateQuery();
+ });
+
+ // END Search UI
+
// Hide drop downs by click and drag
$(document).click(function() {
TSCORE.hideAllDropDownMenus();
});
};
+ function updateQuery() {
+ var query = "";
+ if(!$('#searchRecursive').is(':checked')) {
+ query = "| "
+ }
+
+ var searchTerms = $('#searchTerms').val();
+ if(searchTerms.length > 0 ) {
+ searchTerms = searchTerms.split(" ");
+ searchTerms.forEach(function(term) {
+ if(term.length > 1) {
+ query = query + " " + term;
+ }
+ })
+ }
+
+ var tags = $('#searchTags').val();
+ if(tags.length > 0 ) {
+ tags = tags.split(" ");
+ tags.forEach(function(tag) {
+ if(tag.length > 1) {
+ query = query + " +" + tag;
+ }
+ })
+ }
+
+ var fileType = $('#searchFileType').val();
+ if(fileType.length > 0) {
+ query = query + " " + fileType;
+ }
+
+ console.log();
+ $('#searchBox').val(query);
+ }
+
+ function showSearchOptions() {
+ $('#searchRecursive').prop('checked', true);
+ $('#searchTerms').val("");
+ $('#searchTags').val("");
+ $('#searchFileType').val("");
+
+ var leftPosition = $(".col2").position().left + $(".col2").width();
+ leftPosition = leftPosition - ($("#searchOptions").width() + 2);
+ $("#searchOptions").css({left: leftPosition});
+ $("#searchOptions").show();
+ }
+
function startSearch() {
$('#searchOptions').hide();
TSCORE.PerspectiveManager.redrawCurrentPerspective();
@@ -751,8 +821,6 @@ define(function(require, exports, module) {
function cancelSearch() {
clearSearchFilter();
- //$('#searchToolbar').hide();
- //$('#showSearchButton').show();
// Restoring initial dir listing without subdirectories
TSCORE.IO.listDirectoryPromise(TSCORE.currentPath).then(
function(entries) {
diff --git a/data/js/search.js b/data/js/search.js
index 1760cd95e..fd0efed6f 100644
--- a/data/js/search.js
+++ b/data/js/search.js
@@ -53,7 +53,7 @@ define(function(require, exports, module) {
function prepareQuery(queryText) {
// cleaning up the query, reducing the spaces
var queryText = queryText.toLowerCase().replace(/^\s+|\s+$/g, '');
- var recursive = queryText.indexOf('?') === 0;
+ var recursive = !(queryText.indexOf('~') === 0);
if (recursive) {
queryText = queryText.substring(1, queryText.length);
}
diff --git a/data/js/search.ui.js b/data/js/search.ui.js
new file mode 100644
index 000000000..bf0dc96fe
--- /dev/null
+++ b/data/js/search.ui.js
@@ -0,0 +1,173 @@
+/* Copyright (c) 2016 The TagSpaces Authors. All rights reserved.
+ * Use of this source code is governed by a AGPL3 license that
+ * can be found in the LICENSE file. */
+
+/* global define, Handlebars, isNode */
+define(function(require, exports, module) {
+ 'use strict';
+ console.log('Loading core.ui.js ...');
+ var TSCORE = require('tscore');
+
+ var initUI = function() {
+ // Search UI
+ $('#searchBox')
+ .keyup(function(e) {
+ if (e.keyCode === 13) { // Start the search on ENTER
+ startSearch();
+ } else if (e.keyCode == 27) { // Hide search on ESC
+ cancelSearch();
+ } else {
+ TSCORE.Search.nextQuery = this.value;
+ }
+ if (this.value.length === 0) {
+ TSCORE.Search.nextQuery = this.value;
+ TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ }
+ })
+ .focus(function(e) {
+ $("#searchOptions").hide();
+ });
+
+ $('#showSearchButton').on('click', function() {
+ // Showing the expanded search area
+ TSCORE.showSearchArea();
+ });
+
+ $('#searchButton').on("click", function(e) {
+ startSearch();
+ });
+
+ $('#startSearchButton').on("click", function(e) {
+ e.preventDefault();
+ startSearch();
+ });
+
+ $('#showSearchOptionsButton').on("click", function() {
+ showSearchOptions();
+ });
+
+ $('#searchOptions').on('click', '.close', function() {
+ $('#searchOptions').hide();
+ cancelSearch();
+ });
+
+ $('#cancelSearchButton').on('click', function(e) {
+ e.preventDefault();
+ $('#searchOptions').hide();
+ cancelSearch();
+ });
+
+ $('#searchRecursive').on('click', function(e) {
+ updateQuery();
+ });
+
+ $('#searchTerms').on('blur', function(e) {
+ updateQuery();
+ });
+
+ $('#searchTags').on('blur', function(e) {
+ updateQuery();
+ });
+
+ $('#searchFileType').on('change', function(e) {
+ updateQuery();
+ });
+
+ // END Search UI
+
+ // Hide drop downs by click and drag
+ $(document).click(function() {
+ TSCORE.hideAllDropDownMenus();
+ });
+ };
+
+ function updateQuery() {
+ var query = "";
+ if(!$('#searchRecursive').is(':checked')) {
+ query = "| "
+ }
+
+ var searchTerms = $('#searchTerms').val();
+ if(searchTerms.length > 0 ) {
+ searchTerms = searchTerms.split(" ");
+ searchTerms.forEach(function(term) {
+ if(term.length > 1) {
+ query = query + " " + term;
+ }
+ })
+ }
+
+ var tags = $('#searchTags').val();
+ if(tags.length > 0 ) {
+ tags = tags.split(" ");
+ tags.forEach(function(tag) {
+ if(tag.length > 1) {
+ query = query + " +" + tag;
+ }
+ })
+ }
+
+ var fileType = $('#searchFileType').val();
+ if(fileType.length > 0) {
+ query = query + " " + fileType;
+ }
+
+ console.log();
+ $('#searchBox').val(query);
+ }
+
+ function showSearchOptions() {
+ $('#searchRecursive').prop('checked', true);
+ $('#searchTerms').val("");
+ $('#searchTags').val("");
+ $('#searchFileType').val("");
+
+ var leftPosition = $(".col2").position().left + $(".col2").width();
+ leftPosition = leftPosition - ($("#searchOptions").width() + 2);
+ $("#searchOptions").css({left: leftPosition});
+ $("#searchOptions").show();
+ }
+
+ function startSearch() {
+ $('#searchOptions').hide();
+ TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ }
+
+ function cancelSearch() {
+ clearSearchFilter();
+ // Restoring initial dir listing without subdirectories
+ TSCORE.IO.listDirectoryPromise(TSCORE.currentPath).then(
+ function(entries) {
+ TSPOSTIO.listDirectory(entries);
+ }
+ ).catch(function(err) {
+ TSPOSTIO.errorOpeningPath(TSCORE.currentPath);
+ console.warn("Error listing directory" + err);
+ });
+ }
+
+ function showSearchArea() {
+ $('#showSearchButton').hide();
+ $('#searchToolbar').show();
+ $('#searchBox').focus();
+ }
+
+ // Handle external links
+ function openLinkExternally(url) {
+ TSCORE.IO.openFile(url);
+ }
+
+ function clearSearchFilter() {
+ $('#searchToolbar').hide();
+ $('#showSearchButton').show();
+ $('#searchOptions').hide();
+ $('#searchBox').val('');
+ $('#clearFilterButton').removeClass('filterOn');
+ TSCORE.Search.nextQuery = '';
+ }
+
+ // Public API definition
+ exports.initUI = initUI;
+ exports.clearSearchFilter = clearSearchFilter;
+ exports.showSearchArea = showSearchArea;
+});
diff --git a/data/locales/en_US/ns.common.json b/data/locales/en_US/ns.common.json
index c696750a6..180180c2b 100644
--- a/data/locales/en_US/ns.common.json
+++ b/data/locales/en_US/ns.common.json
@@ -123,6 +123,7 @@
"openSettingTooltip": "Open Settings",
"searchOptions": "Search Options",
"searchAdvanced": "Advanced Search",
+ "showAdvancedSearch": "Open Advanced Search",
"searchPlaceholder": "Search",
"clearFilterTooltip": "Clear Filter",
"includeSubfoldersInSearch": "Include files from the subfolders (by adding questionmark \" ? \" in front of the query)",