Skip to content

Commit 15fda13

Browse files
committed
add edit and update feature
1 parent 9042515 commit 15fda13

File tree

6 files changed

+79
-29
lines changed

6 files changed

+79
-29
lines changed

public/stylesheets/style.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,23 @@ a.nav-item:hover, a.nav-item:active, a.nav-item:link, a.nav-item:visited {
119119
/* -------------------------------------------------------------------- */
120120
.has-text-dark {
121121
color: hsl(0, 0%, 21%);
122-
}
122+
}
123+
124+
::-webkit-scrollbar {
125+
width: 2px;
126+
}
127+
128+
/* Track */
129+
::-webkit-scrollbar-track {
130+
background: #f1f1f1;
131+
}
132+
133+
/* Handle */
134+
::-webkit-scrollbar-thumb {
135+
background: #868;
136+
}
137+
138+
/* Handle on hover */
139+
::-webkit-scrollbar-thumb:hover {
140+
background: #555;
141+
}

routes/blogs.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,30 @@ router.get("/blog/:id", function(req, res) {
4242
})
4343
})
4444

45-
// //EDIT
46-
// router.get("/:id/edit", middleware.checkCampgroundOwnership, function(req, res){
47-
// Campground.findById(req.params.id, function(err, foundCampground){
48-
// if(err){
49-
// res.redirect("/campgrounds")
50-
// } else{
51-
// res.render("campgrounds/edit", {campground: foundCampground})
52-
// }
53-
// })
54-
// })
45+
//EDIT
46+
router.get("/blog/:id/edit", middleware.checkBlogOwnership, function(req, res){
47+
Blog.findById(req.params.id, function(err, foundBlog){
48+
if(err){
49+
res.redirect("/")
50+
} else{
51+
res.render("blogs/edit", {blog: foundBlog})
52+
}
53+
})
54+
})
5555

56-
// //UPDATE
57-
// router.put("/:id", middleware.checkCampgroundOwnership, function(req, res){
58-
// Campground.findByIdAndUpdate(req.params.id, req.body.cmp, function(err, updatedCmp){
59-
// if(err){
60-
// res.redirect("/campgrounds")
61-
// } else{
62-
// res.redirect("/campgrounds/" + req.params.id)
63-
// }
64-
// })
65-
// })
56+
//UPDATE
57+
router.put("/blog/:id", middleware.checkBlogOwnership, function(req, res){
58+
Blog.findByIdAndUpdate(req.params.id, req.body.blog, function(err, updatedBlog){
59+
if(err){
60+
res.redirect("/")
61+
} else{
62+
res.redirect("/blog/" + req.params.id)
63+
}
64+
})
65+
})
6666

6767
//DELETE
6868
router.delete("/blog/:id", function(req, res){
69-
console.log("routed to delte")
7069
Blog.findByIdAndRemove(req.params.id, function(err){
7170
if(err){
7271
console.log(err)

views/blogs/edit.ejs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%- include('../partials/header') %>
2+
<center><h3 class="title is-3" style="padding: 50px;">EDIT <%=blog.title%></h3></center>
3+
<form action="/blog/<%=blog._id%>?_method=PUT" method="POST" style="margin: auto; width: 40%;">
4+
<div class="field">
5+
<input class="input is-info" type="text" name="blog[title]" value="<%=blog.title%>" required>
6+
</div>
7+
<div class="field">
8+
<input class="input is-info" type="text" name="blog[image]" value="<%=blog.image%>">
9+
</div>
10+
<div class="field">
11+
<textarea class="textarea is-info" name="blog[body]"><%=blog.body%></textarea>
12+
</div>
13+
<button class="button is-primary is-outlined">Edit</button>
14+
</form>
15+
<%- include('../partials/footer') %>

views/blogs/info.ejs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,31 @@
33
<div class="container">
44
<div class="columns is-centered is-multiline has-text-centered">
55
<div class="column is-8">
6-
<h3 class="title is-3"><b><a href="/blog/<%= %>" class="has-text-dark"><%=blog.title%></a></b></h3>
6+
<h3 class="title is-3"><b><%=blog.title%></b></h3>
7+
<hr>
8+
<img src="<%=blog.image%>" alt="">
79
<h4 class="title is-4 is-spaced"><%=blog.body%></h4>
8-
<h6 class="subtitle is-6" style="padding-top: 10px;">Posted by <em><%=blog.author.username%></em> on April 7th 2017 at 9:33pm</h6>
9-
<hr/>
10+
<h6 class="subtitle is-6" style="padding-top: 10px;">Posted by <em><%=blog.author.username%></em> on April 7th 2017 at 9:33pm</h6>
1011
</div>
1112
</div>
1213
</div>
1314
</div>
14-
<form action="/blog/<%=blog._id%>?_method=DELETE" method="POST">
15-
<center><button class="button is-danger is-outlined">Delete</button></center>
16-
</form>
15+
<center>
16+
<hr width="66%">
17+
<span style="display: inline-flex;">
18+
<form action="/">
19+
<button class="button is-primary" style="margin-right: 500px;">All Blogs</button>
20+
</form>
21+
<%if(currentUser && blog.author.id.equals(currentUser._id)) {%>
22+
<form action="/blog/<%=blog._id%>/edit/">
23+
<button class="button is-warning is-outlined" style="margin-right: 50px;">Edit</button>
24+
</form>
25+
<form action="/blog/<%=blog._id%>?_method=DELETE" method="POST">
26+
<button class="button is-danger is-outlined">Delete</button>
27+
</form>
28+
<%}%>
29+
</span>
30+
</center>
31+
32+
<hr/>
1733
<%- include('../partials/footer') %>

views/home.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<%- include('partials/header') %>
2-
<div class="modal" id="regmodal">
2+
<div class="modal animated fadeIn" id="regmodal">
33
<div class="modal-background"></div>
44
<!-- ----------------------------------------
55
SIGN UP AND LOGIN FORM----------------

views/partials/header.ejs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"> -->
88
<link rel="stylesheet" href="/stylesheets/style.css">
99
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
1011
<!-- end of styles and fonts -->
1112
</head>
1213
<body>

0 commit comments

Comments
 (0)