Skip to content

Commit fc779cf

Browse files
author
Zane
committed
ArticleEdit split
1 parent bfc5677 commit fc779cf

File tree

8 files changed

+136
-122
lines changed

8 files changed

+136
-122
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
namespace App\Controller\Editor;
3+
4+
use Symfony\Component\HttpFoundation\JsonResponse;
5+
use Symfony\Component\HttpFoundation\Response;
6+
use Symfony\Component\Routing\Attribute\Route;
7+
8+
9+
class ArticleEditAuthors extends ArticleEditBaseController
10+
{
11+
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/get-authors-modal', name: 'app_article_edit_authors_get-modal', methods: ['GET'])]
12+
public function getAuthorsModal(int $articleId) : Response
13+
{
14+
try {
15+
$this->loadArticleEditor($articleId);
16+
17+
return $this->json([
18+
"title" => "👥 Modifica autori",
19+
"body" => $this->twig->render('article/editor/authors-modal.html.twig', [
20+
"Article" => $this->articleEditor,
21+
"LatestAuthors" => $this->factory->createUserCollection()->loadLatestAuthors()
22+
])
23+
]);
24+
25+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
26+
}
27+
28+
29+
#[Route('/ajax/editor/authors/', name: 'app_article_edit_authors_autocomplete', methods: ['GET'])]
30+
public function authorsAutocomplete() : Response
31+
{
32+
$this->ajaxOnly();
33+
34+
try {
35+
36+
if( empty($this->getUser()) ) {
37+
throw $this->createAccessDeniedException('Non sei loggato!');
38+
}
39+
40+
$username = $this->request->get('username');
41+
42+
$authors = $this->factory->createUserCollection();
43+
44+
empty($username) ? $authors->loadLatestAuthors() : $authors->loadBySearchUsername($username);
45+
46+
return $this->render('article/editor/authors-autocomplete.html.twig', [
47+
'Authors' => $authors
48+
]);
49+
50+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
51+
}
52+
53+
54+
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/set-authors', name: 'app_article_edit_authors_submit', methods: ['POST'])]
55+
public function setAuthors(int $articleId) : JsonResponse|Response
56+
{
57+
try {
58+
59+
$arrAuthorIds = $this->request->get('authors') ?? [];
60+
$this->loadArticleEditor($articleId)->setAuthorsFromIds($arrAuthorIds);
61+
$this->factory->getEntityManager()->flush();
62+
return $this->jsonOKResponse("Autori salvati");
63+
64+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
65+
}
66+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
namespace App\Controller\Editor;
3+
4+
use Symfony\Component\HttpFoundation\JsonResponse;
5+
use Symfony\Component\HttpFoundation\Response;
6+
use Symfony\Component\Routing\Attribute\Route;
7+
8+
9+
class ArticleEditTags extends ArticleEditBaseController
10+
{
11+
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/get-tags-modal', name: 'app_article_edit_tags_get-modal', methods: ['GET'])]
12+
public function getTagsModal(int $articleId) : Response
13+
{
14+
try {
15+
$this->loadArticleEditor($articleId);
16+
17+
return $this->json([
18+
"title" => "🏷️ Modifica tag",
19+
"body" => $this->twig->render('article/editor/tags-modal.html.twig', [
20+
"Article" => $this->articleEditor,
21+
"CommonTagGroups" => $this->factory->createTagCollection()->getCommonGrouped()
22+
])
23+
]);
24+
25+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
26+
}
27+
28+
29+
#[Route('/ajax/editor/tags/', name: 'app_article_edit_tags_autocomplete', methods: ['GET'])]
30+
public function tagsAutocomplete() : Response
31+
{
32+
$this->ajaxOnly();
33+
34+
try {
35+
36+
if( empty($this->getUser()) ) {
37+
throw $this->createAccessDeniedException('Non sei loggato!');
38+
}
39+
40+
$tag = $this->request->get('tag');
41+
42+
return $this->render('article/editor/tags-autocomplete.html.twig', [
43+
'Tags' => $this->factory->createTagCollection()->loadBySearchTagOrCreate($tag)
44+
]);
45+
46+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
47+
}
48+
49+
50+
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/set-tags', name: 'app_article_edit_tags_submit', methods: ['POST'])]
51+
public function setTags(int $articleId) : JsonResponse|Response
52+
{
53+
try {
54+
55+
$arrIdsAndTags = $this->request->get('tags') ?? [];
56+
$this->loadArticleEditor($articleId)->setTagsFromIdsAndTags($arrIdsAndTags);
57+
$this->factory->getEntityManager()->flush();
58+
return $this->jsonOKResponse("Tag salvati");
59+
60+
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
61+
}
62+
}
Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
<?php
22
namespace App\Controller\Editor;
33

4-
use App\Controller\BaseController;
54
use Error;
65
use Exception;
76
use Symfony\Component\HttpFoundation\JsonResponse;
87
use Symfony\Component\HttpFoundation\Response;
98
use Symfony\Component\Routing\Attribute\Route;
109

1110

12-
class ArticleEditorController extends BaseController
11+
class ArticleEditorController extends ArticleEditBaseController
1312
{
14-
//<editor-fold defaultstate="collapsed" desc="*** 📜 Title and Body ***">
1513
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}', name: 'app_editor_article_update', methods: ['POST'])]
1614
public function update(int $articleId) : JsonResponse|Response
1715
{
@@ -30,116 +28,4 @@ public function update(int $articleId) : JsonResponse|Response
3028

3129
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
3230
}
33-
//</editor-fold>
34-
35-
//<editor-fold defaultstate="collapsed" desc="*** 👥 Authors ***">
36-
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/get-authors-modal', name: 'app_editor_article_get-authors-modal', methods: ['GET'])]
37-
public function getAuthorsModal(int $articleId) : Response
38-
{
39-
try {
40-
$this->loadArticleEditor($articleId);
41-
42-
return $this->json([
43-
"title" => "👥 Modifica autori",
44-
"body" => $this->twig->render('article/editor/authors-modal.html.twig', [
45-
"Article" => $this->articleEditor,
46-
"LatestAuthors" => $this->factory->createUserCollection()->loadLatestAuthors()
47-
])
48-
]);
49-
50-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
51-
}
52-
53-
54-
#[Route('/ajax/editor/authors/', name: 'app_editor_article_authors-autocomplete', methods: ['GET'])]
55-
public function authorsAutocomplete() : Response
56-
{
57-
$this->ajaxOnly();
58-
59-
try {
60-
61-
if( empty($this->getUser()) ) {
62-
throw $this->createAccessDeniedException('Non sei loggato!');
63-
}
64-
65-
$username = $this->request->get('username');
66-
67-
$authors = $this->factory->createUserCollection();
68-
69-
empty($username) ? $authors->loadLatestAuthors() : $authors->loadBySearchUsername($username);
70-
71-
return $this->render('article/editor/authors-autocomplete.html.twig', [
72-
'Authors' => $authors
73-
]);
74-
75-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
76-
}
77-
78-
79-
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/set-authors', name: 'app_editor_article_set-authors', methods: ['POST'])]
80-
public function setAuthors(int $articleId) : JsonResponse|Response
81-
{
82-
try {
83-
84-
$arrAuthorIds = $this->request->get('authors') ?? [];
85-
$this->loadArticleEditor($articleId)->setAuthorsFromIds($arrAuthorIds);
86-
$this->factory->getEntityManager()->flush();
87-
return $this->jsonOKResponse("Autori salvati");
88-
89-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
90-
}
91-
//</editor-fold>
92-
93-
//<editor-fold defaultstate="collapsed" desc="*** 🏷️ Tags ***">
94-
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/get-tags-modal', name: 'app_editor_article_get-tags-modal', methods: ['GET'])]
95-
public function getTagsModal(int $articleId) : Response
96-
{
97-
try {
98-
$this->loadArticleEditor($articleId);
99-
100-
return $this->json([
101-
"title" => "🏷️ Modifica tag",
102-
"body" => $this->twig->render('article/editor/tags-modal.html.twig', [
103-
"Article" => $this->articleEditor,
104-
"CommonTagGroups" => $this->factory->createTagCollection()->getCommonGrouped()
105-
])
106-
]);
107-
108-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
109-
}
110-
111-
#[Route('/ajax/editor/tags/', name: 'app_editor_article_tags-autocomplete', methods: ['GET'])]
112-
public function tagsAutocomplete() : Response
113-
{
114-
$this->ajaxOnly();
115-
116-
try {
117-
118-
if( empty($this->getUser()) ) {
119-
throw $this->createAccessDeniedException('Non sei loggato!');
120-
}
121-
122-
$tag = $this->request->get('tag');
123-
124-
return $this->render('article/editor/tags-autocomplete.html.twig', [
125-
'Tags' => $this->factory->createTagCollection()->loadBySearchTagOrCreate($tag)
126-
]);
127-
128-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
129-
}
130-
131-
132-
#[Route('/ajax/editor/article/{articleId<[1-9]+[0-9]*>}/set-tags', name: 'app_editor_article_set-tags', methods: ['POST'])]
133-
public function setTags(int $articleId) : JsonResponse|Response
134-
{
135-
try {
136-
137-
$arrIdsAndTags = $this->request->get('tags') ?? [];
138-
$this->loadArticleEditor($articleId)->setTagsFromIdsAndTags($arrIdsAndTags);
139-
$this->factory->getEntityManager()->flush();
140-
return $this->jsonOKResponse("Tag salvati");
141-
142-
} catch(Exception|Error $ex) { return $this->textErrorResponse($ex); }
143-
}
144-
//</editor-fold>
14531
}

‎templates/article/editor/authors-modal.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<h6 class="mb-2">Autori attuali</h6>
1212
<div class="list-group list-group-flush border rounded-3 p-2 tli-article-editor-current-authors-list"
13-
data-changed="0" data-save-url="{{ path('app_editor_article_set-authors', {'articleId': Article.id}) }}">
13+
data-changed="0" data-save-url="{{ path('app_article_edit_authors_submit', {'articleId': Article.id}) }}">
1414

1515
{% embed 'article/editor/authors-modal-list-items.html.twig' with {'Authors': Article.Authors} only %}
1616
{% block addAuthorClass %}d-none{% endblock %}
@@ -27,7 +27,7 @@
2727

2828

2929
<div class="tli-authors-autocomplete-container"
30-
data-autocomplete-url="{{ path('app_editor_article_authors-autocomplete') }}">
30+
data-autocomplete-url="{{ path('app_article_edit_authors_autocomplete') }}">
3131

3232
<h6 class="mb-2">Aggiungi altri autori</h6>
3333
<div class="mb-2">

‎templates/article/editor/button-edit-authors.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% if Article.currentUserCanEdit %}
22

33
<button type="button" class="btn btn-outline-primary fw-bold"
4-
data-tli-modal-url="{{ path('app_editor_article_get-authors-modal', {articleId: Article.id}) }}">
4+
data-tli-modal-url="{{ path('app_article_edit_authors_get-modal', {articleId: Article.id}) }}">
55
<i class="fa-solid fa-user-pen"></i> Modifica autori
66
</button>
77

‎templates/article/editor/button-edit-tags.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{% if Article.currentUserCanEdit %}
22

33
<button type="button" class="btn btn-outline-primary fw-bold"
4-
data-tli-modal-url="{{ path('app_editor_article_get-tags-modal', {articleId: Article.id}) }}">
4+
data-tli-modal-url="{{ path('app_article_edit_tags_get-modal', {articleId: Article.id}) }}">
55
<i class="fa-solid fa-tags"></i> Modifica tag
66
</button>
77

‎templates/article/editor/tags-missing-warning.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{% embed 'parts/alert-warning-message.html.twig' %}
44
{% block alertBody %}
5-
<a href="#" data-tli-modal-url="{{ path('app_editor_article_get-tags-modal', {articleId: Article.id}) }}">Nessun tag assegnato all'articolo</a>
5+
<a href="#" data-tli-modal-url="{{ path('app_article_edit_tags_get-modal', {articleId: Article.id}) }}">Nessun tag assegnato all'articolo</a>
66
{% endblock %}
77
{% endembed %}
88

‎templates/article/editor/tags-modal.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
<h6 class="text-secondary mb-3"><i class="fas fa-tag"></i> Tag già assegnati all'articolo:</h6>
6767
<div class="tli-tags-strip tli-article-editor-current-tags-list mb-2" data-changed="0"
68-
data-save-url="{{ path('app_editor_article_set-tags', {'articleId': Article.id}) }}">
68+
data-save-url="{{ path('app_article_edit_tags_submit', {'articleId': Article.id}) }}">
6969

7070
{% embed 'article/editor/tags-modal-list-items.html.twig' with {'Tags': Article.Tags} %}
7171
{% block removeTagClass %}{% endblock %}
@@ -96,7 +96,7 @@
9696

9797

9898
<div class="tli-tags-autocomplete-container"
99-
data-autocomplete-url="{{ path('app_editor_article_tags-autocomplete') }}">
99+
data-autocomplete-url="{{ path('app_article_edit_tags_autocomplete') }}">
100100

101101
<h6 class="text-secondary mb-2"><i class="fa-solid fa-magnifying-glass"></i> Cerca un tag o creane uno nuovo:</h6>
102102
<div class="mb-2">

0 commit comments

Comments
 (0)