Skip to content

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

fixing undefined in the file name #430

uggrock63ce2b0b9d24
diff --git a/data/js/tagutils.js b/data/js/tagutils.js
index 9cc41079b..33b2ac7a5 100644
--- a/data/js/tagutils.js
+++ b/data/js/tagutils.js
@@ -301,14 +301,20 @@ define(function(require, exports, module) {
// Internal
function generateFileName(fileName, tags) {
var tagsString = '';
+ var tagDelimiter = TSCORE.Config.getTagDelimiter() || " ";
+ var prefixTagContainer = TSCORE.Config.getPrefixTagContainer() || "";
+
// Creating the string will all the tags by more that 0 tags
- if (tags.length > 0) {
+ if (tags && tags.length > 0) {
tagsString = BEGIN_TAG_CONTAINER;
for (var i = 0; i < tags.length; i++) {
- tagsString += tags[i] + TSCORE.Config.getTagDelimiter();
+ if(i === tags.length-1) {
+ tagsString = tagsString + tags[i].trim();
+ } else {
+ tagsString = tagsString + tags[i].trim() + tagDelimiter;
+ }
}
- tagsString = tagsString.trim();
- tagsString += END_TAG_CONTAINER;
+ tagsString = tagsString.trim() + END_TAG_CONTAINER;
}
console.log('The tags string: ' + tagsString);
var fileExt = extractFileExtension(fileName);
@@ -322,18 +328,20 @@ define(function(require, exports, module) {
// Filename does not contains tags.
if (lastDotPosition < 0) {
// File does not have an extension
- newFileName = fileName + tagsString;
+ newFileName = fileName.trim() + tagsString;
} else {
// File has an extension
- newFileName = fileName.substring(0, lastDotPosition) + TSCORE.Config.getPrefixTagContainer() + tagsString + '.' + fileExt;
+ newFileName = fileName.substring(0, lastDotPosition).trim() + prefixTagContainer + tagsString + '.' + fileExt;
}
} else {
// File does not have an extension
- newFileName = fileName.substring(0, beginTagContainer) + tagsString + fileName.substring(endTagContainer + 1, fileName.length);
+ newFileName = fileName.substring(0, beginTagContainer).trim() + prefixTagContainer + tagsString + fileName.substring(endTagContainer + 1, fileName.length).trim();
}
if (newFileName.length < 1) {
throw 'Generated filename is invalid';
}
+ // Removing double prefix
+ newFileName = newFileName.split(prefixTagContainer + "" + prefixTagContainer).join(prefixTagContainer);
return newFileName;
}
diff --git a/data/templates/OptionsDialog.html b/data/templates/OptionsDialog.html
index ddcddb14c..274394b77 100644
--- a/data/templates/OptionsDialog.html
+++ b/data/templates/OptionsDialog.html
@@ -163,11 +163,19 @@
</div>
<div class='form-group col-sm-12'>
<label for='tagsDelimiterInput' data-i18n="ns.dialogs:tagDelimiter"></label>
- <input type='text' class='form-control' id='tagsDelimiterInput' />
+ <select class="form-control" id='tagsDelimiterInput'>
+ <option value=' ' selected='selected'>space (&nbsp;&nbsp;) - recommended</option>
+ <option value='_'>underscore ( _ )</option>
+ <option value=','>comma ( , )</option>
+ </select>
</div>
<div class='form-group col-sm-12'>
<label for='prefixTagContainerInput' data-i18n="ns.dialogs:prefixTagContainer"></label>
- <input type='text' class='form-control' id='prefixTagContainerInput' />
+ <select class="form-control" id='prefixTagContainerInput'>
+ <option value='' selected='selected'>no prefix - recommended</option>
+ <option value=' '>space (&nbsp;&nbsp;)</option>
+ <option value='_'>underdscore ( _ )</option>
+ </select>
</div>
<!--div class='form-group col-sm-12'>
<label for='extensionsPathInput' data-i18n="ns.dialogs:extensionsFolder"></label>