Skip to content

Commit

Permalink
Basic Add Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaitlyn Parkhurst committed Nov 20, 2021
1 parent db426a7 commit 101b1c3
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Web/lib/BlogDB/Web.pm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ sub startup ($self) {
$auth->post( '/user/settings/email' )->to( 'User#post_email' )->name( 'do_user_email' );

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

# $r->get ( '/view/:id/:name' )->to( 'Blog#get_blog' )->name( 'blog' ); # View A Specific Blog.
#
Expand Down
46 changes: 46 additions & 0 deletions Web/lib/BlogDB/Web/Controller/Blog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ sub post_unpublish ($c) {
# Handle New Blogs

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

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

sub post_new_blog ($c) {
Expand Down Expand Up @@ -76,11 +78,55 @@ sub post_new_blog ($c) {
}

sub get_edit_new_blog ($c) {
$c->set_template( 'blog/new/item' );

my $blog_id = $c->stash->{blog_id} = $c->param('id');
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );


# Populate the form with the current values.

$c->stash->{form_title} = $blog->title;
$c->stash->{form_url} = $blog->url;
$c->stash->{form_img_url} = $blog->img_url;
$c->stash->{form_rss_url} = $blog->rss_url;
$c->stash->{form_tagline} = $blog->tagline;
$c->stash->{form_about} = $blog->about;

# Make sure we have added the tags to the page.
push @{$c->stash->{tags}}, $c->db->resultset('Tag')->all;

}

sub post_edit_new_blog ($c) {

my $blog_id = $c->stash->{blog_id} = $c->param('id');
my $blog = $c->stash->{blog_obj} = $c->db->resultset('PendingBlog')->find( $blog_id );


# TODO: This section should be guarded by checking that the user
# has a UUID that allows editing, or is a logged in user with
# such permissions as allows editing it.
$c->stash->{form_title} = $c->param("title");
$c->stash->{form_url} = $c->param("url");
$c->stash->{form_img_url} = $c->param("img_url");
$c->stash->{form_rss_url} = $c->param("rss_url");
$c->stash->{form_tagline} = $c->param("tagline");
$c->stash->{form_about} = $c->param("about");


$blog->title( $c->stash->{form_title} );
$blog->url( $c->stash->{form_url} );
$blog->img_url( $c->stash->{form_img_url} );
$blog->rss_url( $c->stash->{form_rss_url} );
$blog->tagline( $c->stash->{form_tagline} );
$blog->about( $c->stash->{form_about} );

$blog->update;

# Send the user back to the standard GET path.
$c->redirect_to( $c->url_for( 'edit_new_blog', id => $blog->id ) );

}

1;
12 changes: 12 additions & 0 deletions Web/templates/default/blog/new/index.html.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
%% cascade default::_::layout { title => 'List Pending Blogs',
%%
%% }

%% override panel -> {

%% for $blogs -> $blog {
[% $blog.title %]

%% }

%% }
78 changes: 78 additions & 0 deletions Web/templates/default/blog/new/item.html.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
%% cascade default::_::layout { title => 'Edit ' ~ $blog_url,
%%
%% }

%% override panel -> {

<h3>[% $blog_url %]</h3>

<div class="row">
<!-- Error Handling On LHS -->
<div class="col">
%% if ( $errors.size() ) {
<div style="margin-top: 2em" class="alert alert-danger" role="alert">
There were errors with your request that could not be resolved:
<ul>
%% for $errors -> $error {
<li>[% $error %]</li>
%% }
</ul>
</div>
%% }
</div>
</div>

<div class="row">
<div class="col">
<form method="post" action="[% $c.url_for( 'do_edit_new_blog' ) %]">

%% include 'default/_/form/input.tx' { type => 'text', name => 'title',
%% title => 'Title',
%% help => 'The title of the blog',
%% value => $form_title,
%% };

%% include 'default/_/form/input.tx' { type => 'text', name => 'tagline',
%% title => 'Tagline',
%% help => 'The tagline of the blog.',
%% value => $form_tagline,
%% };

<textarea name="about" rows="4">[% $form_about %]</textarea>

<br />

<h2>Existing Tags</h2>
%% for $tags -> $tag {
<p>
#[% $tag.name %]
[% $tag.is_adult ? mark_raw("<small>(Adult)</small>") : "" %]
</p>

%% }
<br />
%% include 'default/_/form/input.tx' { type => 'text', name => 'url',
%% title => 'Homepage URL',
%% help => 'The url of the blog',
%% value => $form_url,
%% };

%% include 'default/_/form/input.tx' { type => 'text', name => 'img_url',
%% title => 'Homepage Image URL',
%% help => 'A URL to a screenshot of the homepage.',
%% value => $form_img_url,
%% };

%% include 'default/_/form/input.tx' { type => 'text', name => 'rss_url',
%% title => 'RSS URL',
%% help => 'A URL to an RSS feed for the blog.',
%% value => $form_rss_url,
%% };

<button type="submit" class="btn btn-primary float-end">Update Blog</button>

</form>
</div>
</div>

%% }

0 comments on commit 101b1c3

Please sign in to comment.