Implement flag button
This commit is contained in:
parent
419769545b
commit
0cd3142250
|
@ -32,7 +32,6 @@ Run the tests locally (against development environment):
|
||||||
|
|
||||||
## TODOs
|
## TODOs
|
||||||
|
|
||||||
1. Implement flag post button
|
|
||||||
1. Implement
|
1. Implement
|
||||||
[bcrypt](https://metacpan.org/pod/Mojolicious::Plugin::BcryptSecure)
|
[bcrypt](https://metacpan.org/pod/Mojolicious::Plugin::BcryptSecure)
|
||||||
1. Some sort of admin/moderator login and view
|
1. Some sort of admin/moderator login and view
|
||||||
|
|
|
@ -81,6 +81,11 @@ sub startup($self) {
|
||||||
->to('thread#bump')
|
->to('thread#bump')
|
||||||
->name('bump_thread');
|
->name('bump_thread');
|
||||||
|
|
||||||
|
$thread->under('/flag')
|
||||||
|
->get('/:thread_id', [thread_id => qr/[0-9]+/])
|
||||||
|
->to('thread#flag')
|
||||||
|
->name('flag_thread');
|
||||||
|
|
||||||
# Remark
|
# Remark
|
||||||
my $remark = $r->under('/remark');
|
my $remark = $r->under('/remark');
|
||||||
|
|
||||||
|
@ -93,6 +98,11 @@ sub startup($self) {
|
||||||
->get('/:remark_id', [remark_id => qr/[0-9]+/])
|
->get('/:remark_id', [remark_id => qr/[0-9]+/])
|
||||||
->to('remark#by_id')
|
->to('remark#by_id')
|
||||||
->name('single_remark');
|
->name('single_remark');
|
||||||
|
|
||||||
|
$remark->under('/flag')
|
||||||
|
->get('/:remark_id', [remark_id => qr/[0-9]+/])
|
||||||
|
->to('remark#flag')
|
||||||
|
->name('flag_remark');
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -57,4 +57,18 @@ sub create($self) {
|
||||||
return $self->render;
|
return $self->render;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub flag($self) {
|
||||||
|
my $remark_id = $self->param('remark_id');
|
||||||
|
my $thread_id = $self->remark->thread_id_for($remark_id);
|
||||||
|
my $redirect_url =
|
||||||
|
$self->url_for('single_thread', thread_id => $thread_id)
|
||||||
|
->fragment('info')->to_abs;
|
||||||
|
|
||||||
|
|
||||||
|
$self->remark->flag($remark_id);
|
||||||
|
$self->flash(info => "Remark #$remark_id has been flagged. 🚩");
|
||||||
|
|
||||||
|
$self->redirect_to($redirect_url);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -96,4 +96,14 @@ sub bump($self) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub flag($self) {
|
||||||
|
my $thread_id = $self->param('thread_id');
|
||||||
|
my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs;
|
||||||
|
|
||||||
|
$self->thread->flag($thread_id);
|
||||||
|
$self->flash(info => "Thread #$thread_id has been flagged. 🚩");
|
||||||
|
|
||||||
|
$self->redirect_to($redirect_url);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -106,4 +106,20 @@ sub thread_id_for($self, $remark_id) {
|
||||||
END_SQL
|
END_SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub flag($self, $remark_id) {
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $remark_id)
|
||||||
|
UPDATE remarks
|
||||||
|
SET flagged_status = TRUE
|
||||||
|
WHERE remark_id = ?;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
|
sub unflag($self, $remark_id) {
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $remark_id)
|
||||||
|
UPDATE remarks
|
||||||
|
SET flagged_status = FALSE
|
||||||
|
WHERE remark_id = ?;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -97,4 +97,20 @@ sub bump($self, $thread_id) {
|
||||||
END_SQL
|
END_SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub flag($self, $thread_id) {
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||||
|
UPDATE threads
|
||||||
|
SET flagged_status = TRUE
|
||||||
|
WHERE thread_id = ?;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
|
sub unflag($self, $thread_id) {
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||||
|
UPDATE threads
|
||||||
|
SET flagged_status = FALSE
|
||||||
|
WHERE thread_id = ?;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -46,7 +46,11 @@ subtest 'Post new remark', sub {
|
||||||
subtest 'Flagging remark', sub {
|
subtest 'Flagging remark', sub {
|
||||||
$t->get_ok('/remark/single/1')->status_is(200)
|
$t->get_ok('/remark/single/1')->status_is(200)
|
||||||
->element_exists('a[href*="flag"]')
|
->element_exists('a[href*="flag"]')
|
||||||
->text_like(h2 => qr/Thread #1/);
|
->text_like(h2 => qr/Remark #1/);
|
||||||
}
|
|
||||||
|
$t->get_ok('/remark/flag/1')->status_is(200)
|
||||||
|
->element_exists('p[class="field-with-info"]')
|
||||||
|
->text_like(p => qr/Remark #1 has been flagged/);
|
||||||
|
};
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
12
t/thread.t
12
t/thread.t
|
@ -72,9 +72,13 @@ subtest 'Bumping thread', sub {
|
||||||
->element_exists('a[href*="bump"]')
|
->element_exists('a[href*="bump"]')
|
||||||
->text_like(h2 => qr/Threads List/);
|
->text_like(h2 => qr/Threads List/);
|
||||||
|
|
||||||
|
$t->get_ok('/thread/single/1')->status_is(200)
|
||||||
|
->element_exists('a[href*="bump"]')
|
||||||
|
->text_like(h2 => qr/Thread #1/);
|
||||||
|
|
||||||
$t->get_ok('/thread/bump/1')->status_is(200)
|
$t->get_ok('/thread/bump/1')->status_is(200)
|
||||||
->element_exists('p[class="field-with-info"]')
|
->element_exists('p[class="field-with-info"]')
|
||||||
->text_like(p => qr/Thread #[0-9]+ has been bumped/);
|
->text_like(p => qr/Thread #1 has been bumped/);
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'Flagging thread', sub {
|
subtest 'Flagging thread', sub {
|
||||||
|
@ -85,6 +89,10 @@ subtest 'Flagging thread', sub {
|
||||||
$t->get_ok('/thread/single/1')->status_is(200)
|
$t->get_ok('/thread/single/1')->status_is(200)
|
||||||
->element_exists('a[href*="flag"]')
|
->element_exists('a[href*="flag"]')
|
||||||
->text_like(h2 => qr/Thread #1/);
|
->text_like(h2 => qr/Thread #1/);
|
||||||
}
|
|
||||||
|
$t->get_ok('/thread/flag/1')->status_is(200)
|
||||||
|
->element_exists('p[class="field-with-info"]')
|
||||||
|
->text_like(p => qr/Thread #1 has been flagged/);
|
||||||
|
};
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
|
@ -11,4 +11,5 @@
|
||||||
</div>
|
</div>
|
||||||
<nav>
|
<nav>
|
||||||
<%= link_to Thread => single_thread => {thread_id => $remark->{'thread_id'}} %>
|
<%= link_to Thread => single_thread => {thread_id => $remark->{'thread_id'}} %>
|
||||||
|
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}} %>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<nav>
|
<nav>
|
||||||
<%= link_to Remark => post_remark => {thread_id => $thread->{'id'}} %>
|
<%= link_to Remark => post_remark => {thread_id => $thread->{'id'}} %>
|
||||||
<%= link_to Bump => bump_thread => {thread_id => $thread->{'id'}} %>
|
<%= link_to Bump => bump_thread => {thread_id => $thread->{'id'}} %>
|
||||||
|
<%= link_to Flag => flag_thread => {thread_id => $thread->{'id'}} %>
|
||||||
</nav>
|
</nav>
|
||||||
<% if (my $first_remark = $remarks->[0]) { =%>
|
<% if (my $first_remark = $remarks->[0]) { =%>
|
||||||
<div class="remarks" id="remarks">
|
<div class="remarks" id="remarks">
|
||||||
|
@ -25,6 +26,9 @@
|
||||||
<h4 class="date"><%= $remark->{'date'} %></h4>
|
<h4 class="date"><%= $remark->{'date'} %></h4>
|
||||||
<h5 class="author"><%= $remark->{'author'} %></h5>
|
<h5 class="author"><%= $remark->{'author'} %></h5>
|
||||||
<p class="body"><%= $remark->{'body'} %></p>
|
<p class="body"><%= $remark->{'body'} %></p>
|
||||||
|
<nav>
|
||||||
|
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}} %>
|
||||||
|
</nav>
|
||||||
</article>
|
</article>
|
||||||
<% } =%>
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
Bump (<%= $thread->{'bump_count'} %> bumps)
|
Bump (<%= $thread->{'bump_count'} %> bumps)
|
||||||
<% end %>
|
<% end %>
|
||||||
</nav>
|
</nav>
|
||||||
|
<nav>
|
||||||
|
<%= link_to Flag => flag_thread => {thread_id => $thread->{'id'}} %>
|
||||||
|
</nav>
|
||||||
</article>
|
</article>
|
||||||
<% } =%>
|
<% } =%>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue