Re-work the nav bar at the top a lil; fix date format display; implement routing for the remark mod stuff

This commit is contained in:
swag 2022-12-08 12:41:23 -06:00
parent d01acbcde2
commit bfb5ab9986
7 changed files with 115 additions and 18 deletions

View File

@ -71,6 +71,11 @@ sub startup($self) {
$self->remark->per_page($remarks_per_page)
}
if (my $date_format = $self->config->{'date_format'}) {
$self->thread->date_format($date_format);
$self->remark->date_format($date_format);
}
$self->asset->process('main.css', 'css/PostText.css');
push @{$self->commands->namespaces}, 'PostText::Command';
@ -160,6 +165,20 @@ sub startup($self) {
$mod_thread->get('/unhide/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unhide_thread')
->name('unhide_thread');
my $mod_remark = $moderator->under('/remark');
$mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/])
->to('moderator#unflag_remark')
->name('unflag_remark');
$mod_remark->get('/hide/:remark_id', [remark_id => qr/\d+/])
->to('moderator#hide_remark')
->name('hide_remark');
$mod_remark->get('/unhide/:remark_id', [remark_id => qr/\d+/])
->to('moderator#unhide_remark')
->name('unhide_remark');
}
1;

View File

@ -88,4 +88,39 @@ sub unhide_thread($self) {
$self->redirect_to($redirect_url);
}
sub unflag_remark($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->moderator->unflag_remark($remark_id);
$self->flash(info => "Remark #$remark_id has been unflagged. ◀️");
$self->redirect_to($redirect_url);
}
sub hide_remark($self) {
my $remark_id = $self->param('remark_id');
my $redirect_url = $self->url_for(single_remark => remark_id => $remark_id)
->fragment('info')->to_abs;
$self->moderator->hide_remark($remark_id);
$self->flash(info => "Remark #$remark_id has been hidden. 🫥");
$self->redirect_to($redirect_url);
}
sub unhide_remark($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->moderator->unhide_remark($remark_id);
$self->flash(info => "Remark #$remark_id has been unhidden. ⏪");
$self->redirect_to($redirect_url);
}
1;

View File

@ -60,4 +60,29 @@ sub unhide_thread($self, $thread_id) {
END_SQL
}
sub unflag_remark($self, $remark_id) {
$self->pg->db->query(<<~'END_SQL', $remark_id)
UPDATE remarks
SET flagged_status = FALSE
WHERE remark_id = ?;
END_SQL
}
sub hide_remark($self, $remark_id) {
$self->pg->db->query(<<~'END_SQL', $remark_id)
UPDATE remarks
SET hidden_status = TRUE,
flagged_status = FALSE
WHERE remark_id = ?;
END_SQL
}
sub unhide_remark($self, $remark_id) {
$self->pg->db->query(<<~'END_SQL', $remark_id)
UPDATE remarks
SET hidden_status = FALSE
WHERE remark_id = ?;
END_SQL
}
1;

View File

@ -6,8 +6,10 @@ has 'pg';
has per_page => 5;
has date_format => 'Dy Mon FMDD HH24:MI TZ YYYY';
sub by_page_for($self, $thread_id, $this_page = 1) {
my $date_format = $self->{'date_format'};
my $date_format = $self->date_format;
my $row_count = $self->per_page;
my $offset = ($this_page - 1) * $row_count;
my @data = ($date_format, $thread_id, $row_count, $offset);
@ -60,7 +62,7 @@ sub last_page_for($self, $thread_id) {
}
sub last_for($self, $thread_id) {
my $date_format = $self->{'date_format'};
my $date_format = $self->date_format;
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash;
SELECT remark_id AS id,
@ -75,7 +77,7 @@ sub last_for($self, $thread_id) {
}
sub by_id($self, $remark_id) {
my $date_format = $self->{'date_format'};
my $date_format = $self->date_format;
$self->pg->db->query(<<~'END_SQL', $date_format, $remark_id)->hash;
SELECT remark_id AS id,

View File

@ -6,6 +6,8 @@ has 'pg';
has per_page => 5;
has date_format => 'Dy Mon FMDD HH24:MI TZ YYYY';
sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
my @data = ($author, $title, $body, $hidden, $flagged);
@ -23,7 +25,7 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
}
sub by_page($self, $this_page = 1) {
my $date_format = $self->{'date_format'};
my $date_format = $self->date_format;
my $row_count = $self->per_page;
my $offset = ($this_page - 1) * $row_count;
@ -65,7 +67,7 @@ sub count($self) {
}
sub by_id($self, $thread_id) {
my $date_format = $self->{'date_format'};
my $date_format = $self->date_format;
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash;
SELECT thread_id AS id,

View File

@ -45,9 +45,9 @@ subtest Login => sub {
->status_is(302)
->header_like(Location => qr{thread/list});
#$t->get_ok('/moderator/remark/unflag/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
$t->get_ok('/moderator/remark/unflag/1')
->status_is(302)
->header_like(Location => qr{thread/single});
};
subtest Hide => sub {
@ -58,12 +58,12 @@ subtest Login => sub {
->status_is(302)
->header_like(Location => qr{thread/list});
#$t->get_ok('/moderator/remark/hide/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
#$t->get_ok('/moderator/remark/unhide/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
$t->get_ok('/moderator/remark/hide/1')
->status_is(302)
->header_like(Location => qr{remark/single});
$t->get_ok('/moderator/remark/unhide/1')
->status_is(302)
->header_like(Location => qr{thread/single});
};
subtest 'Buttons for mods', sub {
@ -83,6 +83,20 @@ subtest Login => sub {
$t->get_ok('/logout')
->status_is(302)
->header_like(Location => qr{thread/list});
subtest 'No mod, no buttons', sub {
$t->get_ok('/thread/single/1')
->status_is(200)
->element_exists_not('a[href*="/hide/1"]' )
->element_exists_not('a[href*="/unhide/1"]')
->element_exists_not('a[href*="/unflag/1"]');
$t->get_ok('/remark/single/1')
->status_is(200)
->element_exists_not('a[href*="/hide/1"]' )
->element_exists_not('a[href*="/unhide/1"]')
->element_exists_not('a[href*="/unflag/1"]');
};
};
done_testing();

View File

@ -9,14 +9,14 @@
<nav>
<%= link_to List => 'threads_list' %>
<%= link_to New => 'post_thread' %>
<% unless (is_mod) { =%>
<%= link_to Login => 'mod_login' %>
</nav>
<% if (is_mod) { =%>
<nav>
<% } =%>
<% if (is_mod) { =%>
<%= link_to Flagged => 'flagged_list' %>
<%= link_to Logout => 'mod_logout' %>
</nav>
<% } =%>
</nav>
<hr>
<% if (flash 'error') { =%>
<p class="field-with-error" id="error"><%= flash 'error' %></p>