Skip to content

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

Refactoring of perspectiveUI Adding support of thumbnails Adding buttons for switching tags and filedetails columns

uggrock7ad7db2e8a59
diff --git a/data/ext/perspectiveDefault/extension.js b/data/ext/perspectiveDefault/extension.js
index 72b6aa0f6..0375a3678 100644
--- a/data/ext/perspectiveDefault/extension.js
+++ b/data/ext/perspectiveDefault/extension.js
@@ -12,7 +12,7 @@ define(function(require, exports, module) {
var extensionVersion = "1.0";
var extensionManifestVersion = 1;
var extensionLicense = "AGPL";
-
+
console.debug("Loading "+extensionID);
var TSCORE = require("tscore");
@@ -38,119 +38,12 @@ define(function(require, exports, module) {
var load = function () {
console.debug("Loading perspective "+extensionID);
-
- $('#'+extensionID+"FileTable_wrapper").hide();
-
- updateIndexData(TSCORE.fileList);
-
- $( "#"+extensionID+"ReIndexButton" ).button( "enable" );
+
+ UI.reInitTableWithData(TSCORE.fileList);
+
TSCORE.hideLoadingAnimation();
}
- var enhanceIndexData = function(index) {
- console.debug("Enhancing directory index...");
- var enhancedIndex = [];
- var tags = undefined;
- var ext = undefined;
- var title = undefined;
- var fileSize = undefined;
- var fileLMDT = undefined;
- var path = undefined;
- var filename = undefined;
- for (var i=0; i < index.length; i++) {
- if (index[i].type == "file"){
- // Considering Unix HiddenEntries (. in the beginning of the filename)
- if (TSCORE.Config.Settings["showUnixHiddenEntries"] ||
- (!TSCORE.Config.Settings["showUnixHiddenEntries"] && (index[i].name.indexOf(".") != 0))) {
- filename = index[i].name;
- path = index[i].path;
- tags = TSCORE.TagUtils.extractTags(path);
- title = TSCORE.TagUtils.extractTitle(path);
- ext = TSCORE.TagUtils.extractFileExtension(path)
- fileSize = index[i].size;
- fileLMDT = index[i].lmdt;
-
- if(fileSize == undefined) fileSize = "";
- if(fileLMDT == undefined) fileLMDT = "";
- var entry = [title,tags,fileSize,fileLMDT,path,filename,ext];
- enhancedIndex.push(entry);
- }
- }
- }
- return enhancedIndex;
- }
-
- var updateIndexData = function (index) {
- console.debug("Updating index data.");
-
- // Clearing the old data
- UI.fileTable.fnClearTable();
-
- UI.fileTable.fnAddData( enhanceIndexData(index) );
- //UI.fileTable.fnAddData(index);
-
-
- UI.fileTable.$('tr')
- .droppable({
- accept: ".tagButton",
- hoverClass: "activeRow",
- drop: function( event, ui ) {
- var tagName = ui.draggable.attr("tag");
- var targetFilePath = UI.fileTable.fnGetData( this )[4];
- console.log("Tagging file: "+tagName+" to "+targetFilePath);
-
- $(this).toggleClass("ui-selected");
-
- clearSelectedFiles();
- TSCORE.selectedFiles.push(targetFilePath);
- UI.handleElementActivation();
-
- TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [tagName]);
- }
- })
- .dblclick( function() {
- console.debug("Opening file...");
- var rowData = UI.fileTable.fnGetData( this );
-
- TSCORE.FileOpener.openFile(rowData[4]); // 4 is the filePath
- } );
-
- UI.fileTable.$('.fileTitleButton')
- .draggable({
- cancel:false,
- appendTo: "body",
- helper: "clone",
- revert: true,
- start: function() {
- selectFile(this, $(this).attr("filepath"));
- }
- })
- .click( function() {
- selectFile(this, $(this).attr("filepath"));
- } )
- .dropdown( 'attach' , '#fileMenu' );
-
- UI.fileTable.$('.extTagButton')
- .click( function() {
- selectFile(this, $(this).attr("fileName"));
- TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));
- } )
- .dropdown( 'attach' , '#extensionMenu' );
-
- UI.fileTable.$('.tagButton')
- .click( function() {
- selectFile(this, $(this).attr("fileName"));
- TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));
- } )
- .dropdown( 'attach' , '#tagMenu' );
-
- $('#'+extensionID+"FileTable_wrapper").show();
-
- $( "#"+extensionID+"ReIndexButton" ).button( "enable" );
-
- TSCORE.hideLoadingAnimation();
- }
-
var setFileFilter = function (filter) {
$( "#"+extensionID+"FilterBox").val(filter);
UI.fileTable.fnFilter(filter);
@@ -199,13 +92,6 @@ define(function(require, exports, module) {
return prevFilePath;
}
- var selectFile = function(tagButton, filePath) {
- clearSelectedFiles();
- $(tagButton).parent().parent().toggleClass("ui-selected");
- TSCORE.selectedFiles.push(filePath);
- UI.handleElementActivation();
- }
-
// Vars
exports.Title = extensionTitle;
exports.ID = extensionID;
@@ -218,7 +104,6 @@ define(function(require, exports, module) {
// Methods
exports.init = init;
exports.load = load;
- exports.updateIndexData = updateIndexData;
exports.setFileFilter = setFileFilter;
exports.clearSelectedFiles = clearSelectedFiles;
exports.getNextFile = getNextFile;
diff --git a/data/ext/perspectiveDefault/perspectiveUI.js b/data/ext/perspectiveDefault/perspectiveUI.js
index 41cf5dbca..7246b503b 100644
--- a/data/ext/perspectiveDefault/perspectiveUI.js
+++ b/data/ext/perspectiveDefault/perspectiveUI.js
@@ -9,11 +9,67 @@ console.debug("Loading UI for perspectiveDefault");
var TSCORE = require("tscore");
+ var TC_TITLE = 0,
+ TC_TAGS = 1,
+ TC_FILESIZE = 2,
+ TC_FILELMDT = 3,
+ TC_FILEPATH = 4,
+ TC_FILENAME = 5,
+ TC_FILEEXT = 6;
+
+ 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();
+
+ this.showThumbs = true;
+ this.showFileDetails = false;
+ this.showTags = true;
+ }
+
+ // Helper function user by basic and search views
+ function buttonizeTitle(title, fileName, filePath, fileExt) {
+ if(title.length < 1) {
+ title = "n/a";
+ }
+
+ var thumbHTML = "";
+
+ if(supportedFileTypeThumnailing.indexOf(fileExt) >= 0) {
+ thumbHTML = $('<p>').append($('<li>', {
+ title: fileName,
+ filepath: filePath
+ }).append( $('<img>', {
+ title: fileName,
+ class: "thumbImg",
+ src: 'file:///'+filePath
+ }))).html();
+ }
+
+ var titleButtonsHTML = $('<span>').append($('<button>', {
+ title: fileName,
+ filepath: filePath,
+ class: 'fileTitleButton',
+ text: title
+ })).html();
+
+ return titleButtonsHTML + thumbHTML;
+ }
+
+ // Helper function user by basic and search views
+ function buttonizeFileName(fileName, filePath) {
+ if(filePath == undefined) {
+ filePath = TSCORE.currentPath+TSCORE.TagUtils.DIR_SEPARATOR+fileName;
+ }
+ return $('<span>').append($('<button>', {
+ title: fileName,
+ filepath: filePath,
+ class: 'fileButton',
+ text: fileName
+ })).html();
}
ExtUI.prototype.buildUI = function() {
@@ -22,54 +78,65 @@ console.debug("Loading UI for perspectiveDefault");
this.viewToolbar.append($("<button>", {
text: "Subdirs",
disabled: true,
- title: "Include subdirectories",
- id: this.extensionID+"ReIndexButton",
+ title: "Include Subdirectories",
+ id: this.extensionID+"IncludeSubDirsButton",
}));
this.viewToolbar.append($("<button>", {
text: "Add Tag",
disabled: true,
- title: "TagSelectedFiles",
+ title: "Tag Selected Files",
id: this.extensionID+"TagButton",
}));
this.viewToolbar.append($("<input>", {
type: "checkbox",
disabled: false,
- title: "TagSelectedFiles",
id: this.extensionID+"ShowTmbButton",
}));
this.viewToolbar.append($("<label>", {
for: this.extensionID+"ShowTmbButton",
- text: "Thumbnails",
- title: "Some file thumbnails",
+ text: "Toggle Thumbnails",
+ title: "Toggle file thumbnails",
}));
+ this.viewToolbar.append($("<button>", {
+ text: "Zoom out",
+ disabled: false,
+ title: "Decrease Thumbnails Size",
+ id: this.extensionID+"DecreaseThumbsButton",
+ }));
+
+ this.viewToolbar.append($("<button>", {
+ text: "Zoom in",
+ disabled: false,
+ title: "Increase Thumbnails Size",
+ id: this.extensionID+"IncreaseThumbsButton",
+ }));
+
this.viewToolbar.append($("<input>", {
type: "checkbox",
disabled: false,
- title: "TagSelectedFiles",
id: this.extensionID+"ShowFileDetailsButton",
}));
this.viewToolbar.append($("<label>", {
for: this.extensionID+"ShowFileDetailsButton",
- text: "File Details",
- title: "Some file details",
+ text: "Toggle File Details",
+ title: "Toggle file details",
}));
this.viewToolbar.append($("<input>", {
type: "checkbox",
disabled: false,
- title: "TagSelectedFiles",
id: this.extensionID+"ShowTagsButton",
}));
this.viewToolbar.append($("<label>", {
for: this.extensionID+"ShowTagsButton",
text: "Tags",
- title: "Some file details",
+ title: "Toggle Tags",
}));
this.viewToolbar.append($("<span>", {
@@ -92,7 +159,6 @@ console.debug("Loading UI for perspectiveDefault");
}
ExtUI.prototype.initTable = function() {
- // Column order in json [title(0),tags(1),fileSize(2),fileLMDT(3),path(4),filename(5),extension(6)];
this.fileTable = $('#'+this.extensionID+"FileTable").dataTable( {
"bJQueryUI": false,
"bPaginate": false,
@@ -110,23 +176,31 @@ console.debug("Loading UI for perspectiveDefault");
],
"aoColumnDefs": [
{ // Title column
- "mRender": function ( data, type, row ) { return TSCORE.buttonizeTitle(data,row[0],row[4]) },
- "aTargets": [ 0 ]
+ "mRender": function ( data, type, row ) {
+ return buttonizeTitle(data,row[TC_TITLE],row[TC_FILEPATH],row[TC_FILEEXT])
+ },
+ "aTargets": [ TC_TITLE ]
},
{ // Tags column
- "mRender": function ( data, type, row ) { return TSCORE.generateTagButtons(data,row[6],row[5],row[4]) },
+ "mRender": function ( data, type, row ) {
+ return TSCORE.generateTagButtons(data,row[TC_FILEEXT],row[TC_FILENAME],row[TC_FILEPATH])
+ },
"aTargets": [ 1 ]
},
{ // Filesize column
- "mRender": function ( data, type, row ) { return TSCORE.TagUtils.formatFileSize(data) },
+ "mRender": function ( data, type, row ) {
+ return TSCORE.TagUtils.formatFileSize(data)
+ },
"aTargets": [ 2 ]
},
{ // Last changed date column
- "mRender": function ( data, type, row ) { return TSCORE.TagUtils.formatDateTime(data, true) },
+ "mRender": function ( data, type, row ) {
+ return TSCORE.TagUtils.formatDateTime(data, true)
+ },
"aTargets": [ 3 ]
},
- // { "bVisible": false, "aTargets": [ 5 ] },
- // { "bSearchable": false, "aTargets": [ 0 ] },
+ { "bVisible": false, "aTargets": [ TC_FILESIZE, TC_FILELMDT, TC_FILEPATH ] },
+ { "bSearchable": false, "aTargets": [ TC_FILEPATH ] }
// { "sClass": "center", "aTargets": [ 0 ] }
]
} );
@@ -134,11 +208,10 @@ console.debug("Loading UI for perspectiveDefault");
// Disable alerts in datatable
this.fileTable.dataTableExt.sErrMode = 'throw';
- var myTable = this.fileTable;
- var myHandleActivateion = this.handleElementActivation;
+ var self = this;
// Makes the body of the fileTable selectable
- $("tbody", $(myTable)).selectable({
+ $("tbody", $(this.fileTable)).selectable({
filter: 'tr',
start: function() {
console.debug("Start selecting");
@@ -147,31 +220,153 @@ console.debug("Loading UI for perspectiveDefault");
},
stop: function(){
$(".ui-selected", this).each(function(){
- var rowData = myTable.fnGetData( this );
+ var rowData = self.fileTable.fnGetData( this );
// Add the filename which is located in the first column to the list of selected filenames
- TSCORE.selectedFiles.push(rowData[4]);
- myHandleActivateion();
+ TSCORE.selectedFiles.push(rowData[TC_FILEPATH]);
+ self.handleElementActivation();
});
console.debug("Selected files: "+TSCORE.selectedFiles);
}
})
}
+ ExtUI.prototype.reInitTableWithData = function(fileList) {
+ $('#'+this.extensionID+"FileTable_wrapper").hide();
+
+ // Clearing the old data
+ this.fileTable.fnClearTable();
+ this.fileTable.fnAddData( fileList );
+
+ var self = this;
+
+ this.fileTable.$('tr')
+ .droppable({
+ accept: ".tagButton",
+ hoverClass: "activeRow",
+ drop: function( event, ui ) {
+ var tagName = ui.draggable.attr("tag");
+
+ var targetFilePath = self.fileTable.fnGetData( this )[TC_FILEPATH];
+
+ console.log("Tagging file: "+tagName+" to "+targetFilePath);
+
+ $(this).toggleClass("ui-selected");
+
+ TSCORE.ViewManager.clearSelectedFiles();
+
+ TSCORE.selectedFiles.push(targetFilePath);
+
+ TSCORE.TagUtils.addTag(TSCORE.selectedFiles, [tagName]);
+
+ self.handleElementActivation();
+ }
+ })
+ .dblclick( function() {
+ console.debug("Opening file...");
+ var rowData = self.fileTable.fnGetData( this );
+
+ TSCORE.FileOpener.openFile(rowData[TC_FILEPATH]);
+ } );
+
+ this.fileTable.$('.fileTitleButton')
+ .draggable({
+ cancel:false,
+ appendTo: "body",
+ helper: "clone",
+ revert: true,
+ start: function() {
+ selectFile(this, $(this).attr("filepath"));
+ }
+ })
+ .click( function() {
+ self.selectFile(this, $(this).attr("filepath"));
+ } )
+ .dropdown( 'attach' , '#fileMenu' );
+
+ this.fileTable.$('.extTagButton')
+ .click( function() {
+ self.selectFile(this, $(this).attr("filepath"));
+ TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));
+ } )
+ .dropdown( 'attach' , '#extensionMenu' );
+
+ this.fileTable.$('.tagButton')
+ .draggable({
+ cancel:false,
+ appendTo: "body",
+ helper: "clone",
+ revert: true,
+ start: function() {
+ self.selectFile(this, $(this).attr("filepath"));
+ }
+ })
+ .click( function() {
+ self.selectFile(this, $(this).attr("filepath"));
+ TSCORE.openTagMenu(this, $(this).attr("tag"), $(this).attr("filepath"));
+ } )
+ .dropdown( 'attach' , '#tagMenu' );
+
+ $('#'+this.extensionID+"FileTable_wrapper").show();
+
+ $( "#"+this.extensionID+"IncludeSubDirsButton" ).button( "enable" );
+
+ }
+
+ ExtUI.prototype.selectFile = function(tagButton, filePath) {
+ TSCORE.ViewManager.clearSelectedFiles();
+
+ $(tagButton).parent().parent().toggleClass("ui-selected");
+
+ TSCORE.selectedFiles.push(filePath);
+
+ this.handleElementActivation();
+ }
+
ExtUI.prototype.toggleThumbnails = function() {
console.debug("thumbs toggled");
}
+
+ ExtUI.prototype.increaseThumbnails = function() {
+ console.debug("thumbs zoom");
+ }
+ ExtUI.prototype.decreaseThumbnails = function() {
+ console.debug("thumbs zoom out");
+ }
+
+ ExtUI.prototype.toggleFileDetails = function() {
+ if(this.showFileDetails) {
+ this.fileTable.fnSetColumnVis( TC_FILESIZE, false );
+ this.fileTable.fnSetColumnVis( TC_FILELMDT, false );
+ this.fileTable.fnSetColumnVis( TC_FILEPATH, false );
+ } else {
+ this.fileTable.fnSetColumnVis( TC_FILESIZE, true );
+ this.fileTable.fnSetColumnVis( TC_FILELMDT, true );
+ this.fileTable.fnSetColumnVis( TC_FILEPATH, true );
+ }
+ this.showFileDetails = !this.showFileDetails;
+ }
+
+ ExtUI.prototype.toggleTags = function() {
+ if(this.showTags) {
+ this.fileTable.fnSetColumnVis( TC_TAGS, false );
+ } else {
+ this.fileTable.fnSetColumnVis( TC_TAGS, true );
+ }
+ this.showTags = !this.showTags;
+ }
+
ExtUI.prototype.initButtons = function() {
var self = this;
// Initialize file buttons
- $( "#"+this.extensionID+"ReIndexButton" ).button({
- text: true,
+ $( "#"+this.extensionID+"IncludeSubDirsButton" ).button({
+ text: false,
icons: {
- primary: "ui-icon-refresh"
+ primary: "ui-icon-script"
}
})
.click(function() {
- $( "#"+self.extensionID+"ReIndexButton" ).button( "disable" );
+ $( "#"+self.extensionID+"IncludeSubDirsButton" ).button( "disable" );
TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);
});
@@ -186,33 +381,54 @@ console.debug("Loading UI for perspectiveDefault");
});
$( "#"+this.extensionID+"ShowTmbButton" ).button({
- text: true,
+ text: false,
icons: {
primary: "ui-icon-image"
}
})
.click(function() {
self.toggleThumbnails();
- });
+ });
+ $( "#"+this.extensionID+"DecreaseThumbsButton" ).button({
+ text: false,
+ icons: {
+ primary: "ui-icon-minus"
+ }
+ })
+ .click(function() {
+ self.decreaseThumbnails();
+ });
+
+ $( "#"+this.extensionID+"IncreaseThumbsButton" ).button({
+ text: false,
+ icons: {
+ primary: "ui-icon-plus"
+ }
+ })
+ .click(function() {
+ self.increaseThumbnails();
+ });
+
$( "#"+this.extensionID+"ShowFileDetailsButton" ).button({
- text: true,
+ text: false,
icons: {
primary: "ui-icon-contact"
}
})
.click(function() {
- // self.toggleThumbnails();
- });
+ self.toggleFileDetails();
+ })
+ .prop('checked', false);
$( "#"+this.extensionID+"ShowTagsButton" ).button({
- text: true,
+ text: false,
icons: {
primary: "ui-icon-tag"
}
})
.click(function() {
- // self.toggleThumbnails();
+ self.toggleTags();
});
$( "#clearFilterButton" ).button({