Added tag list; upload: tags autocompletion
This commit is contained in:
parent
86724568fd
commit
9896106f1c
5 changed files with 55 additions and 5 deletions
|
@ -46,3 +46,4 @@ listPosts.unsafe=registered
|
||||||
listUsers=registered
|
listUsers=registered
|
||||||
listComments=registered
|
listComments=registered
|
||||||
retrievePost=anonymous
|
retrievePost=anonymous
|
||||||
|
listTags=anonymous
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
$(function()
|
$(function()
|
||||||
{
|
{
|
||||||
var handler = $('#file-handler');
|
var tags = [];
|
||||||
var tags = []; //todo: retrieve tags
|
$.getJSON('/tags?json', function(data)
|
||||||
|
{
|
||||||
|
tags = data['tags'];
|
||||||
|
});
|
||||||
|
|
||||||
|
var handler = $('#file-handler');
|
||||||
handler.on('dragenter', function(e)
|
handler.on('dragenter', function(e)
|
||||||
{
|
{
|
||||||
$(this).addClass('active');
|
$(this).addClass('active');
|
||||||
|
@ -146,9 +150,16 @@ $(function()
|
||||||
postDom.removeAttr('id');
|
postDom.removeAttr('id');
|
||||||
postDom.data('file', file);
|
postDom.data('file', file);
|
||||||
$('.file-name strong', postDom).text(file.name);
|
$('.file-name strong', postDom).text(file.name);
|
||||||
$('.tags input', postDom).tagit({caseSensitive: true, availableTags: tags, placeholderText: $('.tags input').attr('placeholder')});
|
|
||||||
$('.posts').append(postDom);
|
$('.posts').append(postDom);
|
||||||
|
|
||||||
|
postDom.show();
|
||||||
|
var tagItOptions =
|
||||||
|
{ caseSensitive: true,
|
||||||
|
availableTags: tags,
|
||||||
|
placeholderText: $('.tags input').attr('placeholder')
|
||||||
|
};
|
||||||
|
$('.tags input', postDom).tagit(tagItOptions);
|
||||||
|
|
||||||
if (!file.type.match('image.*'))
|
if (!file.type.match('image.*'))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -4,9 +4,33 @@ class TagController
|
||||||
/**
|
/**
|
||||||
* @route /tags
|
* @route /tags
|
||||||
*/
|
*/
|
||||||
public static function listAction()
|
public function listAction()
|
||||||
{
|
{
|
||||||
$this->context->subTitle = 'tags';
|
$this->context->subTitle = 'tags';
|
||||||
throw new Exception('Not implemented');
|
|
||||||
|
PrivilegesHelper::confirmWithException($this->context->user, Privilege::ListTags);
|
||||||
|
|
||||||
|
$dbQuery = R::$f->begin();
|
||||||
|
$dbQuery->select('tag.name, COUNT(1) AS count');
|
||||||
|
$dbQuery->from('tag');
|
||||||
|
$dbQuery->innerJoin('post_tag');
|
||||||
|
$dbQuery->on('tag.id = post_tag.tag_id');
|
||||||
|
$dbQuery->groupBy('tag.id');
|
||||||
|
$rows = $dbQuery->get();
|
||||||
|
|
||||||
|
$tags = [];
|
||||||
|
$tagDistribution = [];
|
||||||
|
foreach ($rows as $row)
|
||||||
|
{
|
||||||
|
$tags []= $row['name'];
|
||||||
|
$tagDistribution[$row['name']] = $row['count'];
|
||||||
|
}
|
||||||
|
array_multisort(
|
||||||
|
array_values($tagDistribution), SORT_DESC, SORT_NUMERIC,
|
||||||
|
array_keys($tagDistribution), SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE,
|
||||||
|
$tagDistribution);
|
||||||
|
|
||||||
|
$this->context->transport->tags = $tags;
|
||||||
|
$this->context->transport->tagDistribution = $tagDistribution;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,5 @@ class Privilege extends Enum
|
||||||
const RetrievePost = 4;
|
const RetrievePost = 4;
|
||||||
const ListUsers = 5;
|
const ListUsers = 5;
|
||||||
const ListComments = 6;
|
const ListComments = 6;
|
||||||
|
const ListTags = 7;
|
||||||
}
|
}
|
||||||
|
|
13
src/Views/tag-list.phtml
Normal file
13
src/Views/tag-list.phtml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php if (isset($this->context->transport->errorMessage)): ?>
|
||||||
|
<p class="alert alert-error"><?php echo $this->context->transport->errorMessage ?></p>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul>
|
||||||
|
<?php foreach ($this->context->transport->tagDistribution as $tagName => $count): ?>
|
||||||
|
<li>
|
||||||
|
<a href="<?php echo \Chibi\UrlHelper::route('post', 'list', ['query' => $tagName]) ?>">
|
||||||
|
<?php echo $tagName . ' (' . $count . ')' ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif ?>
|
Loading…
Reference in a new issue