Allow browsing public snips

Fixed big with branch name not existing if nothing committed
This commit is contained in:
Tim 2023-04-06 20:30:11 +02:00
parent ce456adf10
commit 004044022d
7 changed files with 49 additions and 4 deletions

View File

@ -28,6 +28,16 @@ class SnipController extends AbstractController
{ {
return $this->render('snip/index.html.twig', [ return $this->render('snip/index.html.twig', [
'snips' => $this->repository->findByUser($this->getUser()), 'snips' => $this->repository->findByUser($this->getUser()),
'title' => 'My Snips'
]);
}
#[Route('/public', name: '_public')]
public function public(): Response
{
return $this->render('snip/index.html.twig', [
'snips' => $this->repository->findPublic(),
'title' => 'Public Snips'
]); ]);
} }

View File

@ -49,4 +49,14 @@ class SnipRepository extends ServiceEntityRepository
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }
public function findPublic(): array
{
$qb = $this->createQueryBuilder('s');
$qb->where('s.public = :public')
->setParameter('public', true)
->orderBy('s.createdAt', 'DESC');
return $qb->getQuery()->getResult();
}
} }

View File

@ -22,6 +22,9 @@ class SnipServiceFactory
$repoPath = sprintf('%s/%s', $this->snipBasePath, $snip->getId()); $repoPath = sprintf('%s/%s', $this->snipBasePath, $snip->getId());
if (!is_dir($repoPath)) { if (!is_dir($repoPath)) {
$repo = $git->init($repoPath); $repo = $git->init($repoPath);
touch(sprintf('%s/.gitignore', $repoPath));
$repo->addFile('.gitignore');
$repo->commit('Initial commit');
} else { } else {
$repo = $git->open($repoPath); $repo = $git->open($repoPath);
} }

View File

@ -19,6 +19,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ path('snip_new') }}">New snip</a> <a class="nav-link" href="{{ path('snip_new') }}">New snip</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="{{ path('snip_public') }}">Public snips</a>
</li>
{% endif %} {% endif %}
</ul> </ul>
<ul class="navbar-nav my-2 my-lg-0"> <ul class="navbar-nav my-2 my-lg-0">

View File

@ -1,16 +1,22 @@
{% extends 'base/base.html.twig' %} {% extends 'base/base.html.twig' %}
{% block title %}My snips{% endblock %} {% block title %}{{ title }}{% endblock %}
{% block body %} {% block body %}
<h1>My snips</h1> <h1>{{ title }}</h1>
<a class="btn btn-success" href="{{ path('snip_new') }}"> <a class="btn btn-success" href="{{ path('snip_new') }}">
<i class="fa fa-plus"></i> Add <i class="fa fa-plus"></i> Add
</a><br><br> </a><br><br>
<div class="list-group"> <div class="list-group">
{% for snip in snips %} {% for snip in snips %}
<a class="list-group-item" href="{{ path('snip_single', {snip: snip.id}) }}"> <a class="list-group-item" href="{{ path('snip_single', {snip: snip.id}) }}">
{{ include('snip/badge.html.twig', {snip: snip}) }} {{ snip }} {% if snip.createdBy == app.user %}
{{ include('snip/badge.html.twig', {snip: snip}) }}
{% endif %}
{{ snip }}
{% if snip.createdBy != app.user %}
{{ include('user/badge.html.twig', {user: snip.createdBy}) }}
{% endif %}
</a> </a>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -27,7 +27,19 @@
<p class="card-text">Current branch: {{ branch }}</p> <p class="card-text">Current branch: {{ branch }}</p>
</div> </div>
<div class="card-body"> <div class="card-body">
<p class="card-text">{{ content|nl2br }}</p> <pre><code>{{ content }}</code></pre>
</div> </div>
</div> </div>
{% endblock %} {% endblock %}
{% block css %}
{{ parent() }}
<link rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
{% endblock %}
{% block js %}
{{ parent() }}
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
{% endblock %}

View File

@ -0,0 +1 @@
<span class="badge bg-secondary">{{ user }}</span>