Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Add option to append tags #339

Merged
merged 6 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/main/lychee_locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ lychee.locale = {
PHOTOS_NEW_TAGS:
"Enter your tags for all %d selected photos. Existing tags will be overwritten. You can add multiple tags by separating them with a comma:",
PHOTO_SET_TAGS: "Set Tags",
TAGS_OVERRIDE_INFO: "If this is unchecked, the tags will be added to the existing tags of the photo.",
PHOTO_CAMERA: "Camera",
PHOTO_CAPTURED: "Captured",
PHOTO_MAKE: "Make",
Expand Down Expand Up @@ -294,6 +295,7 @@ lychee.locale = {
ERROR_SEARCH_DEACTIVATED: "Search functionality has been deactivated under settings.",
SUCCESS: "OK",
RETRY: "Retry",
OVERRIDE: "Override",

SETTINGS_SUCCESS_LOGIN: "Login Info updated.",
SETTINGS_SUCCESS_SORT: "Sorting order updated.",
Expand Down
18 changes: 13 additions & 5 deletions scripts/main/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ photo.editTags = function (photoIDs) {
}

/**
* @param {{tags: string}} data
* @param {{tags: string,override: boolean}} data
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
* @returns {void}
*/
const action = function (data) {
Expand All @@ -803,13 +803,18 @@ photo.editTags = function (photoIDs) {
.map((tag) => tag.trim())
.filter((tag) => tag !== "" && tag.indexOf(",") === -1)
.sort();
photo.setTags(photoIDs, newTags);
photo.setTags(photoIDs, newTags, data.override);
};

const setTagDialogBody = `
<p></p>
<form>
<div class="input-group stacked"><input class='text' name='tags' type='text' minlength='1'></div>
<div class='input-group compact-inverse'>
<label for="override">${lychee.locale["OVERRIDE"]}</label>
<input type='checkbox' id='tag_dialog_override_input' name='override' />
<p>${lychee.locale["TAGS_OVERRIDE_INFO"]}</p>
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</form>`;

/**
Expand All @@ -822,6 +827,7 @@ photo.editTags = function (photoIDs) {
photoIDs.length === 1 ? lychee.locale["PHOTO_NEW_TAGS"] : sprintf(lychee.locale["PHOTOS_NEW_TAGS"], photoIDs.length);
formElements.tags.placeholder = "Tags";
formElements.tags.value = oldTags.join(", ");
formElements.override.checked = true;
};

basicModal.show({
Expand All @@ -843,11 +849,12 @@ photo.editTags = function (photoIDs) {
/**
* @param {string[]} photoIDs
* @param {string[]} tags
* @param {boolean} shall_override
* @returns {void}
*/
photo.setTags = function (photoIDs, tags) {
photo.setTags = function (photoIDs, tags, shall_override) {
if (visible.photo()) {
photo.json.tags = tags;
photo.json.tags = override ? tags : photo.json.tags.concat(tags.filter((t) => !photo.json.tags.includes(t)));
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
view.photo.tags();
}

Expand All @@ -860,6 +867,7 @@ photo.setTags = function (photoIDs, tags) {
{
photoIDs: photoIDs,
tags: tags,
shall_override: shall_override,
},
function () {
// If we have any tag albums, force a refresh.
Expand All @@ -878,7 +886,7 @@ photo.setTags = function (photoIDs, tags) {
*/
photo.deleteTag = function (photoID, index) {
photo.json.tags.splice(index, 1);
photo.setTags([photoID], photo.json.tags);
photo.setTags([photoID], photo.json.tags, true);
};

/**
Expand Down