From b4cbfc4fe4aeab21b95ad14df666960ac2b2be9a Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Fri, 21 Oct 2022 17:44:57 +0200 Subject: [PATCH] Add option to append tags (#1564) * Add option to append tags * Add test * Fix phpdoc comment * Rename into `shall_override` and other review fixes * Sync frontend * Sync frontend * Fix missing locales * Sync frontend --- app/Http/Controllers/PhotoController.php | 7 +++++- .../Requests/Photo/SetPhotosTagsRequest.php | 6 +++++ app/Locale/ChineseSimplified.php | 2 ++ app/Locale/ChineseTraditional.php | 2 ++ app/Locale/Czech.php | 2 ++ app/Locale/Dutch.php | 2 ++ app/Locale/English.php | 2 ++ app/Locale/French.php | 2 ++ app/Locale/German.php | 2 ++ app/Locale/Greek.php | 2 ++ app/Locale/Italian.php | 2 ++ app/Locale/NorwegianBokmal.php | 2 ++ app/Locale/Polish.php | 2 ++ app/Locale/Portuguese.php | 2 ++ app/Locale/Russian.php | 2 ++ app/Locale/Slovak.php | 2 ++ app/Locale/Spanish.php | 2 ++ app/Locale/Swedish.php | 2 ++ app/Locale/Vietnamese.php | 2 ++ public/Lychee-front | 2 +- public/dist/leaflet.markercluster.js.map | 0 public/dist/main.js | 22 +++++++++++++------ public/dist/view.js | 2 ++ tests/Feature/Lib/PhotosUnitTest.php | 3 +++ tests/Feature/PhotosOperationsTest.php | 3 ++- 25 files changed, 69 insertions(+), 10 deletions(-) mode change 100644 => 100755 public/dist/leaflet.markercluster.js.map diff --git a/app/Http/Controllers/PhotoController.php b/app/Http/Controllers/PhotoController.php index c26d64748e3..9b27fcab677 100644 --- a/app/Http/Controllers/PhotoController.php +++ b/app/Http/Controllers/PhotoController.php @@ -219,9 +219,14 @@ public function setPublic(SetPhotoPublicRequest $request): void public function setTags(SetPhotosTagsRequest $request): void { $tags = $request->tags(); + /** @var Photo $photo */ foreach ($request->photos() as $photo) { - $photo->tags = $tags; + if ($request->shallOverride) { + $photo->tags = $tags; + } else { + $photo->tags = array_unique(array_merge($photo->tags, $tags)); + } $photo->save(); } } diff --git a/app/Http/Requests/Photo/SetPhotosTagsRequest.php b/app/Http/Requests/Photo/SetPhotosTagsRequest.php index a186c28e715..df09a36d8c3 100644 --- a/app/Http/Requests/Photo/SetPhotosTagsRequest.php +++ b/app/Http/Requests/Photo/SetPhotosTagsRequest.php @@ -17,12 +17,17 @@ class SetPhotosTagsRequest extends BaseApiRequest implements HasPhotos, HasTags use HasTagsTrait; use AuthorizeCanEditPhotosTrait; + public const SHALL_OVERRIDE_ATTRIBUTE = 'shall_override'; + + public bool $shallOverride; + /** * {@inheritDoc} */ public function rules(): array { return [ + self::SHALL_OVERRIDE_ATTRIBUTE => 'required|boolean', HasPhotos::PHOTO_IDS_ATTRIBUTE => 'required|array|min:1', HasPhotos::PHOTO_IDS_ATTRIBUTE . '.*' => ['required', new RandomIDRule(false)], HasTags::TAGS_ATTRIBUTE => 'present|array', @@ -37,5 +42,6 @@ protected function processValidatedValues(array $values, array $files): void { $this->photos = Photo::query()->findOrFail($values[HasPhotos::PHOTO_IDS_ATTRIBUTE]); $this->tags = $values[HasTags::TAGS_ATTRIBUTE]; + $this->shallOverride = $values[self::SHALL_OVERRIDE_ATTRIBUTE]; } } \ No newline at end of file diff --git a/app/Locale/ChineseSimplified.php b/app/Locale/ChineseSimplified.php index 7d1d43a56aa..87f07229077 100644 --- a/app/Locale/ChineseSimplified.php +++ b/app/Locale/ChineseSimplified.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => '搜索功能已在设置中停用。', 'SUCCESS' => 'OK', 'RETRY' => '重试', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => '登录信息已更新.', 'SETTINGS_SUCCESS_SORT' => '排序顺序已更新。', diff --git a/app/Locale/ChineseTraditional.php b/app/Locale/ChineseTraditional.php index 2dcabca6f2a..54593078b6e 100644 --- a/app/Locale/ChineseTraditional.php +++ b/app/Locale/ChineseTraditional.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => '搜索功能已在設為停用。', 'SUCCESS' => '好', 'RETRY' => '重試', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => '登錄信息已更新', 'SETTINGS_SUCCESS_SORT' => '排序順序已更新。', diff --git a/app/Locale/Czech.php b/app/Locale/Czech.php index 60c3f30b9fb..fa8d5e3ad13 100644 --- a/app/Locale/Czech.php +++ b/app/Locale/Czech.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Funkce hledání byla v nastavení deaktivována.', 'SUCCESS' => 'OK', 'RETRY' => 'Opakovat', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Přihlašovací údaje byly aktualizovány.', 'SETTINGS_SUCCESS_SORT' => 'Stav řazení byl aktulizován.', diff --git a/app/Locale/Dutch.php b/app/Locale/Dutch.php index 4bcd5da3704..1572c919989 100644 --- a/app/Locale/Dutch.php +++ b/app/Locale/Dutch.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Probeer opnieuw', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Login Info updated.', 'SETTINGS_SUCCESS_SORT' => 'Sorting order updated.', diff --git a/app/Locale/English.php b/app/Locale/English.php index 5dced1c9ba4..dc21537b33c 100644 --- a/app/Locale/English.php +++ b/app/Locale/English.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Retry', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Login Info updated.', 'SETTINGS_SUCCESS_SORT' => 'Sorting order updated.', diff --git a/app/Locale/French.php b/app/Locale/French.php index 603b7857c1d..bb56e4eec9e 100644 --- a/app/Locale/French.php +++ b/app/Locale/French.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'La recherche a été désactivée dans les paramètres.', 'SUCCESS' => 'OK', 'RETRY' => 'Réessayer', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Informations de connexions mise à jour.', 'SETTINGS_SUCCESS_SORT' => 'Ordre d’affichage mis à jour.', diff --git a/app/Locale/German.php b/app/Locale/German.php index f04e37783b6..c7a66750d86 100644 --- a/app/Locale/German.php +++ b/app/Locale/German.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Suchfunktion wurde unter Einstellungen deaktiviert.', 'SUCCESS' => 'OK', 'RETRY' => 'Noch einmal versuchen', + 'OVERRIDE' => 'Überschreiben', + 'TAGS_OVERRIDE_INFO' => 'Wenn das nicht aktiviert ist, werden die Tags zu den vorhandenen Tags des Fotos hinzugefügt.', 'SETTINGS_SUCCESS_LOGIN' => 'Benutzerdaten aktualisiert', 'SETTINGS_SUCCESS_SORT' => 'Sortierreihenfolge aktualisiert', diff --git a/app/Locale/Greek.php b/app/Locale/Greek.php index f4c67bb3057..bf8697bb83e 100644 --- a/app/Locale/Greek.php +++ b/app/Locale/Greek.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Προσπάθεια ξανά', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Τα στοιχεία εισόδου ενημερώθηκαν.', 'SETTINGS_SUCCESS_SORT' => 'Η Ταξινόμηση ενημερώθηκε.', diff --git a/app/Locale/Italian.php b/app/Locale/Italian.php index 0f30f817b42..7dbedb8eeac 100644 --- a/app/Locale/Italian.php +++ b/app/Locale/Italian.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Riprova', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Informazioni di Login Aggiornate.', 'SETTINGS_SUCCESS_SORT' => 'Modalità di ordinamento aggiornate.', diff --git a/app/Locale/NorwegianBokmal.php b/app/Locale/NorwegianBokmal.php index 4f6b13691c3..7c5dfd34275 100644 --- a/app/Locale/NorwegianBokmal.php +++ b/app/Locale/NorwegianBokmal.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Søkefunksjoner har blitt deaktivert under innstillinger', 'SUCCESS' => 'OK', 'RETRY' => 'Prøv igjen', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Innlogging oppdatert.', 'SETTINGS_SUCCESS_SORT' => 'Sorteringsrekkefølge oppdatert.', diff --git a/app/Locale/Polish.php b/app/Locale/Polish.php index 5d4a5048c2d..bb956023b20 100644 --- a/app/Locale/Polish.php +++ b/app/Locale/Polish.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Funkcja wyszkukiwania została wyłączona w ustawieniach.', 'SUCCESS' => 'OK', 'RETRY' => 'Ponów', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Zaktualizowano informacje o loginie.', 'SETTINGS_SUCCESS_SORT' => 'Zaktualizowano kolejność sortowania.', diff --git a/app/Locale/Portuguese.php b/app/Locale/Portuguese.php index dc741a2314b..82a456cf6a2 100644 --- a/app/Locale/Portuguese.php +++ b/app/Locale/Portuguese.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'A funcionalidade de procura foi desativada nas configurações.', 'SUCCESS' => 'OK', 'RETRY' => 'Tentar de novo', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Informação de Login atualizada.', 'SETTINGS_SUCCESS_SORT' => 'Ordenação atualizada.', diff --git a/app/Locale/Russian.php b/app/Locale/Russian.php index a678dee1fe7..860145d44db 100644 --- a/app/Locale/Russian.php +++ b/app/Locale/Russian.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'Ок', 'RETRY' => 'Повторить', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Учётные данные обновлены.', 'SETTINGS_SUCCESS_SORT' => 'Порядок сортировки обновлён.', diff --git a/app/Locale/Slovak.php b/app/Locale/Slovak.php index 89df6b5bf5f..a9ead834756 100644 --- a/app/Locale/Slovak.php +++ b/app/Locale/Slovak.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Opakovať', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Užívateľské dáta aktualizované', 'SETTINGS_SUCCESS_SORT' => 'Triedenie aktualizované', diff --git a/app/Locale/Spanish.php b/app/Locale/Spanish.php index 66c9551b6cb..bf833961616 100644 --- a/app/Locale/Spanish.php +++ b/app/Locale/Spanish.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'La función de búsqueda se ha desactivado en la configuración.', 'SUCCESS' => 'Vale', 'RETRY' => 'Procesar de nuevo', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Información de inicio de sesión actualizada', 'SETTINGS_SUCCESS_SORT' => 'Orden de clasificación actualizado', diff --git a/app/Locale/Swedish.php b/app/Locale/Swedish.php index 05faa01e09c..e27a38694e9 100644 --- a/app/Locale/Swedish.php +++ b/app/Locale/Swedish.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Search functionality has been deactivated under settings.', 'SUCCESS' => 'OK', 'RETRY' => 'Försök igen', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Login Info updated.', 'SETTINGS_SUCCESS_SORT' => 'Sorting order updated.', diff --git a/app/Locale/Vietnamese.php b/app/Locale/Vietnamese.php index e8b8a29fe94..5b4e2467c33 100644 --- a/app/Locale/Vietnamese.php +++ b/app/Locale/Vietnamese.php @@ -297,6 +297,8 @@ public function get_locale(): array 'ERROR_SEARCH_DEACTIVATED' => 'Tính năng tìm kiếm đã tắt trong phần cài đặt', 'SUCCESS' => 'OK', 'RETRY' => 'Thử lại', + 'OVERRIDE' => 'Override', + 'TAGS_OVERRIDE_INFO' => 'If this is unchecked, the tags will be added to the existing tags of the photo.', 'SETTINGS_SUCCESS_LOGIN' => 'Thông tin đăng nhập đã được cập nhật.', 'SETTINGS_SUCCESS_SORT' => 'Thứ tự sắp xếp đã được cập nhật.', diff --git a/public/Lychee-front b/public/Lychee-front index 5cadab5233a..bf7178e4de8 160000 --- a/public/Lychee-front +++ b/public/Lychee-front @@ -1 +1 @@ -Subproject commit 5cadab5233a78b9bf408e1468a7e890ccdb7041b +Subproject commit bf7178e4de8766ca9917b41de3a8ddee2645c68e diff --git a/public/dist/leaflet.markercluster.js.map b/public/dist/leaflet.markercluster.js.map old mode 100644 new mode 100755 diff --git a/public/dist/main.js b/public/dist/main.js index 0ebc54e336a..a791732739a 100644 --- a/public/dist/main.js +++ b/public/dist/main.js @@ -7054,6 +7054,7 @@ lychee.locale = { PHOTO_NEW_TAGS: "Enter your tags for this photo. You can add multiple tags by separating them with a comma:", 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", @@ -7100,6 +7101,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.", @@ -9092,7 +9094,7 @@ _photo3.editTags = function (photoIDs) { } /** - * @param {{tags: string}} data + * @param {{tags: string, override: boolean}} data * @returns {void} */ var action = function action(data) { @@ -9102,10 +9104,10 @@ _photo3.editTags = function (photoIDs) { }).filter(function (tag) { return tag !== "" && tag.indexOf(",") === -1; }).sort(); - _photo3.setTags(photoIDs, newTags); + _photo3.setTags(photoIDs, newTags, data.override); }; - var setTagDialogBody = "\n\t\t
\n\t\t"; + var setTagDialogBody = "\n\t\t\n\t\t"; /** * @param {ModalDialogFormElements} formElements @@ -9116,6 +9118,8 @@ _photo3.editTags = function (photoIDs) { dialog.querySelector("p").textContent = 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.previousElementSibling.textContent = lychee.locale["OVERRIDE"]; + formElements.override.nextElementSibling.textContent = lychee.locale["TAGS_OVERRIDE_INFO"]; }; basicModal.show({ @@ -9137,11 +9141,14 @@ _photo3.editTags = function (photoIDs) { /** * @param {string[]} photoIDs * @param {string[]} tags + * @param {boolean} shall_override * @returns {void} */ -_photo3.setTags = function (photoIDs, tags) { +_photo3.setTags = function (photoIDs, tags, shall_override) { if (visible.photo()) { - _photo3.json.tags = tags; + _photo3.json.tags = shall_override ? tags : _photo3.json.tags.concat(tags.filter(function (t) { + return !_photo3.json.tags.includes(t); + })); view.photo.tags(); } @@ -9151,7 +9158,8 @@ _photo3.setTags = function (photoIDs, tags) { api.post("Photo::setTags", { photoIDs: photoIDs, - tags: tags + tags: tags, + shall_override: shall_override }, function () { // If we have any tag albums, force a refresh. if (albums.json && albums.json.tag_albums.length !== 0) { @@ -9168,7 +9176,7 @@ _photo3.setTags = function (photoIDs, tags) { */ _photo3.deleteTag = function (photoID, index) { _photo3.json.tags.splice(index, 1); - _photo3.setTags([photoID], _photo3.json.tags); + _photo3.setTags([photoID], _photo3.json.tags, true); }; /** diff --git a/public/dist/view.js b/public/dist/view.js index 285a6457eee..8052550db6b 100644 --- a/public/dist/view.js +++ b/public/dist/view.js @@ -2865,6 +2865,7 @@ lychee.locale = { PHOTO_NEW_TAGS: "Enter your tags for this photo. You can add multiple tags by separating them with a comma:", 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", @@ -2911,6 +2912,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.", diff --git a/tests/Feature/Lib/PhotosUnitTest.php b/tests/Feature/Lib/PhotosUnitTest.php index f34bd2010be..9bb7d121c07 100644 --- a/tests/Feature/Lib/PhotosUnitTest.php +++ b/tests/Feature/Lib/PhotosUnitTest.php @@ -204,18 +204,21 @@ public function set_star( * * @param string[] $ids * @param string[] $tags + * @param bool $override * @param int $expectedStatusCode * @param string|null $assertSee */ public function set_tag( array $ids, array $tags, + bool $override = true, int $expectedStatusCode = 204, ?string $assertSee = null ): void { $response = $this->testCase->postJson('/api/Photo::setTags', [ 'photoIDs' => $ids, 'tags' => $tags, + 'shall_override' => $override, ]); $response->assertStatus($expectedStatusCode); if ($assertSee) { diff --git a/tests/Feature/PhotosOperationsTest.php b/tests/Feature/PhotosOperationsTest.php index 9294130d652..4995e9cf48f 100644 --- a/tests/Feature/PhotosOperationsTest.php +++ b/tests/Feature/PhotosOperationsTest.php @@ -83,6 +83,7 @@ public function testManyFunctionsAtOnce(): void $this->photos_tests->set_description($id, 'A night photography'); $this->photos_tests->set_star([$id], true); $this->photos_tests->set_tag([$id], ['night']); + $this->photos_tests->set_tag([$id], ['trees'], false); $this->photos_tests->set_public($id, true); $this->photos_tests->set_license($id, 'WTFPL', 422, 'license must be one out of'); $this->photos_tests->set_license($id, 'CC0'); @@ -141,7 +142,7 @@ public function testManyFunctionsAtOnce(): void 'license' => 'reserved', 'is_public' => 1, 'is_starred' => true, - 'tags' => ['night'], + 'tags' => ['night', 'trees'], ]); /**