From bc4388333946be83c7b3b15ad8e21d7a0f356dff Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Tue, 29 Oct 2013 09:04:42 +0100 Subject: [PATCH] Closed #54 - added mass tag - Moved tag forms to separate files - Tag forms got tag autocompletion --- config.ini | 1 + lib/chibi-core | 2 +- public_html/media/css/post-list.css | 18 +++++++++ public_html/media/css/post-small.css | 31 +++++++++++++++ public_html/media/css/tag-list.css | 4 +- public_html/media/js/core.js | 7 +++- public_html/media/js/mass-tag.js | 34 +++++++++++++++++ src/Controllers/PostController.php | 57 +++++++++++++++++++++++++--- src/Controllers/TagController.php | 15 ++++++++ src/Models/Privilege.php | 1 + src/Views/post-list.phtml | 4 ++ src/Views/post-small.phtml | 17 ++++++++- src/Views/tag-list.phtml | 48 +++-------------------- src/Views/tag-mass-tag.phtml | 21 ++++++++++ src/Views/tag-merge.phtml | 21 ++++++++++ src/Views/tag-rename.phtml | 21 ++++++++++ 16 files changed, 246 insertions(+), 56 deletions(-) create mode 100644 public_html/media/js/mass-tag.js create mode 100644 src/Views/tag-mass-tag.phtml create mode 100644 src/Views/tag-merge.phtml create mode 100644 src/Views/tag-rename.phtml diff --git a/config.ini b/config.ini index d29e2fab..b9deeb05 100644 --- a/config.ini +++ b/config.ini @@ -97,3 +97,4 @@ deleteComment.all=moderator listTags=anonymous mergeTags=moderator renameTags=moderator +massTag=moderator diff --git a/lib/chibi-core b/lib/chibi-core index 6f606d10..dae26a24 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit 6f606d107513424139b0070d944d4f14dcb12423 +Subproject commit dae26a24c48a5140175ef7d0843b6b762692b8cd diff --git a/public_html/media/css/post-list.css b/public_html/media/css/post-list.css index 87ecea9f..16d3e68a 100644 --- a/public_html/media/css/post-list.css +++ b/public_html/media/css/post-list.css @@ -7,3 +7,21 @@ .posts { margin: 0 auto; } + +.form-wrapper { + text-align: center; +} +.small-screen .form-wrapper { + width: 100%; +} +form.aligned { + width: 24em; + text-align: left; + margin: 0 auto; +} +form.aligned label.left { + width: 7em; +} +form h1 { + text-align: center; +} diff --git a/public_html/media/css/post-small.css b/public_html/media/css/post-small.css index 29286f38..d6971d2f 100644 --- a/public_html/media/css/post-small.css +++ b/public_html/media/css/post-small.css @@ -5,6 +5,10 @@ position: relative; display: inline-block; } +.post .link { + color: black; +} + .post-type-youtube:after, .post-type-flash:after { position: absolute; @@ -29,6 +33,33 @@ } +.post .toggle-tag { + position: absolute; + z-index: 2; + width: 100px; + height: 30px; + background: whitesmoke; + opacity: .5; + border: 1px solid black; + margin: 60px 25px; + line-height: 30px; +} +.post .toggle-tag:hover { + opacity: 1; +} +.post.taggable.tagged .toggle-tag { + background-color: #0f0; + color: black; +} +.post.taggable:not(.tagged) .toggle-tag { + background-color: #f00; + color: white; +} +.post .link { + z-index: 1; +} + + .post:focus, .post:hover { border: 1px solid firebrick; diff --git a/public_html/media/css/tag-list.css b/public_html/media/css/tag-list.css index 01f86060..63e23c12 100644 --- a/public_html/media/css/tag-list.css +++ b/public_html/media/css/tag-list.css @@ -21,6 +21,7 @@ .form-wrapper { width: 50%; + max-width: 24em; display: inline-block; text-align: center; } @@ -34,9 +35,6 @@ form.aligned { form.aligned label.left { width: 7em; } -form.aligned input { - width: 24em; -} form h1 { text-align: center; } diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 60e961ba..5080ab6b 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -144,8 +144,10 @@ function extractLast(term) $(function() { - var searchInput = $('#top-nav .search input'); - searchInput + $('[data-autocomplete-url]').each(function() + { + var searchInput = $(this); + searchInput // don't navigate away from the field on tab when selecting an item .bind("keydown", function(event) { @@ -179,6 +181,7 @@ $(function() return false; } }); + }); }); function getTagItOptions() diff --git a/public_html/media/js/mass-tag.js b/public_html/media/js/mass-tag.js new file mode 100644 index 00000000..32a9501a --- /dev/null +++ b/public_html/media/js/mass-tag.js @@ -0,0 +1,34 @@ +$(function() +{ + $('.post a.toggle-tag').click(function(e) + { + if(e.isPropagationStopped()) + return; + + e.preventDefault(); + e.stopPropagation(); + + var aDom = $(this); + if (aDom.hasClass('inactive')) + return; + aDom.addClass('inactive'); + + var url = $(this).attr('href') + '?json'; + $.get(url, {submit: 1}, function(data) + { + if (data['success']) + { + aDom.removeClass('inactive'); + aDom.parents('.post').toggleClass('tagged'); + aDom.text(aDom.parents('.post').hasClass('tagged') + ? aDom.attr('data-text-tagged') + : aDom.attr('data-text-untagged')); + } + else + { + alert(data['errorMessage']); + aDom.removeClass('inactive'); + } + }); + }); +}); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 3616e372..ed5f45cf 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -48,20 +48,28 @@ class PostController /** - * @route /posts - * @route /posts/{page} - * @route /posts/{query}/ - * @route /posts/{query}/{page} + * @route /{source} + * @route /{source}/{page} + * @route /{source}/{query}/ + * @route /{source}/{query}/{page} + * @route /{source}/{additionalInfo}/{query}/ + * @route /{source}/{additionalInfo}/{query}/{page} + * @validate source posts|mass-tag * @validate page \d* * @validate query [^\/]* + * @validate additionalInfo [^\/]* */ - public function listAction($query = null, $page = 1) + public function listAction($query = null, $page = 1, $source = 'posts', $additionalInfo = null) { $this->context->stylesheets []= 'post-small.css'; $this->context->stylesheets []= 'post-list.css'; $this->context->stylesheets []= 'paginator.css'; if ($this->context->user->hasEnabledEndlessScrolling()) $this->context->scripts []= 'paginator-endless.js'; + if ($source == 'mass-tag') + $this->context->scripts []= 'mass-tag.js'; + $this->context->source = $source; + $this->context->additionalInfo = $additionalInfo; //redirect requests in form of /posts/?query=... to canonical address $formQuery = InputHelper::get('query'); @@ -70,7 +78,7 @@ class PostController $this->context->transport->searchQuery = $formQuery; if (strpos($formQuery, '/') !== false) throw new SimpleException('Search query contains invalid characters'); - $url = \Chibi\UrlHelper::route('post', 'list', ['query' => urlencode($formQuery)]); + $url = \Chibi\UrlHelper::route('post', 'list', ['source' => $source, 'additionalInfo' => $additionalInfo, 'query' => urlencode($formQuery)]); \Chibi\UrlHelper::forward($url); return; } @@ -81,6 +89,12 @@ class PostController $this->context->subTitle = 'posts'; $this->context->transport->searchQuery = $query; PrivilegesHelper::confirmWithException(Privilege::ListPosts); + if ($source == 'mass-tag') + { + PrivilegesHelper::confirmWithException(Privilege::MassTag); + $this->context->massTagTag = $additionalInfo; + $this->context->massTagQuery = $query; + } $postCount = Model_Post::getEntityCount($query); $pageCount = ceil($postCount / $postsPerPage); @@ -97,6 +111,37 @@ class PostController + /** + * @route /post/{id}/toggle-tag/{tag} + * @validate tag [^\/]* + */ + public function toggleTagAction($id, $tag) + { + $post = Model_Post::locate($id); + R::preload($post, ['uploader' => 'user']); + $this->context->transport->post = $post; + $tag = Model_Tag::validateTag($tag); + + if (InputHelper::get('submit')) + { + PrivilegesHelper::confirmWithException(Privilege::MassTag); + $tags = array_map(function($x) { return $x->name; }, $post->sharedTag); + + if (in_array($tag, $tags)) + $tags = array_diff($tags, [$tag]); + else + $tags += [$tag]; + + $dbTags = Model_Tag::insertOrUpdate($tags); + $post->sharedTag = $dbTags; + + R::store($post); + $this->context->transport->success = true; + } + } + + + /** * @route /favorites * @route /favorites/{page} diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 269f5539..1e305387 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -70,4 +70,19 @@ class TagController $this->context->transport->success = true; } } + + /** + * @route /mass-tag-redirect + */ + public function massTagRedirectAction() + { + PrivilegesHelper::confirmWithException(Privilege::MassTag); + if (InputHelper::get('submit')) + { + $suppliedQuery = InputHelper::get('query'); + $suppliedTag = InputHelper::get('tag'); + $suppliedTag = Model_Tag::validateTag($suppliedTag); + \Chibi\UrlHelper::forward(\Chibi\UrlHelper::route('post', 'list', ['source' => 'mass-tag', 'query' => urlencode($suppliedQuery), 'additionalInfo' => $suppliedTag])); + } + } } diff --git a/src/Models/Privilege.php b/src/Models/Privilege.php index d43be24b..1f391214 100644 --- a/src/Models/Privilege.php +++ b/src/Models/Privilege.php @@ -33,4 +33,5 @@ class Privilege extends Enum const ListTags = 21; const MergeTags = 27; const RenameTags = 27; + const MassTag = 29; } diff --git a/src/Views/post-list.phtml b/src/Views/post-list.phtml index cf3d490c..4173e722 100644 --- a/src/Views/post-list.phtml +++ b/src/Views/post-list.phtml @@ -1,3 +1,7 @@ +context->source) and $this->context->source == 'mass-tag' and PrivilegesHelper::confirm(Privilege::MassTag)): ?> + renderFile('tag-mass-tag') ?> + + context->transport->posts)): ?>

No posts to show.

diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml index 6b2280f7..2ce8606c 100644 --- a/src/Views/post-small.phtml +++ b/src/Views/post-small.phtml @@ -1,5 +1,18 @@ -
- +context->post->type))] ?> +context->source) and $this->context->source == 'mass-tag'): ?> + + context->additionalInfo, array_map(function($x) { return $x->name; }, $this->context->post->sharedTag))): ?> + + + + +
+ context->source) and $this->context->source == 'mass-tag'): ?> + + + + + @<?php echo $this->context->post->id ?>
diff --git a/src/Views/tag-list.phtml b/src/Views/tag-list.phtml index 97549116..6dbe5d8d 100644 --- a/src/Views/tag-list.phtml +++ b/src/Views/tag-list.phtml @@ -12,49 +12,13 @@
-
-
-

merge tags

-
- -
-
- -
- -
-
- - - -
- - -
-
-
+ renderFile('tag-merge') ?> -
-
-

rename tags

-
- -
-
- -
- -
-
- - - -
- - -
-
-
+ renderFile('tag-rename') ?> + + + + renderFile('tag-mass-tag') ?> diff --git a/src/Views/tag-mass-tag.phtml b/src/Views/tag-mass-tag.phtml new file mode 100644 index 00000000..93332f72 --- /dev/null +++ b/src/Views/tag-mass-tag.phtml @@ -0,0 +1,21 @@ +
+
+

mass tag

+
+ +
+
+ +
+ +
+
+ + + +
+ + +
+
+
diff --git a/src/Views/tag-merge.phtml b/src/Views/tag-merge.phtml new file mode 100644 index 00000000..36996ae2 --- /dev/null +++ b/src/Views/tag-merge.phtml @@ -0,0 +1,21 @@ +
+
+

merge tags

+
+ +
+
+ +
+ +
+
+ + + +
+ + +
+
+
diff --git a/src/Views/tag-rename.phtml b/src/Views/tag-rename.phtml new file mode 100644 index 00000000..f6bc741e --- /dev/null +++ b/src/Views/tag-rename.phtml @@ -0,0 +1,21 @@ +
+
+

rename tags

+
+ +
+
+ +
+ +
+
+ + + +
+ + +
+
+