Added tag history section to tag presenter
This commit is contained in:
parent
e64fb9bfad
commit
cb53572a2d
6 changed files with 49 additions and 4 deletions
|
@ -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(); });
|
||||
|
|
|
@ -7,7 +7,6 @@ var reprValue = function(value) {
|
|||
};
|
||||
%>
|
||||
|
||||
<h1>History</h1>
|
||||
<table class="history">
|
||||
<tbody>
|
||||
<% _.each(history, function( historyEntry) { %>
|
||||
|
@ -35,10 +34,14 @@ var reprValue = function(value) {
|
|||
</td>
|
||||
|
||||
<td class="subject">
|
||||
<% if (historyEntry.type == 0) { %>
|
||||
<% if (historyEntry.type === 0) { %>
|
||||
<a href="#/post/<%= historyEntry.primaryKey %>">
|
||||
@<%= historyEntry.primaryKey %>
|
||||
</a>
|
||||
<% } else if (historyEntry.type === 1) { %>
|
||||
<a href="#/tag/<%= historyEntry.data.name %>">
|
||||
#<%= historyEntry.data.name %>
|
||||
</a>
|
||||
<% } else { %>
|
||||
?
|
||||
<% } %>
|
||||
|
|
|
@ -268,6 +268,7 @@
|
|||
|
||||
<% if (privileges.canViewHistory) { %>
|
||||
<div class="post-history-wrapper">
|
||||
<h1>History</h1>
|
||||
<%= historyTemplate({
|
||||
history: postHistory,
|
||||
formatRelativeTime: formatRelativeTime
|
||||
|
|
|
@ -93,6 +93,16 @@
|
|||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (privileges.canViewHistory) { %>
|
||||
<div class="post-history-wrapper">
|
||||
<h3>History</h3>
|
||||
<%= historyTemplate({
|
||||
history: tag.history,
|
||||
formatRelativeTime: formatRelativeTime
|
||||
}) %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<div class="post-list">
|
||||
<h3>Example usages</h3>
|
||||
|
||||
|
|
|
@ -111,6 +111,7 @@ final class TagController extends AbstractController
|
|||
[
|
||||
TagViewProxy::FETCH_IMPLICATIONS => true,
|
||||
TagViewProxy::FETCH_SUGGESTIONS => true,
|
||||
TagViewProxy::FETCH_HISTORY => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,28 @@
|
|||
<?php
|
||||
namespace Szurubooru\Controllers\ViewProxies;
|
||||
use Szurubooru\Privilege;
|
||||
use Szurubooru\Services\PrivilegeService;
|
||||
use Szurubooru\Services\TagHistoryService;
|
||||
|
||||
class TagViewProxy extends AbstractViewProxy
|
||||
{
|
||||
const FETCH_IMPLICATIONS = 'fetchImplications';
|
||||
const FETCH_SUGGESTIONS = 'fetchSuggestions';
|
||||
const FETCH_HISTORY = 'fetchHistory';
|
||||
|
||||
private $privilegeService;
|
||||
private $tagHistoryService;
|
||||
private $snapshotViewProxy;
|
||||
|
||||
public function __construct(
|
||||
PrivilegeService $privilegeService,
|
||||
TagHistoryService $tagHistoryService,
|
||||
SnapshotViewProxy $snapshotViewProxy)
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue