Skip to content

Commit

Permalink
remove workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Oct 12, 2020
1 parent 3f08eaa commit f7daf5e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions ejs/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<a type="button" href="/workshop" class="btn btn-success btn-lg">Create new workshop</a>
<a type="button" href="/update-workshop" class="btn btn-success btn-lg">Update</a>
<a type="button" href="/remove-workshop" class="btn btn-danger btn-lg">Remove</a>

<ul class="list-unstyled"></ul>
<% workshops.forEach(function(workshop) { %>
Expand Down
26 changes: 26 additions & 0 deletions ejs/remove-workshop.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">

<head>
<% include ./head %>
</head>

<body class="container">

<form action="/remove-workshop" method="post">
<div class="form-group">
<label for="name">Workshop name to delete</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Workshop Name" required>
</div>

<button type="submit" class="btn btn-danger">Remove</button>
<a type="button" class="btn btn-secondary" href="/">Cancel</a>
</form>

<footer>
<% include ./footer %>
</footer>

</body>

</html>
12 changes: 11 additions & 1 deletion js/inMemoryWorkshop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ function addWorkshop(name, description) {

function removeWorkshopByName(name) {
return new Promise((resolve, reject) => {
reject(new Error("Not implemented"))

var obj = JSON.parse(JSON.stringify(inMemoryWorkshop))
for (var i = 0; i < inMemoryWorkshop.length; i++) {
console.log("obj"+obj[i].name)
console.log(name)
if (obj[i].name == name) {
console.log("here")
inMemoryWorkshop.splice(i,1)
}
}
resolve()
})
}

Expand Down
17 changes: 13 additions & 4 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ app.get('/workshop', function (req, res) {
})

app.get('/update-workshop', function (req, res) {
console.log("get")
res.render('update-workshop')
})

app.get('/remove-workshop', function (req, res) {
res.render('remove-workshop')
})
app.post('/workshop', function (req, res) {
console.log("add")
const name = req.body.name
Expand All @@ -58,11 +59,19 @@ app.get('/workshop/:name', function (req, res) {
})

app.post('/remove-workshop', function (req, res) {
res.status(500).send("TODO")
const name = req.body.name
InMemoryWorkshop.removeWorkshopByName(name).then(() => {
InMemoryWorkshop.getWorkshopList()
.then(workshops => {
res.render("index", {
workshops: workshops
})
})
})
.catch(e => res.send(e.message))
})

app.post('/update-workshop', function (req, res) {
// res.status(500).send("TODO")
console.log("update")
const name = req.body.name
const oldName = req.body.oldName
Expand Down

0 comments on commit f7daf5e

Please sign in to comment.