[Catalyst-commits] r12325 - in trunk/examples/SmallBoard: .
lib/SmallBoard/Controller root/src root/src/board
dhoss at dev.catalyst.perl.org
dhoss at dev.catalyst.perl.org
Sun Dec 13 04:40:15 GMT 2009
Author: dhoss
Date: 2009-12-13 04:40:15 +0000 (Sun, 13 Dec 2009)
New Revision: 12325
Added:
trunk/examples/SmallBoard/root/src/board/list.tt2
trunk/examples/SmallBoard/root/src/board/reply.tt2
trunk/examples/SmallBoard/root/src/board/view.tt2
Modified:
trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm
trunk/examples/SmallBoard/lib/SmallBoard/Controller/Root.pm
trunk/examples/SmallBoard/root/src/index.tt2
trunk/examples/SmallBoard/smallboard.db
Log:
replies now work
Modified: trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm 2009-12-13 03:23:46 UTC (rev 12324)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Controller/Board.pm 2009-12-13 04:40:15 UTC (rev 12325)
@@ -32,7 +32,7 @@
sub load_threads : Chained('board_base') PathPart('') CaptureArgs(1) {
my ($self, $c, $thread_id) = @_;
- my $thread = $c->model('Board')->find($thread_id);
+ my $thread = $c->model('Board::Thread')->find($thread_id);
if ($thread_id) {
$c->stash( thread => $thread );
@@ -42,8 +42,11 @@
}
}
-sub view : Chained('load_threads') PathPart('view') Args(0) {}
+sub view : Chained('load_threads') PathPart('view') Args(0) {
+ my ($self, $c) = @_;
+}
+
sub create : Chained('board_base') PathPart('new') Args(0) {
my ($self, $c) = @_;
@@ -56,8 +59,44 @@
}
}
+
+sub reply : Chained('load_threads') PathPart('reply') Args(0) {
+ my ($self, $c) = @_;
+ my $parent = $c->stash->{thread};
+ if ( $c->req->param('submitted') ) {
+ my $params = $c->req->params;
+ delete $params->{$_} for qw/submitted submit/;
+ my $reply = $c->model('Board::Thread')->create($params);
+ $reply->update({ parent_id => $parent->thread_id }) or die "Error :$!";
+ $c->msg("Reply added!");
+ }
+ $c->stash(
+ parent => $parent,
+ );
+}
+
+sub list : Path Args(1) {
+ my ($self, $c, $page) = @_;
+
+ $page ||= 1;
+ my $rs = $c->model("Board::Thread")->search(
+ {
+ parent_id => undef,
+ },
+ {
+ rows => 50,
+ order_by => "thread_id",
+ page => $page,
+ }
+);
+ $c->stash(
+ threads => [ $rs->all ],
+ pager => $rs->pager,
+ );
+}
+
=head1 AUTHOR
Devin Austin
Modified: trunk/examples/SmallBoard/lib/SmallBoard/Controller/Root.pm
===================================================================
--- trunk/examples/SmallBoard/lib/SmallBoard/Controller/Root.pm 2009-12-13 03:23:46 UTC (rev 12324)
+++ trunk/examples/SmallBoard/lib/SmallBoard/Controller/Root.pm 2009-12-13 04:40:15 UTC (rev 12325)
@@ -29,7 +29,11 @@
sub index :Path :Args(0) {
my ( $self, $c ) = @_;
+ my @threads = $c->model('Board::Thread')->search({ parent_id => undef }, { order_by => 'thread_id DESC', limit => 50 });
# main links: create message, delete message etc.
+ $c->stash(
+ threads =>\@threads
+ );
}
sub default :Path {
Added: trunk/examples/SmallBoard/root/src/board/list.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/board/list.tt2 (rev 0)
+++ trunk/examples/SmallBoard/root/src/board/list.tt2 2009-12-13 04:40:15 UTC (rev 12325)
@@ -0,0 +1,10 @@
+
+<p>Listing threads:</p>
+[% IF pager.current_page != pager.first_page ||
+ pager.current_page != pager.last_page %]
+<a href="[% c.uri_for_action("board/list", [ pager.previous_page ]) %]"><<</a>|
+<a href="[% c.uri_for_action("board/list", [ pager.next_page ]) %]">>></a>
+[% END %]
+[% FOR thread IN threads %]
+<div><a href="[% c.uri_for_action("board/view", [thread.thread_id]) %]">[% thread.title %]</a> - [% thread.children.count %] replies</div>
+[% END %]
Added: trunk/examples/SmallBoard/root/src/board/reply.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/board/reply.tt2 (rev 0)
+++ trunk/examples/SmallBoard/root/src/board/reply.tt2 2009-12-13 04:40:15 UTC (rev 12325)
@@ -0,0 +1,8 @@
+<p>Replying to [% parent.title %]</p>
+<form method="POST" action="">
+<input type="hidden" name="submitted" value=1 />
+<p>Title: <input type="text" name="title" /></p>
+<p>Content:</p>
+<textarea name="content" rows="10" cols="45">
+</textarea>
+<p><input type="submit" name="submit" value="Post" />
Added: trunk/examples/SmallBoard/root/src/board/view.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/board/view.tt2 (rev 0)
+++ trunk/examples/SmallBoard/root/src/board/view.tt2 2009-12-13 04:40:15 UTC (rev 12325)
@@ -0,0 +1,4 @@
+
+<h2>[% thread.title %]</h2>
+<div>[% thread.content %]</div>
+<div><a href="[% c.uri_for_action('board/reply', [thread.thread_id]) %]">reply</a></div>
Modified: trunk/examples/SmallBoard/root/src/index.tt2
===================================================================
--- trunk/examples/SmallBoard/root/src/index.tt2 2009-12-13 03:23:46 UTC (rev 12324)
+++ trunk/examples/SmallBoard/root/src/index.tt2 2009-12-13 04:40:15 UTC (rev 12325)
@@ -1,3 +1,6 @@
<h2>SMALLBOARD IS SMALL</h2>
-|<a href="[% c.uri_for_action("board/create") %]">create a new thread</a> |
-<p>Recent threads:</p>
+|<a href="[% c.uri_for_action('board/create') %]">create a new thread</a> |
+<p>Recent threads (<a href="[% c.uri_for_action('board/list') %]">view all</a>):</p>
+[% FOR thread IN threads %]
+<div><a href="[% c.uri_for_action("board/view", [thread.thread_id]) %]">[% thread.title %]</a> - [% thread.get_direct_children.count %] replies</div>
+[% END %]
Modified: trunk/examples/SmallBoard/smallboard.db
===================================================================
--- trunk/examples/SmallBoard/smallboard.db 2009-12-13 03:23:46 UTC (rev 12324)
+++ trunk/examples/SmallBoard/smallboard.db 2009-12-13 04:40:15 UTC (rev 12325)
@@ -1,8 +1,8 @@
-SQLite format 3 @
è Gè ]5{indexnested_idx_parent_idnestedCREATE INDEX nested_idx_parent_id ON nested (parent_id)6GtablenestednestedCREATE TABLE nested (
+SQLite format 3 @
è Gè ]5{indexnested_idx_parent_idnestedCREATE INDEX nested_idx_parent_id ON nested (parent_id)6GtablenestednestedCREATE TABLE nested (
thread_id INTEGER PRIMARY KEY NOT NULL,
title varchar NOT NULL,
content text NOT NULL,
parent_id int,
path varchar NOT NULL
-)
ï ï testtest1
- û û
\ No newline at end of file
+)
ïÞÊ . +7testing a replytesting a reply again2.1 testtest1.1 testtest2 testtest1
+ ê ûöðê
\ No newline at end of file
More information about the Catalyst-commits
mailing list