TagSpaces is an offline, open source, document manager with tagging support
updating the OCRO perspective by adding thumbnail and search support
Ilian9b14101fbb3c
diff --git a/data/ext/perspectiveOCRO/controller.js b/data/ext/perspectiveOCRO/controller.jsindex 302ff01b5..c12c98151 100644--- a/data/ext/perspectiveOCRO/controller.js+++ b/data/ext/perspectiveOCRO/controller.js@@ -1,48 +1,218 @@-// Sample ownCloud search answer-// [{"name":"paris.jpg","text":"\/photos, 223.4 kB, Score: 1.00","link":"\/owncloud6\/index.php\/apps\/files\/download\/photos\/paris.jpg","type":"Images","container":null}]+/* Copyright (c) 2012-2014 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 */-function perspectiveOCROCtrl($scope) {- $scope.data;- $scope.TSCORE;+define(function(require, exports, module) {+ "use strict";- $scope.update = function() {- $scope.data = $scope.TSCORE.Search.searchData($scope.TSCORE.fileList, $scope.TSCORE.Search.nextQuery);- $scope.$apply();+ console.log("Loading perspectiveOCRO controller");++ var TSCORE = require("tscore");+ var TSPOSTIO = require("tspostioapi");++ var supportedFileTypeThumnailing = ['jpg','jpeg','png','gif','bmp','svg'];+ var thumbFolder = ".ts";+ var thumbExt = ".jpg";+ var PREVIEW_TAGS_CNT = 5;+ var extensionID;+ var templates;++ var searchResults;++ var $viewContainer;++ var init = function (id,tmpls) {+ templates = tmpls;+ extensionID = id;+ $viewContainer = $("#"+extensionID+"Container");};- $scope.setTSCORE = function(tscore) {- $scope.TSCORE = tscore;+ var load = function () {+ console.log("Loading data in "+extensionID);++ // Load new filtered data+ searchResults = TSCORE.Search.searchData(TSCORE.fileList, TSCORE.Search.nextQuery);++ var filesData = [];++ _.each(searchResults, function (value) {+ filesData.push(+ createFileContext(+ value[TSCORE.fileListTITLE],+ value[TSCORE.fileListFILEPATH],+ value[TSCORE.fileListFILEEXT],+ value[TSCORE.fileListTAGS]+ )+ )+ });++ $viewContainer.append(templates.fileTiles({files: filesData}));++ // Adding event listeners+ $viewContainer.find("img").each(function() {+ var filePath = $(this).attr("data-filepath");+ var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);+ if(supportedFileTypeThumnailing.indexOf(fileExt) >= 0) {+ //$(this).error(function() { $(this).attr("src",filePath) });+ // Start a js worker for the thumbnail generation+ $(this).attr("onerror","this.src='"+filePath+"'");+ } else {+ //$(this).error(function() { $(this).attr("src","assets/spacer.png") });+ $(this).attr("onerror","this.src='assets/spacer.png'");+ }+ });++ $viewContainer.find(".fileTile").each(function() {+ var filePath = $(this).attr("data-filepath");+ $(this).hammer().on("doubletap", function () {+ TSCORE.FileOpener.openFile(filePath);+ //selectFile(filePath);+ })+ .click(function () {+ //selectFile(filePath);+ })+ });++ if(searchResults.length !== undefined) {+ if(TSCORE.Search.nextQuery.length > 0) {+ $("#statusBar").text(searchResults.length+" files found for '"+TSCORE.Search.nextQuery+"'");+ } else {+ $("#statusBar").text(searchResults.length+" files found");+ }+ }};- $scope.selectFile = function(file) {- console.log("Selecting file..."+file);- $scope.TSCORE.PerspectiveManager.clearSelectedFiles();+ var createFileContext = function(title, filePath, fileExt, fileTags) {+ var fileName = TSCORE.TagUtils.extractFileNameWithoutExt(filePath);+ var fileContainingPath = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);+ //var tmbPath = fileContainingPath+TSCORE.dirSeparator+thumbFolder+TSCORE.dirSeparator+fileName+thumbExt;- //var titleBut = $($event.target).parent().find(".fileTitleButton");+ var webdavPath = "owncloud6/remote.php/webdav";- //$(titleBut).parent().parent().toggleClass("ui-selected");- //$(titleBut).parent().parent().find(".fileSelection").find("i")- // .toggleClass("fa-check-square")- // .toggleClass("fa-square-o");+ var fileID = filePath.substring(filePath.indexOf(webdavPath)+webdavPath.length,filePath.length);- $scope.TSCORE.selectedFiles.push(file);+ //var tmbPath = location.protocol+"//"+location.host+"/owncloud6/index.php/core/preview.png?file="+fileID;++ // thumbnail from the gallery plugin, user name have to be specified+ var tmbPath = location.protocol+"//"+location.host+"/owncloud6/index.php/apps/gallery/ajax/thumbnail.php?file=na"+fileID+"&square=1";++ if(isCordova || isWeb) {++ } else {+ tmbPath = "file:///"+tmbPath;+ }++ var context = {+ filepath: filePath,+ tmbpath: tmbPath,+ fileext: fileExt,+ title: title,+ tags : []+ };++ if(fileTags.length > 0) {+ var tagString = ""+fileTags ;+ var tags = tagString.split(",");++ var tagCounter = 0;+ if (tags.length > PREVIEW_TAGS_CNT) {+ tagCounter = PREVIEW_TAGS_CNT+1;+ tags[PREVIEW_TAGS_CNT] = "...";+ } else {+ tagCounter = tags.length;+ }+ for (var i=0; i < tagCounter; i++) {+ context.tags.push({+ tag: tags[i],+ filepath: filePath,+ style: TSCORE.generateTagStyle(TSCORE.Config.findTag(tags[i]))+ });+ }+ }++ return context;+ };++ var getNextFile = function (filePath) {+ var nextFilePath;+ searchResults.forEach(function(entry, index) {+ if(entry[TSCORE.fileListFILEPATH] === filePath) {+ var nextIndex = index+1;+ if(nextIndex < searchResults.length) {+ nextFilePath = searchResults[nextIndex][TSCORE.fileListFILEPATH];+ } else {+ nextFilePath = searchResults[0][TSCORE.fileListFILEPATH];+ }+ }+ console.log("Path: "+entry[TSCORE.fileListFILEPATH]);+ });+ TSCORE.PerspectiveManager.clearSelectedFiles();+ console.log("Next file: "+nextFilePath);+ return nextFilePath;};- $scope.openFile = function(file) {- console.log("Open file..."+file);- $scope.TSCORE.FileOpener.openFile(file);+ var getPrevFile = function (filePath) {+ var prevFilePath;+ searchResults.forEach(function(entry, index) {+ if(entry[TSCORE.fileListFILEPATH] === filePath) {+ var prevIndex = index-1;+ if(prevIndex >= 0) {+ prevFilePath = searchResults[prevIndex][TSCORE.fileListFILEPATH];+ } else {+ prevFilePath = searchResults[searchResults.length-1][TSCORE.fileListFILEPATH];+ }+ }+ console.log("Path: "+entry[TSCORE.fileListFILEPATH]);+ });+ TSCORE.PerspectiveManager.clearSelectedFiles();+ console.log("Prev file: "+prevFilePath);+ return prevFilePath;};- $scope.openContextMenu = function($event, file, tag) {- console.log("Open context menu..."+file);- $scope.TSCORE.hideAllDropDownMenus();- //self.selectFile(this, $(this).attr("filepath"));- $scope.TSCORE.openTagMenu($event.target, tag, file);- $scope.TSCORE.showContextMenu("#tagMenu", $event.target);+ var searchOC = function(query) {+ console.log("Searching oc index on: "+location.protocol+"//"+location.host);+ var tags,+ ext,+ title,+ fileSize,+ fileLMDT,+ path,+ filename;++ $.ajax({+ url: location.protocol+"//"+location.host+'/owncloud6/index.php/search/ajax/search.php?query='+query,+ type: 'GET'+ })+ .done(function(data) {+ var searchResults = [];+ data.forEach(function(entry, index) {+ //if(entry.indexOf("/"+thumbFolder)>0) {+ searchResults.push({+ "name": entry.name,+ "isFile": true,+ "size": undefined,+ "lmdt": undefined,+ "path": entry.link+ });+ });+ console.log("Search results "+JSON.stringify(searchResults));+ TSPOSTIO.listDirectory(searchResults);+ })+ .fail(function(data) {+ console.log("AJAX failed "+data);+ })+ ;};-}-function myToolbarCtrl($scope) {- $scope.TSCORE;-}\ No newline at end of file+ exports.init = init;+ exports.load = load;+ exports.searchOC = searchOC;+// exports.clearSelectedFiles = clearSelectedFiles;+ exports.getNextFile = getNextFile;+ exports.getPrevFile = getPrevFile;+// exports.removeFileUI = removeFileUI;+// exports.updateFileUI = updateFileUI;++});\ No newline at end of filediff --git a/data/ext/perspectiveOCRO/extension.css b/data/ext/perspectiveOCRO/extension.cssnew file mode 100644index 000000000..9b231339c--- /dev/null+++ b/data/ext/perspectiveOCRO/extension.css@@ -0,0 +1,17 @@+#perspectiveOCROContainer .fileTile {+ margin: 3px;+ padding: 1px 1px 1px 3px;+ float: left;+ border: 1px solid #D4D4D4;+ text-align: left;+ width: 170px;+ height: 170px;+ overflow: hidden;+ position:relative;+ background-color: white;+}++#perspectiveOCROContainer .thumbImgTile {+ max-width: 160px;+ max-height: 160px;+}\ No newline at end of filediff --git a/data/ext/perspectiveOCRO/extension.js b/data/ext/perspectiveOCRO/extension.jsindex 28ff09355..ab4d1e52d 100644--- a/data/ext/perspectiveOCRO/extension.js+++ b/data/ext/perspectiveOCRO/extension.js@@ -1,4 +1,4 @@-/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.+/* Copyright (c) 2012-2014 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 */@@ -16,7 +16,7 @@ define(function(require, exports, module) {console.log("Loading "+extensionID);- var TSCORE = require("tscore");+ var TSCORE = require("tscore");var extensionDirectory = TSCORE.Config.getExtensionPath()+"/"+extensionID;@@ -24,7 +24,7 @@ define(function(require, exports, module) {$viewToolbar,$viewFooter;- var tableScope;+ var controller;function init() {console.log("Initializing perspective "+extensionID);@@ -37,64 +37,53 @@ define(function(require, exports, module) {$viewToolbar.empty();$viewFooter.empty();- $viewToolbar.html('<div id="myToolbar"><div class="btn-group">'+ // ng-app ng-controller="myToolbarCtrl"- '<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:toggleSelectAll" title="" id="{{id}}ToogleSelectAll"><i class="fa fa-square-o fa-lg fa-fw"></i></button>'+- '<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:downloadTooltip" id="{{id}}DownloadButton"><i class="fa fa-download fa-lg"></i></button>'+- '<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:reloadDirectoryTooltip" id="{{id}}ReloadFolderButton"><i class="fa fa-refresh fa-lg"></i></button>'+- '<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:showSubfolderContentTooltip" id="{{id}}IncludeSubDirsButton"><i class="fa fa-retweet fa-lg"></i></button>'+- //'<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:toggleThumbnailsTooltip" data-toggle="button" id="{{id}}ShowTmbButton"><i class="fa fa-picture-o fa-lg"></i></button>'+- '<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:increasThumbnailsTooltip" id="{{id}}IncreaseThumbsButton"><i class="fa fa-search-plus fa-lg"></i></button>'+- '</div>');+ require([+ extensionDirectory+'/templates.js',+ extensionDirectory+'/controller.js',+ 'css!'+extensionDirectory+'/extension.css'+ ], function(tmpls, ctrl) {+ controller = ctrl;++ // Adding UI blocks+ $viewToolbar.html(tmpls.mainToolBar({"id":extensionID}));++ $("body").append(tmpls.dialogOCSetting());++ ctrl.init(extensionID,tmpls);++ initUI();++ });+ }+ var initUI = function() {$("#"+extensionID+"ReloadFolderButton").click(function() {TSCORE.navigateToDirectory(TSCORE.currentPath);});- $viewContainer.html('<div ng-app ng-controller="perspectiveOCROCtrl" id="myTable" >'+- '<li title="{{entry[5]}}" filepath="{{entry[5]}}" ng-repeat="entry in data" ng-click="selectFile(entry[5])" ng-dblclick="openFile(entry[5])" class="fileTile">'+- '<span><img class="thumbImgTile" style="max-width: 200px; max-height: 200px;" src="{{entry[5]}}"></span>'+- '<p class="titleInFileTile">{{entry[1]}}</p>'+- '<span class="tagsInFileTile">'+- '<button ng-repeat="tag in entry[2] track by $index" class="btn btn-sm tagButton ui-draggable" tag="{{tag}}" filepath="{{entry[5]}}" style="">{{tag}} <!--span class="caret"></span--></button>'+- '</span>'+- '<span class="fileExtTile">{{entry[0]}}</span>'+- '<button class="btn btn-link fileTileSelector" filepath="{{entry[5]}}"><i class="fa fa-square-o"></i></button></p>'+- '</li>' +- '</div>');-- $("body").append('<div class="modal" id="dialogOCSettings" tabindex="-1" role="dialog" aria-hidden="true">'+- '<div class="modal-dialog">'+- '<div class="modal-content">'+- '<div class="modal-header">'+- '<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times fa-lg"></i></button>'+- '<h4 class="modal-title" id="myModalLabel1" data-i18n="">Settings</h4>'+- '</div>'+- '<div class="modal-body">'+- '<iframe id="aboutIframe" nwdisable style="width: 100%; height: 350px; border: 0;" src="../../../index.php/settings/personal"></iframe>'+- '</div>'+- '<div class="modal-footer">'+- '<button class="btn btn-primary" data-dismiss="modal" title="Close Dialog" aria-hidden="true"><i class="fa fa-check fa-lg"></i></button>'+- '</div>'+- '</div><!-- /.modal-content -->'+- '</div><!-- /.modal-dialog -->'+- '</div><!-- /.modal -->');-- require([- extensionDirectory+'/angular.min.js',- //extensionDirectory+'/angular-touch.min.js',- extensionDirectory+'/controller.js'- ], function() {- angular.module('app', ['ngTouch']);- tableScope = angular.element($("#myTable")).scope();- tableScope.setTSCORE(TSCORE);- }- );- }+ $("#"+extensionID+"searchBoxOC")+ .keyup(function(e) {+ // On enter fire the search+ if (e.keyCode === 13) {+ $( "#clearFilterButton").addClass("filterOn");+ searchOC(TSCORE.Search.nextQuery);+ $("#searchOptions").hide();+ } else {+ TSCORE.Search.nextQuery = this.value;+ }+ if (this.value.length === 0) {+ $( "#clearFilterButton").removeClass("filterOn");+ TSCORE.PerspectiveManager.redrawCurrentPerspective();+ }+ })+ };- var load = function () {- console.log("Loading perspective "+extensionID);+ var searchOC = function(query) {+ controller.searchOC(query);+ };+ var makeUIReadOnly = function () {if(isWeb) {$("#mainTopMenu").html(' '+'<a class="btn btn-link" href="#" onclick="$(\'#dialogOCSettings\').modal({backdrop: \'static\',show: true});"><i class="fa fa-gears fa-lg"></i> <span data-i18n="ns.perspectiveList:ocSettings">User Account</span></a>'+@@ -139,10 +128,21 @@ define(function(require, exports, module) {//TODO hide unneeded area settings- if(tableScope === undefined) {- window.setTimeout( function() { tableScope.update(); }, 1000);+ };++ var load = function () {+ console.log("Loading data in "+extensionID);++ // Clear old data+ $viewContainer.children().remove();+ $viewFooter.children().remove();++ makeUIReadOnly();++ if(controller === undefined) {+ window.setTimeout(function() { controller.load(); }, 1000);} else {- tableScope.update();+ controller.load();}};@@ -163,41 +163,11 @@ define(function(require, exports, module) {};var getNextFile = function (filePath) {- var nextFilePath;- 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;+ return controller.getNextFile(filePath)};var getPrevFile = function (filePath) {- var prevFilePath;- 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;+ return controller.getPrevFile(filePath)};// Varsdiff --git a/data/ext/perspectiveOCRO/templates.js b/data/ext/perspectiveOCRO/templates.jsnew file mode 100644index 000000000..635732998--- /dev/null+++ b/data/ext/perspectiveOCRO/templates.js@@ -0,0 +1,65 @@+/* Copyright (c) 2012-2014 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 */++define(function(require, exports, module) {+ "use strict";++ console.log("Loading perspectiveOCRO templates");++ exports.mainToolBar = Handlebars.compile(+ '<div id="{{id}}MainToolbar" class="btn-toolbar">' ++ '<div class="btn-group">'++ '<button class="btn btn-link" data-i18n="[title]ns.perspectiveOCRO:toggleSelectAll" title="" id="{{id}}ToogleSelectAll"><i class="fa fa-square-o fa-lg fa-fw"></i></button>'++ '<button class="btn btn-link" data-i18n="[title]ns.perspectiveOCRO:downloadTooltip" id="{{id}}DownloadButton"><i class="fa fa-download fa-lg"></i></button>'++ '<button class="btn btn-link" data-i18n="[title]ns.perspectiveOCRO:reloadDirectoryTooltip" id="{{id}}ReloadFolderButton"><i class="fa fa-refresh fa-lg"></i></button>'++ '<button class="btn btn-link" data-i18n="[title]ns.perspectiveOCRO:showSubfolderContentTooltip" id="{{id}}IncludeSubDirsButton"><i class="fa fa-retweet fa-lg"></i></button>'++ //'<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:toggleThumbnailsTooltip" data-toggle="button" id="{{id}}ShowTmbButton"><i class="fa fa-picture-o fa-lg"></i></button>'++ //'<button class="btn btn-link" data-i18n="[title]ns.perspectiveList:increasThumbnailsTooltip" id="{{id}}IncreaseThumbsButton"><i class="fa fa-search-plus fa-lg"></i></button>'++ '</div>'++ '<div class="btn-group pull-right" style="padding-right: 10px;">'++ '<input type="search" name="Search" class="form-control" id="{{id}}searchBoxOC" placeholder="Search" data-i18n="[placeholder]ns.common:searchPlaceholder">'++ //'<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>'++ '</div>'++ '</div>'+ );++ exports.dialogOCSetting = Handlebars.compile(+ '<div class="modal" id="dialogOCSettings" tabindex="-1" role="dialog" aria-hidden="true">'++ '<div class="modal-dialog">'++ '<div class="modal-content">'++ '<div class="modal-header">'++ '<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times fa-lg"></i></button>'++ '<h4 class="modal-title" id="myModalLabel1" data-i18n="">Settings</h4>'++ '</div>'++ '<div class="modal-body">'++ '<iframe id="aboutIframe" nwdisable style="width: 100%; height: 350px; border: 0;" src="../../../index.php/settings/personal"></iframe>'++ '</div>'++ '<div class="modal-footer">'++ '<button class="btn btn-primary" data-dismiss="modal" title="Close Dialog" aria-hidden="true"><i class="fa fa-check fa-lg"></i></button>'++ '</div>'++ '</div><!-- /.modal-content -->'++ '</div><!-- /.modal-dialog -->'++ '</div><!-- /.modal -->'+ );++ exports.fileTiles = Handlebars.compile(+ '<ol style="padding: 0px; margin: 0px;">'++ '{{#each files}}'++ '<li title="{{filepath}}" data-filepath="{{filepath}}" class="fileTile">'++ '<span><img class="thumbImgTile" data-filepath="{{filepath}}" src="{{tmbpath}}"></span>'++ '<p class="titleInFileTile">{{title}}</p>' ++ '<span class="tagsInFileTile">'++ '{{#each tags}}'++ '<button class="btn btn-sm tagButton fileTagsTile" style="{{style}}">{{tag}} </button>'++ '{{/each}}'++ '</span>' ++ '<span class="fileExtTile">{{fileext}}</span>'++ '<button class="btn btn-link fileTileSelector" data-filepath="{{filepath}}"><i class="fa fa-square-o"></i></button>' ++ '</li>'++ '{{/each}}'++ '</ol>'+ );++});\ No newline at end of file