Skip to content

Commit 101b1c3

Browse files
author
Kaitlyn Parkhurst
committed
Basic Add Blog
1 parent db426a7 commit 101b1c3

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

Web/lib/BlogDB/Web.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ sub startup ($self) {
8787
$auth->post( '/user/settings/email' )->to( 'User#post_email' )->name( 'do_user_email' );
8888

8989
# /blog/ routes
90-
$r->post ( '/blog/new' )->to( 'Blog#post_new_blog' )->name( 'do_new_blog' ); # Create a new blog.
90+
$r->get ( '/blog/new' )->to( 'Blog#get_new_blogs' )->name( 'new_blogs' ); # List new blogs.
91+
$r->post ( '/blog/new' )->to( 'Blog#post_new_blog' )->name( 'do_new_blog' ); # Create a new blog.
92+
$r->get ( '/blog/new/:id' )->to( 'Blog#get_edit_new_blog' )->name( 'edit_new_blog' ); # Show edit a new blog page.
93+
$r->post ( '/blog/new/:id' )->to( 'Blog#post_edit_new_blog')->name( 'do_edit_new_blog' ); # Update a new blog.
9194

9295
# $r->get ( '/view/:id/:name' )->to( 'Blog#get_blog' )->name( 'blog' ); # View A Specific Blog.
9396
#

Web/lib/BlogDB/Web/Controller/Blog.pm

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ sub post_unpublish ($c) {
4040
# Handle New Blogs
4141

4242
sub get_new_blogs ($c) {
43+
$c->set_template( 'blog/new/index' );
4344

45+
push @{$c->stash->{blogs}}, $c->db->resultset('PendingBlog')->all;
4446
}
4547

4648
sub post_new_blog ($c) {
@@ -76,11 +78,55 @@ sub post_new_blog ($c) {
7678
}
7779

7880
sub get_edit_new_blog ($c) {
81+
$c->set_template( 'blog/new/item' );
82+
83+
my $blog_id = $c->stash->{blog_id} = $c->param('id');
84+
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );
85+
86+
87+
# Populate the form with the current values.
88+
89+
$c->stash->{form_title} = $blog->title;
90+
$c->stash->{form_url} = $blog->url;
91+
$c->stash->{form_img_url} = $blog->img_url;
92+
$c->stash->{form_rss_url} = $blog->rss_url;
93+
$c->stash->{form_tagline} = $blog->tagline;
94+
$c->stash->{form_about} = $blog->about;
95+
96+
# Make sure we have added the tags to the page.
97+
push @{$c->stash->{tags}}, $c->db->resultset('Tag')->all;
7998

8099
}
81100

82101
sub post_edit_new_blog ($c) {
83102

103+
my $blog_id = $c->stash->{blog_id} = $c->param('id');
104+
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );
105+
106+
107+
# TODO: This section should be guarded by checking that the user
108+
# has a UUID that allows editing, or is a logged in user with
109+
# such permissions as allows editing it.
110+
$c->stash->{form_title} = $c->param("title");
111+
$c->stash->{form_url} = $c->param("url");
112+
$c->stash->{form_img_url} = $c->param("img_url");
113+
$c->stash->{form_rss_url} = $c->param("rss_url");
114+
$c->stash->{form_tagline} = $c->param("tagline");
115+
$c->stash->{form_about} = $c->param("about");
116+
117+
118+
$blog->title( $c->stash->{form_title} );
119+
$blog->url( $c->stash->{form_url} );
120+
$blog->img_url( $c->stash->{form_img_url} );
121+
$blog->rss_url( $c->stash->{form_rss_url} );
122+
$blog->tagline( $c->stash->{form_tagline} );
123+
$blog->about( $c->stash->{form_about} );
124+
125+
$blog->update;
126+
127+
# Send the user back to the standard GET path.
128+
$c->redirect_to( $c->url_for( 'edit_new_blog', id => $blog->id ) );
129+
84130
}
85131

86132
1;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
%% cascade default::_::layout { title => 'List Pending Blogs',
2+
%%
3+
%% }
4+
5+
%% override panel -> {
6+
7+
%% for $blogs -> $blog {
8+
[% $blog.title %]
9+
10+
%% }
11+
12+
%% }
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
%% cascade default::_::layout { title => 'Edit ' ~ $blog_url,
2+
%%
3+
%% }
4+
5+
%% override panel -> {
6+
7+
<h3>[% $blog_url %]</h3>
8+
9+
<div class="row">
10+
<!-- Error Handling On LHS -->
11+
<div class="col">
12+
%% if ( $errors.size() ) {
13+
<div style="margin-top: 2em" class="alert alert-danger" role="alert">
14+
There were errors with your request that could not be resolved:
15+
<ul>
16+
%% for $errors -> $error {
17+
<li>[% $error %]</li>
18+
%% }
19+
</ul>
20+
</div>
21+
%% }
22+
</div>
23+
</div>
24+
25+
<div class="row">
26+
<div class="col">
27+
<form method="post" action="[% $c.url_for( 'do_edit_new_blog' ) %]">
28+
29+
%% include 'default/_/form/input.tx' { type => 'text', name => 'title',
30+
%% title => 'Title',
31+
%% help => 'The title of the blog',
32+
%% value => $form_title,
33+
%% };
34+
35+
%% include 'default/_/form/input.tx' { type => 'text', name => 'tagline',
36+
%% title => 'Tagline',
37+
%% help => 'The tagline of the blog.',
38+
%% value => $form_tagline,
39+
%% };
40+
41+
<textarea name="about" rows="4">[% $form_about %]</textarea>
42+
43+
<br />
44+
45+
<h2>Existing Tags</h2>
46+
%% for $tags -> $tag {
47+
<p>
48+
#[% $tag.name %]
49+
[% $tag.is_adult ? mark_raw("<small>(Adult)</small>") : "" %]
50+
</p>
51+
52+
%% }
53+
<br />
54+
%% include 'default/_/form/input.tx' { type => 'text', name => 'url',
55+
%% title => 'Homepage URL',
56+
%% help => 'The url of the blog',
57+
%% value => $form_url,
58+
%% };
59+
60+
%% include 'default/_/form/input.tx' { type => 'text', name => 'img_url',
61+
%% title => 'Homepage Image URL',
62+
%% help => 'A URL to a screenshot of the homepage.',
63+
%% value => $form_img_url,
64+
%% };
65+
66+
%% include 'default/_/form/input.tx' { type => 'text', name => 'rss_url',
67+
%% title => 'RSS URL',
68+
%% help => 'A URL to an RSS feed for the blog.',
69+
%% value => $form_rss_url,
70+
%% };
71+
72+
<button type="submit" class="btn btn-primary float-end">Update Blog</button>
73+
74+
</form>
75+
</div>
76+
</div>
77+
78+
%% }

0 commit comments

Comments
 (0)