Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
feat(torrent/tags): Add tags show in page torrent_detail,torrents_list
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 19, 2019
1 parent e198704 commit f621685
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
6 changes: 5 additions & 1 deletion apps/controllers/TorrentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ public function actionIndex()
return $this->render('torrents/list', [
'torrents' => $torrents
]);

}

public function actionSearch()
{
// TODO
}

public function actionTags()
{
// TODO
}
}
22 changes: 22 additions & 0 deletions apps/models/Torrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Torrent
private $descr;
private $uplver;

/** @var array */
private $tags;

private $torrent_name;
private $torrent_type;
private $torrent_size;
Expand Down Expand Up @@ -258,4 +261,23 @@ public function getCategory()
{
return (new Category())->setId($this->category);
}

/**
* @return array
*/
public function getTags(): array
{
if (is_null($this->tags)) {
$this->tags = app()->pdo->createCommand('
SELECT tag, class_name, pinned FROM tags
INNER JOIN map_torrents_tags mtt on tags.id = mtt.tag_id
INNER JOIN torrents t on mtt.torrent_id = t.id
WHERE t.id = :tid ORDER BY tags.pinned DESC')->bindParams([
'tid' => $this->id
])->queryAll();
app()->redis->hSet('Torrent:' . $this->id . ':base_content', 'tags', $this->tags);
}

return $this->tags;
}
}
2 changes: 1 addition & 1 deletion apps/public/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ jQuery(document).ready(function () {
let exist_tag_set = new Set(exist_tag_value.split(' '));
if (exist_tag_set.has(add_tag)) {
exist_tag_set.delete(add_tag);
} else {
} else if (exist_tag_set.size < 10 /* Max tags size */) {
exist_tag_set.add(add_tag);
}
tags_input.val(Array.from(exist_tag_set).join(' '));
Expand Down
14 changes: 13 additions & 1 deletion apps/views/torrent/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,19 @@
<b>Peers:</b> <span style="color: green;"><i class="fas fa-arrow-up fa-fw"></i> <?= $torrent->getComplete() ?></span> / <span style="color: red;"><i class="fas fa-arrow-down fa-fw"></i> <?= $torrent->getIncomplete() ?></span> / <span><i class="fas fa-check fa-fw"></i> <?= $torrent->getDownloaded() ?></span>
</div>
<div data-field="info_hash" data-infohash="<?= $torrent->getInfoHash() ?>"><b>Info Hash:</b> <kbd><?= $torrent->getInfoHash() ?></kbd></div>

</div>
</div>
<div class="panel" id="torrent_tags_panel">
<div class="panel-heading"><b>Torrent Tags</b></div>
<div class="panel-body" id="torrent_tags">
<?php $tags = $torrent->getTags(); ?>
<?php if (count($tags) > 0) : ?>
<?php foreach ($tags as $tag): ?>
<a href="/torrents/tags?tag=<?= $tag['tag'] ?>" class="label label-outline <?= $tag['class_name'] ?>"><?= $tag['tag'] ?></a>
<?php endforeach; ?>
<?php else: ?>
No tags for this torrent
<?php endif; ?>
</div>
</div>
</div>
Expand Down
14 changes: 12 additions & 2 deletions apps/views/torrents/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,18 @@
<!--suppress HtmlUnknownTarget -->
<a href="/torrent/details?id=<?= $torrent->getId() ?>" target="_blank"><b><?= $torrent->getTitle() ?></b></a>
</div>
<div data-item="t-sub-info" data-subtitle="<?= $this->e($torrent->getSubtitle()) ?>">
<?= $torrent->getSubtitle() ?>
<div data-item="t-sub-info">
<?php $tags = $torrent->getTags(); ?>
<?php if (count($tags) > 0) : ?>
<span data-item="t-tags">
<?php foreach ($torrent->getTags() as $tag): ?>
<?php if ($tag['pinned']): // Only show pinned tag in torrent list ?>
<a href="/torrents/tags?tag=<?= $tag['tag'] ?>" class="label label-outline <?= $tag['class_name'] ?>"><?= $tag['tag'] ?></a>
<?php endif; ?>
<?php endforeach; ?>
</span>&nbsp;
<?php endif; ?>
<span data-item="subtitle" data-subtitle="<?= $this->e($torrent->getSubtitle()) ?>"><?= $torrent->getSubtitle() ?></span>
</div>
</div>
<div class="pull-right">
Expand Down

0 comments on commit f621685

Please sign in to comment.