TagSpaces is an offline, open source, document manager with tagging support
moving listsubdirectories to utils.js
uggrock567d3ac60438
diff --git a/data/chromium/chrome.api.js b/data/chromium/chrome.api.jsindex c061b1c5c..bb3af5382 100644--- a/data/chromium/chrome.api.js+++ b/data/chromium/chrome.api.js@@ -110,7 +110,7 @@ define(function(require, exports, module) {function listDirectoryPromise(dirPath) {- console.log("Listing directory: " + dirPath);+ //console.log("Listing directory: " + dirPath);return new Promise(function(resolve, reject) {var anotatedDirList = [];$.ajax({@@ -118,7 +118,6 @@ define(function(require, exports, module) {type: 'GET'}).done(function(data) {- //console.log("Dir List "+data);var folders = data.substring(data.indexOf(dataBegin) + dataBegin.length, data.lastIndexOf(dataEnd));folders = folders.split(dataBegin).join("");folders = folders.split(dataEnd);@@ -131,9 +130,10 @@ define(function(require, exports, module) {fileProp;anotatedDirList = [];+// sciping the first entry pointing to the parent directoryfor (var i = 1; i < folders.length; i++) {- console.log("Dir " + folders[i]);+ //console.log("Dir " + folders[i]);name = folders[i].substring(2, folders[i].indexOf('","'));path = dirPath + TSCORE.dirSeparator + name;isFile = (folders[i].indexOf(dataFile) > 1);@@ -161,29 +161,6 @@ define(function(require, exports, module) {});}- function listSubDirectories(dirPath) {- console.log("Listing sub directories: " + dirPath);- TSCORE.showLoadingAnimation();- listDirectoryPromise(dirPath).then(function(entries) {- var anotatedDirList = [];- // skiping the first entry pointing to the parent directory- for (var i = 1; i < entries.length; i++) {- if (!entries[i].isFile) {- anotatedDirList.push({- "name": entries[i].name,- "path": entries[i].path- });- }- }- TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);- }, function(error) {- TSPOSTIO.errorOpeningPath(dirPath);- TSCORE.hideLoadingAnimation();- console.error("Error listDirectory " + dirPath + " error: " + error);- });- }--function getPropertiesPromise(filePath) {return new Promise(function(resolve, reject) {// TODO use listDirectory to get size and lmdt@@ -319,7 +296,6 @@ define(function(require, exports, module) {exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;- exports.listSubDirectories = listSubDirectories; /** TODO move in ioutils */exports.getPropertiesPromise = getPropertiesPromise;diff --git a/data/cordova/cordova.api.js b/data/cordova/cordova.api.jsindex bf71b9927..fcdecd954 100644--- a/data/cordova/cordova.api.js+++ b/data/cordova/cordova.api.js@@ -417,56 +417,6 @@ define(function(require, exports, module) {});}- function listSubDirectories(dirPath) {- console.log("Listing sub directories of: " + dirPath);- // directory path format DCIM/Camera/ !- if (dirPath.lastIndexOf("/") === 0 || dirPath.lastIndexOf("/") != dirPath.length - 1) {- dirPath = dirPath + "/"; // TODO make it platform independent- }-- dirPath = normalizePath(dirPath);- console.log("Listing sub directories of : " + dirPath + " normalized.");- TSCORE.showLoadingAnimation();-- fsRoot.getDirectory(dirPath, {- create: false,- exclusive: false- },- function(dirEntry) {- var directoryReader = dirEntry.createReader();-- // Get a list of all the entries in the directory- directoryReader.readEntries(- function(entries) {- var i;- var anotatedDirList = [];- for (i = 0; i < entries.length; i++) {- if (entries[i].isDirectory) {- anotatedDirList.push({- "name": entries[i].name,- "path": entries[i].fullPath- });- }- }- //console.log("Dir content: " + JSON.stringify(entries));- TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);- },- function(error) { // error get file system- //TSPOSTIO.errorOpeningPath(dirPath);- TSCORE.hideLoadingAnimation();- console.error("Listing sub directories failed: " + error.code);- }- );- },- function(error) {- //TSPOSTIO.errorOpeningPath(dirPath);- TSCORE.hideLoadingAnimation();- console.error("Getting sub directories of : " + dirPath + " failed: " + error.code);- }- );- }--function getPropertiesPromise(filePath) {return new Promise(function(resolve, reject) {filePath = normalizePath(filePath);@@ -852,7 +802,6 @@ define(function(require, exports, module) {exports.createDirectoryTree = createDirectoryTree;exports.listDirectoryPromise = listDirectoryPromise;- exports.listSubDirectories = listSubDirectories; /** @deprecated */exports.getPropertiesPromise = getPropertiesPromise;diff --git a/data/js/directorybrowser.js b/data/js/directorybrowser.jsindex 695218fad..aa8766d2b 100644--- a/data/js/directorybrowser.js+++ b/data/js/directorybrowser.js@@ -10,7 +10,7 @@ define(function(require, exports, module) {function initUI() {$('#gotoParentDirButton').click(function() {var parent = TSCORE.TagUtils.extractParentDirectoryPath($('#directoryPath').val());- TSCORE.IO.listSubDirectories(parent);+ TSCORE.Utils.listSubDirectories(parent);});if (isWin) {$('#driveSelectorForm').show();@@ -18,7 +18,7 @@ define(function(require, exports, module) {driveSelector.change(function() {$('#subdirectoriesArea').empty();$('#directoryPath').val(driveSelector.val());- TSCORE.IO.listSubDirectories(driveSelector.val());+ TSCORE.Utils.listSubDirectories(driveSelector.val());});}$('#selectDirectoryButton').click(function() {@@ -42,7 +42,7 @@ define(function(require, exports, module) {'style': 'margin: 1px;','text': ' ' + TSCORE.subfoldersDirBrowser[j].name}).prepend('<i class=\'fa fa-folder-o\'></i>').click(function() {- TSCORE.IO.listSubDirectories($(this).attr('path'));+ TSCORE.Utils.listSubDirectories($(this).attr('path'));})); // jshint ignore:line}}diff --git a/data/js/utils.js b/data/js/utils.jsindex 506ab9e53..2721cead6 100644--- a/data/js/utils.js+++ b/data/js/utils.js@@ -5,6 +5,8 @@define(function(require, exports, module) {'use strict';var TSCORE = require('tscore');+ var TSPOSTIO = require('tspostioapi');+console.log('Loading utils.js ...');var TSCORE = require('tscore');@@ -43,14 +45,14 @@ define(function(require, exports, module) {return canvas.toDataURL("image/png");}- var arrayBufferToStr = function(buf) {+ function arrayBufferToStr(buf) {var str = '',bytes = new Uint8Array(buf);for (var i = 0; i < bytes.length; i++) {str += String.fromCharCode(bytes[i]);}return decodeURIComponent(escape(str));- };+ }function arrayBufferToBuffer(ab) {var buffer = new Buffer(ab.byteLength);@@ -61,19 +63,19 @@ define(function(require, exports, module) {return buffer;}- var baseName = function(dirPath) {+ function baseName(dirPath) {var fileName = dirPath.substring(dirPath.lastIndexOf(TSCORE.dirSeparator) + 1, dirPath.length);return fileName ? fileName : dirPath;- };+ }- var dirName = function(dirPath) {+ function dirName(dirPath) {return dirPath.replace(/\\/g, '/').replace(/\/[^\/]*$/, '');- };+ }- var getFileExt = function(fileURL) {+ function getFileExt(fileURL) {var ext = fileURL.split('.').pop();return (ext === fileURL) ? "" : ext;- };+ }function walkDirectory(path, options, fileCallback, dirCallback) {return TSCORE.IO.listDirectoryPromise(path).then(function(entries) {@@ -105,6 +107,28 @@ define(function(require, exports, module) {});}+ function listSubDirectories(dirPath) {+ console.log("Listing sub directories: " + dirPath);+ TSCORE.showLoadingAnimation();+ TSCORE.IO.listDirectoryPromise(dirPath).then(function(entries) {+ var anotatedDirList = [];+ // skiping the first entry pointing to the parent directory+ for (var i = 1; i < entries.length; i++) {+ if (!entries[i].isFile) {+ anotatedDirList.push({+ "name": entries[i].name,+ "path": entries[i].path+ });+ }+ }+ TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);+ }, function(error) {+ TSPOSTIO.errorOpeningPath(dirPath);+ TSCORE.hideLoadingAnimation();+ console.error("Error listDirectory " + dirPath + " error: " + error);+ });+ }+exports.arrayBufferToDataURL = arrayBufferToDataURL;exports.base64ToArrayBuffer = base64ToArrayBuffer;exports.dataURLtoBlob = dataURLtoBlob;@@ -116,4 +140,5 @@ define(function(require, exports, module) {exports.arrayBufferToBuffer = arrayBufferToBuffer;exports.walkDirectory = walkDirectory;+ exports.listSubDirectories = listSubDirectories;});