From 05c48be785b631bab20813eaaff5925cd2bf4b6f Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 9 Mar 2019 13:22:32 +0100 Subject: [PATCH 1/3] Link tags after adding them through autosuggest. --- controllers/ProvideAutoSuggest.php | 3 ++- models/Tag.php | 4 ++-- templates/PhotoPage.php | 9 +++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/controllers/ProvideAutoSuggest.php b/controllers/ProvideAutoSuggest.php index c0bd6a4..fc10474 100644 --- a/controllers/ProvideAutoSuggest.php +++ b/controllers/ProvideAutoSuggest.php @@ -41,8 +41,9 @@ class ProvideAutoSuggest extends JSONController $results = Tag::matchPeople($data); foreach ($results as $id_tag => $tag) $this->payload['items'][] = [ - 'label' => $tag, + 'label' => $tag['tag'], 'id_tag' => $id_tag, + 'url' => BASEURL . '/' . $tag['slug'] . '/', ]; } } diff --git a/models/Tag.php b/models/Tag.php index dfc9e93..ce66363 100644 --- a/models/Tag.php +++ b/models/Tag.php @@ -335,8 +335,8 @@ class Tag if (!is_array($tokens)) $tokens = explode(' ', $tokens); - return Registry::get('db')->queryPair(' - SELECT id_tag, tag + return Registry::get('db')->queryPairs(' + SELECT id_tag, tag, slug FROM tags WHERE LOWER(tag) LIKE {string:tokens} AND kind = {string:person} diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php index c695c64..f959ca9 100644 --- a/templates/PhotoPage.php +++ b/templates/PhotoPage.php @@ -175,9 +175,14 @@ class PhotoPage extends SubTemplate appendCallback: function(item) { var request = new HttpRequest("post", "', $this->photo->getPageUrl(), '", "id_tag=" + item.id_tag, function(response) { - var newNode = document.createElement("li"); + var newLink = document.createElement("a"); + newLink.href = item.url; + var newLabel = document.createTextNode(item.label); - newNode.appendChild(newLabel); + newLink.appendChild(newLabel); + + var newNode = document.createElement("li"); + newNode.appendChild(newLink); var list = document.getElementById("tag_list"); list.appendChild(newNode); From 42e5c7fe379a54bf4c2b61eb110271a68b0b5edb Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sat, 9 Mar 2019 13:48:18 +0100 Subject: [PATCH 2/3] Allow regular users to unlink tags from photos. --- controllers/ViewPhoto.php | 17 +++++++++++++--- public/css/default.css | 10 +++++---- templates/PhotoPage.php | 43 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/controllers/ViewPhoto.php b/controllers/ViewPhoto.php index 6c15130..cff5ed6 100644 --- a/controllers/ViewPhoto.php +++ b/controllers/ViewPhoto.php @@ -98,8 +98,19 @@ class ViewPhoto extends HTMLController } // We are! - $photo->linkTags([(int) $_POST['id_tag']]); - echo json_encode(['success' => true]); - exit; + if (!isset($_POST['delete'])) + { + $photo->linkTags([(int) $_POST['id_tag']]); + echo json_encode(['success' => true]); + exit; + } + + // ... deleting, that is. + else + { + $photo->unlinkTags([(int) $_POST['id_tag']]); + echo json_encode(['success' => true]); + exit; + } } } diff --git a/public/css/default.css b/public/css/default.css index 9fbf28e..861d257 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -588,14 +588,16 @@ a#previous_photo:hover, a#next_photo:hover { } #sub_photo #tag_list li { display: inline; + padding-right: 0.75em; } -#sub_photo #tag_list li:after { - content: ', '; +#tag_list .delete-tag { + opacity: 0.25; } -#sub_photo #tag_list li:last-child:after { - content: ''; +#tag_list .delete-tag:hover { + opacity: 1.0; } + #photo_exif_box { background: #fff; box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); diff --git a/templates/PhotoPage.php b/templates/PhotoPage.php index f959ca9..a8300c6 100644 --- a/templates/PhotoPage.php +++ b/templates/PhotoPage.php @@ -148,8 +148,14 @@ class PhotoPage extends SubTemplate foreach ($this->photo->getTags() as $tag) { echo ' -
  • - +
  • + '; + + if ($tag->kind === 'Person') + echo ' + '; + + echo '
  • '; } @@ -168,6 +174,28 @@ class PhotoPage extends SubTemplate