TagSpaces is an offline, open source, document manager with tagging support
refactorings
uggrockd9a28d0712bc
diff --git a/data/node-webkit/node-webkit.api.js b/data/node-webkit/node-webkit.api.jsindex 0c88a62d0..ce7a05ac8 100644--- a/data/node-webkit/node-webkit.api.js+++ b/data/node-webkit/node-webkit.api.js@@ -835,23 +835,23 @@ define(function(require, exports, module) {exports.createDirectoryIndex = createDirectoryIndex;exports.createDirectoryTree = createDirectoryTree;- exports.listDirectory = listDirectory; /** @deprecated */exports.listDirectoryPromise = listDirectoryPromise;+ exports.listDirectory = listDirectory; /** @deprecated */exports.getDirectoryMetaInformation = getDirectoryMetaInformation;exports.getPropertiesPromise = getPropertiesPromise;exports.getFileProperties = getFileProperties; /** @deprecated */- exports.createDirectoryPromise = createDirectoryPromise;- exports.createDirectory = createDirectory; /** @deprecated */- exports.createMetaFolder = createMetaFolder; /** @deprecated */-exports.loadTextFilePromise = loadTextFilePromise;exports.loadTextFile = loadTextFile;exports.getFile = getFile;exports.getFileContent = getFileContent; /** @deprecated */exports.getFileContentPromise = getFileContentPromise;+ exports.createDirectoryPromise = createDirectoryPromise;+ exports.createDirectory = createDirectory; /** @deprecated */+ exports.createMetaFolder = createMetaFolder; /** @deprecated */+exports.saveFilePromise = saveFilePromise;exports.saveTextFile = saveTextFile; /** @deprecated */exports.saveBinaryFile = saveBinaryFile; /** @deprecated */diff --git a/data/web/web.api.js b/data/web/web.api.jsindex 391c8e50b..db427577c 100644--- a/data/web/web.api.js+++ b/data/web/web.api.js@@ -54,7 +54,22 @@ define(function(require, exports, module) {davClient = new nl.sara.webdav.Client(location.hostname, useHTTPS, location.port);}- window.setTimeout(connectDav(), 2000);+ //window.setTimeout(+ connectDav()+ //, 2000);++ function getNameForPath(path) {+ if (path.lastIndexOf("/") == path.length - 1) {+ path = path.substring(0, path.lastIndexOf("/"));+ }+ var encodedName = path.substring(path.lastIndexOf("/") + 1, path.length);+ return decodeURI(encodedName);+ }++ function isDirectory(path) {+ // TODO find a better solution+ return path.lastIndexOf("/") == path.length - 1;+ }function checkStatusCode(code) {var status = parseInt(code / 100);@@ -64,6 +79,46 @@ define(function(require, exports, module) {return false;}++ function focusWindow() {+ // Bring the TagSpaces window on top of the windows+ window.focus();+ };++ function checkNewVersion() {+ //+ console.log("Checking for new version not relevant fot the webdav version");+ };+++ function createDirectoryIndex(dirPath) {+ TSCORE.showWaitingDialog($.i18n.t("ns.common:waitDialogDiectoryIndexing"));++ var directoryIndex = [];+ TSCORE.Utils.walkDirectory(dirPath, {recursive: true}, function(fileEntry) {+ directoryIndex.push(fileEntry);+ }).then(+ function(entries) {+ TSPOSTIO.createDirectoryIndex(directoryIndex);+ },+ function(err) {+ console.warn("Error creating index: " + err);+ }+ ).catch(function() {+ TSCORE.hideWaitingDialog();+ });+ };++ function createDirectoryTree(dirPath) {+ console.log("Creating directory index for: " + dirPath);+ TSCORE.showLoadingAnimation();++ var directoyTree = [];+ //console.log(JSON.stringify(directoyTree));+ TSPOSTIO.createDirectoryTree(directoyTree);+ };++function listDirectory(dirPath, readyCallback) {listDirectoryPromise(dirPath).then(function(anotatedDirList) {if (readyCallback) {@@ -138,64 +193,144 @@ define(function(require, exports, module) {});}- var getDirectoryMetaInformation = function(dirPath, readyCallback) {+ function getDirectoryMetaInformation(dirPath, readyCallback) {listDirectory(dirPath, function(anotatedDirList) {TSCORE.metaFileList = anotatedDirList;readyCallback(anotatedDirList);});};- function getNameForPath(path) {- if (path.lastIndexOf("/") == path.length - 1) {- path = path.substring(0, path.lastIndexOf("/"));- }- var encodedName = path.substring(path.lastIndexOf("/") + 1, path.length);- return decodeURI(encodedName);- }- function isDirectory(path) {- return path.lastIndexOf("/") == path.length - 1;+ function getPropertiesPromise(filePath) {+ return new Promise(function(resolve, reject) {+ davClient.propfind(encodeURI(filePath), function(status, data) {+ console.log("Properties Status / Content: " + status + " / " + JSON.stringify(data._responses));+ var fileProperties = {};+ if (checkStatusCode(status)) {+ for (var entry in data._responses) {+ fileProperties.path = filePath;+ fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;+ fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;+ }+ resolve(fileProperties);+ } else {+ reject("getFileProperties " + filePath + " failed " + status);+ }+ }, 1);+ });}- var createDirectoryIndex = function(dirPath) {- TSCORE.showWaitingDialog($.i18n.t("ns.common:waitDialogDiectoryIndexing"));+ function getFileProperties(filePath) {+ getPropertiesPromise(filePath).then(function(fileProperties) {+ TSPOSTIO.getFileProperties(fileProperties);+ }, function(error) {+ TSCORE.hideLoadingAnimation();+ TSCORE.closeFileViewer();+ TSCORE.showAlertDialog("File " + filePath + " get properties failed");+ console.error(error);+ }+ );+ };- var directoryIndex = [];- TSCORE.Utils.walkDirectory(dirPath, {recursive: true}, function(fileEntry) {- directoryIndex.push(fileEntry);- }).then(- function(entries) {- TSPOSTIO.createDirectoryIndex(directoryIndex);- },- function(err) {- console.warn("Error creating index: " + err);++ function loadTextFile(filePath) {+ console.log("Loading file: " + filePath);+ loadTextFilePromise(filePath).then(function(data) {+ TSPOSTIO.loadTextFile(data);+ }, function(error) {+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");+ console.error(error);}- ).catch(function() {- TSCORE.hideWaitingDialog();- });+ );};- var createDirectoryTree = function(dirPath) {- console.log("Creating directory index for: " + dirPath);- TSCORE.showLoadingAnimation();+ function loadTextFilePromise(filePath) {+ // TODO refactor+ return getFileContentPromise(filePath, "text");+ }- var directoyTree = [];- //console.log(JSON.stringify(directoyTree));- TSPOSTIO.createDirectoryTree(directoyTree);+ function getFileContent(filePath, result, error) {++ getFileContentPromise(filePath).then(result, error);};- var createDirectory = function(dirPath, silentMode) {- createDirectoryPromise(dirPath).then(function(dirPath) {+ function getFileContentPromise(filePath, type) {+ console.log("getFileContent file: " + filePath);+ return new Promise(function(resolve, reject) {+ var ajax = davClient.getAjax("GET", filePath);+ ajax.onreadystatechange = null;+ ajax.responseType = type || "arraybuffer";+ ajax.onerror = reject;++ ajax.onload = function() {+ var response = ajax.response || ajax.responseText;+ if (checkStatusCode(ajax.status)) {+ resolve(response);+ } else {+ reject("getFileContentPromise ajax error");+ }+ };+ ajax.send();+ });+ }+++ function saveFilePromise(filePath, content, overWrite, silentMod, mode) {+ return new Promise(function(resolve, reject) {+ var isNewFile = false;+ davClient.propfind(encodeURI(filePath), function(status, data) {+ console.log("Check file exists: Status / Content: " + status + " / " + data);+ if (parseInt(status) === 404) {+ isNewFile = true;+ }+ if (isNewFile || overWrite === true || mode === "text") {+ davClient.put(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ if (checkStatusCode(status)) {+ resolve(isNewFile);+ } else {+ reject("saveFilePromise: " + filePath + " failed " + status);+ }+ },+ content,+ 'application/octet-stream'+ );+ } else {+ reject("File Already Exists.");+ }+ }, 1);+ });+ }++ function saveTextFile(filePath, content, overWrite, silentMode) {+ console.log("Saving file: " + filePath); //+" content: "+content);+ saveFilePromise(filePath, content, overWrite, silentMode, "text").then(function(isNewFile) {if (silentMode !== true) {- TSPOSTIO.createDirectory(dirPath);+ TSPOSTIO.saveTextFile(filePath, isNewFile);}}, function(error) {- TSCORE.showAlertDialog("Creating directory" + dirPath + "failed");+ TSCORE.showAlertDialog("Save file " + filePath + " failed.");console.error(error);});};+ function saveBinaryFile(filePath, content, overWrite, silentMode) {+ console.log("Saving binary file: " + filePath); //+" content: "+content);+ saveFilePromise(filePath, content, overWrite, silentMode).then(function(isNewFile) {+ if (silentMode !== true) {+ TSPOSTIO.saveBinaryFile(filePath, isNewFile);+ }+ }, function(error) {+ TSCORE.showAlertDialog("Save file " + filePath + " failed.");+ console.error(error);+ }+ );+ };++function createDirectoryPromise(dirPath) {console.log("Creating directory: " + dirPath);return new Promise(function(resolve, reject) {@@ -213,167 +348,136 @@ define(function(require, exports, module) {});}- var copyFile = function(filePath, newFilePath) {- if (filePath.toLowerCase() === newFilePath.toLowerCase()) {- TSCORE.hideWaitingDialog();- TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotCopyied"));- return false;- }-- copyFilePromise(filePath, newFilePath).then(function(filePath, newFilePath) {- TSPOSTIO.copyFile(filePath, newFilePath);+ function createDirectory(dirPath, silentMode) {+ createDirectoryPromise(dirPath).then(function(dirPath) {+ if (silentMode !== true) {+ TSPOSTIO.createDirectory(dirPath);+ }}, function(error) {- TSCORE.hideWaitingDialog();- TSCORE.showAlertDialog($.i18n.t("ns.common:fileCopyFailed", {fileName:newFilePath}));+ TSCORE.showAlertDialog("Creating directory" + dirPath + "failed");console.error(error);});};+function copyFilePromise(filePath, newFilePath) {console.log("Copying file: " + filePath + " to " + newFilePath);return new Promise(function(resolve, reject) {- davClient.copy(- encodeURI(filePath),- function(status, data, headers) {- console.log("Copy File Status/Content/Headers: " + status + " / " + data + " / " + headers);- if (checkStatusCode(status)) {- resolve(filePath, newFilePath);- } else {- reject("copyFile " + filePath + " failed " + status);- }- },- encodeURI(newFilePath),- davClient.FAIL_ON_OVERWRITE- );+ if (filePath.toLowerCase() === newFilePath.toLowerCase()) {+ TSCORE.hideWaitingDialog();+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotCopyied"));+ reject($.i18n.t("ns.common:fileTheSame"));+ } else {+ davClient.copy(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Copy File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ if (checkStatusCode(status)) {+ resolve(filePath, newFilePath);+ } else {+ reject("copyFile " + filePath + " failed " + status);+ }+ },+ encodeURI(newFilePath),+ davClient.FAIL_ON_OVERWRITE+ );+ }});}- var renameFile = function(filePath, newFilePath) {- if (filePath === newFilePath) {- TSCORE.hideWaitingDialog();- TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotMoved"));- return false;- }-- renameFilePromise(filePath, newFilePath).then(function() {- TSPOSTIO.renameFile(filePath, newFilePath);- }, function(error) {- TSCORE.showAlertDialog("Renaming: " + filePath + " failed.");- console.error(error);- }- );- };-- var renameDirectory = function(dirPath, newDirName) {- var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + encodeURIComponent(newDirName);- renameDirectoryPromise(dirPath, newDirPath).then(function() {- TSPOSTIO.renameDirectory(dirPath, newDirName);+ function copyFile(filePath, newFilePath) {+ copyFilePromise(filePath, newFilePath).then(function(filePath, newFilePath) {+ TSPOSTIO.copyFile(filePath, newFilePath);}, function(error) {TSCORE.hideWaitingDialog();- TSCORE.showAlertDialog($.i18n.t("ns.common:pathIsNotDirectory", {dirName:dirPath}),- $.i18n.t("ns.common:directoryRenameFailed"));+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileCopyFailed", {fileName:newFilePath}));console.error(error);});};+function renameFilePromise(filePath, newFilePath) {console.log("Renaming file: " + filePath + " to " + newFilePath);- return renameDirectoryPromise(filePath, newFilePath);- }-- function renameDirectoryPromise(dirPath, newDirPath) {- console.log("Renaming directory: " + dirPath + " to " + newDirPath);return new Promise(function(resolve, reject){- davClient.move(- encodeURI(dirPath),- function(status, data, headers) {- console.log("Rename Directory Status/Content/Headers: " + status + " / " + data + " / " + headers);- if (checkStatusCode(status)) {- resolve([dirPath, newDirPath]);- } else {- reject("rename: " + dirPath + " failed " + status);- }- },- encodeURI(newDirPath),- davClient.FAIL_ON_OVERWRITE- );+ if (filePath === newFilePath) {+ TSCORE.hideWaitingDialog();+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotMoved"));+ reject($.i18n.t("ns.common:fileTheSame"));+ } else {+ davClient.move(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Rename File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ if (checkStatusCode(status)) {+ resolve([filePath, newFilePath]);+ } else {+ reject("rename: " + filePath + " failed " + status);+ }+ },+ encodeURI(newFilePath),+ davClient.FAIL_ON_OVERWRITE+ );+ }});}- var loadTextFile = function(filePath) {- console.log("Loading file: " + filePath);- loadTextFilePromise(filePath).then(function(data) {- TSPOSTIO.loadTextFile(data);+ function renameFile(filePath, newFilePath) {+ renameFilePromise(filePath, newFilePath).then(function() {+ TSPOSTIO.renameFile(filePath, newFilePath);}, function(error) {- TSCORE.showAlertDialog("Loading " + filePath + " failed.");+ TSCORE.showAlertDialog("Renaming: " + filePath + " failed.");console.error(error);});};- function loadTextFilePromise(filePath) {- return getFileContentPromise(filePath, "text");- }- var saveTextFile = function(filePath, content, overWrite, silentMode) {- console.log("Saving file: " + filePath); //+" content: "+content);- saveFilePromise(filePath, content, overWrite, silentMode, "text").then(function(isNewFile) {- if (silentMode !== true) {- TSPOSTIO.saveTextFile(filePath, isNewFile);- }- }, function(error) {- TSCORE.showAlertDialog("Save file " + filePath + " failed.");- console.error(error);+ function renameDirectoryPromise(dirPath, newDirName) {+ console.log("Renaming directory: " + dirPath + " to " + newDirName);+ return new Promise(function(resolve, reject){+ var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;+ if (dirPath === newDirPath) {+ TSCORE.hideWaitingDialog();+ TSCORE.showAlertDialog($.i18n.t("ns.common:fileTheSame"), $.i18n.t("ns.common:fileNotMoved"));+ reject($.i18n.t("ns.common:fileTheSame"));+ } else {+ davClient.move(+ encodeURI(dirPath),+ function(status, data, headers) {+ console.log("Rename Directory Status/Content/Headers: " + status + " / " + data + " / " + headers);+ if (checkStatusCode(status)) {+ resolve([dirPath, newDirPath]);+ } else {+ reject("rename: " + dirPath + " failed " + status);+ }+ },+ encodeURI(newDirPath),+ davClient.FAIL_ON_OVERWRITE+ );}- );- };+ });+ }- var saveBinaryFile = function(filePath, content, overWrite, silentMode) {- console.log("Saving binary file: " + filePath); //+" content: "+content);- saveFilePromise(filePath, content, overWrite, silentMode).then(function(isNewFile) {- if (silentMode !== true) {- TSPOSTIO.saveBinaryFile(filePath, isNewFile);- }+ function renameDirectory(dirPath, newDirName) {+ renameDirectoryPromise(dirPath, newDirName).then(function() {+ TSPOSTIO.renameDirectory(dirPath, newDirName);}, function(error) {- TSCORE.showAlertDialog("Save file " + filePath + " failed.");- console.error(error);+ TSCORE.hideWaitingDialog();+ TSCORE.showAlertDialog($.i18n.t("ns.common:pathIsNotDirectory", {dirName:dirPath}),+ $.i18n.t("ns.common:directoryRenameFailed"));});};- function saveFilePromise(filePath, content, overWrite, silentMod, mode) {- return new Promise(function(resolve, reject) {- var isNewFile = false;- davClient.propfind(encodeURI(filePath), function(status, data) {- console.log("Check file exists: Status / Content: " + status + " / " + data);- if (parseInt(status) === 404) {- isNewFile = true;- }- if (isNewFile || overWrite === true || mode === "text") {- davClient.put(- encodeURI(filePath),- function(status, data, headers) {- console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);- if (checkStatusCode(status)) {- resolve(isNewFile);- } else {- reject("saveFilePromise: " + filePath + " failed " + status);- }- },- content,- 'application/octet-stream'- );- } else {- reject("File Already Exists.");- }- }, 1);- });+ function deleteFilePromise(path) {+ //+ return deleteDirectoryPromise(path);}- var deleteElement = function(path) {+ function deleteElement(path) {console.log("Deleting: " + path);deleteDirectoryPromise(path).then(function() {TSPOSTIO.deleteElement(path);@@ -385,6 +489,7 @@ define(function(require, exports, module) {);};+function deleteDirectoryPromise(path) {return new Promise(function(resolve, reject) {davClient.remove(@@ -401,11 +506,7 @@ define(function(require, exports, module) {});}- function deleteFilePromise(path) {- return deleteDirectoryPromise(path);- }-- var deleteDirectory = function(path) {+ function deleteDirectory(path) {console.log("deleteDirectory: " + path);deleteDirectoryPromise(path).then(function() {TSPOSTIO.deleteDirectory(path);@@ -417,111 +518,70 @@ define(function(require, exports, module) {);};- var checkAccessFileURLAllowed = function() {- console.log("checkAccessFileURLAllowed function not relevant for webdav..");- };-- var checkNewVersion = function() {- console.log("Checking for new version not relevant fot the webdav version");- };- var selectDirectory = function() {+ function selectDirectory() {+ //TSCORE.showAlertDialog("Select directory is still not implemented in the webdav edition");};- var openDirectory = function(dirPath) {- console.log("openDirectory function not relevant for webdav..");+ function selectFile() {+ //+ TSCORE.showAlertDialog("selectFile not relevant for webdav");};- var openFile = function(filePath) {- console.log("openFile function not relevant for webdav..");- };- var selectFile = function() {- console.log("selectFile function not relevant for webdav..");+ function openDirectory(dirPath) {+ //+ TSCORE.showAlertDialog("openDirectory not relevant for webdav.");};- var getFileProperties = function(filePath) {- getFilePropertiesPromise(filePath).then(function(fileProperties) {- TSPOSTIO.getFileProperties(fileProperties);- }, function(error) {- TSCORE.hideLoadingAnimation();- TSCORE.closeFileViewer();- TSCORE.showAlertDialog("File " + filePath + " get properties failed");- console.error(error);- }- );+ function openFile(filePath) {+ //+ TSCORE.showAlertDialog("openFile not relevant for webdav");};- function getFilePropertiesPromise(filePath) {- return new Promise(function(resolve, reject) {- davClient.propfind(encodeURI(filePath), function(status, data) {- console.log("Properties Status / Content: " + status + " / " + JSON.stringify(data._responses));- var fileProperties = {};- if (checkStatusCode(status)) {- for (var entry in data._responses) {- fileProperties.path = filePath;- fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;- fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;- }- resolve(fileProperties);- } else {- reject("getFileProperties " + filePath + " failed " + status);- }- }, 1);- });- }-- // Bring the TagSpaces window on top of the windows- var focusWindow = function() {- window.focus();- };+ exports.focusWindow = focusWindow;+ exports.checkNewVersion = checkNewVersion;- var getFileContent = function(filePath, result, error) {- getFileContentPromise(filePath).then(result, error);- };+ exports.createDirectoryIndex = createDirectoryIndex;+ exports.createDirectoryTree = createDirectoryTree;- function getFileContentPromise(filePath, type) {- console.log("getFileContent file: " + filePath);- return new Promise(function(resolve, reject) {- var ajax = davClient.getAjax("GET", filePath);- ajax.onreadystatechange = null;- ajax.responseType = type || "arraybuffer";- ajax.onerror = reject;+ exports.listDirectoryPromise = listDirectoryPromise;+ exports.listDirectory = listDirectory;- ajax.onload = function() {- var response = ajax.response || ajax.responseText;- if (checkStatusCode(ajax.status)) {- resolve(response);- } else {- reject("getFileContentPromise ajax error");- }- };- ajax.send();- });- }+ exports.getPropertiesPromise = getPropertiesPromise;+ exports.getFileProperties = getFileProperties; /** @deprecated */- exports.focusWindow = focusWindow;- exports.createDirectory = createDirectory;- exports.copyFile = copyFile;- exports.renameFile = renameFile;- exports.renameDirectory = renameDirectory;exports.loadTextFile = loadTextFile;- exports.saveTextFile = saveTextFile;- exports.saveBinaryFile = saveBinaryFile;- exports.listDirectory = listDirectory;- exports.deleteElement = deleteElement;- exports.deleteDirectory = deleteDirectory;- exports.createDirectoryIndex = createDirectoryIndex;- exports.createDirectoryTree = createDirectoryTree;+ exports.getFileContent = getFileContent;+ exports.getFileContentPromise = getFileContentPromise;++ exports.saveFilePromise = saveFilePromise;+ exports.saveTextFile = saveTextFile; /** @deprecated */+ exports.saveBinaryFile = saveBinaryFile; /** @deprecated */++ exports.createDirectoryPromise = createDirectoryPromise;+ exports.createDirectory = createDirectory; /** @deprecated */++ exports.copyFilePromise = copyFilePromise;+ exports.copyFile = copyFile; /** @deprecated */++ exports.renameFilePromise = renameFilePromise;+ exports.renameFile = renameFile; /** @deprecated */++ exports.renameDirectoryPromise = renameDirectoryPromise;+ exports.renameDirectory = renameDirectory; /** @deprecated */++ exports.deleteFilePromise = deleteFilePromise;+ exports.deleteElement = deleteElement; /** @deprecated */++ exports.deleteDirectoryPromise = deleteDirectoryPromise;+ exports.deleteDirectory = deleteDirectory; /** @deprecated */+exports.selectDirectory = selectDirectory;+ exports.selectFile = selectFile;+exports.openDirectory = openDirectory;exports.openFile = openFile;- exports.selectFile = selectFile;- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;- exports.checkNewVersion = checkNewVersion;- exports.getFileProperties = getFileProperties;- exports.getFileContent = getFileContent;- exports.listDirectoryPromise = listDirectoryPromise;- exports.getFileContentPromise = getFileContentPromise;+});