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.canChangeImplications = auth.hasPrivilege(auth.privileges.changeTagImplications);
|
||||||
privileges.canChangeSuggestions = auth.hasPrivilege(auth.privileges.changeTagSuggestions);
|
privileges.canChangeSuggestions = auth.hasPrivilege(auth.privileges.changeTagSuggestions);
|
||||||
privileges.canBan = auth.hasPrivilege(auth.privileges.banTags);
|
privileges.canBan = auth.hasPrivilege(auth.privileges.banTags);
|
||||||
|
privileges.canViewHistory = auth.hasPrivilege(auth.privileges.viewHistory);
|
||||||
|
|
||||||
promise.wait(
|
promise.wait(
|
||||||
util.promiseTemplate('tag'),
|
util.promiseTemplate('tag'),
|
||||||
util.promiseTemplate('post-list-item'))
|
util.promiseTemplate('post-list-item'),
|
||||||
.then(function(tagTemplate, postListItemTemplate) {
|
util.promiseTemplate('history'))
|
||||||
|
.then(function(tagTemplate, postListItemTemplate, historyTemplate) {
|
||||||
templates.tag = tagTemplate;
|
templates.tag = tagTemplate;
|
||||||
templates.postListItem = postListItemTemplate;
|
templates.postListItem = postListItemTemplate;
|
||||||
|
templates.history = historyTemplate;
|
||||||
|
|
||||||
reinit(params, loaded);
|
reinit(params, loaded);
|
||||||
}).fail(function() {
|
}).fail(function() {
|
||||||
|
@ -81,6 +84,8 @@ App.Presenters.TagPresenter = function(
|
||||||
tag: tag,
|
tag: tag,
|
||||||
siblings: siblings,
|
siblings: siblings,
|
||||||
tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')),
|
tagCategories: JSON.parse(jQuery('head').attr('data-tag-categories')),
|
||||||
|
formatRelativeTime: util.formatRelativeTime,
|
||||||
|
historyTemplate: templates.history,
|
||||||
}));
|
}));
|
||||||
$el.find('.post-list').hide();
|
$el.find('.post-list').hide();
|
||||||
$el.find('form').submit(function(e) { e.preventDefault(); });
|
$el.find('form').submit(function(e) { e.preventDefault(); });
|
||||||
|
|
|
@ -7,7 +7,6 @@ var reprValue = function(value) {
|
||||||
};
|
};
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<h1>History</h1>
|
|
||||||
<table class="history">
|
<table class="history">
|
||||||
<tbody>
|
<tbody>
|
||||||
<% _.each(history, function( historyEntry) { %>
|
<% _.each(history, function( historyEntry) { %>
|
||||||
|
@ -35,10 +34,14 @@ var reprValue = function(value) {
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td class="subject">
|
<td class="subject">
|
||||||
<% if (historyEntry.type == 0) { %>
|
<% if (historyEntry.type === 0) { %>
|
||||||
<a href="#/post/<%= historyEntry.primaryKey %>">
|
<a href="#/post/<%= historyEntry.primaryKey %>">
|
||||||
@<%= historyEntry.primaryKey %>
|
@<%= historyEntry.primaryKey %>
|
||||||
</a>
|
</a>
|
||||||
|
<% } else if (historyEntry.type === 1) { %>
|
||||||
|
<a href="#/tag/<%= historyEntry.data.name %>">
|
||||||
|
#<%= historyEntry.data.name %>
|
||||||
|
</a>
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
?
|
?
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -268,6 +268,7 @@
|
||||||
|
|
||||||
<% if (privileges.canViewHistory) { %>
|
<% if (privileges.canViewHistory) { %>
|
||||||
<div class="post-history-wrapper">
|
<div class="post-history-wrapper">
|
||||||
|
<h1>History</h1>
|
||||||
<%= historyTemplate({
|
<%= historyTemplate({
|
||||||
history: postHistory,
|
history: postHistory,
|
||||||
formatRelativeTime: formatRelativeTime
|
formatRelativeTime: formatRelativeTime
|
||||||
|
|
|
@ -93,6 +93,16 @@
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
<% if (privileges.canViewHistory) { %>
|
||||||
|
<div class="post-history-wrapper">
|
||||||
|
<h3>History</h3>
|
||||||
|
<%= historyTemplate({
|
||||||
|
history: tag.history,
|
||||||
|
formatRelativeTime: formatRelativeTime
|
||||||
|
}) %>
|
||||||
|
</div>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<div class="post-list">
|
<div class="post-list">
|
||||||
<h3>Example usages</h3>
|
<h3>Example usages</h3>
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ final class TagController extends AbstractController
|
||||||
[
|
[
|
||||||
TagViewProxy::FETCH_IMPLICATIONS => true,
|
TagViewProxy::FETCH_IMPLICATIONS => true,
|
||||||
TagViewProxy::FETCH_SUGGESTIONS => true,
|
TagViewProxy::FETCH_SUGGESTIONS => true,
|
||||||
|
TagViewProxy::FETCH_HISTORY => true,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Controllers\ViewProxies;
|
namespace Szurubooru\Controllers\ViewProxies;
|
||||||
|
use Szurubooru\Privilege;
|
||||||
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
use Szurubooru\Services\TagHistoryService;
|
||||||
|
|
||||||
class TagViewProxy extends AbstractViewProxy
|
class TagViewProxy extends AbstractViewProxy
|
||||||
{
|
{
|
||||||
const FETCH_IMPLICATIONS = 'fetchImplications';
|
const FETCH_IMPLICATIONS = 'fetchImplications';
|
||||||
const FETCH_SUGGESTIONS = 'fetchSuggestions';
|
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 = [])
|
public function fromEntity($tag, $config = [])
|
||||||
{
|
{
|
||||||
|
@ -21,6 +39,13 @@ class TagViewProxy extends AbstractViewProxy
|
||||||
|
|
||||||
if (!empty($config[self::FETCH_SUGGESTIONS]))
|
if (!empty($config[self::FETCH_SUGGESTIONS]))
|
||||||
$result->suggestions = $this->fromArray($tag->getSuggestedTags());
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue