Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
278 additions
and
83 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
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
|
||
'use strict' | ||
|
||
module.exports = class List { | ||
|
||
constructor() { | ||
this.items = [] | ||
} | ||
|
||
add(item, qty) { | ||
const data = {item: item, qty: qty} | ||
this.items.push(data) | ||
} | ||
|
||
getAll() { | ||
return this.items | ||
} | ||
|
||
delete(name) { | ||
const index = this.items.indexOf(name) | ||
if(index !== -1) this.items.splice(index, 1) | ||
} | ||
|
||
count() { | ||
return this.items.count | ||
} | ||
|
||
} |
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,57 @@ | ||
{ | ||
"name": "10_auth", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"acceptance": "jest --coverage --detectOpenHandles", | ||
"jsdoc": "node_modules/.bin/jsdoc -c jsdoc.conf", | ||
"linter": "node_modules/.bin/eslint .", | ||
"test": "jest --coverage --detectOpenHandles", | ||
"unit": "node_modules/.bin/jest --coverage --runInBand tests/unit/" | ||
}, | ||
"jest": { | ||
"testEnvironment": "node", | ||
"verbose": true, | ||
"collectCoverage": true, | ||
"coverageDirectory": "docs/coverage/", | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 0, | ||
"functions": 0, | ||
"lines": 0, | ||
"statements": 0 | ||
} | ||
} | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"bcrypt": "^3.0.3", | ||
"bcrypt-promise": "^2.0.0", | ||
"fs-extra": "^7.0.1", | ||
"handlebars": "^4.1.2", | ||
"jimp": "^0.6.0", | ||
"koa": "^2.6.2", | ||
"koa-body": "^4.0.8", | ||
"koa-bodyparser": "^4.2.1", | ||
"koa-router": "^7.4.0", | ||
"koa-session": "^5.10.1", | ||
"koa-static": "^5.0.0", | ||
"koa-views": "^6.1.5", | ||
"mime-types": "^2.1.22", | ||
"sqlite-async": "^1.0.11" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.15.2", | ||
"handlebars-validate": "^0.1.2", | ||
"html-validator-cli": "^6.0.0", | ||
"http-status-codes": "^1.3.2", | ||
"jest": "^24.1.0", | ||
"jsdoc": "^3.5.5", | ||
"jsdoc-route-plugin": "^0.1.0", | ||
"puppeteer": "^1.12.2", | ||
"site-validator-cli": "^1.0.1", | ||
"supertest": "^4.0.2" | ||
} | ||
} |
File renamed without changes
File renamed without changes.
File renamed without changes.
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,61 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
const Koa = require('koa') | ||
const Router = require('koa-router') | ||
const stat = require('koa-static') | ||
const bodyParser = require('koa-bodyparser') | ||
const handlebars = require('koa-hbs-renderer') | ||
|
||
const app = new Koa() | ||
const router = new Router() | ||
app.use(stat('public')) | ||
app.use(bodyParser()) | ||
app.use(handlebars({ paths: { views: `${__dirname}/views` } })) | ||
app.use(router.routes()) | ||
|
||
const port = 8080 | ||
|
||
const items = [] | ||
|
||
// const ToDo = require('./modules/todo') | ||
// const todo = new ToDo() | ||
|
||
router.get('/', async ctx => { | ||
try { | ||
const data = {} | ||
if(ctx.query.msg) data.msg = ctx.query.msg | ||
data.items = items.map( (element, index) => ({key: index, item: element.item, qty: element.qty})) | ||
console.log(data.items) | ||
ctx.render('home', data) | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.render('home', {msg: err.message}) | ||
} | ||
}) | ||
|
||
router.post('/', ctx => { | ||
try { | ||
const body = ctx.request.body | ||
const data = {item: body.item, qty: body.qty} | ||
items.push(data) | ||
ctx.redirect('/') | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.redirect(`/?msg=${err.message}`) | ||
} | ||
}) | ||
|
||
router.get('/delete/:key', ctx => { | ||
try { | ||
console.log(`key: ${ctx.params.key}`) | ||
items.splice(ctx.params.key, 1) | ||
ctx.redirect('/msg=item deleted') | ||
} catch(err) { | ||
console.log(err.message) | ||
ctx.redirect(`/${err.message}`) | ||
} | ||
}) | ||
|
||
module.exports = app.listen(port, () => console.log(`listening on port ${port}`)) |
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,27 @@ | ||
|
||
'use strict' | ||
|
||
module.exports = class List { | ||
|
||
constructor() { | ||
this.items = [] | ||
} | ||
|
||
add(item, qty) { | ||
const data = {item: item, qty: qty} | ||
this.items.push(data) | ||
} | ||
|
||
getAll() { | ||
return this.items.map( (element, index) => ({key: index, item: element.item, qty: element.qty})) | ||
} | ||
|
||
delete(id) { | ||
this.items.splice(id, 1) | ||
} | ||
|
||
count() { | ||
return this.items.count | ||
} | ||
|
||
} |
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,22 @@ | ||
{ | ||
"name": "todo", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"linter": "node_modules/.bin/eslint ." | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"handlebars": "^4.2.0", | ||
"koa": "^2.8.1", | ||
"koa-bodyparser": "^4.2.1", | ||
"koa-handlebars": "^1.0.0", | ||
"koa-hbs-renderer": "^1.2.0", | ||
"koa-router": "^7.4.0", | ||
"koa-static": "^5.0.0", | ||
"koa-views": "^6.2.1" | ||
}, | ||
"devDependencies": {} | ||
} |
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,19 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>ToDo List</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
</head> | ||
<body> | ||
<h1>ToDo List</h1> | ||
<h2>Your list is empty, lets add some items...</h2> | ||
<form method="post" action="/"> | ||
Item: | ||
<input type="text" name="item" /> | ||
Qty: | ||
<input type="text" name="qty" /> | ||
<input type="submit" value="Add Item" /> | ||
</form> | ||
</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,33 @@ | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>ToDo List</title> | ||
<link rel="stylesheet" href="style.css" /> | ||
</head> | ||
<body> | ||
<h1>ToDo List</h1> | ||
<h2>My List</h2> | ||
{{#if msg}} | ||
<p class="msg">{{msg}}</p> | ||
{{/if}} | ||
{{#if items.length}} | ||
<table> | ||
<caption>Shopping List</caption> | ||
<tr><th>Item</th><th>Qty</th><th>Action</th></tr> | ||
{{#each items}} | ||
<tr><td>{{this.item}}</td><td>{{this.qty}}</td><td><a href="/delete/{{this.key}}">delete</a></td></tr> | ||
{{/each}} | ||
</table> | ||
{{else}} | ||
<h2>Your list is empty, lets add some items...</h2> | ||
{{/if}} | ||
<form method="post" action="/"> | ||
Item: | ||
<input type="text" name="item" /> | ||
Qty: | ||
<input type="text" name="qty" /> | ||
<input type="submit" value="Add Item" /> | ||
</form> | ||
</body> | ||
</html> |