TagSpaces is an offline, open source, document manager with tagging support
Enhancing perspectiveThumb
uggrock53d174eeae87
diff --git a/data/css/tagspaces.css b/data/css/tagspaces.cssindex e329bf020..7c437f34b 100644--- a/data/css/tagspaces.css+++ b/data/css/tagspaces.css@@ -127,7 +127,7 @@ html, body {float: right;color: white;font-weight: bold;- /*background-color: @fileExtColor; */+ background-color: gray;}#viewsRadio {diff --git a/data/ext/perspectiveGraph/extension.js b/data/ext/perspectiveGraph/extension.jsindex 41a9a67ac..c000c8e54 100644--- a/data/ext/perspectiveGraph/extension.js+++ b/data/ext/perspectiveGraph/extension.js@@ -255,15 +255,11 @@ define(function(require, exports, module) {}exports.setFileFilter = function setFileFilter(filter) {- //$( "#"+extensionID+"FilterBox").val(filter);- //fileTable.fnFilter(filter);+}exports.clearSelectedFiles = function() {- // Deselect all- $(".selectedRow", $(fileTable)).each(function(){- $(this).toggleClass('selectedRow');- });+}var initUI = function() {diff --git a/data/ext/perspectiveThumb/extension.js b/data/ext/perspectiveThumb/extension.jsindex 7ea729651..561f2bc47 100644--- a/data/ext/perspectiveThumb/extension.js+++ b/data/ext/perspectiveThumb/extension.js@@ -7,100 +7,79 @@ define(function(require, exports, module) {console.log("Loading perspectiveThumb");- exports.Title = "Thumbs"- exports.ID = "perspectiveThumb"; // ID should be equal to the directory name where the ext. is located- exports.Type = "perspective";- exports.Icon = "icon-picture";+ var extensionTitle = "Calendar"+ var extensionID = "perspectiveThumb"; // ID should be equal to the directory name where the ext. is located+ var extensionType = "perspective";+ var extensionIcon = "icon-picture";+ var extensionVersion = "1.0";+ var extensionManifestVersion = 1;+ var extensionLicense = "AGPL";- var TSCORE = require("tscore");-- var viewContainer = undefined;- var viewToolbar = undefined;- var viewFooter = undefined;-- var supportedFileTypeThumnailing = ['jpg','jpeg','png','gif'];+ var TSCORE = require("tscore");++ var extensionDirectory = TSCORE.Config.getExtensionPath()+"/"+extensionID;+ var UI = undefined;- exports.init = function init() {- console.log("Initializing View "+exports.ID);-- viewContainer = $("#"+exports.ID+"Container");- viewToolbar = $("#"+exports.ID+"Toolbar");- viewFooter = $("#"+exports.ID+"Footer");-- viewContainer.empty();- viewToolbar.empty();- viewFooter.empty();-- viewToolbar.append($("<button>", {- class: "btn disabled",- disabled: true,- title: "Create new file",- id: this.extensionID+"CreateFileButton",- })- .append( $("<i>", { class: "icon-file", }) )- .append("New")- .click(function() {- TSCORE.showFileCreateDialog();- })- );-- viewContainer.append($("<ol>", {- style: "overflow: visible;",- class: "selectableFiles",- id: exports.ID+"SelectableFiles",- text: "Empty viewer."- }));-- $( "#"+exports.ID+"SelectableFiles" ).selectable({- stop: function() {- TSCORE.selectedFiles = [];- $( ".ui-selected", this ).each(function() {- TSCORE.selectedFiles.push($(this).attr("filepath"));- });- console.log("Selected files: "+TSCORE.selectedFiles);- // TSCORE.handleElementActivation();-- // On selecting only one file opens it in the viewer- if(TSCORE.selectedFiles.length == 1) {- TSCORE.FileOpener.openFile(TSCORE.selectedFiles[0]);- }- }- });+ var init = function () {+ console.log("Initializing perspective "+extensionID);+ require([+ extensionDirectory+'/perspectiveUI.js',+ 'datatables'+ ], function(extUI) {+ UI = new extUI.ExtUI(extensionID);+ UI.buildUI();+ UI.initMainContainer();+ }+ );}- exports.load = function load() {- console.log("Showing View "+exports.ID);-- // Purging the thumbnail view, avoiding memory leak- document.getElementById(exports.ID+"SelectableFiles").innerHTML = "";-- $("#"+exports.ID+"SelectableFiles").empty();-- for (var i=0; i < TSCORE.fileList.length; i++) {- var fileName = TSCORE.fileList[i][TSCORE.fileListTITLE];- var fileExt = TSCORE.fileList[i][TSCORE.fileListFILEEXT];- var filePath = TSCORE.fileList[i][TSCORE.fileListFILEPATH];- if(supportedFileTypeThumnailing.indexOf(fileExt) >= 0) {- $("#"+exports.ID+"SelectableFiles").append(- $('<li>', { title: fileName, filepath: filePath, style: 'border: 1px dashed gray;' }).append(- $('<img>', { title: fileName, class: "thumbImg", src: 'file:///'+filePath })));- } else {- $("#"+exports.ID+"SelectableFiles").append(- $('<li>', { title: fileName, filepath: filePath, style: 'border: 1px dashed gray;' }).append(- $('<span>', { class: "fileExtension", text: fileExt})));- }- }-- $( exports.ID+"CreateFileButton" ).removeClass("disabled");+ var load = function () {+ console.log("Loading perspective "+extensionID);+ if(UI != undefined) {+ UI.reInit(TSCORE.fileList);+ TSCORE.hideLoadingAnimation();+ }TSCORE.hideLoadingAnimation();}- exports.setFileFilter = function setFileFilter(filter) {+ var getNextFile = function (filePath) {+ var nextFilePath = undefined;++ console.log("Next file: "+nextFilePath);+ return nextFilePath;+ }++ var getPrevFile = function (filePath) {+ var prevFilePath = undefined;++ console.log("Prev file: "+prevFilePath);+ return prevFilePath;+ }++ var setFileFilter = function (filter) {console.log("setFileFilter not implemented in "+exports.ID);}- exports.clearSelectedFiles = function() {- // TODO Deselect all- //$("#"+exports.ID+"SelectableFiles").+ var clearSelectedFiles = function() {+ TSCORE.selectedFiles = [];+ $("#"+extensionID+"Container").find(".ui-selected").removeClass("ui-selected");}++ // Vars+ exports.Title = extensionTitle;+ exports.ID = extensionID;+ exports.Type = extensionType;+ exports.Icon = extensionIcon;+ exports.Version = extensionVersion;+ exports.ManifestVersion = extensionManifestVersion;+ exports.License = extensionLicense;++ // Methods+ exports.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/perspectiveThumb/perspectiveUI.js b/data/ext/perspectiveThumb/perspectiveUI.jsnew file mode 100644index 000000000..871e9ebe3--- /dev/null+++ b/data/ext/perspectiveThumb/perspectiveUI.js@@ -0,0 +1,309 @@+/* 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 UI for perspectiveDefault");++ var TSCORE = require("tscore");++ var TMB_SIZES = [ "100px", "200px", "300px", "400px", "500px" ];++ var supportedFileTypeThumnailing = ['jpg','jpeg','png','gif'];++ function ExtUI(extID) {+ this.extensionID = extID;+ this.viewContainer = $("#"+this.extensionID+"Container").empty();+ this.viewToolbar = $("#"+this.extensionID+"Toolbar").empty();+ this.viewFooter = $("#"+this.extensionID+"Footer").empty();++ }++ ExtUI.prototype.buildUI = function() {+ console.log("Init UI module");++ var self = this;++ this.viewToolbar.append($("<div >", {+ class: "btn-group",+ })++ .append($("<button>", {+ class: "btn ",+ title: "Toggle Select All Files",+ id: this.extensionID+"ToogleSelectAll",+ })+ .click(function() {+ if($(this).find("i").attr("class") == "icon-check-empty") {+ TSCORE.selectedFiles = [];+ $('#'+self.extensionID+'FileTable tbody tr').each(function(){+ //$(this).addClass('ui-selected');+ //$(this).find(".fileSelection").prop("checked",true);+ TSCORE.selectedFiles.push($(this).find(".fileTitleButton").attr("filepath"));+ //self.handleElementActivation();+ });+ $(this).find("i").removeClass("icon-check-empty");+ $(this).find("i").addClass("icon-check");+ } else {+ TSCORE.PerspectiveManager.clearSelectedFiles();+ $(this).find("i").removeClass("icon-check");+ $(this).find("i").addClass("icon-check-empty");+ }+ })+ .append( "<i class='icon-check-empty'>" )+ )++ )++ this.viewToolbar.append($("<div>", {+ class: "btn-group",+ id: this.extensionID+"Toolbar",+ })++ .append($("<button>", {+ class: "btn ",+ title: "Create new file",+ id: this.extensionID+"CreateFileButton",+ })+ .prop('disabled', true)+ .click(function() {+ TSCORE.showFileCreateDialog();+ })+ .append( "<i class='icon-plus'>" )+ )++ .append($("<button>", {+ class: "btn",+ title: "Show subfolders content. \nOn subfolder with many files, this step can take some time!",+ id: this.extensionID+"IncludeSubDirsButton",+ })+ // .prop('disabled', true)+ .click(function() {+ // $(this).prop('disabled', true);+ TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);+ })+ .append( $("<i>", { class: "icon-retweet", }) )+ )++ .append($("<button>", {+ class: "btn",+ title: "Tag Selected Files",+ id: this.extensionID+"TagButton",+ })+ // .prop('disabled', true)+ .click(function() {+ TSCORE.showAddTagsDialog();+ })+ .append( $("<i>", { class: "icon-tag", }) )+ )++ ); // end toolbar+++ this.viewToolbar.append($("<div >", {+ class: "input-append pull-right",+ })+ // Filter+ .append($("<input>", {+ type: "text",+ //name: "fileFilter",+ class: "input-medium",+ id: this.extensionID+"FilterBox",+ placeholder: "Filename Filter",+ style: "width: 100px;"+ }).keyup(function() {+ self.setFilter(this.value);+ }))++ .append($("<button>", {+ class: "btn",+ title: "Clear Filter",+ id: this.extensionID+"ClearFilterButton",+ })+ .append( $("<i>", { class: "icon-remove", }) )+ .click(function(evt) {+ evt.preventDefault();+ self.setFilter("");+ })+ )+ ); // End Filter++ }++ ExtUI.prototype.initMainContainer = function() {++ }++ // Helper function for organizing the files in data buckets+ function groupDataByDate() {+ var dataGroupedByDate = TSCORE.fileList;++ // Group by date+ dataGroupedByDate = _.groupBy( dataGroupedByDate, function(value){+ var tmpDate = new Date(value[TSCORE.fileListFILELMDT])+ tmpDate.setHours(0,0,0,0);+ tmpDate.setDate(1);+ return tmpDate.getTime();+ });++ // Sort by date+ dataGroupedByDate = _.sortBy(dataGroupedByDate, function(value) {+ var tmpDate = new Date(value[0][TSCORE.fileListFILELMDT]);+ return -tmpDate.getTime();+ });++ return dataGroupedByDate;+ }++ ExtUI.prototype.reInit = function() {+ this.viewContainer.empty();+ this.viewContainer.addClass("accordion");++ $( this.extensionID+"CreateFileButton" ).prop("disabled", false);+ $( this.extensionID+"IncludeSubDirsButton" ).prop('disabled', false);++ var self = this;+// console.log("Grouping by date: "+value[0][TSCORE.fileName]+" length: "+value.length);++ var i=0;+ _.each(groupDataByDate(), function (value) {+ i++;++ var tmpDate = new Date(value[0][TSCORE.fileListFILELMDT]);+ tmpDate.setHours(0,0,0,0);+ var groupingTitle = TSCORE.TagUtils.formatDateTime(tmpDate, false);++ self.viewContainer.append($("<div>", {+ "class": "accordion-group",+ "style": "width: 99%; border: 0px #aaa solid;",+ })+ .append($("<div>", {+ "class": "accordion-heading btn-group",+ "style": "width:100%; margin: 0px;",+ })++ .append($("<button>", { // Grouped content toggle button+ "class": "btn btn-link",+ "data-toggle": "collapse",+ "data-target": "#"+self.extensionID+"sortingButtons"+i,+ "title": "Toggle Group",+ }+ )+ .html("<i class='icon-minus-sign-alt'></i>")+ )// End date toggle button++ .append($("<button>", {+ "class": "btn btn-link btn-small",+ "text": groupingTitle,+ })+ )++ ) // end heading++ .append($("<div>", {+ "class": "accordion-body collapse in",+ "id": self.extensionID+"sortingButtons"+i,+ "style": "margin: 0px 0px 0px 3px; border: 0px;",+ })+ .append($("<div>", {+ "class": "accordion-inner",+ "id": self.extensionID+"sortingButtonsContent"+i,+ "style": "padding: 2px; border: 0px;",+ })+ ) // end accordion-inner+ ) // end accordion button++ ); // end group++ var groupedContent = $("<ol>", {+ style: "overflow: visible;",+ class: "selectableFiles",+ }).appendTo( "#"+self.extensionID+"sortingButtonsContent"+i );++ // Iterating over the files in group+ for(var j=0; j < value.length; j++) {+ var previewContent = "";+ if(supportedFileTypeThumnailing.indexOf(value[j][TSCORE.fileListFILEEXT]) >= 0) {+ previewContent = $('<img>', {+// title: value[j][TSCORE.fileListTITLE]+"\n"+value[j][TSCORE.fileListFILELMDT],+ class: "thumbImg",+ src: 'file:///'+value[j][TSCORE.fileListFILEPATH]+ });+ } else {+ previewContent = $('<span>', {+ class: "fileExtension",+ text: value[j][TSCORE.fileListFILEEXT],+// title: value[j][TSCORE.fileListTITLE]+"\n"+value[j][TSCORE.fileListFILELMDT],+ });+ }+ groupedContent.append(+ $('<li>', {+ title: value[j][TSCORE.fileListTITLE]+"\n"+value[j][TSCORE.fileListFILELMDT],+ filepath: value[j][TSCORE.fileListFILEPATH],+ style: 'border: 1px dashed gray;'+ })+ .append(previewContent)+ .dblclick(function() {+ var filePath = $(this).attr("filepath");+ TSCORE.FileOpener.openFile(filePath);+ self.selectFile($(this), filePath);+ })+ .click(function() {+ var filePath = $(this).attr("filepath");+ self.selectFile($(this), filePath);+ })+ );+ }++ $( "#"+self.extensionID+"sortingButtonsContent"+i ).selectable({+ start: function() {+ TSCORE.PerspectiveManager.clearSelectedFiles();+ },+ stop: function() {+ TSCORE.selectedFiles = [];+ $( ".ui-selected", this ).each(function() {+ TSCORE.selectedFiles.push($(this).attr("filepath"));+ });+ console.log("Selected files: "+TSCORE.selectedFiles);+ self.handleElementActivation();+ }+ });+ });++ }++ ExtUI.prototype.selectFile = function(uiElement, filePath) {+ TSCORE.PerspectiveManager.clearSelectedFiles();++ $(uiElement).toggleClass("ui-selected");++ TSCORE.selectedFiles.push(filePath);++ this.handleElementActivation();+ }++ ExtUI.prototype.setFilter = function(filterValue) {+ TSCORE.PerspectiveManager.clearSelectedFiles();+++ console.log("Filter to value: "+filterValue);+ }++ ExtUI.prototype.handleElementActivation = function() {+ console.log("Entering element activation handler...");++ var tagButton = $( "#"+this.extensionID+"TagButton" );++ if (TSCORE.selectedFiles.length > 1) {+ tagButton.prop('disabled', false);+ } else if (TSCORE.selectedFiles.length == 1) {+ tagButton.prop('disabled', false);+ } else {+ tagButton.prop('disabled', true);+ }+ }++ exports.ExtUI = ExtUI;+});\ No newline at end of filediff --git a/data/loader.js b/data/loader.jsindex 55e6f1b04..aa291d29d 100644--- a/data/loader.js+++ b/data/loader.js@@ -99,6 +99,7 @@ requirejs.config({jquerydropdowncss: 'libs/jquerydropdown/jquery.dropdown',less: 'libs/less/less-1.3.3.min',jqueryeditinplace: 'libs/jqueryeditinplace/jquery.editinplace',+ underscore: 'libs/underscore/underscore',tscore: 'js/core.api',tssetting: 'js/settings.api',@@ -113,6 +114,7 @@ requirejs.config({tsioapi: IO_JS,},shim: {+ 'underscore': { exports: '_' },'bootstrap': { deps: ['jquery'] },'jquerysimplecolorpicker': { deps: ['jquery','bootstrap'] },'jqueryui': { deps: ['jquery'] },@@ -143,7 +145,8 @@ requirejs.config({'jquerysimplecolorpicker','jquerylayout','jquerydropdown',- ] },+ ] },+}});@@ -152,8 +155,11 @@ define(function (require, exports, module) {//require("less");+// require(['underscore'], function (_) { });++var TSCORE = undefined;- requirejs(['tscore'], function (core) {+ requirejs(['tscore','underscore'], function (core,_) {TSCORE = core;TSCORE.initApp();});