forked from jleveau/M2-Workshops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Seynshun/dev
Dev
- Loading branch information
Showing
20 changed files
with
1,753 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true | ||
}, | ||
extends: [ | ||
'standard' | ||
], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module' | ||
}, | ||
rules: { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const inMemoryWorkshop = [] | ||
|
||
function getWorkshopList () { | ||
return new Promise((resolve) => { | ||
resolve(inMemoryWorkshop) | ||
}) | ||
} | ||
|
||
function getWorkshopByName (name) { | ||
return new Promise((resolve, reject) => { | ||
if (!name) { | ||
reject(new Error('name parameter is required')) | ||
} | ||
resolve(inMemoryWorkshop.find(workshop => workshop.name === workshop)) | ||
}) | ||
} | ||
|
||
function addWorkshop (name, description) { | ||
return new Promise((resolve, reject) => { | ||
if (!name) { | ||
reject(new Error('Workshop name required')) | ||
} | ||
if (!description) { | ||
reject(new Error('Workshop description required')) | ||
} | ||
inMemoryWorkshop.push({ | ||
name, | ||
description | ||
}) | ||
resolve() | ||
}) | ||
} | ||
|
||
function removeWorkshopByName (name) { | ||
return new Promise((resolve, reject) => { | ||
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() | ||
}) | ||
} | ||
|
||
function updateWorkshop (name, oldName) { | ||
return new Promise((resolve, reject) => { | ||
var obj = JSON.parse(JSON.stringify(inMemoryWorkshop)) | ||
for (var i = 0; i < inMemoryWorkshop.length; i++) { | ||
if (obj[i].name === oldName) { | ||
obj[i].name = name | ||
inMemoryWorkshop[i] = obj[i] | ||
} | ||
} | ||
resolve() | ||
}) | ||
} | ||
|
||
module.exports = { | ||
getWorkshopList, | ||
getWorkshopByName, | ||
addWorkshop, | ||
removeWorkshopByName, | ||
updateWorkshop | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
const express = require('express') | ||
const app = express() | ||
const InMemoryWorkshop = require('./inMemoryWorkshop') | ||
const path = require('path') | ||
const ejs = require('ejs') | ||
var bodyParser = require('body-parser') | ||
|
||
app.use(bodyParser.urlencoded({ extended: false })) | ||
|
||
// set the view engine to ejs | ||
app.set('view engine', 'ejs') | ||
app.set('views', path.join(__dirname, '..', 'frontend/')) | ||
app.use(express.static(path.join(__dirname, '..', 'frontend/style'))) | ||
|
||
app.get('/', function (req, res) { | ||
InMemoryWorkshop.getWorkshopList() | ||
.then(workshops => { | ||
res.render('index', { | ||
workshops: workshops | ||
}) | ||
}) | ||
}) | ||
|
||
app.get('/workshop', function (req, res) { | ||
console.log('get') | ||
res.render('workshop') | ||
}) | ||
|
||
app.get('/update-workshop', function (req, res) { | ||
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 | ||
const description = req.body.description | ||
InMemoryWorkshop.addWorkshop(name, description).then(() => { | ||
InMemoryWorkshop.getWorkshopList() | ||
.then(workshops => { | ||
res.render('index', { | ||
workshops: workshops | ||
}) | ||
}) | ||
}) | ||
.catch(e => res.send(e.message)) | ||
}) | ||
|
||
app.get('/workshop/:name', function (req, res) { | ||
const workshopName = req.params.name | ||
InMemoryWorkshop.getWorkshopByName(workshopName) | ||
.then(workshop => { | ||
res.render('ejs/workshop', workshop) | ||
}) | ||
.catch(e => ejs.send(e.message)) | ||
}) | ||
|
||
app.post('/remove-workshop', function (req, res) { | ||
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) { | ||
console.log('update') | ||
const name = req.body.name | ||
const oldName = req.body.oldName | ||
InMemoryWorkshop.updateWorkshop(name, oldName).then(() => { | ||
InMemoryWorkshop.getWorkshopList() | ||
.then(workshops => { | ||
res.render('index', { | ||
workshops: workshops | ||
}) | ||
}) | ||
}) | ||
.catch(e => res.send(e.message)) | ||
}) | ||
|
||
app.listen(3000, function () { | ||
console.log('Workshop app listening on port 3000!') | ||
}) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<% include ./head %> | ||
</head> | ||
|
||
<body class="container"> | ||
|
||
<div class="jumbotron"> | ||
<h1>Workshops</h1> | ||
<p>here is the list of workshop</p> | ||
</div> | ||
|
||
<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) { %> | ||
<li class="media my-4"> | ||
<div class="media-body"> | ||
<h5 class="mt-0 mb-1"><%= workshop.name %></h5> | ||
<%= workshop.description %> | ||
</div> | ||
</li> | ||
<% }); %> | ||
</ul> | ||
|
||
<footer> | ||
<% include ./footer %> | ||
</footer> | ||
|
||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<% include ./head %> | ||
</head> | ||
|
||
<body class="container"> | ||
|
||
<form action="/update-workshop" method="post"> | ||
<div class="form-group"> | ||
<label for="oldName">Old Name</label> | ||
<input type="text" name="oldName" class="form-control" id="oldName" placeholder="Workshop Name" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="name">Name</label> | ||
<input type="text" name="name" class="form-control" id="name" placeholder="Workshop Name" required> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Save</button> | ||
<a type="button" class="btn btn-secondary" href="/">Cancel</a> | ||
</form> | ||
|
||
<footer> | ||
<% include ./footer %> | ||
</footer> | ||
|
||
</body> | ||
|
||
</html> |
File renamed without changes.
Empty file.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.