Commit 6ec1910f authored by Emma's avatar Emma 🏳🌈

add "pin"/"unpin" to actions menu

parent 2c6acb79
Pipeline #56693317 passed with stage
in 1 minute and 41 seconds
......@@ -203,6 +203,12 @@
"css": "home",
"code": 59411,
"src": "fontawesome"
},
{
"uid": "6373242453e92e8ce419b8391463867a",
"css": "pin-outline",
"code": 59412,
"src": "typicons"
}
]
}
\ No newline at end of file
......@@ -24,6 +24,7 @@
<symbol id="mail" viewBox="0 0 1000 1000"><path d="M929 839V411q-18 20-39 36-149 115-238 189-28 24-46 37t-48 28-57 13h-2q-26 0-57-13t-48-28-46-37q-88-74-238-189-21-16-39-36v428q0 7 6 13t12 5h822q7 0 12-5t6-13zm0-586v-14l-1-7-1-7-3-5-5-4-8-2H89q-7 0-12 6t-6 12q0 94 83 159 107 84 223 176 4 3 20 17t25 21 25 17 28 16 24 5h2q11 0 24-5t28-16 25-17 25-21 20-17q116-92 224-176 30-24 56-65t26-73zm71-21v607q0 37-26 63t-63 27H89q-36 0-63-27T0 839V232q0-37 26-63t63-26h822q37 0 63 26t26 63z"/></symbol>
<symbol id="menu" viewBox="0 0 857.1 1000"><path d="M857 750v71q0 15-10 25t-26 11H36q-15 0-25-11T0 821v-71q0-15 11-25t25-11h785q15 0 26 11t10 25zm0-286v72q0 14-10 25t-26 10H36q-15 0-25-10T0 536v-72q0-14 11-25t25-10h785q15 0 26 10t10 25zm0-285v71q0 14-10 25t-26 11H36q-15 0-25-11T0 250v-71q0-15 11-26t25-10h785q15 0 26 10t10 26z"/></symbol>
<symbol id="pencil" viewBox="0 0 857.1 1000"><path d="M203 857l50-51-131-131-51 51v60h72v71h60zm291-518q0-12-12-12-5 0-9 4L170 633q-4 4-4 10 0 12 13 12 5 0 9-4l303-302q3-4 3-10zm-30-107l232 232-464 465H0V696zm381 54q0 29-20 50l-93 93-232-233 93-92q20-21 50-21 29 0 51 21l131 131q20 22 20 51z"/></symbol>
<symbol id="pin-outline" viewBox="0 0 886 1000"><path d="M856 296q30 30 30 73t-30 75q-16 16-36 24-106 51-144 125-51 102-51 246 0 45-29 74t-75 30q-47 0-75-30L279 744 0 943l199-279L30 496q-20-18-27-49t5-64q27-65 96-65 146 0 246-50l11-7q69-37 118-141 7-20 21-34 30-30 74-29t74 31zM583 546q53-107 196-175L574 160q-69 146-176 200l-13 6q-120 57-281 57l416 416q0-168 63-293z"/></symbol>
<symbol id="pin" viewBox="0 0 834 1000"><path d="M573 813q0 23-15 38t-37 15q-21 0-37-16L315 681 0 917l236-315L68 433q-24-23-12-56 14-32 48-32 157 0 270-57 90-45 151-171 9-24 36-32t50 13l208 209q21 23 14 50t-32 36q-127 63-172 152-56 110-56 268z"/></symbol>
<symbol id="plus" viewBox="0 0 785.7 1000"><path d="M786 411v107q0 22-16 38t-38 15H500v233q0 22-16 37t-38 16H339q-22 0-38-16t-15-37V571H54q-23 0-38-15T0 518V411q0-23 16-38t38-16h232V125q0-22 15-38t38-16h107q23 0 38 16t16 38v232h232q23 0 38 16t16 38z"/></symbol>
<symbol id="search" viewBox="0 0 928.6 1000"><path d="M643 464q0-103-73-176t-177-74-177 74-73 176 73 177 177 73 177-73 73-177zm286 465q0 29-22 50t-50 21q-30 0-50-21L616 788q-100 69-223 69-80 0-153-31t-125-84-84-125T0 464t31-152 84-126 125-84 153-31 153 31 125 84 84 126 31 152q0 123-69 223l191 191q21 21 21 51z"/></symbol>
......
......@@ -11,10 +11,9 @@ const KEY_DOWN = 40;
const FOCUSABLE_ELEMENTS = `> .dropdown__toggle,
> .dropdown__menu a[href],
> .dropdown__menu button:not([disabled]),
> .dropdown__menu input:not([disabled])`;
> .dropdown__menu input:not([type="hidden"]):not([disabled])`;
const MENU_ACTIONS = `.dropdown__menu a[href],
.dropdown__menu input[type="button"],
.dropdown__menu button[type="submit"],
.dropdown__menu button:not([type])`;
......
......@@ -64,6 +64,20 @@ unlock:
methods: [POST]
requirements: { submission_id: "%number_regex%" }
pin:
controller: App\Controller\SubmissionController::pin
defaults: { pin: true, slug: '-' }
path: /f/{forum_name}/{submission_id}/{slug}/pin
methods: [POST]
requirements: { submission_id: "%number_regex%" }
unpin:
controller: App\Controller\SubmissionController::pin
defaults: { pin: false, slug: '-' }
path: /f/{forum_name}/{submission_id}/{slug}/unpin
methods: [POST]
requirements: { submission_id: "%number_regex%" }
submit:
controller: App\Controller\SubmissionController::submit
defaults: { forum_name: null }
......
......@@ -287,4 +287,40 @@ final class SubmissionController extends AbstractController {
'slug' => Slugger::slugify($submission->getTitle()),
]);
}
/**
* @IsGranted("ROLE_USER")
* @IsGranted("moderator", subject="forum", statusCode=403)
*
* @param EntityManager $em
* @param Request $request
* @param Forum $forum
* @param Submission $submission
* @param bool $pin
*
* @return Response
*/
public function pin(EntityManager $em, Request $request, Forum $forum, Submission $submission, bool $pin) {
$this->validateCsrf('pin', $request->request->get('token'));
$submission->setSticky($pin);
$em->flush();
if ($pin) {
$this->addFlash('notice', 'flash.submission_pinned');
} else {
$this->addFlash('notice', 'flash.submission_unpinned');
}
if ($request->headers->has('Referer')) {
return $this->redirect($request->headers->get('Referer'));
}
return $this->redirectToRoute('submission', [
'forum_name' => $forum->getName(),
'submission_id' => $submission->getId(),
'slug' => Slugger::slugify($submission->getTitle()),
]);
}
}
......@@ -52,8 +52,6 @@ class SubmissionData {
*/
private $forum;
private $sticky = false;
public function __construct(Forum $forum = null) {
$this->forum = $forum;
}
......@@ -66,7 +64,6 @@ class SubmissionData {
$self->body = $submission->getBody();
$self->userFlag = $submission->getUserFlag();
$self->forum = $submission->getForum();
$self->sticky = $submission->isSticky();
return $self;
}
......@@ -79,7 +76,7 @@ class SubmissionData {
$this->forum,
$user,
$ip,
$this->sticky,
false,
$this->userFlag
);
}
......@@ -101,7 +98,6 @@ class SubmissionData {
}
$submission->setUserFlag($this->userFlag);
$submission->setSticky($this->sticky);
}
public function getEntityId() {
......@@ -147,12 +143,4 @@ class SubmissionData {
public function setForum($forum) {
$this->forum = $forum;
}
public function isSticky(): bool {
return $this->sticky;
}
public function setSticky(bool $sticky) {
$this->sticky = $sticky;
}
}
......@@ -77,8 +77,6 @@ final class SubmissionType extends AbstractType {
$editing && $this->authorizationChecker->isGranted('moderator', $forum) ||
$this->authorizationChecker->isGranted('ROLE_ADMIN')
) {
$builder->add('sticky', CheckboxType::class, ['required' => false]);
$this->addUserFlagOption($builder, $forum);
}
......
......@@ -190,8 +190,8 @@
{% if is_granted('moderator', submission.forum) %}
<li class="dropdown">
<button class="dropdown__toggle fg-inherit text-sm unbuttonize" type="button">
<span>{{ 'nav.actions'|trans }}</span>
<button class="dropdown__toggle fg-inherit text-sm unbuttonize no-underline" type="button">
<span class="no-underline__exempt">{{ 'nav.actions'|trans }}</span>
<span class="dropdown__arrow" aria-hidden="true"></span>
</button>
<ul class="card dropdown__menu unlistify">
......@@ -199,6 +199,7 @@
{{ block('submission_nav_edit') }}
{{ block('submission_nav_delete') }}
{% endif %}
{{ block('submission_nav_pin') }}
{{ block('submission_nav_lock') }}
{{ block('submission_nav_ban') }}
{{ block('submission_nav_global_ban') }}
......@@ -243,6 +244,22 @@
{% endif %}
{% endblock submission_nav_delete %}
{% block submission_nav_pin %}
{% from '_macros/icon.html.twig' import icon %}
<li>
<form action="{{ path(submission.sticky ? 'unpin' : 'pin', {
forum_name: submission.forum.name,
submission_id: submission.id,
}) }}" method="post">
<input type="hidden" name="token" value="{{ csrf_token('pin') }}">
<button class="unbuttonize menu-link no-wrap">
{{- submission.sticky ? icon('pin-outline') : icon('pin') }}
{{ submission.sticky ? 'action.unpin'|trans : 'action.pin'|trans -}}
</button>
</form>
</li>
{% endblock submission_nav_pin %}
{% block submission_nav_lock %}
{% from '_macros/icon.html.twig' import icon %}
<li>
......
......@@ -15,15 +15,7 @@
{{ form_row(form.userFlag) }}
{% endif %}
{% if form.sticky is defined %}
{{ form_row(form.sticky) }}
{% endif %}
<div class="form__row form__button-row">
{{ form_widget(form.submit) }}
{% if form.delete is defined %}
{{ form_widget(form.delete, {attr: {class: 'delete-submission-button'}}) }}
{% endif %}
</div>
{{ form_end(form) }}
......@@ -37,6 +37,8 @@ action:
clear: Clear
clear_all: Clear all
dismiss: Dismiss
pin: Pin
unpin: Unpin
add_moderator:
title: Add moderator to %forum%
......@@ -141,6 +143,8 @@ flash:
editing_credentials_of_other_user: You are editing the credentials of another user. This can prevent them from logging in.
notifications_cleared: Your notifications have been cleared.
you_must_reauthenticate: You must reauthenticate to access this page.
submission_pinned: The submission was pinned.
submission_unpinned: The submission was unpinned.
forum:
moderators: Moderators
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment