Browse Source

Search and miscelanea

imwald
Nuša Pukšič 10 months ago
parent
commit
2929d4ab15
  1. 3
      config/packages/security.yaml
  2. 9
      src/Controller/NzineController.php
  3. 2
      src/Service/NostrClient.php
  4. 20
      src/Twig/Components/IndexTabs.php
  5. 4
      templates/components/SearchComponent.html.twig
  6. 29
      templates/components/UserMenu.html.twig
  7. 4
      templates/home.html.twig
  8. 2
      templates/pages/author.html.twig
  9. 3
      templates/pages/nzine.html.twig
  10. 4
      templates/pages/search.html.twig
  11. 1
      translations/messages.en.yaml

3
config/packages/security.yaml

@ -26,5 +26,6 @@ security:
# Note: Only the *first* access control that matches will be used # Note: Only the *first* access control that matches will be used
access_control: access_control:
- { path: ^/admin, roles: ROLE_USER } - { path: ^/admin, roles: ROLE_USER }
- { path: ^/nzine, roles: ROLE_USER } - { path: ^/search, roles: ROLE_USER }
# - { path: ^/nzine, roles: ROLE_USER }
# - { path: ^/profile, roles: ROLE_USER } # - { path: ^/profile, roles: ROLE_USER }

9
src/Controller/NzineController.php

@ -154,7 +154,12 @@ class NzineController extends AbstractController
// add the new and updated indices to the main index // add the new and updated indices to the main index
foreach ($catIndices as $idx) { foreach ($catIndices as $idx) {
$mainIndex->addTag(['e' => $idx->getId() ]); //remove e tags and add new
// $tags = array_splice($mainIndex->getTags(), -3);
// $mainIndex->setTags($tags);
// TODO add relay hints
$mainIndex->addTag(['a' => KindsEnum::PUBLICATION_INDEX->value .':'. $idx->getPublicKey() .':'. $idx->getSlug()]);
// $mainIndex->addTag(['e' => $idx->getId() ]);
} }
// re-sign main index and save to relays // re-sign main index and save to relays
@ -204,6 +209,8 @@ class NzineController extends AbstractController
return $index->getSlug() == $nzine->getSlug(); return $index->getSlug() == $nzine->getSlug();
}); });
dump($indices);die();
$mainIndex = array_pop($mainIndexCandidates); $mainIndex = array_pop($mainIndexCandidates);
return $this->render('pages/nzine.html.twig', [ return $this->render('pages/nzine.html.twig', [

2
src/Service/NostrClient.php

@ -176,7 +176,7 @@ class NostrClient
$filter = new Filter(); $filter = new Filter();
$filter->setKinds([KindsEnum::LONGFORM]); $filter->setKinds([KindsEnum::LONGFORM]);
// TODO make filters configurable // TODO make filters configurable
$filter->setSince(strtotime('-8 weeks')); // $filter->setSince(strtotime('-1 week')); //
$requestMessage = new RequestMessage($subscriptionId, [$filter]); $requestMessage = new RequestMessage($subscriptionId, [$filter]);
// if user is logged in, use their settings // if user is logged in, use their settings

20
src/Twig/Components/IndexTabs.php

@ -20,7 +20,7 @@ class IndexTabs
public int $activeTab = 1; // Default active tab public int $activeTab = 1; // Default active tab
#[LiveProp] #[LiveProp]
/** ['id' => 1, 'label' => 'Tab 1'] */ /** ['id' => 1, 'label' => 'Tab 1', 'i' => <index> ] */
public array $tabs = []; public array $tabs = [];
#[LiveAction] #[LiveAction]
@ -39,24 +39,26 @@ class IndexTabs
// TODO extract categories from index and feed into tabs // TODO extract categories from index and feed into tabs
foreach ($index->getTags() as $tag) { foreach ($index->getTags() as $tag) {
if (array_key_first($tag) === 'a') { if (array_key_first($tag) === 'a') {
$ref = $tag['a']; $ref = $tag[1];
$relayHint = $tag[2] ?? null;
list($kind,$npub,$slug) = explode(':',$ref); list($kind,$npub,$slug) = explode(':',$ref);
$cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['slug' => $slug]); $cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['slug' => $slug]);
} elseif (array_key_first($tag) === 'e') {
$cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['id' => $tag['e']]);
$next = count($this->tabs) + 1; $next = count($this->tabs) + 1;
$this->tabs[] = ['id' => $next, 'label' => $cat->getTitle()]; $this->tabs[] = ['id' => $next, 'label' => $cat->getTitle(), 'i' => $cat];
} elseif (array_key_first($tag) === 'e') {
// ignore 'e's, we want 'a's
//$cat = $this->entityManager->getRepository(EventEntity::class)->findOneBy(['id' => $tag[1]]);
//$next = count($this->tabs) + 1;
//$this->tabs[] = ['id' => $next, 'label' => $cat->getTitle()];
} }
} }
} }
public function getTabContent(): string|array public function getTabContent(): string|array
{ {
// return current index
return match ($this->activeTab) { return match ($this->activeTab) {
1 => [ 1 => 'This will eventually be content.',
'30023:c1e6505c02da8d1b0a5b3d6db6e19b2eb22dcd54f0e86306ec8a213902b3157e:809797',
'30032:c1e6505c02da8d1b0a5b3d6db6e19b2eb22dcd54f0e86306ec8a213902b3157e:012025-7zsaxt'
],
2 => 'This is content for Tab 2. No AJAX needed!', 2 => 'This is content for Tab 2. No AJAX needed!',
default => 'No content available.', default => 'No content available.',
}; };

4
templates/components/SearchComponent.html.twig

@ -8,7 +8,9 @@
</label> </label>
<!-- Loading Indicator --> <!-- Loading Indicator -->
<span data-loading>{{ 'text.searching'|trans }}</span> <div style="text-align: center">
<span data-loading>{{ 'text.searching'|trans }}</span>
</div>
<!-- Results --> <!-- Results -->
{% if this.results is not empty %} {% if this.results is not empty %}

29
templates/components/UserMenu.html.twig

@ -2,22 +2,28 @@
{% if app.user %} {% if app.user %}
<p>Hello, {{ app.user.displayName }}</p> <p>Hello, {{ app.user.displayName }}</p>
{% if is_granted('ROLE_ADMIN') %} {% if is_granted('ROLE_ADMIN') %}
<ul> {# <ul>#}
<li> {# <li>#}
<a href="{{ path('admin_roles') }}">{{ 'heading.roles'|trans }}</a> {# <a href="{{ path('admin_roles') }}">{{ 'heading.roles'|trans }}</a>#}
</li> {# </li>#}
</ul> {# </ul>#}
{% endif %} {% endif %}
<ul> <ul>
<li> <li>
<a href="{{ path('author-profile', {npub: app.user.npub }) }}">Profile</a> <a href="{{ path('author-profile', {npub: app.user.npub }) }}">Profile</a>
</li> </li>
{# <li>#}
{# <a href="{{ path('editor-create') }}">Write an article</a>#}
{# </li>#}
{# <li>#}
{# <a href="{{ path('nzine_index') }}">{{ 'heading.createNzine'|trans }}</a>#}
{# </li>#}
<li> <li>
<a href="{{ path('editor-create') }}">Write an article</a> <a href="{{ path('app_search_index') }}">{{ 'heading.search'|trans }}</a>
</li>
<li>
<a href="{{ path('nzine_index') }}">{{ 'heading.createNzine'|trans }}</a>
</li> </li>
{# <li>#}
{# <a href="{{ path('app_index_index') }}">{{ 'heading.index'|trans }}</a>#}
{# </li>#}
<li> <li>
<a href="/logout" data-action="live#$render">{{ 'heading.logout'|trans }}</a> <a href="/logout" data-action="live#$render">{{ 'heading.logout'|trans }}</a>
</li> </li>
@ -25,9 +31,4 @@
{% else %} {% else %}
<twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>{{ 'heading.logIn'|trans }}</twig:Atoms:Button> <twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }}>{{ 'heading.logIn'|trans }}</twig:Atoms:Button>
{% endif %} {% endif %}
<ul>
<li>
<a href="{{ path('app_search_index') }}">{{ 'heading.search'|trans }}</a>
</li>
</ul>
</div> </div>

4
templates/home.html.twig

@ -9,6 +9,6 @@
{% endblock %} {% endblock %}
{% block aside %} {% block aside %}
<h6>Magazines</h6> {# <h6>Magazines</h6>#}
<twig:Organisms:ZineList /> {# <twig:Organisms:ZineList />#}
{% endblock %} {% endblock %}

2
templates/pages/author.html.twig

@ -26,5 +26,5 @@
{% endblock %} {% endblock %}
{% block aside %} {% block aside %}
<twig:Organisms:ZineList :nzines="nzines" /> {# <twig:Organisms:ZineList :nzines="nzines" />#}
{% endblock %} {% endblock %}

3
templates/pages/nzine.html.twig

@ -8,10 +8,9 @@
<twig:IndexTabs :index="index" /> <twig:IndexTabs :index="index" />
</div> </div>
{% endblock %} {% endblock %}
{% block aside %} {% block aside %}
<p>TODO search</p> {# <p>TODO search & add to index</p> #}
{% endblock %} {% endblock %}

4
templates/pages/search.html.twig

@ -8,6 +8,6 @@
{% endblock %} {% endblock %}
{% block aside %} {% block aside %}
<h6>Magazines</h6> {# <h6>Magazines</h6>#}
<twig:Organisms:ZineList /> {# <twig:Organisms:ZineList />#}
{% endblock %} {% endblock %}

1
translations/messages.en.yaml

@ -10,3 +10,4 @@ heading:
createNzine: 'Create an N-Zine' createNzine: 'Create an N-Zine'
editNzine: 'Edit your N-Zine' editNzine: 'Edit your N-Zine'
search: 'Search' search: 'Search'
index: 'Index'

Loading…
Cancel
Save