Skip to content

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

enhancing the search functionality

uggrock5934d77dfb2d
diff --git a/data/index.html b/data/index.html
index a0fff3294..523f1eb69 100644
--- a/data/index.html
+++ b/data/index.html
@@ -222,8 +222,8 @@
<div class="flexMaxWidth"></div>
<div id="searchToolbar">
<div class="flexLayout">
- <button class="btn btn-link" data-i18n="[title]ns.common:clearFilterTooltip" id="clearFilterButton">
- <i class="fa fa-lg fa-eraser"></i>
+ <button class="btn btn-link" data-i18n="[title]ns.common:showSearchOptions" 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">
<button class="btn btn-link" data-i18n="[title]ns.common:searchPlaceholder" id="searchButton">
@@ -857,20 +857,72 @@
</ul>
</div>
-<div id="searchOptions" class="dropdown clearfix" style="position: absolute; top: 80px; right: 5px; width: 330px;">
+<div id="searchOptions" class="dropdown clearfix" style="position: absolute; top: 45px; right: 0px; width: 400px;">
<div class="dropdown-menu" style="display:block;position:static;">
<li class="dropdown-header">
<button class="close">&times;</button>
- <span data-i18n="ns.common:searchOptions">Search Options</span>
+ <span data-i18n="ns.common:searchAdvanced">Advanced Search</span>
</li>
<div style="padding: 10px;">
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:includeSubfoldersInSearch"></span><br>
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:excludeTermFromSearch"></span><br>
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:includeTagInSearch"></span><br>
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:excludeTagInSearch"></span><br>
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:andedSearch"></span><br>
- <i class="fa fa-exclamation-circle"></i>&nbsp;<span data-i18n="ns.common:searchInFilenameOnly"></span><br>
- <!--button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"><i class="fa fa-check fa-lg"></i></button-->
+ <form class="form-horizontal">
+ <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>
+ </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>
+ </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>
+ </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>
+ </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>
+ <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>
+ </form>
+
</div>
</div>
</div>
diff --git a/data/js/core.api.js b/data/js/core.api.js
index 20b1cdef7..bd0fd772d 100644
--- a/data/js/core.api.js
+++ b/data/js/core.api.js
@@ -260,7 +260,7 @@ define(function(require, exports, module) {
function removeFileModel(model, filePath) {
console.log('Removing file from model');
for (var i = 0; i < model.length; i++) {
- if (model[i][exports.fileListFILEPATH] === filePath) {
+ if (model[i].path === filePath) {
model.splice(i, 1);
}
}
@@ -272,14 +272,11 @@ define(function(require, exports, module) {
fileExt = tsTagUtils.extractFileExtension(newPath),
fileTags = tsTagUtils.extractTags(newPath);
for (var i = 0; i < model.length; i++) {
- if (model[i][exports.fileListFILEPATH] == oldPath) {
- model[i][exports.fileListFILEPATH] = newPath;
- model[i][exports.fileListTITLE] = title;
- model[i][exports.fileListTAGS] = fileTags;
- model[i][exports.fileListFILEEXT] = fileExt; // TODO complete the list
- //model[i][exports.fileListFILELMDT] = newPath;
- //model[i][exports.fileListFILENAME] = newPath;
- //model[i][exports.fileListFILESIZE] = newPath;
+ if (model[i].path == oldPath) {
+ model[i].path = newPath;
+ model[i].title = title;
+ model[i].tags = fileTags;
+ model[i].extension = fileExt; // TODO complete the list
}
}
}
@@ -298,7 +295,7 @@ define(function(require, exports, module) {
}
csv += headers.join(',') + '\n';
for (var i = 0; i < fileList.length; i++) {
- var row = fileList[i][exports.fileListFILEPATH] + ',' + fileList[i][exports.fileListTITLE] + ',' + fileList[i][exports.fileListFILESIZE] + ',' + fileList[i][exports.fileListTAGS];
+ var row = fileList[i].path + ',' + fileList[i].title + ',' + fileList[i].size + ',' + fileList[i].tags;
rows.push(row);
}
csv += rows.join('\n');
@@ -309,11 +306,10 @@ define(function(require, exports, module) {
var rows = [];
for (var i = 0; i < fileList.length; i++) {
var row = [];
- row.path = fileList[i][exports.fileListFILEPATH];
- row.title = fileList[i][exports.fileListTITLE];
- row.size = fileList[i][exports.fileListFILESIZE];
- var tags = fileList[i][exports.fileListTAGS];
- for (var j = 0; j < tags.length; j++) {
+ row.path = fileList[i].path;
+ row.title = fileList[i].title;
+ row.size = fileList[i].size;
+ for (var j = 0; j < fileList[i].tags.length; j++) {
row['tag' + j] = tags[j];
}
rows.push(row);
@@ -485,6 +481,7 @@ define(function(require, exports, module) {
exports.metaFileExt = ".json";
exports.thumbFileExt = ".png";
exports.contentFileExt = ".txt";
+ exports.directoryExt = "DIRECTORY";
exports.locationDesktop;
exports.initApp = initApp;
exports.reLayout = reLayout;
@@ -566,14 +563,7 @@ define(function(require, exports, module) {
exports.startTime = startTime;
exports.subfoldersDirBrowser = subfoldersDirBrowser;
exports.directoryBrowser = directoryBrowser;
- exports.fileListFILEEXT = 0;
- exports.fileListTITLE = 1;
- exports.fileListTAGS = 2;
- exports.fileListFILESIZE = 3;
- exports.fileListFILELMDT = 4;
- exports.fileListFILEPATH = 5;
- exports.fileListFILENAME = 6;
- exports.fileListMETA = 7;
+
//document events
exports.createDocumentEvent = createDocumentEvent;
exports.fireDocumentEvent = fireDocumentEvent;
diff --git a/data/js/core.ui.js b/data/js/core.ui.js
index 28f3565d7..e822e9e1c 100644
--- a/data/js/core.ui.js
+++ b/data/js/core.ui.js
@@ -337,6 +337,7 @@ define(function(require, exports, module) {
Promise.all(fileOperations).then(function(success) {
// TODO handle copying sidecar files
TSCORE.hideWaitingDialog();
+ TSCORE.navigateToDirectory(TSCORE.currentPath);
TSCORE.showSuccessDialog("Files successfully copied");
}, function(err) {
TSCORE.hideWaitingDialog();
@@ -643,78 +644,45 @@ define(function(require, exports, module) {
$('#locationContent').hide();
// Search UI
- $('#searchToolbar').on('click', '#closeSearchOptionButton', function() {
- $('#searchOptions').hide();
- });
-
$('#searchOptions').on('click', '.close', function() {
$('#searchOptions').hide();
});
- $('#searchToolbar').on('click', '#includeSubfoldersOption', function() {
- var searchQuery = $('#searchBox').val();
- if (searchQuery.indexOf('?') === 0) {
- $('#includeSubfoldersOption i').removeClass('fa-toggle-on').addClass('fa-toggle-off');
- $('#searchBox').val(searchQuery.substring(1, searchQuery.length));
- } else {
- $('#includeSubfoldersOption i').removeClass('fa-toggle-off').addClass('fa-toggle-on');
- $('#searchBox').val('?' + searchQuery);
- }
- });
-
- /*$('#searchBox').on('show.bs.popover', function() {
- var searchQuery = $('#searchBox').val();
- if (searchQuery.indexOf('?') === 0) {
- $('#includeSubfoldersOption i').removeClass('fa-toggle-off').addClass('fa-toggle-on');
- } else {
- $('#includeSubfoldersOption i').removeClass('fa-toggle-on').addClass('fa-toggle-off');
- }
- });*/
-
- $('#searchBox').prop('disabled', true)
- .focus(function() {
- if (!TSCORE.FileOpener.isFileOpened()) {
- $("#searchOptions").show();
- }
- })
+ $('#searchBox')
.keyup(function(e) {
- // On enter fire the search
- if (e.keyCode === 13) {
- $('#clearFilterButton').addClass('filterOn');
- TSCORE.PerspectiveManager.redrawCurrentPerspective();
- $('#searchOptions').hide();
- $('#searchButton').focus();
- } else if (e.keyCode == 27) {
+ 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;
- $('#clearFilterButton').removeClass('filterOn');
TSCORE.PerspectiveManager.redrawCurrentPerspective();
}
- }).blur(function() {
- if (this.value.length === 0) {
- $('#clearFilterButton').removeClass('filterOn');
- TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ })
+ /*.blur(function() {
+ if (this.value.length < 1) {
+ cancelSearch();
}
- });
+ })*/;
$('#showSearchButton').on('click', function() {
+ // Showing the expanded search area
TSCORE.showSearchArea();
});
- $('#searchButton').prop('disabled', true).click(function(evt) {
- evt.preventDefault();
- $('#clearFilterButton').addClass('filterOn');
- $('#searchOptions').hide();
- TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ $('#searchButton').on("click", function(e) {
+ e.preventDefault();
+ startSearch();
});
- $('#clearFilterButton').prop('disabled', true).click(function(e) {
+ $('#showSearchOptionsButton').on("click", function(e) {
e.preventDefault();
- cancelSearch();
+ TSCORE.showSearchArea();
+ $("#searchOptions").show();
});
// Search UI END
@@ -776,10 +744,15 @@ define(function(require, exports, module) {
});
};
+ function startSearch() {
+ $('#searchOptions').hide();
+ TSCORE.PerspectiveManager.redrawCurrentPerspective();
+ }
+
function cancelSearch() {
clearSearchFilter();
- $('#searchToolbar').hide();
- $('#showSearchButton').show();
+ //$('#searchToolbar').hide();
+ //$('#showSearchButton').show();
// Restoring initial dir listing without subdirectories
TSCORE.IO.listDirectoryPromise(TSCORE.currentPath).then(
function(entries) {
@@ -803,6 +776,8 @@ define(function(require, exports, module) {
}
function clearSearchFilter() {
+ $('#searchToolbar').hide();
+ $('#showSearchButton').show();
$('#searchOptions').hide();
$('#searchBox').val('');
$('#clearFilterButton').removeClass('filterOn');
diff --git a/data/js/meta.js b/data/js/meta.js
index 12da8c660..2df967dce 100644
--- a/data/js/meta.js
+++ b/data/js/meta.js
@@ -35,8 +35,8 @@ define(function(require, exports, module) {
function findMetaObjectFromFileList(filePath) {
var metaObj = null;
TSCORE.fileList.every(function(element) {
- if (element[TSCORE.fileListFILEPATH] === filePath) {
- metaObj = element[TSCORE.fileListMETA];
+ if (element.path === filePath) {
+ metaObj = element.meta;
return false;
}
return true;
@@ -46,6 +46,7 @@ define(function(require, exports, module) {
function saveMetaData(filePath, metaData) {
var metaFilePath = findMetaFilebyPath(filePath, TSCORE.metaFileExt);
+ var currentVersion = TSCORE.Config.DefaultSettings.appVersion + "." + TSCORE.Config.DefaultSettings.appBuild;
if (!metaFilePath) {
var name = TSCORE.Utils.baseName(filePath) + TSCORE.metaFileExt;
metaFilePath = TSCORE.currentPath + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + name;
@@ -55,7 +56,13 @@ define(function(require, exports, module) {
"path": metaFilePath,
};
TSCORE.metaFileList.push(entry);
+ metaData.appVersionCreated = currentVersion;
}
+
+ metaData.appName = TSCORE.Config.DefaultSettings.appName;
+ metaData.appVersionUpdated = currentVersion;
+ metaData.lastUpdated = new Date();
+
var content = JSON.stringify(metaData);
TSCORE.IO.saveTextFilePromise(metaFilePath, content, true);
}
@@ -127,6 +134,7 @@ define(function(require, exports, module) {
});
}
+ // should be in sync with the function from the PRO version
function generateImageThumbnail(fileURL) {
return new Promise(function(resolve, reject) {
var canvas = document.createElement("canvas");
@@ -162,12 +170,12 @@ define(function(require, exports, module) {
function loadMetaFileJsonPromise(entry) {
return new Promise(function(resolve, reject) {
- var filePath = entry[TSCORE.fileListFILEPATH];
+ var filePath = entry.path;
var metaFileJson = findMetaFilebyPath(filePath, TSCORE.metaFileExt);
if (metaFileJson) {
TSCORE.IO.getFileContentPromise(metaFileJson, "text").then(function(result) {
var metaData = JSON.parse(result);
- entry[TSCORE.fileListMETA].metaData = metaData;
+ entry.meta.metaData = metaData;
resolve(filePath);
}).catch(function(err) {
console.warn("Getting meta information failed for: " + filePath);
diff --git a/data/js/perspective.manager.js b/data/js/perspective.manager.js
index a0b0b96fc..3dae231a9 100644
--- a/data/js/perspective.manager.js
+++ b/data/js/perspective.manager.js
@@ -204,10 +204,10 @@ define(function(require, exports, module) {
if (TSCORE.Config.getShowUnixHiddenEntries() || !TSCORE.Config.getShowUnixHiddenEntries() && dirList[i].path.indexOf(TSCORE.dirSeparator + '.') < 0) {
filename = dirList[i].name.replace(/(<([^>]+)>)/gi, ''); // sanitizing filename
path = dirList[i].path.replace(/(<([^>]+)>)/gi, ''); // sanitizing filepath
- title = TSCORE.TagUtils.extractTitle(path);
+ title = TSCORE.TagUtils.extractTitle(filename);
if (dirList[i].isFile) {
- ext = TSCORE.TagUtils.extractFileExtension(path);
+ ext = TSCORE.TagUtils.extractFileExtension(filename);
tags = TSCORE.TagUtils.extractTags(path);
if (dirList[i].size) {
@@ -233,16 +233,17 @@ define(function(require, exports, module) {
metaData: null
};
- entry = [
- ext,
- title,
- tags,
- fileSize,
- fileLMDT,
- path,
- filename,
- metaObj
- ];
+ entry = {
+ "extension": ext,
+ "title": title,
+ "tags": tags,
+ "size": fileSize,
+ "lmdt": fileLMDT,
+ "path": path,
+ "name": filename,
+ "isDirectoriy": false,
+ "meta": metaObj
+ };
TSCORE.fileList.push(entry);
metaDataLoadingPromises.push(TSCORE.Meta.loadMetaFileJsonPromise(entry));
} else {
diff --git a/data/js/search.js b/data/js/search.js
index c099a1379..1760cd95e 100644
--- a/data/js/search.js
+++ b/data/js/search.js
@@ -32,7 +32,7 @@ define(function(require, exports, module) {
console.log('Calculating tags from search results');
var allTags = [];
data.forEach(function(fileEntry) {
- fileEntry[TSCORE.fileListTAGS].forEach(function(tag) {
+ fileEntry.tags.forEach(function(tag) {
allTags.push(tag.toLowerCase());
});
});
@@ -195,18 +195,49 @@ define(function(require, exports, module) {
var found = false;
queryObj.includedTerms.forEach(function(term) {
if (content.indexOf(term[0]) >= 0) {
+ console.log("Term " + term[0] + " found in " + fileEntry.path);
found = true;
}
- if (found) {
- console.log("Term " + term[0] + " found in " + fileEntry.path);
+ });
+ if (found) {
+ var indexOfMetaDirectory = fileEntry.path.indexOf(TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator);
+ if (indexOfMetaDirectory > 0) { // file is in the meta folder
+ var metaExtLocation = fileEntry.path.lastIndexOf(TSCORE.metaFileExt);
+ var contentExtLocation = fileEntry.path.lastIndexOf(TSCORE.contentFileExt);
+ var metaFolderLocation = fileEntry.path.lastIndexOf(TSCORE.metaFolderFile);
+
+ // file is meta file (json) and not tsm.json
+ if (metaExtLocation > indexOfMetaDirectory && metaFolderLocation < 0) {
+ // TODO parse file and find tags
+ fileEntry.name = fileEntry.name.substring(0, fileEntry.name.indexOf(TSCORE.metaFileExt));
+ fileEntry.path = fileEntry.path.substring(0, indexOfMetaDirectory + 1) + fileEntry.name;
+ }
+
+ // file is text file containing extracted contentent (txt)
+ if (contentExtLocation > indexOfMetaDirectory ) {
+ fileEntry.name = fileEntry.name.substring(0, fileEntry.name.indexOf(TSCORE.contentFileExt));
+ fileEntry.path = fileEntry.path.substring(0, indexOfMetaDirectory + 1) + fileEntry.name;
+ }
+
+ // file is meta directory file (tsm.json)
+ if (metaFolderLocation > indexOfMetaDirectory ) {
+ fileEntry.path = fileEntry.path.substring(0, indexOfMetaDirectory + 1);
+ fileEntry.name = TSCORE.TagUtils.extractDirectoryName(fileEntry.path) + "." + TSCORE.directoryExt;
+ }
+
+ // TODO try to get the properties of the file and update the size and lmdt
+ fileEntry.size = 0; // evtl lmdt = 0
searchResults.push(fileEntry);
}
- });
+ }
+ resolve();
}, function(err) {
+ resolve();
console.log("Failed loading content for: " + fileEntry.path);
});
+ } else {
+ resolve();
}
- resolve();
});
}
//, function(dirEntry) {}
diff --git a/data/locales/en_US/ns.common.json b/data/locales/en_US/ns.common.json
index 4f6ad3d21..c696750a6 100644
--- a/data/locales/en_US/ns.common.json
+++ b/data/locales/en_US/ns.common.json
@@ -122,6 +122,7 @@
"openNewInstanceTooltip": "Open New TagSpaces Instance",
"openSettingTooltip": "Open Settings",
"searchOptions": "Search Options",
+ "searchAdvanced": "Advanced Search",
"searchPlaceholder": "Search",
"clearFilterTooltip": "Clear Filter",
"includeSubfoldersInSearch": "Include files from the subfolders (by adding questionmark \" ? \" in front of the query)",