From cb53572a2ddc52d4eb0f5df061a5bca525f761a4 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 7 Nov 2014 13:52:37 +0100 Subject: [PATCH] Added tag history section to tag presenter --- public_html/js/Presenters/TagPresenter.js | 9 +++++-- public_html/templates/history.tpl | 7 ++++-- public_html/templates/post.tpl | 1 + public_html/templates/tag.tpl | 10 ++++++++ src/Controllers/TagController.php | 1 + src/Controllers/ViewProxies/TagViewProxy.php | 25 ++++++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) diff --git a/public_html/js/Presenters/TagPresenter.js b/public_html/js/Presenters/TagPresenter.js index b7ea4470..f6abdc6f 100644 --- a/public_html/js/Presenters/TagPresenter.js +++ b/public_html/js/Presenters/TagPresenter.js @@ -35,13 +35,16 @@ App.Presenters.TagPresenter = function( privileges.canChangeImplications = auth.hasPrivilege(auth.privileges.changeTagImplications); privileges.canChangeSuggestions = auth.hasPrivilege(auth.privileges.changeTagSuggestions); privileges.canBan = auth.hasPrivilege(auth.privileges.banTags); + privileges.canViewHistory = auth.hasPrivilege(auth.privileges.viewHistory); promise.wait( util.promiseTemplate('tag'), - util.promiseTemplate('post-list-item')) - .then(function(tagTemplate, postListItemTemplate) { + util.promiseTemplate('post-list-item'), + util.promiseTemplate('history')) + .then(function(tagTemplate, postListItemTemplate, historyTemplate) { templates.tag = tagTemplate; templates.postListItem = postListItemTemplate; + templates.history = historyTemplate; reinit(params, loaded); }).fail(function() { @@ -81,6 +84,8 @@ App.Presenters.TagPresenter = function( tag: tag, siblings: siblings, tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')), + formatRelativeTime: util.formatRelativeTime, + historyTemplate: templates.history, })); $el.find('.post-list').hide(); $el.find('form').submit(function(e) { e.preventDefault(); }); diff --git a/public_html/templates/history.tpl b/public_html/templates/history.tpl index 524244c6..ad4c51c9 100644 --- a/public_html/templates/history.tpl +++ b/public_html/templates/history.tpl @@ -7,7 +7,6 @@ var reprValue = function(value) { }; %> -

History

<% _.each(history, function( historyEntry) { %> @@ -35,10 +34,14 @@ var reprValue = function(value) {
- <% if (historyEntry.type == 0) { %> + <% if (historyEntry.type === 0) { %> @<%= historyEntry.primaryKey %> + <% } else if (historyEntry.type === 1) { %> + + #<%= historyEntry.data.name %> + <% } else { %> ? <% } %> diff --git a/public_html/templates/post.tpl b/public_html/templates/post.tpl index c9a724bf..e72813d7 100644 --- a/public_html/templates/post.tpl +++ b/public_html/templates/post.tpl @@ -268,6 +268,7 @@ <% if (privileges.canViewHistory) { %>
+

History

<%= historyTemplate({ history: postHistory, formatRelativeTime: formatRelativeTime diff --git a/public_html/templates/tag.tpl b/public_html/templates/tag.tpl index a2ed50e0..5e0de37e 100644 --- a/public_html/templates/tag.tpl +++ b/public_html/templates/tag.tpl @@ -93,6 +93,16 @@
<% } %> + <% if (privileges.canViewHistory) { %> +
+

History

+ <%= historyTemplate({ + history: tag.history, + formatRelativeTime: formatRelativeTime + }) %> +
+ <% } %> +

Example usages

diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index b6c402d0..899605cc 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -111,6 +111,7 @@ final class TagController extends AbstractController [ TagViewProxy::FETCH_IMPLICATIONS => true, TagViewProxy::FETCH_SUGGESTIONS => true, + TagViewProxy::FETCH_HISTORY => true, ]; } } diff --git a/src/Controllers/ViewProxies/TagViewProxy.php b/src/Controllers/ViewProxies/TagViewProxy.php index bcc39c31..6d58a3f4 100644 --- a/src/Controllers/ViewProxies/TagViewProxy.php +++ b/src/Controllers/ViewProxies/TagViewProxy.php @@ -1,10 +1,28 @@ privilegeService = $privilegeService; + $this->tagHistoryService = $tagHistoryService; + $this->snapshotViewProxy = $snapshotViewProxy; + } public function fromEntity($tag, $config = []) { @@ -21,6 +39,13 @@ class TagViewProxy extends AbstractViewProxy if (!empty($config[self::FETCH_SUGGESTIONS])) $result->suggestions = $this->fromArray($tag->getSuggestedTags()); + + if (!empty($config[self::FETCH_HISTORY])) + { + $result->history = $this->privilegeService->hasPrivilege(Privilege::VIEW_HISTORY) + ? $this->snapshotViewProxy->fromArray($this->tagHistoryService->getTagHistory($tag)) + : []; + } } return $result; }