TagSpaces is an offline, open source, document manager with tagging support
Search functionality extracted in the tagspaces core
Ilian4d8330883bdc
diff --git a/data/ext/perspectiveGrid/extension.js b/data/ext/perspectiveGrid/extension.jsindex bf9be3ede..516934828 100644--- a/data/ext/perspectiveGrid/extension.js+++ b/data/ext/perspectiveGrid/extension.js@@ -43,11 +43,15 @@ define(function(require, exports, module) {var load = function () {console.log("Loading perspective "+extensionID);if(UI != undefined) {- UI.reInit(TSCORE.fileList);- TSCORE.hideLoadingAnimation();+ UI.reInit();+ } else {+ TSCORE.hideLoadingAnimation();}- TSCORE.hideLoadingAnimation();};++ var clearSelectedFiles = function() {+ UI.clearSelectedFiles();+ };var getNextFile = function (filePath) {return UI.getNextFile(filePath);@@ -56,15 +60,6 @@ define(function(require, exports, module) {var getPrevFile = function (filePath) {return UI.getPrevFile(filePath);};-- var setFileFilter = function (filter) {- UI.setFilter(filter);- console.log("setFileFilter not implemented in "+exports.ID);- };-- var clearSelectedFiles = function() {- UI.clearSelectedFiles();- };// Varsexports.Title = extensionTitle;@@ -78,9 +73,7 @@ define(function(require, exports, module) {// Methodsexports.init = init;exports.load = load;- exports.setFileFilter = setFileFilter;exports.clearSelectedFiles = clearSelectedFiles;exports.getNextFile = getNextFile;exports.getPrevFile = getPrevFile;-});\ No newline at end of filediff --git a/data/ext/perspectiveGrid/perspectiveUI.js b/data/ext/perspectiveGrid/perspectiveUI.jsindex 45b263f57..219c2aa5f 100644--- a/data/ext/perspectiveGrid/perspectiveUI.js+++ b/data/ext/perspectiveGrid/perspectiveUI.js@@ -26,8 +26,6 @@ console.log("Loading UI for perspectiveDefault");this.currentGrouping = ""; // tagchain, day, month, yearthis.thumbEnabled = false;this.currentTmbSize = 0;- this.currentFilter = "";- this.nextFilter = "";this.searchResults = undefined;this.supportedGroupings = [];@@ -199,7 +197,6 @@ console.log("Loading UI for perspectiveDefault");var context = {id: this.extensionID,};- //console.log(uiTemplate(context));this.viewToolbar.html(toolbarTemplate(context));$("#"+this.extensionID+"ToogleSelectAll")@@ -240,78 +237,25 @@ console.log("Loading UI for perspectiveDefault");self.toggleThumbnails();});- $("#"+this.extensionID+"IncreaseThumbsButton")+ $("#"+this.extensionID+"IncreaseThumbsButton").click(function() {self.switchThumbnailSize();}).prop('disabled', true);-- $("#"+this.extensionID+"FilterBox")- /*.focus(function(e) {- $(this).removeClass("input-medium");- $(this).addClass("input-large");- })*/- .keyup(function(e) {- // On enter fire the search- if (e.keyCode == 13) {- $( "#"+self.extensionID+"ClearFilterButton").addClass("filterOn");- //TSCORE.startTime = new Date().getTime();- self.reInit();- } else {- self.nextFilter = this.value;- }- if (this.value.length == 0) {- //TSCORE.startTime = new Date().getTime();- $( "#"+self.extensionID+"ClearFilterButton").removeClass("filterOn");- self.reInit();- }- })- .blur(function() {- //$(this).addClass("input-medium");- //$(this).removeClass("input-large");- if (this.value.length == 0) {- $( "#"+self.extensionID+"ClearFilterButton").removeClass("filterOn");- //TSCORE.startTime = new Date().getTime();- self.reInit();- }- });-- $("#"+this.extensionID+"SearchButton").click(function(evt) {- evt.preventDefault();- $( "#"+self.extensionID+"ClearFilterButton").addClass("filterOn");- //TSCORE.startTime = new Date().getTime();- self.reInit();- });-- $("#"+this.extensionID+"ClearFilterButton")- .click(function(evt) {- evt.preventDefault();- $("#"+self.extensionID+"ClearFilterButton").removeClass("filterOn");- $("#"+self.extensionID+"FilterBox").val("");- //$("#"+self.extensionID+"FilterBox").val("").addClass("input-medium");- //$("#"+self.extensionID+"FilterBox").val("").removeClass("input-large");- self.setFilter("");- self.reInit();- });// Init Tag Context Menusthis.viewContainer.on("contextmenu click", ".tagButton", function (e) {TSCORE.hideAllDropDownMenus();-+ self.selectFile($(this).attr("filepath"));TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));-- $("#tagMenu").css({- display: "block",- left: e.pageX,- top: e.pageY- });+ TSCORE.showContextMenu("#tagMenu", $(this));return false;});this.initFileGroupingMenu();};- ExtUI.prototype.setFilter = function(filterValue) {+ /* ExtUI.prototype.setFilter = function(filterValue) {console.log("Filter to value: "+filterValue);$("#"+this.extensionID+"FilterBox").val(filterValue);@@ -322,7 +266,7 @@ console.log("Loading UI for perspectiveDefault");}this.nextFilter = filterValue;- };+ }; */ExtUI.prototype.switchThumbnailSize = function() {this.currentTmbSize = this.currentTmbSize + 1;@@ -470,110 +414,20 @@ console.log("Loading UI for perspectiveDefault");return data;};---- /** Filtering the data- *- * @param {Object} data The data to be filtered- */- ExtUI.prototype.filterData = function(data) {-- // By empty filter just return the data- if(this.nextFilter.length <= 0) {- return data;- }-- var query = this.nextFilter.toLowerCase();- query = query.replace(/^\s+|\s+$/g, "");- var queryTerms = query.split(" ");-- // Analysing filter- var includedTerms = [];- var excludedTerms = [];- var includedTags = [];- var excludedTags = [];-- queryTerms.forEach(function (value, index) {- if(value.length > 1) {- if(value.indexOf("!") == 0) {- excludedTerms.push([value.substring(1,value.length),false]);- } else if(value.indexOf("+") == 0) {- includedTags.push([value.substring(1,value.length),true]);- } else if(value.indexOf("-") == 0) {- excludedTags.push([value.substring(1,value.length),true]);- } else {- includedTerms.push([value,false]);- }- }- });-- data = _.filter(data, function(value) {- // Searching in the whole filename- var searchIn = value[TSCORE.fileListFILENAME].toLowerCase();- var tags = value[TSCORE.fileListTAGS];- var result = true;- if(tags.length < 1 && includedTags.length > 0) {- return false;- }- for (var i=0; i < includedTerms.length; i++) {- if(searchIn.indexOf(includedTerms[i][0]) >= 0) {- includedTerms[i][1] = true;- } else {- return false;- }- };- for (var i=0; i < excludedTerms.length; i++) {- if(searchIn.indexOf(excludedTerms[i][0]) < 0) {- excludedTerms[i][1] = true;- } else {- return false;- }- };-- for (var i=0; i < includedTags.length; i++) {- includedTags[i][1] = false;- for (var j=0; j < tags.length; j++) {- if(tags[j].toLowerCase() == includedTags[i][0]) {- includedTags[i][1] = true;- }- }- };- for (var i=0; i < includedTags.length; i++) {- result = result & includedTags[i][1];- }-- for (var i=0; i < excludedTags.length; i++) {- excludedTags[i][1] = true;- for (var j=0; j < tags.length; j++) {- if(tags[j].toLowerCase() == excludedTags[i][0]) {- excludedTags[i][1] = false;- }- }- };- for (var i=0; i < excludedTags.length; i++) {- result = result & excludedTags[i][1];- }-- return result;- });-- this.currentFilter = this.nextFilter;- return data;- };ExtUI.prototype.reInit = function() {-+ // Clear old datathis.viewContainer.empty();+ this.viewFooter.empty();+this.viewContainer.addClass("accordion");-$( this.extensionID+"IncludeSubDirsButton" ).prop('disabled', false);var self = this;- this.searchResults = self.filterData(TSCORE.fileList);+ // Load new filtered data+ this.searchResults = TSCORE.Search.searchData(TSCORE.fileList, TSCORE.Search.nextQuery);- this.viewFooter.empty();if(this.searchResults.length == 0) {this.viewFooter.html("<div class='searchSummary'>No files found.</div>");} else {@@ -584,7 +438,6 @@ console.log("Loading UI for perspectiveDefault");}));}-var i=0;_.each(self.calculateGrouping(this.searchResults), function (value) {i++;@@ -607,9 +460,9 @@ console.log("Loading UI for perspectiveDefault");"title": "Toggle Group",})- .html("<i class='icon-minus-sign-alt' /i> ")+ .html("<i class='fa fa-minus-square' /i> ").click(function() {- $(this).find('i').toggleClass("icon-minus-sign-alt").toggleClass("icon-plus-sign-alt");+ $(this).find('i').toggleClass("fa-minus-square").toggleClass("fa-plus-square");}))// End date toggle button@@ -732,6 +585,7 @@ console.log("Loading UI for perspectiveDefault");});this.refreshThumbnails();+ TSCORE.hideLoadingAnimation();};ExtUI.prototype.clearSelectedFiles = function() {@@ -810,4 +664,5 @@ console.log("Loading UI for perspectiveDefault");};exports.ExtUI = ExtUI;+});\ No newline at end of filediff --git a/data/ext/perspectiveGrid/toolbar.html b/data/ext/perspectiveGrid/toolbar.htmlindex 88b0b7a45..246c3d66e 100644--- a/data/ext/perspectiveGrid/toolbar.html+++ b/data/ext/perspectiveGrid/toolbar.html@@ -25,19 +25,4 @@<i class="fa fa-group"></i> Group <span class="caret"></span></button><ul id="{{id}}GroupingMenu" class="dropdown-menu "></ul>-</div>-<div class="input-group pull-right" style="width: 180px; padding-right: 4px;">- <input type="text" class="form-control" id="{{id}}FilterBox" placeholder="Search" title="Search hints:- All terms should be true in order the file to appear in the search results- term: the term should be part of the file title or file extension- !term: the term should not be part of the file title or file extension- +tagname: file should be tagged with this tag- -tagname: file should not be tagged with this tag">- <span class="input-group-btn">- <button class="btn btn-default" title="Search" id="{{id}}SearchButton">- <i class="fa fa-search"></i>- </button>- <button class="btn btn-default" title="Clear Filter" id="{{id}}ClearFilterButton">- <i class="fa fa-times"></i>- </button></span></div>\ No newline at end of filediff --git a/data/ext/perspectiveHealth/extension.js b/data/ext/perspectiveHealth/extension.jsindex f91846503..1e8a1d697 100644--- a/data/ext/perspectiveHealth/extension.js+++ b/data/ext/perspectiveHealth/extension.js@@ -23,7 +23,7 @@ define(function(require, exports, module) {var extensionDirectory = TSCORE.Config.getExtensionPath()+"/"+extensionID;- var vizMode = "quantYours" // tree+ var vizMode = "quantYours"; // treeexports.init = function init() {console.log("Initializing View "+extensionID);@@ -33,12 +33,12 @@ define(function(require, exports, module) {viewFooter = $("#"+extensionID+"Footer").empty();initUI();- }+ };exports.load = function load() {console.log("Loading View "+extensionID);reDraw();- }+ };var reDraw = function() {switch (vizMode) {@@ -51,7 +51,8 @@ define(function(require, exports, module) {var svg = d3.select("#"+extensionID+"Container").append("svg").attr("width", viewContainer.width())- .attr("height", viewContainer.height())+ .attr("height", viewContainer.height()+ );viz.draw(svg);TSCORE.hideLoadingAnimation();});@@ -59,21 +60,17 @@ define(function(require, exports, module) {default:break;}- }+ };exports.updateTreeData = function updateIndexData(fsTreeData) {console.log("Updating tree data, not supported here...");TSCORE.hideLoadingAnimation();- }-- exports.setFileFilter = function setFileFilter(filter) {-- }-+ };+exports.clearSelectedFiles = function() {- }+ };var initUI = function() {@@ -139,7 +136,7 @@ define(function(require, exports, module) {); // end toolbar- }+ };// Varsexports.Title = extensionTitle;diff --git a/data/ext/perspectiveList/extension.js b/data/ext/perspectiveList/extension.jsindex 3d01d8e20..7c219444b 100644--- a/data/ext/perspectiveList/extension.js+++ b/data/ext/perspectiveList/extension.js@@ -22,15 +22,15 @@ define(function(require, exports, module) {function init() {console.log("Initializing perspective "+extensionID);- // TODO use css require extension for loading 'css!datatablescss'require([extensionDirectory+'/perspectiveUI.js',- 'datatables'- ], function(extUI) {+ "text!"+extensionDirectory+'/toolbar.html',+ extensionDirectory+'/datatables/jquery.dataTables.min.js',+ ], function(extUI, toolbarTPL) {+ var toolbarTemplate = Handlebars.compile( toolbarTPL );UI = new extUI.ExtUI(extensionID);- UI.buildUI();- UI.initTable();- platformTuning();+ UI.buildUI(toolbarTemplate);+ platformTuning();});};@@ -46,15 +46,12 @@ define(function(require, exports, module) {var load = function () {console.log("Loading perspective "+extensionID);if(UI != undefined) {- UI.reInitTableWithData();- TSCORE.hideLoadingAnimation();- }- };-- var setFileFilter = function (filter) {- UI.setFilter(filter);+ UI.reInit();+ } else {+ TSCORE.hideLoadingAnimation();+ }};-+var clearSelectedFiles = function() {TSCORE.selectedFiles = [];$('#'+extensionID+'FileTable tbody tr').each(function(){@@ -64,41 +61,11 @@ define(function(require, exports, module) {};var getNextFile = function (filePath) {- var nextFilePath = undefined;- var data = UI.fileTable._('tr', {"filter":"applied"});- data.forEach(function(entry, index) {- if(entry[TSCORE.fileListFILEPATH] == filePath) {- var nextIndex = index+1;- if(nextIndex < data.length) {- nextFilePath = data[nextIndex][TSCORE.fileListFILEPATH];- } else {- nextFilePath = data[0][TSCORE.fileListFILEPATH];- }- }- console.log("Path: "+entry[TSCORE.fileListFILEPATH]);- });- TSCORE.PerspectiveManager.clearSelectedFiles();- console.log("Next file: "+nextFilePath);- return nextFilePath;+ return UI.getNextFile(filePath);};var getPrevFile = function (filePath) {- var prevFilePath = undefined;- var data = UI.fileTable._('tr', {"filter":"applied"});- data.forEach(function(entry, index) {- if(entry[TSCORE.fileListFILEPATH] == filePath) {- var prevIndex = index-1;- if(prevIndex >= 0) {- prevFilePath = data[prevIndex][TSCORE.fileListFILEPATH];- } else {- prevFilePath = data[data.length-1][TSCORE.fileListFILEPATH];- }- }- console.log("Path: "+entry[TSCORE.fileListFILEPATH]);- });- TSCORE.PerspectiveManager.clearSelectedFiles();- console.log("Prev file: "+prevFilePath);- return prevFilePath;+ return UI.getPrevFile(filePath);};// Vars@@ -113,9 +80,7 @@ define(function(require, exports, module) {// Methodsexports.init = init;exports.load = load;- exports.setFileFilter = setFileFilter;exports.clearSelectedFiles = clearSelectedFiles;exports.getNextFile = getNextFile;- exports.getPrevFile = getPrevFile;-+ exports.getPrevFile = getPrevFile;});\ No newline at end of filediff --git a/data/ext/perspectiveList/perspectiveUI.js b/data/ext/perspectiveList/perspectiveUI.jsindex 863ac44e3..1e07c823f 100644--- a/data/ext/perspectiveList/perspectiveUI.js+++ b/data/ext/perspectiveList/perspectiveUI.js@@ -5,7 +5,7 @@define(function(require, exports, module) {"use strict";-console.log("Loading UI for perspectiveDefault");+console.log("Loading UI for perspectiveList");var TSCORE = require("tscore");@@ -28,99 +28,20 @@ console.log("Loading UI for perspectiveDefault");extensionDirectory = TSCORE.Config.getExtensionPath()+"/"+this.extensionID;}-- // Helper function user by basic and search views- function buttonizeTitle(title, fileName, filePath, fileExt) {- if(title.length < 1) {- title = filePath;- }-- //TODO minimize platform specific calls- var tmbPath = undefined;- if(isCordova) {- tmbPath = filePath;- } else {- tmbPath = "file:///"+filePath;- }-- var thumbHTML = "";- if(supportedFileTypeThumnailing.indexOf(fileExt) >= 0) {- thumbHTML = $('<span>').append( $('<img>', {- title: fileName,- class: "thumbImg",- filepath: tmbPath,- style: "width: 0px; height: 0px; border: 0px"- })).html();- thumbHTML = "<br>" + thumbHTML;- }-- var checkboxHTML = $('<input>', {- type: "checkbox",- class: "fileSelection",- });-- /*var titleHTML = $('<span>', {- text: fileName,- class: "fileTitle"- });*/-- var buttonHTML = $('<button>', {- title: "Options for "+fileName,- filepath: filePath,- class: 'btn btn-link fileTitleButton',- }).append($('<span>', {- id: "fileExt"- })- .append($("<span>", { text: fileExt }))- .append(" <span class='caret white-caret'></span>")- );-- var fileHTML = $('<p>', {})- .append(checkboxHTML)- .append(buttonHTML)- // .append(titleHTML)- .append(thumbHTML);-- return fileHTML.html();- }- ExtUI.prototype.buildUI = function() {+ ExtUI.prototype.buildUI = function(toolbarTemplate) {console.log("Init UI module");var self = this;-- // Init File Context Menus- this.viewContainer.on("contextmenu click", ".fileTitleButton", function (e) {- TSCORE.hideAllDropDownMenus();- e.preventDefault();-- self.selectFile(this, $(this).attr("filepath"));- TSCORE.showContextMenu("#fileMenu", $(this));+ var context = {+ id: this.extensionID,+ };+ // Init Toolbar++ this.viewToolbar.html(toolbarTemplate(context));- return false;- });-- this.viewContainer.on("contextmenu click", ".tagButton", function (e) {- TSCORE.hideAllDropDownMenus();-- TSCORE.selectedTag = $(this).attr("tag");- self.selectFile(this, $(this).attr("filepath"));- TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));-- TSCORE.showContextMenu("#tagMenu", $(this));-- return false;- });-- this.viewToolbar.append($("<div >", {- class: "btn-group",- })- .append($("<button>", {- class: "btn btn-default",- title: "Toggle Select All Files",- id: this.extensionID+"ToogleSelectAll",- })+ $("#"+this.extensionID+"ToogleSelectAll").click(function() {if($(this).find("i").attr("class") == "fa fa-square-o") {TSCORE.selectedFiles = [];@@ -137,157 +58,75 @@ console.log("Loading UI for perspectiveDefault");$(this).find("i").removeClass("fa fa-check-square-o");$(this).find("i").addClass("fa fa-square-o");}- })- .append( "<i class='fa fa-square-o'>" )- )-- );+ });- this.viewToolbar.append($("<div>", {- class: "btn-group",- // id: this.extensionID+"Toolbar",- })-- .append($("<button>", {- class: "btn btn-default",- title: "Create new file",- id: this.extensionID+"CreateFileButton",- })+ $("#"+this.extensionID+"CreateFileButton").prop('disabled', true).click(function() {TSCORE.showFileCreateDialog();- })- .append( "<i class='fa fa-plus'>" )- )-- .append($("<button>", {- class: "btn btn-default",- title: "Show subfolders content. \nOn subfolder with many files, this step can take some time!",- id: this.extensionID+"IncludeSubDirsButton",- })+ });++ $("#"+this.extensionID+"IncludeSubDirsButton").prop('disabled', true).click(function() {$( this ).prop('disabled', true);- TSCORE.startTime = new Date().getTime();TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);- })- .append( $("<i>", { class: "fa fa-retweet", }) )- )-- .append($("<button>", {- class: "btn btn-default",- title: "Tag Selected Files",- id: this.extensionID+"TagButton",- })+ });++ $("#"+this.extensionID+"TagButton").prop('disabled', true).click(function() {TSCORE.showAddTagsDialog();- })- .append( $("<i>", { class: "fa fa-tag", }) )- )- ); // end toolbar+ });- this.viewToolbar.append($("<div >", {- class: "btn-group",- })- .append($("<button>", {- class: "btn btn-default ",- "data-toggle": "button",- title: "Toggle file thumbnails",- id: this.extensionID+"ShowTmbButton",- })+ $("#"+this.extensionID+"ShowTmbButton").click(function() {self.toggleThumbnails();- })- .append( $("<i>", { class: "fa fa-picture-o", }) )- )+ });- .append($("<button>", {- class: "btn btn-default",- title: "Increase Thumbnails Size",- id: this.extensionID+"IncreaseThumbsButton",- })+ $("#"+this.extensionID+"IncreaseThumbsButton").click(function() {self.switchThumbnailSize();})- .append( $("<i>", { class: "fa fa-search-plus", }) )- .prop('disabled', true)- )-- ); // end toolbar+ .prop('disabled', true);- this.viewToolbar.append($("<div >", {- class: "btn-group",- "data-toggle": "buttons-checkbox",- })- .append($("<button>", {- class: "btn btn-default ",- title: "Toggle File Details",- id: this.extensionID+"ShowFileDetailsButton",- })- .click(function() {- self.toggleFileDetails();- })- .append( $("<i>", { class: "fa fa-list-alt", }) )- )+ $("#"+this.extensionID+"ShowFileDetailsButton")+ .click(function() {+ self.toggleFileDetails();+ });- .append($("<button>", {- class: "btn btn-default active",- title: "Toggle Tags",- id: this.extensionID+"ShowTagsButton",- })- .click(function() {- self.toggleTags();- })- .append( $("<i>", { class: "fa fa-tags", }) )- )- ); // end button group+ $("#"+this.extensionID+"ShowTagsButton")+ .click(function() {+ self.toggleTags();+ });+ // Init Toolbar END- this.viewToolbar.append($("<div >", {- class: "input-group pull-right",- style: "position:absolute; width: 160px; top:40px; right:2px;"- })- // Filter- .append($("<input>", {- type: "text",- class: "form-control pull-right",- id: this.extensionID+"FilterBox",- placeholder: "Filename Filter",- style: "width: 120px;"- }).keyup(function() {- self.setFilter(this.value);- }))-- .append($("<span>", {- class: "input-group-btn",- })- .append($("<button>", {- class: "btn btn-default",- title: "Clear Filter",- id: this.extensionID+"ClearFilterButton",- })- .append( $("<i>", { class: "fa fa-times", }) )- .click(function(evt) {- evt.preventDefault();- self.setFilter("");- })- )- )- ); // End Filter+ // Init Container+ // Init File Context Menu+ this.viewContainer.on("contextmenu click", ".fileTitleButton", function (e) {+ TSCORE.hideAllDropDownMenus();+ e.preventDefault();+ self.selectFile(this, $(this).attr("filepath"));+ TSCORE.showContextMenu("#fileMenu", $(this));+ return false;+ });++ // Init Tag Context Menu+ this.viewContainer.on("contextmenu click", ".tagButton", function (e) {+ TSCORE.hideAllDropDownMenus();+ self.selectFile(this, $(this).attr("filepath"));+ TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));+ TSCORE.showContextMenu("#tagMenu", $(this));+ return false;+ });this.viewContainer.append($("<table>", {- cellpadding: "0",- cellspacing: "0",- border: "0",- style: "width: 100%",+ cellpadding: "0", cellspacing: "0", border: "0", style: "width: 100%",class: "table content disableTextSelection",id: this.extensionID+"FileTable",}));-- };-- ExtUI.prototype.initTable = function() {+this.fileTable = $('#'+this.extensionID+"FileTable").dataTable( {"bJQueryUI": false,"bPaginate": false,@@ -363,19 +202,17 @@ console.log("Loading UI for perspectiveDefault");} );// Disable alerts in datatable- this.fileTable.dataTableExt.sErrMode = 'throw';-- var self = this;--+ this.fileTable.dataTableExt.sErrMode = 'throw';};- ExtUI.prototype.reInitTableWithData = function() {- $('#'+this.extensionID+"FileTable_wrapper").hide();-- // Clearing the old data+ ExtUI.prototype.reInit = function() {+ // Clearing old datathis.fileTable.fnClearTable();- this.fileTable.fnAddData( TSCORE.fileList );++ // Load new filtered data+ this.searchResults = TSCORE.Search.searchData(TSCORE.fileList, TSCORE.Search.nextQuery);++ this.fileTable.fnAddData( this.searchResults );var self = this;@@ -384,7 +221,7 @@ console.log("Loading UI for perspectiveDefault");accept: ".tagButton",hoverClass: "activeRow",drop: function( event, ui ) {- var tagName = TSCORE.selectedTag; //ui.draggable.attr("tag");+ var tagName = TSCORE.selectedTag;var targetFilePath = self.fileTable.fnGetData( this )[TSCORE.fileListFILEPATH];@@ -431,10 +268,6 @@ console.log("Loading UI for perspectiveDefault");"revert": true,"start": function() { self.selectFile(this, $(this).attr("filepath")); }});- /*.dblclick( function() {- console.log("Opening file...");- TSCORE.FileOpener.openFile($(this).attr("filepath"));- });*/this.fileTable.$('.fileSelection').click( function() {@@ -448,21 +281,6 @@ console.log("Loading UI for perspectiveDefault");}self.handleElementActivation();} );-/*- this.fileTable.$('.thumbImg')- .dblclick( function() {- console.log("Opening file...");- TSCORE.FileOpener.openFile($(this).attr("filepath"));- } ); */-/*- this.fileTable.$('.fileTitle')- .editInPlace({- callback: function(unused, newTitle) {- TSCORE.TagUtils.changeTitle($(this).parent().find(".fileTitleButton").attr("filepath"),newTitle);- },- show_buttons: false,- callback_skip_dom_reset: true- }); */this.fileTable.$('.tagButton').draggable({@@ -476,16 +294,64 @@ console.log("Loading UI for perspectiveDefault");}});- $('#'+this.extensionID+"FileTable_wrapper").show();-- $( "#"+this.extensionID+"CreateFileButton" ).prop('disabled', false);- $( "#"+this.extensionID+"IncludeSubDirsButton" ).prop('disabled', false);-- this.refreshThumbnails();+ //$("#"+this.extensionID+"FileTable_wrapper").show();+ $("#"+this.extensionID+"CreateFileButton" ).prop('disabled', false);+ $("#"+this.extensionID+"IncludeSubDirsButton" ).prop('disabled', false);+ this.refreshThumbnails();+ TSCORE.hideLoadingAnimation();};++ // Helper function user by basic and search views+ function buttonizeTitle(title, fileName, filePath, fileExt) {+ if(title.length < 1) {+ title = filePath;+ }++ //TODO minimize platform specific calls+ var tmbPath = undefined;+ if(isCordova) {+ tmbPath = filePath;+ } else {+ tmbPath = "file:///"+filePath;+ }++ var thumbHTML = "";+ if(supportedFileTypeThumnailing.indexOf(fileExt) >= 0) {+ thumbHTML = $('<span>').append( $('<img>', {+ title: fileName,+ class: "thumbImg",+ filepath: tmbPath,+ style: "width: 0px; height: 0px; border: 0px"+ })).html();+ thumbHTML = "<br>" + thumbHTML;+ }++ var checkboxHTML = $('<input>', {+ type: "checkbox",+ class: "fileSelection",+ });++ var buttonHTML = $('<button>', {+ title: "Options for "+fileName,+ filepath: filePath,+ class: 'btn btn-link fileTitleButton',+ }).append($('<span>', {+ id: "fileExt"+ })+ .append($("<span>", { text: fileExt }))+ .append(" <span class='caret white-caret'></span>")+ );++ var fileHTML = $('<p>', {})+ .append(checkboxHTML)+ .append(buttonHTML)+ .append(thumbHTML);++ return fileHTML.html();+ }- ExtUI.prototype.setFilter = function(filterValue) {+ /* ExtUI.prototype.setFilter = function(filterValue) {TSCORE.PerspectiveManager.clearSelectedFiles();$( "#"+this.extensionID+"FilterBox").val(filterValue).focus();@@ -499,17 +365,15 @@ console.log("Loading UI for perspectiveDefault");this.handleElementActivation();console.log("Filter to value: "+filterValue);- };+ }; */ExtUI.prototype.selectFile = function(uiElement, filePath) {TSCORE.PerspectiveManager.clearSelectedFiles();$(uiElement).parent().parent().toggleClass("ui-selected");-$(uiElement).parent().parent().find(".fileSelection").prop("checked",true);TSCORE.selectedFiles.push(filePath);-this.handleElementActivation();};@@ -544,7 +408,6 @@ console.log("Loading UI for perspectiveDefault");};ExtUI.prototype.disableThumbnails = function() {- //this.currentTmbSize = 0;$( "#"+this.extensionID+"IncreaseThumbsButton" ).prop('disabled', true);$.each(this.fileTable.$('.thumbImg'), function() {$(this).attr('style', "width: 0px; height: 0px; border: 0px");@@ -588,5 +451,43 @@ console.log("Loading UI for perspectiveDefault");}};+ ExtUI.prototype.getNextFile = function(filePath) {+ var nextFilePath = undefined;+ var self = this;+ this.searchResults.forEach(function(entry, index) {+ if(entry[TSCORE.fileListFILEPATH] == filePath) {+ var nextIndex = index+1;+ if(nextIndex < self.searchResults.length) {+ nextFilePath = self.searchResults[nextIndex][TSCORE.fileListFILEPATH];+ } else {+ nextFilePath = self.searchResults[0][TSCORE.fileListFILEPATH];+ }+ }+ console.log("Path: "+entry[TSCORE.fileListFILEPATH]);+ });+ TSCORE.PerspectiveManager.clearSelectedFiles();+ console.log("Next file: "+nextFilePath);+ return nextFilePath;+ };++ ExtUI.prototype.getPrevFile = function(filePath) {+ var prevFilePath = undefined;+ var self = this;+ this.searchResults.forEach(function(entry, index) {+ if(entry[TSCORE.fileListFILEPATH] == filePath) {+ var prevIndex = index-1;+ if(prevIndex >= 0) {+ prevFilePath = self.searchResults[prevIndex][TSCORE.fileListFILEPATH];+ } else {+ prevFilePath = self.searchResults[self.searchResults.length-1][TSCORE.fileListFILEPATH];+ }+ }+ console.log("Path: "+entry[TSCORE.fileListFILEPATH]);+ });+ TSCORE.PerspectiveManager.clearSelectedFiles();+ console.log("Prev file: "+prevFilePath);+ return prevFilePath;+ };+exports.ExtUI = ExtUI;});\ No newline at end of filediff --git a/data/ext/perspectiveList/toolbar.html b/data/ext/perspectiveList/toolbar.htmlnew file mode 100644index 000000000..b76a00339--- /dev/null+++ b/data/ext/perspectiveList/toolbar.html@@ -0,0 +1,33 @@+<div class="btn-group">+ <button class="btn btn-default" title="Toggle Select All Files" id="{{id}}ToogleSelectAll">+ <i class="fa fa-square-o"></i>+ </button>+</div>+<div class="btn-group">+ <button class="btn btn-default" title="Create new file" id="{{id}}CreateFileButton">+ <i class="fa fa-plus"></i>+ </button>+ <button class="btn btn-default" title="Show subfolders content.+ On subfolder with many files, this step can take some time!" id="{{id}}IncludeSubDirsButton">+ <i class="fa fa-retweet"></i>+ </button>+ <button class="btn btn-default" title="Tag Selected Files" id="{{id}}TagButton">+ <i class="fa fa-tag"></i>+ </button>+</div>+<div class="btn-group">+ <button class="btn btn-default active" data-toggle="button" title="Toggle file thumbnails" id="{{id}}ShowTmbButton">+ <i class="fa fa-picture-o"></i>+ </button>+ <button class="btn btn-default" title="Increase Thumbnails Size" id="{{id}}IncreaseThumbsButton">+ <i class="fa fa-search-plus"></i>+ </button>+</div>+<div class="btn-group" data-toggle="buttons-checkbox">+ <button class="btn btn-default " title="Toggle File Details" id="{{id}}ShowFileDetailsButton">+ <i class="fa fa-list-alt"></i>+ </button>+ <button class="btn btn-default active" title="Toggle Tags" id="{{id}}ShowTagsButton">+ <i class="fa fa-tags"></i>+ </button>+</div>\ No newline at end of filediff --git a/data/index.html b/data/index.htmlindex f5dd98db9..736ea5ab4 100644--- a/data/index.html+++ b/data/index.html@@ -102,7 +102,7 @@ can be found in the LICENSE file.<span class="icon-bar"></span></button><div class="form-inline pull-right">- <div class="input-group" style="width: 300px; padding-right: 4px; margin-top: 2px;">+ <div class="input-group" style="width: 300px; margin-right: 14px; margin-top: 2px;"><input type="text" class="form-control" id="searchBox" placeholder="Search" title="Search hints:All terms should be true in order the file to appear in the search resultsterm: the term should be part of the file title or file extension@@ -114,9 +114,9 @@ can be found in the LICENSE file.<button class="btn btn-default" title="Search" id="searchButton" style="border-left-width: 0px;"><i class="fa fa-search"></i></button>- <!--button class="btn btn-default" title="Clear Filter" id="clearFilterButton">+ <button class="btn btn-default" title="Clear Filter" id="clearFilterButton"><i class="fa fa-times"></i>- </button-->+ </button></span><!--div class="form-group"><input type="text" style="padding: 4px; height: 30px; margin-top: 2px;" class="form-control" id="searchBox" style="" placeholder="Search">diff --git a/data/js/core.api.js b/data/js/core.api.jsindex 61529bba3..69d5caa09 100644--- a/data/js/core.api.js+++ b/data/js/core.api.js@@ -15,6 +15,7 @@ define(function(require, exports, module) {var tsTagsUI = require("tstagsui");var tsDirectoriesUI = require("tsdirectoriesui");var tsCoreUI = require("tscoreui");+ var tsSearch = require("tssearch");var layoutContainer = undefined;var westLayout = undefined;@@ -65,7 +66,7 @@ define(function(require, exports, module) {tsSettings.upgradeSettings();// Init views- tsPersManager.initViews();+ tsPersManager.initPerspectives();$("#appVersion").text(tsSettings.DefaultSettings["appVersion"]+"beta");$("#appVersion").attr("title","["+tsSettings.DefaultSettings["appVersion"]+"."+tsSettings.DefaultSettings["appBuild"]+"]");@@ -432,6 +433,7 @@ define(function(require, exports, module) {exports.PerspectiveManager = tsPersManager;exports.TagUtils = tsTagUtils;exports.FileOpener = tsFileOpener;+ exports.Search = tsSearch;// Public API definitionexports.initApp = initApp;diff --git a/data/js/core.ui.js b/data/js/core.ui.jsindex d32d3de2b..67774f686 100644--- a/data/js/core.ui.js+++ b/data/js/core.ui.js@@ -309,7 +309,58 @@ define(function(require, exports, module) {// Hide the taggroups by default$('#tagGroupsContent').hide();-+ // Search UI++ $("#searchBox")+ /*.focus(function(e) {+ $(this).removeClass("input-medium");+ $(this).addClass("input-large");+ })*/+ .keyup(function(e) {+ // On enter fire the search+ if (e.keyCode == 13) {+ $( "#clearFilterButton").addClass("filterOn");+ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ } else {+ TSCORE.Search.nextQuery = this.value;+ }+ if (this.value.length == 0) {+ $( "#clearFilterButton").removeClass("filterOn");+ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ }+ })+ .blur(function() {+ //$(this).addClass("input-medium");+ //$(this).removeClass("input-large");+ if (this.value.length == 0) {+ $( "#clearFilterButton").removeClass("filterOn");+ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ }+ });++ $("#searchButton").click(function(evt) {+ evt.preventDefault();+ $( "#clearFilterButton").addClass("filterOn");+ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ });++ $("#clearFilterButton")+ .click(function(evt) {+ evt.preventDefault();+ $("#clearFilterButton").removeClass("filterOn");+ $("#searchBox").val("");+ //$("#"+self.extensionID+"FilterBox").val("").addClass("input-medium");+ //$("#"+self.extensionID+"FilterBox").val("").removeClass("input-large");+ //self.setFilter("");+ $("#silterBox").val("");+ $("#clearFilterButton").removeClass("filterOn");+ TSCORE.Search.nextQuery = "";++ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ });++ // Search UI END+// Hide drop downs by click and drag$(document).click(function () {TSCORE.hideAllDropDownMenus();diff --git a/data/js/directories.ui.js b/data/js/directories.ui.jsindex 55b93b89c..f799f2b2e 100644--- a/data/js/directories.ui.js+++ b/data/js/directories.ui.js@@ -4,7 +4,7 @@define(function(require, exports, module) {"use strict";- console.log("Loading DirectoriesUI...");+ console.log("Loading directories.ui.js ...");var TSCORE = require("tscore");diff --git a/data/js/fileopener.js b/data/js/fileopener.jsindex 43a5ad84a..c90a5c935 100644--- a/data/js/fileopener.js+++ b/data/js/fileopener.js@@ -4,7 +4,7 @@define(function(require, exports, module) {"use strict";- console.log("Loading fileOpener...");+ console.log("Loading fileopener...");var TSCORE = require("tscore");diff --git a/data/js/perspective.manager.js b/data/js/perspective.manager.jsindex c9872d3b5..efe92b173 100644--- a/data/js/perspective.manager.js+++ b/data/js/perspective.manager.js@@ -4,13 +4,13 @@define(function(require, exports, module) {"use strict";-console.log("Loading perspective.manager.js");+console.log("Loading perspective.manager.js ...");var perspectives = undefined;var TSCORE = require("tscore");-var initViews = function () {+var initPerspectives = function () {perspectives = [];$("#viewSwitcher").empty();@@ -56,14 +56,14 @@ var initViews = function () {console.log("Error while executing 'init' on "+perspectives[i].ID+" - "+e);} finally {if( perspectives.length == extensions.length) {- initViewSwitcher();+ initPerspectiveSwitcher();}}});}};-var initViewSwitcher = function() {+var initPerspectiveSwitcher = function() {var extensions = TSCORE.Config.getPerspectives();$("#viewSwitcher").empty();$("#viewSwitcher").append("<li class='dropdown-header'><span id=''>Perspective Switch</span><button type='button' class='close'>×</button></li>");@@ -99,6 +99,18 @@ var initViewSwitcher = function() {}};+var redrawCurrentPerspective = function () {+ for (var i=0; i < perspectives.length; i++) {+ if(perspectives[i].ID == TSCORE.currentView) {+ try {+ return perspectives[i].load();+ } catch(e) {+ console.log("Error while executing 'redrawCurrentPerspective' on "+perspectives[i].ID+" "+e);+ }+ }+ }+};+var getNextFile = function (filePath) {for (var i=0; i < perspectives.length; i++) {if(perspectives[i].ID == TSCORE.currentView) {@@ -169,7 +181,6 @@ var updateFileBrowserData = function(dirList) {var refreshFileListContainer = function() {// TODO consider search view- TSCORE.startTime = new Date().getTime();TSCORE.IO.listDirectory(TSCORE.currentPath);};@@ -179,7 +190,6 @@ var changeView = function (viewType) {//Setting the current viewTSCORE.currentView = viewType;-/* if(TSCORE.currentPath == undefined) {TSCORE.showAlertDialog("Please select first location from the dropdown on the left!");@@ -223,7 +233,7 @@ var clearSelectedFiles = function () {}};-var setFileFilter = function (filter) {+/*var setFileFilter = function (filter) {for (var i=0; i < perspectives.length; i++) {try {if(perspectives[i].ID == TSCORE.currentView){@@ -233,15 +243,15 @@ var setFileFilter = function (filter) {console.log("Error while executing 'setFileFilter' on "+perspectives[i].ID);}}-};+};*/-exports.initViews = initViews;+exports.initPerspectives = initPerspectives;+exports.redrawCurrentPerspective = redrawCurrentPerspective;exports.getNextFile = getNextFile;exports.getPrevFile = getPrevFile;exports.updateTreeData = updateTreeData;exports.updateFileBrowserData = updateFileBrowserData;exports.refreshFileListContainer = refreshFileListContainer;exports.clearSelectedFiles = clearSelectedFiles;-exports.setFileFilter = setFileFilter;});\ No newline at end of filediff --git a/data/js/postioapi.js b/data/js/postioapi.jsindex 9705b8258..3f8ebfa2f 100644--- a/data/js/postioapi.js+++ b/data/js/postioapi.js@@ -5,7 +5,7 @@ define(function(require, exports, module) {"use strict";// Activating browser specific exports modul- console.log("Loading post ioapi ...");+ console.log("Loading postioapi.js ...");var TSCORE = require("tscore");diff --git a/data/js/search.js b/data/js/search.jsnew file mode 100644index 000000000..eb1bc75f5--- /dev/null+++ b/data/js/search.js@@ -0,0 +1,104 @@+/* Copyright (c) 2012-2013 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. */+define(function(require, exports, module) {+"use strict";++ console.log("Loading search.js ...");++ var TSCORE = require("tscore");+ var currentQuery = "";+ var nextQuery = "";++ var searchData = function(data, query) {+ query = query.toLowerCase().replace(/^\s+|\s+$/g, "");++ // By empty filter just return the data+ if(query.length <= 0) {+ return data;+ }++ var queryTerms = query.split(" ");++ // Analysing filter+ var includedTerms = [];+ var excludedTerms = [];+ var includedTags = [];+ var excludedTags = [];++ queryTerms.forEach(function (value, index) {+ if(value.length > 1) {+ if(value.indexOf("!") == 0) {+ excludedTerms.push([value.substring(1,value.length),false]);+ } else if(value.indexOf("+") == 0) {+ includedTags.push([value.substring(1,value.length),true]);+ } else if(value.indexOf("-") == 0) {+ excludedTags.push([value.substring(1,value.length),true]);+ } else {+ includedTerms.push([value,false]);+ }+ }+ });++ data = _.filter(data, function(value) {+ // Searching in the whole filename+ var searchIn = value[TSCORE.fileListFILENAME].toLowerCase();+ var tags = value[TSCORE.fileListTAGS];+ var result = true;+ if(tags.length < 1 && includedTags.length > 0) {+ return false;+ }+ for (var i=0; i < includedTerms.length; i++) {+ if(searchIn.indexOf(includedTerms[i][0]) >= 0) {+ includedTerms[i][1] = true;+ } else {+ return false;+ }+ };+ for (var i=0; i < excludedTerms.length; i++) {+ if(searchIn.indexOf(excludedTerms[i][0]) < 0) {+ excludedTerms[i][1] = true;+ } else {+ return false;+ }+ };++ for (var i=0; i < includedTags.length; i++) {+ includedTags[i][1] = false;+ for (var j=0; j < tags.length; j++) {+ if(tags[j].toLowerCase() == includedTags[i][0]) {+ includedTags[i][1] = true;+ }+ }+ };+ for (var i=0; i < includedTags.length; i++) {+ result = result & includedTags[i][1];+ }++ for (var i=0; i < excludedTags.length; i++) {+ excludedTags[i][1] = true;+ for (var j=0; j < tags.length; j++) {+ if(tags[j].toLowerCase() == excludedTags[i][0]) {+ excludedTags[i][1] = false;+ }+ }+ };+ for (var i=0; i < excludedTags.length; i++) {+ result = result & excludedTags[i][1];+ }++ return result;+ });++ currentQuery = nextQuery;+ return data;+ };++ // Public variables definition+ exports.currentQuery = currentQuery;+ exports.nextQuery = nextQuery;++ // Public API definition+ exports.searchData = searchData;++});\ No newline at end of filediff --git a/data/loader.js b/data/loader.jsindex 832a0371a..8152ff3b4 100644--- a/data/loader.js+++ b/data/loader.js@@ -75,7 +75,6 @@ requirejs.config({bootstrap: 'libs/bootstrap/js/bootstrap',bootstrap3xeditable: 'libs/bootstrap3xeditable/js/bootstrap-editable',jquerysimplecolorpicker:'libs/jquery-simplecolorpicker/jquery.simplecolorpicker',- datatables: 'libs/datatables/js/jquery.dataTables.min',jquerylayout: 'libs/jquerylayout/jquery.layout-latest',underscore: 'libs/underscore/underscore',d3: 'libs/d3/d3.v3',@@ -92,6 +91,7 @@ requirejs.config({tsoptions: 'js/options.ui',tspersmanager: 'js/perspective.manager',tstagutils: 'js/tagutils',+ tssearch: 'js/search',tsfileopener: 'js/fileopener',tstagsui: 'js/tags.ui',tsdirectoriesui: 'js/directories.ui',@@ -117,7 +117,6 @@ requirejs.config({'jquerylayout': { deps: ['jquery','jqueryuidraggable' ] },'jquerydropdown': { deps: ['jquery','bootstrap'] },'bootstrap3xeditable': { deps: ['jquery','jqueryui','bootstrap'] },- 'datatables': { deps: ['jquery'] },'jquerynanoscroller': { deps: ['jquery'] },'select2': { deps: ['jquery'] },'hammerjs': { deps: ['jquery'] },