Add thread creation ability
This commit is contained in:
parent
51b2c54e9a
commit
ff55197474
|
@ -67,17 +67,26 @@ sub startup {
|
||||||
# router
|
# router
|
||||||
my $r = $self->routes;
|
my $r = $self->routes;
|
||||||
|
|
||||||
|
# controller routes
|
||||||
|
## index page
|
||||||
|
$r->get('/')->to(
|
||||||
|
controller => 'Controller::Index',
|
||||||
|
action => 'index'
|
||||||
|
);
|
||||||
# view subforum
|
# view subforum
|
||||||
$r->get('/subforum/:id')->to(
|
$r->get('/subforum/:id')->to(
|
||||||
controller => 'Controller::ViewSubf',
|
controller => 'Controller::ViewSubf',
|
||||||
action => 'subf_view'
|
action => 'subf_view'
|
||||||
);
|
);
|
||||||
|
|
||||||
# controller routes
|
# create thread
|
||||||
## index page
|
$r->get('/thread/new/:id')->to(
|
||||||
$r->get('/')->to(
|
controller => 'Controller::NewThread',
|
||||||
controller => 'Controller::Index',
|
action => 'thread_compose'
|
||||||
action => 'index'
|
);
|
||||||
|
$r->post('/thread/new/:id')->to(
|
||||||
|
controller => 'Controller::NewThread',
|
||||||
|
action => 'thread_submit'
|
||||||
);
|
);
|
||||||
|
|
||||||
## registration page
|
## registration page
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package CharmBoard::Controller::NewThread;
|
||||||
|
|
||||||
|
use utf8;
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use experimental qw(try smartmatch);
|
||||||
|
|
||||||
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||||
|
|
||||||
|
sub thread_compose {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $subf_id = $self->param('id');
|
||||||
|
my $subf_cat =
|
||||||
|
$self->schema->resultset('Subforums')->cat_from_id($subf_id);
|
||||||
|
my $cat_title =
|
||||||
|
$self->schema->resultset('Categories')
|
||||||
|
->title_from_id($subf_cat);
|
||||||
|
|
||||||
|
$self->render(
|
||||||
|
template => 'thread_compose',
|
||||||
|
subf_id => $subf_id,
|
||||||
|
cat_title => $cat_title,
|
||||||
|
subf_title => $self->schema->resultset('Subforums')
|
||||||
|
->title_from_id($subf_id),
|
||||||
|
error => $self->flash('error'),
|
||||||
|
message => $self->flash('message')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
sub thread_submit {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
my $thread_title = $self->param('thread-title');
|
||||||
|
my $post_content = $self->param('post-content');
|
||||||
|
my $post_time = time;
|
||||||
|
|
||||||
|
my $catch_error;
|
||||||
|
|
||||||
|
# make sure post data is valid
|
||||||
|
try {
|
||||||
|
($thread_title, $post_content)
|
||||||
|
or die "Please fill both the title and post content fields"
|
||||||
|
} catch ($catch_error) {
|
||||||
|
$self->flash(error => $catch_error);
|
||||||
|
$self->redirect_to('/thread/new/:id')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
__END__
|
|
@ -1,4 +1,5 @@
|
||||||
% layout 'default', title => $self->board_name;
|
% layout 'default',
|
||||||
|
% title => $self->board_name;
|
||||||
|
|
||||||
<% my $cat_header = begin %>
|
<% my $cat_header = begin %>
|
||||||
% my $_cat_id = shift; my $_name = shift;
|
% my $_cat_id = shift; my $_name = shift;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
% layout 'default', title => $self->board_name . ' - Login';
|
% layout 'default',
|
||||||
|
% title => $self->board_name . ' - Login';
|
||||||
% if ($error) {
|
% if ($error) {
|
||||||
<p style="color: red"><%= $error %></p>
|
<p style="color: red"><%= $error %></p>
|
||||||
%};
|
%};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
% layout 'default', title => $self->board_name . ' - Registration';
|
% layout 'default',
|
||||||
|
% title => $self->board_name . ' - Registration';
|
||||||
% if ($error) {
|
% if ($error) {
|
||||||
<p style="color: red"><%= $error %></p>
|
<p style="color: red"><%= $error %></p>
|
||||||
%};
|
%};
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
% layout 'default', title => $subf_title . ' - ' . $self->board_name;
|
% layout 'default',
|
||||||
|
% title => $subf_title . ' - ' . $self->board_name;
|
||||||
% my @thread_list = @{stash('thread_list')};
|
% my @thread_list = @{stash('thread_list')};
|
||||||
|
|
||||||
<% my $thread_item = begin %>
|
<% my $thread_item = begin %>
|
||||||
|
@ -8,7 +9,8 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<a href="/"><%= $self->board_name %></a> » <%= $cat_title %> » <%= $subf_title %>
|
<a href="/"><%= $self->board_name %></a> » <%= $cat_title %> »
|
||||||
|
<%= $subf_title %>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
|
|
||||||
<% if (! @thread_list) { %>
|
<% if (! @thread_list) { %>
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
% layout 'default',
|
||||||
|
% title => 'New thread - ' . $self->board_name;
|
||||||
|
<a href="/"><%= $self->board_name %></a> » <%= $cat_title %> »
|
||||||
|
<%= $subf_title %> » new thread
|
||||||
|
<br /><br />
|
||||||
|
<form method="post" action="/thread/new/<%= $subf_id %>">
|
||||||
|
<input
|
||||||
|
id="thread-title"
|
||||||
|
name="thread-title"
|
||||||
|
type="text"
|
||||||
|
placeholder="thread title"
|
||||||
|
/><br />
|
||||||
|
<textarea
|
||||||
|
id="post-content"
|
||||||
|
name="post-content"
|
||||||
|
cols="50" rows="5"
|
||||||
|
placeholder="post content">
|
||||||
|
</textarea><br /><br />
|
||||||
|
<input type="submit" value="post!" />
|
||||||
|
</form>
|
Loading…
Reference in New Issue