Skip to content

Commit d5fa85d

Browse files
committed
Blog Edit Page
1 parent dcd50a7 commit d5fa85d

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,17 @@ sub get_edit_new_blog ($c) {
9595
$c->stash->{form_rss_url} = $blog->rss_url;
9696
$c->stash->{form_tagline} = $blog->tagline;
9797
$c->stash->{form_about} = $blog->about;
98+
$c->stash->{form_adult} = $blog->is_adult;
9899

99-
# Make sure we have added the tags to the page.
100-
push @{$c->stash->{tags}}, $c->db->resultset('Tag')->all;
100+
my %seen = map { $_->tag_id => 1 } $blog->search_related('pending_blog_tag_maps', {})->all;
101+
foreach my $tag ( $c->db->resultset('Tag')->all ) {
102+
push @{$c->stash->{tags}}, {
103+
id => $tag->id,
104+
name => $tag->name,
105+
checked => $seen{$tag->id} ? 1 : 0,
106+
};
101107

108+
}
102109
}
103110

104111
sub post_edit_new_blog ($c) {
@@ -116,17 +123,26 @@ sub post_edit_new_blog ($c) {
116123
$c->stash->{form_rss_url} = $c->param("rss_url");
117124
$c->stash->{form_tagline} = $c->param("tagline");
118125
$c->stash->{form_about} = $c->param("about");
126+
$c->stash->{form_adult} = $c->param("is_adult") ? 1 : 0;
119127

120-
121-
$blog->title( $c->stash->{form_title} );
122-
$blog->url( $c->stash->{form_url} );
123-
$blog->img_url( $c->stash->{form_img_url} );
124-
$blog->rss_url( $c->stash->{form_rss_url} );
125-
$blog->tagline( $c->stash->{form_tagline} );
126-
$blog->about( $c->stash->{form_about} );
128+
$blog->title ( $c->stash->{form_title} );
129+
$blog->url ( $c->stash->{form_url} );
130+
$blog->img_url ( $c->stash->{form_img_url} );
131+
$blog->rss_url ( $c->stash->{form_rss_url} );
132+
$blog->tagline ( $c->stash->{form_tagline} );
133+
$blog->about ( $c->stash->{form_about} );
134+
$blog->is_adult( $c->stash->{form_adult} );
127135

128136
$blog->update;
129137

138+
# Remove all tags, then add the tags we have set.
139+
$blog->search_related('pending_blog_tag_maps')->delete;
140+
foreach my $tag_id ( @{$c->every_param('tags')}) {
141+
$blog->create_related('pending_blog_tag_maps', {
142+
tag_id => $tag_id,
143+
});
144+
}
145+
130146
# Send the user back to the standard GET path.
131147
$c->redirect_to( $c->url_for( 'edit_new_blog', id => $blog->id ) );
132148

Web/templates/default/_/layout.tx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
</div>
6464
</nav>
6565

66-
<main class="content-fluid main">
66+
<main class="container-fluid main">
6767

6868
%% block panel -> {}
6969

Web/templates/default/blog/new/item.html.tx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44

55
%% override panel -> {
66

7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
718
<h3>[% $blog_url %]</h3>
819

920
<div class="row">
@@ -39,17 +50,22 @@
3950
%% };
4051

4152
<textarea name="about" rows="4">[% $form_about %]</textarea>
53+
4254

4355
<br />
4456

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>
57+
<div class="form-check form-switch">
5158

52-
%% }
59+
<input class="form-check-input" type="checkbox" value="1" name="is_adult" id="is_adult" [% $form_adult ? " checked " : "" %]>
60+
<label class="form-check-label" for="is_adult">Adult Content</label>
61+
</div>
62+
63+
%% for $tags -> $tag {
64+
<div class="form-check">
65+
<input class="form-check-input" type="checkbox" value="[% $tag.id %]" name="tags" id="tag_[% $tag.id %]" [% $tag.checked ? " checked " : "" %]>
66+
<label class="form-check-label" for="tag_[% $tag.id %]">[% $tag.name %]</label>
67+
</div>
68+
%% }
5369
<br />
5470
%% include 'default/_/form/input.tx' { type => 'text', name => 'url',
5571
%% title => 'Homepage URL',
@@ -73,6 +89,9 @@
7389

7490
</form>
7591
</div>
92+
<div class="col">
93+
<img width="80%" src="/blog_screenshots/[% $blog_id %].jpg">
94+
</div>
7695
</div>
7796

7897
%% }

0 commit comments

Comments
 (0)