Skip to content

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

fixing issue with sidecar files

uggrock3339d495bf87
diff --git a/data/js/core.api.js b/data/js/core.api.js
index 960171bfa..ba46fd5c0 100644
--- a/data/js/core.api.js
+++ b/data/js/core.api.js
@@ -310,7 +310,7 @@ define(function(require, exports, module) {
}
function updateFileModel(model, oldPath, newPath) {
- console.log('Removing file from model');
+ console.log('Updating file from model');
var title = tsTagUtils.extractTitle(newPath),
fileExt = tsTagUtils.extractFileExtension(newPath),
fileTags = tsTagUtils.extractTags(newPath);
diff --git a/data/js/core.ui.js b/data/js/core.ui.js
index 0f8b2896d..86a76fc59 100644
--- a/data/js/core.ui.js
+++ b/data/js/core.ui.js
@@ -360,6 +360,8 @@ define(function(require, exports) {
initTagEditDialog();
+ initFileRenameDialog();
+
TSCORE.Calendar.initCalendarUI();
// Hide drop downs by click and drag
@@ -473,6 +475,7 @@ define(function(require, exports) {
}
function showAlertDialog(message, title) {
+ console.warn(message + ' - ' + title);
if (!title) {
title = $.i18n.t('ns.dialogs:titleAlert');
}
@@ -494,22 +497,6 @@ define(function(require, exports) {
maxVisible: 4,
closeWith: ['button', 'click'],
});
- /*var alertModal = $('#alertDialog');
- alertModal.find('h4').text(title);
- alertModal.find('.modal-body').empty();
- alertModal.find('.modal-body').text(message);
- alertModal.find('#okButton').off('click').click(function() {
- alertModal.modal('hide');
- });
- // Focusing the ok button by default
- alertModal.off('shown.bs.modal');
- alertModal.on('shown.bs.modal', function() {
- alertModal.find('#okButton').focus();
- });
- alertModal.modal({
- backdrop: 'static',
- show: true
- });*/
}
function showConfirmDialog(title, message, okCallback, cancelCallback, confirmShowNextTime) {
@@ -619,26 +606,14 @@ define(function(require, exports) {
});
}
- function showFileRenameDialog(filePath) {
- if (!filePath) {
- filePath = TSCORE.selectedFiles[0];
- }
- if (!filePath) {
- TSCORE.showAlertDialog("Please select a file first.", "Renaming not possible!");
- return false;
- }
- $('#renamedFileName').attr('filepath', filePath);
- //$('#renamedFileName').on("keydown", function(e) {
- // e.preventDefault();
- //})
- $('#renamedFileName').val(TSCORE.TagUtils.extractFileName(filePath));
- $('#formFileRename').validator();
- $('#formFileRename').submit(function(e) {
+ function initFileRenameDialog() {
+ $('#formFileRename').on('submit', function(e) {
e.preventDefault();
if ($('#renameFileButton').prop('disabled') === false) {
$('#renameFileButton').click();
}
});
+ $('#formFileRename').validator();
$('#formFileRename').on('invalid.bs.validator', function() {
$('#renameFileButton').prop('disabled', true);
});
@@ -648,13 +623,25 @@ define(function(require, exports) {
$('#dialogFileRename').on('shown.bs.modal', function() {
$('#renamedFileName').focus();
});
+ $('#dialogFileRename').draggable({
+ handle: ".modal-header"
+ });
+ }
+
+ function showFileRenameDialog(filePath) {
+ if (!filePath) {
+ filePath = TSCORE.selectedFiles[0];
+ }
+ if (!filePath) {
+ TSCORE.showAlertDialog("Please select a file first.", "Renaming not possible!");
+ return false;
+ }
+ $('#renamedFileName').attr('filepath', filePath);
+ $('#renamedFileName').val(TSCORE.TagUtils.extractFileName(filePath));
$('#dialogFileRename').modal({
backdrop: 'static',
show: true
});
- $('#dialogFileRename').draggable({
- handle: ".modal-header"
- });
}
function showFileDeleteDialog(filePath) {
diff --git a/data/js/meta.js b/data/js/meta.js
index ed89d377d..5eb6f8c3f 100644
--- a/data/js/meta.js
+++ b/data/js/meta.js
@@ -70,8 +70,8 @@ define(function(require, exports, module) {
TSCORE.IO.saveTextFilePromise(metaFilePath, content, true);
}
- function updateMetaData(sourceFileName, targetFileName) {
- if (!targetFileName || !sourceFileName) {
+ function updateMetaData(sourceFilePath, targetFilePath) {
+ if (!targetFilePath || !sourceFilePath) {
return false;
}
@@ -79,41 +79,39 @@ define(function(require, exports, module) {
TSCORE.IO.stopWatchingDirectories();
}
- var name = TSCORE.Utils.baseName(sourceFileName);
var fileInMetaFileList = false;
- TSCORE.metaFileList.forEach(function(element, index) {
- if (element.name.indexOf(name) >= 0) {
+ var sourceFileName = TSCORE.Utils.baseName(sourceFilePath);
+ var pathSource = TSCORE.Utils.dirName(sourceFilePath);
+ var pathTarget = TSCORE.Utils.dirName(targetFilePath);
+ TSCORE.metaFileList.forEach(function(metaElement, index) {
+ if (metaElement.name.indexOf(sourceFileName) === 0) {
fileInMetaFileList = true;
- var pathSource = TSCORE.Utils.dirName(sourceFileName);
- var pathTarget = TSCORE.Utils.dirName(targetFileName);
- if (pathTarget.lastIndexOf(TSCORE.dirSeparator) === 0) {
- pathSource = pathSource + TSCORE.dirSeparator;
- }
+ var targetMetaName = TSCORE.Utils.baseName(targetFilePath) + "." + TSCORE.TagUtils.extractFileExtension(metaElement.name);
+ var targetMetaFolderPath = pathTarget + TSCORE.dirSeparator + TSCORE.metaFolder;
+ var targetMetaFilePath = targetMetaFolderPath + TSCORE.dirSeparator + targetMetaName;
+ var sourceMetaFilePath = pathSource + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + metaElement.name;
- var targetName = TSCORE.Utils.baseName(targetFileName) + "." + element.name.split('.').pop();
- var targetFilePath = pathTarget + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + targetName;
+ if (pathSource === pathTarget) {
+ metaElement.name = targetMetaName;
+ metaElement.path = targetMetaFilePath;
+ } else {
+ TSCORE.metaFileList.splice(index, 1);
+ }
createMetaFolderPromise(pathTarget).then(function() {
- TSCORE.IO.renameFilePromise(element.path, targetFilePath).then(function() {
- if (pathSource == TSCORE.currentPath) {
- element.name = targetName;
- element.path = targetFilePath;
- } else {
- TSCORE.metaFileList.splice(index, 1);
- }
+ TSCORE.IO.renameFilePromise(sourceMetaFilePath, targetMetaFilePath).then(function() {
+ console.log('Meta file moved/renamed successfully to ' + targetMetaFilePath);
});
});
-
-
}
});
if (!fileInMetaFileList) { // file is probably from a search list
- var sourcePathTemplate = TSCORE.Utils.dirName(sourceFileName) + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + TSCORE.Utils.baseName(sourceFileName);
- var targetPathTemplate = TSCORE.Utils.dirName(targetFileName) + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + TSCORE.Utils.baseName(targetFileName);
- TSCORE.IO.renameFilePromise(sourcePathTemplate + TSCORE.metaFileExt, targetPathTemplate + TSCORE.metaFileExt);
- TSCORE.IO.renameFilePromise(sourcePathTemplate + TSCORE.thumbFileExt, targetPathTemplate + TSCORE.thumbFileExt);
- TSCORE.IO.renameFilePromise(sourcePathTemplate + TSCORE.contentFileExt, targetPathTemplate + TSCORE.contentFileExt);
+ var sourceMetaPathTemplate = pathSource + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + TSCORE.Utils.baseName(sourceFilePath);
+ var targetMetaPathTemplate = pathTarget + TSCORE.dirSeparator + TSCORE.metaFolder + TSCORE.dirSeparator + TSCORE.Utils.baseName(targetFilePath);
+ TSCORE.IO.renameFilePromise(sourceMetaPathTemplate + TSCORE.metaFileExt, targetMetaPathTemplate + TSCORE.metaFileExt);
+ TSCORE.IO.renameFilePromise(sourceMetaPathTemplate + TSCORE.thumbFileExt, targetMetaPathTemplate + TSCORE.thumbFileExt);
+ TSCORE.IO.renameFilePromise(sourceMetaPathTemplate + TSCORE.contentFileExt, targetMetaPathTemplate + TSCORE.contentFileExt);
}
}
@@ -384,6 +382,7 @@ define(function(require, exports, module) {
return new Promise(function(resolve, reject) {
if (dirPath.lastIndexOf(TSCORE.metaFolder) >= dirPath.length - TSCORE.metaFolder.length) {
console.log("Can not create meta folder in a meta folder");
+ reject();
return;
}
var metaDirPath = dirPath + TSCORE.dirSeparator + TSCORE.metaFolder;