From d6fa055a1b7a2dfec64c20b60a1b26f40201e924 Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Fri, 2 Mar 2018 15:47:56 +0300 Subject: [PATCH 1/6] create delete items implemented --- app/core/controllers/cities.js | 18 +++++- app/core/controllers/users.js | 25 +++++++-- app/core/views/_components/html.pug | 9 +++ app/core/views/cities/index.pug | 32 +++++++++++ app/core/views/home/index.pug | 2 +- app/core/views/users/index.pug | 42 ++++++++++++++ app/index.js | 2 + package.json | 1 + source/css/home.css | 87 +++++++++++++++++++++++------ 9 files changed, 194 insertions(+), 24 deletions(-) diff --git a/app/core/controllers/cities.js b/app/core/controllers/cities.js index 021d40c..bd7e477 100644 --- a/app/core/controllers/cities.js +++ b/app/core/controllers/cities.js @@ -5,15 +5,27 @@ module.exports = { create: async (req, res, next) => { try { const city = await m.city.create(req.body); - return res.render('cities', city); + return res.render('cities', { + section: 'Cities', + cities: await m.city.find({ 'meta.status': 'active' }) + }); } catch (error) { return next(error); } }, - read: async (req, res) => { + read: async (req, res, next) => { if (req.params.city) { - return res.send(await m.city.findById(req.params.city)); + try { + const city = await m.city.findById(req.params.city).exec(); + await city.remove(); + return res.render('cities', { + section: 'Cities', + cities: await m.city.find({ 'meta.status': 'active' }) + }); + } catch (error) { + return next(error); + } } return res.render('cities', { diff --git a/app/core/controllers/users.js b/app/core/controllers/users.js index 11be2e3..523cc86 100644 --- a/app/core/controllers/users.js +++ b/app/core/controllers/users.js @@ -3,26 +3,43 @@ const m = attract('core/models'); module.exports = { create: async (req, res, next) => { + console.log('user:', req.body); try { const user = await m.user.create(req.body); - return res.render('users', user); + return res.render('users', { + section: 'Users', + users: await m.user.find({ 'meta.status': 'active' }), + cities: await m.city.find({ 'meta.status': 'active' }) + }); } catch (error) { return next(error); } }, - read: async (req, res) => { + read: async (req, res, next) => { if (req.params.user) { - return res.send(await m.user.findById(req.params.user)); + try { + const user = await m.user.findById(req.params.user).exec(); + await user.remove(); + return res.render('users', { + section: 'Users', + users: await m.user.find({ 'meta.status': 'active' }), + cities: await m.city.find({ 'meta.status': 'active' }) + }); + } catch (error) { + return next(error); + } } return res.render('users', { section: 'Users', - users: await m.user.find({ 'meta.status': 'active' }) + users: await m.user.find({ 'meta.status': 'active' }), + cities: await m.city.find({ 'meta.status': 'active' }) }); }, delete: async (req, res, next) => { + console.log('del:', req.body); try { const user = await m.user.findById(req.params.user).exec(); await user.remove(); diff --git a/app/core/views/_components/html.pug b/app/core/views/_components/html.pug index 8ff69e6..0a87a76 100644 --- a/app/core/views/_components/html.pug +++ b/app/core/views/_components/html.pug @@ -9,6 +9,15 @@ mixin head() meta(http-equiv='X-UA-Compatible', content='IE=Edge') meta(content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no', name='viewport') link(href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet') + + //// Latest compiled and minified CSS + //link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u', crossorigin='anonymous') + //// Optional theme + //link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css', integrity='sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp', crossorigin='anonymous') + //script(src='http://code.jquery.com/jquery-3.3.1.min.js', integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=', crossorigin='anonymous') + // + //// Latest compiled and minified JavaScript + //script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa', crossorigin='anonymous') link(href='/css/home.min.css', rel='stylesheet') title Express boilerplate diff --git a/app/core/views/cities/index.pug b/app/core/views/cities/index.pug index 60c229b..9029c74 100644 --- a/app/core/views/cities/index.pug +++ b/app/core/views/cities/index.pug @@ -7,3 +7,35 @@ include ../_components/html h3= section p a(href='/') Home + br + a(href='/users') Users + br + + -let n=1; + + mixin list(id, items) + .container + table(id=id width='20%' border='1') + tbody + tr + td № + td City name + td + each item in items + tr + td=n++ + td=item.name + td + a(href=`/cities/${item._id}`) + button(width='100%', height='100%') Delete + + +list('my-list', cities) + + .container + form(action='/cities', method='post') + p.search + .create-container + b City name: + input(type='text', size='50' name='name' placeholder='enter city name') + input(type='submit' value='Create') + diff --git a/app/core/views/home/index.pug b/app/core/views/home/index.pug index e468c89..7b2298c 100644 --- a/app/core/views/home/index.pug +++ b/app/core/views/home/index.pug @@ -5,7 +5,7 @@ include ../_components/html +body() .container h3 Express boilerplate - p= message + p=message .container.actions p Try creating some |   diff --git a/app/core/views/users/index.pug b/app/core/views/users/index.pug index 60c229b..3e134bd 100644 --- a/app/core/views/users/index.pug +++ b/app/core/views/users/index.pug @@ -7,3 +7,45 @@ include ../_components/html h3= section p a(href='/') Home + br + a(href='/cities') Cities + br + + -let n=1; + + b User information: + mixin list(id, items) + .container + table(id=id width='20%' border='1') + tbody + tr + td № + td User name + td User email + td + each item in items + tr + td=n++ + td=item.username + td=item.email + td + a(href=`/users/${item._id}`) + button(width='100%', height='100%') Delete + +list('users-table', users) + br + b Create new user: + .container + form(action='/users', method='post', id='create-form') + .flex-container + input(type='text', name='username' placeholder='enter user name') + input(type='email', name='email' placeholder='enter user email') + mixin list(id, items) + select(id=id, name='city', form='create-form') + each item in items + option(value=item._id)=item.name + +list('city-list', cities) + input(type='submit' value='Create') + script + + + diff --git a/app/index.js b/app/index.js index 613cb1d..3ae3280 100644 --- a/app/index.js +++ b/app/index.js @@ -3,6 +3,7 @@ require('attract')({ basePath: __dirname }); const bodyParser = require('body-parser'); const compression = require('compression'); const express = require('express'); +const logger = require('morgan'); const powered = require('powered'); const serveFavicon = require('serve-favicon'); @@ -25,6 +26,7 @@ m.load(config.mongo).then(() => { app.set('views', `${__dirname}/core/views`); app.set('view engine', 'pug'); app.use( + logger('dev'), powered(), compression(), express.static(`${__dirname}/public`), diff --git a/package.json b/package.json index 510e361..65da303 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "compression": "^1.7.2", "express": "^4.16.2", "mongoose": "^5.0.6", + "morgan": "^1.9.0", "powered": "^1.0.1", "pug": "^2.0.0-beta11", "serve-favicon": "^2.4.5", diff --git a/source/css/home.css b/source/css/home.css index 8499f1e..d837e3f 100644 --- a/source/css/home.css +++ b/source/css/home.css @@ -1,28 +1,33 @@ html { - min-height: 100%; - position: relative; + min-height: 100%; + position: relative; } body { - font-family: 'Lato', sans-serif; - color: #fff; - background-color: #383837; - padding: 0; - margin: 0; + font-family: 'Lato', sans-serif; + color: #fff; + background-color: #383837; + padding: 0; + margin: 0; + font-size: 18px; } -h3, p { - width: 100%; - text-align: center; - font-size: 1.7rem; - padding: 50px 0 0; - margin: 0; +h3 { + width: 100%; + text-align: center; + font-size: 1.7rem; + padding: 50px 0 0; + margin: 0; +} + +p.search { + font-size: 1rem; + margin: 15px 5px 0 0; + padding: 0; } p { - font-size: 1rem; - margin: 0; - padding: 0; + text-align: center; } a { @@ -38,3 +43,53 @@ a:hover { .actions { margin-top: 30px; } + +.flex-container { + display: flex; + flex-direction: column; +} + +.flex-container input, .flex-container select, .create-container input { + outline: none; + border: 1px solid grey; + padding: 4px; + width: 200px; + max-width: 100%; + height: 35px; + border-radius: 5px; +} + +.flex-container input[type='submit'] { + width: 210px; +} + +.create-container { + display: flex; + flex-direction: column; + margin-left: 15px; +} + +.create-container input { + width: 316px; +} + +.create-container input[type='submit'] { + width: 328px; + height: 43px; +} + +.container { + margin-left: 15px; +} + +b { + margin-left: 15px; +} + +td { + padding: 5px; +} + +#city-list { + width: 210px; +} From b2753278799e2a14be04666cdf416b4c5d9d699b Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Fri, 2 Mar 2018 16:08:20 +0300 Subject: [PATCH 2/6] create delete items implemented (lint checked) --- app/core/controllers/cities.js | 2 +- app/core/controllers/users.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/core/controllers/cities.js b/app/core/controllers/cities.js index bd7e477..210662c 100644 --- a/app/core/controllers/cities.js +++ b/app/core/controllers/cities.js @@ -4,7 +4,7 @@ const m = attract('core/models'); module.exports = { create: async (req, res, next) => { try { - const city = await m.city.create(req.body); + await m.city.create(req.body); return res.render('cities', { section: 'Cities', cities: await m.city.find({ 'meta.status': 'active' }) diff --git a/app/core/controllers/users.js b/app/core/controllers/users.js index 523cc86..7119fcc 100644 --- a/app/core/controllers/users.js +++ b/app/core/controllers/users.js @@ -3,9 +3,8 @@ const m = attract('core/models'); module.exports = { create: async (req, res, next) => { - console.log('user:', req.body); try { - const user = await m.user.create(req.body); + await m.user.create(req.body); return res.render('users', { section: 'Users', users: await m.user.find({ 'meta.status': 'active' }), @@ -39,7 +38,6 @@ module.exports = { }, delete: async (req, res, next) => { - console.log('del:', req.body); try { const user = await m.user.findById(req.params.user).exec(); await user.remove(); From 80a1bf0f190739131d1e76541d20909bebaf1f50 Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Sat, 3 Mar 2018 14:06:59 +0300 Subject: [PATCH 3/6] little jQuery added --- .eslintrc.json | 6 ++++++ app/core/controllers/users.js | 21 ++++++--------------- app/core/routes/cities.js | 1 - app/core/views/_components/html.pug | 3 ++- app/core/views/cities/index.pug | 23 ++++++++++------------- app/core/views/users/index.pug | 22 +++++++++------------- source/css/home.css | 2 +- source/js/aj_logic.js | 27 +++++++++++++++++++++++++++ 8 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 source/js/aj_logic.js diff --git a/.eslintrc.json b/.eslintrc.json index 64286d9..fe7779a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,10 @@ { + "env": { + "browser": true, + "commonjs": true, + "es6": true, + "jquery": true + }, "extends": "airbnb-base", "plugins": [ "import" diff --git a/app/core/controllers/users.js b/app/core/controllers/users.js index 7119fcc..b19d88b 100644 --- a/app/core/controllers/users.js +++ b/app/core/controllers/users.js @@ -15,21 +15,10 @@ module.exports = { } }, - read: async (req, res, next) => { + read: async (req, res) => { if (req.params.user) { - try { - const user = await m.user.findById(req.params.user).exec(); - await user.remove(); - return res.render('users', { - section: 'Users', - users: await m.user.find({ 'meta.status': 'active' }), - cities: await m.city.find({ 'meta.status': 'active' }) - }); - } catch (error) { - return next(error); - } + return res.send(await m.user.findById(req.params.user)); } - return res.render('users', { section: 'Users', users: await m.user.find({ 'meta.status': 'active' }), @@ -39,9 +28,11 @@ module.exports = { delete: async (req, res, next) => { try { - const user = await m.user.findById(req.params.user).exec(); + const user = await m.user.findById(req.params.user) + .exec(); await user.remove(); - return res.status(200).end(); + return res.status(200) + .end(); } catch (error) { return next(error); } diff --git a/app/core/routes/cities.js b/app/core/routes/cities.js index 4f58102..0dac8c6 100644 --- a/app/core/routes/cities.js +++ b/app/core/routes/cities.js @@ -3,6 +3,5 @@ module.exports = (router, controller) => { .get(controller.read) .post(controller.create) .delete(controller.delete); - return router; }; diff --git a/app/core/views/_components/html.pug b/app/core/views/_components/html.pug index 0a87a76..1497128 100644 --- a/app/core/views/_components/html.pug +++ b/app/core/views/_components/html.pug @@ -14,7 +14,6 @@ mixin head() //link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css', integrity='sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u', crossorigin='anonymous') //// Optional theme //link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css', integrity='sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp', crossorigin='anonymous') - //script(src='http://code.jquery.com/jquery-3.3.1.min.js', integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=', crossorigin='anonymous') // //// Latest compiled and minified JavaScript //script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', integrity='sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa', crossorigin='anonymous') @@ -24,3 +23,5 @@ mixin head() mixin body() body block + script(src='https://code.jquery.com/jquery-3.3.1.min.js', integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=', crossorigin='anonymous') + script(src='/js/aj_logic.min.js', type='text/javascript') diff --git a/app/core/views/cities/index.pug b/app/core/views/cities/index.pug index 9029c74..28c4540 100644 --- a/app/core/views/cities/index.pug +++ b/app/core/views/cities/index.pug @@ -13,29 +13,26 @@ include ../_components/html -let n=1; - mixin list(id, items) .container - table(id=id width='20%' border='1') + table(id='list-cities' width='20%' border='1') tbody tr td № td City name td - each item in items + each item in cities tr td=n++ td=item.name td - a(href=`/cities/${item._id}`) - button(width='100%', height='100%') Delete + button(class='delete-city', width='100%', height='100%', type='submit', _id=item._id) Delete - +list('my-list', cities) + .container + form(action='/cities', method='post') + p.search + .create-container + b Сreate new city: + input(type='text', size='50' name='name' placeholder='enter city name') + input(type='submit' value='Create') - .container - form(action='/cities', method='post') - p.search - .create-container - b City name: - input(type='text', size='50' name='name' placeholder='enter city name') - input(type='submit' value='Create') diff --git a/app/core/views/users/index.pug b/app/core/views/users/index.pug index 3e134bd..0abd742 100644 --- a/app/core/views/users/index.pug +++ b/app/core/views/users/index.pug @@ -14,24 +14,21 @@ include ../_components/html -let n=1; b User information: - mixin list(id, items) .container - table(id=id width='20%' border='1') + table(id='users-table' width='20%' border='1') tbody tr td № td User name td User email td - each item in items - tr + each item in users + tr(class='user-info') td=n++ td=item.username td=item.email td - a(href=`/users/${item._id}`) - button(width='100%', height='100%') Delete - +list('users-table', users) + button(class='delete-user', width='100%', height='100%' , _id=item._id ) Delete br b Create new user: .container @@ -39,13 +36,12 @@ include ../_components/html .flex-container input(type='text', name='username' placeholder='enter user name') input(type='email', name='email' placeholder='enter user email') - mixin list(id, items) - select(id=id, name='city', form='create-form') - each item in items - option(value=item._id)=item.name - +list('city-list', cities) + select(id='city-list', name='city', form='create-form') + each item in cities + option(value=item._id)=item.name input(type='submit' value='Create') - script + + diff --git a/source/css/home.css b/source/css/home.css index d837e3f..95b596a 100644 --- a/source/css/home.css +++ b/source/css/home.css @@ -74,7 +74,7 @@ a:hover { } .create-container input[type='submit'] { - width: 328px; + width: 327px; height: 43px; } diff --git a/source/js/aj_logic.js b/source/js/aj_logic.js new file mode 100644 index 0000000..1f80e30 --- /dev/null +++ b/source/js/aj_logic.js @@ -0,0 +1,27 @@ +$(document) + .ready(() => { + $('.delete-user') + .each((i, elem) => { + elem.onclick = () => { + $.ajax({ + url: `/users/${elem.getAttribute('_id')}`, + type: 'DELETE', + success() { + location.reload(); + } + }); + }; + }); + $('.delete-city') + .each((i, elem) => { + elem.onclick = () => { + $.ajax({ + url: `/cities/${elem.getAttribute('_id')}`, + type: 'DELETE', + success() { + location.reload(); + } + }); + }; + }); + }); From 0b819f0c631a8a2b370f17f00d37521a652ebd00 Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Sat, 3 Mar 2018 15:05:00 +0300 Subject: [PATCH 4/6] grunt watch repaired --- Gruntfile.js | 2 ++ grunt/watch.task.js | 2 +- package.json | 1 + source/js/aj_logic.js | 19 ++++++++----------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 06eeacb..26ac7a5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,6 +16,8 @@ module.exports = (grunt) => { grunt.initConfig(tasks); grunt.registerTask('build', ['cssmin', 'uglify']); + grunt.registerTask('watch', ['watch']); + grunt.loadNpmTasks('grunt-contrib-watch'); } catch (error) { console.error(`I can't load Grunt; ${error.message}`); } diff --git a/grunt/watch.task.js b/grunt/watch.task.js index 708a0fd..a469586 100644 --- a/grunt/watch.task.js +++ b/grunt/watch.task.js @@ -1,5 +1,5 @@ module.exports = (grunt, path) => { - grunt.registerTask('watch', ['watch']); + grunt.loadNpmTasks('grunt-contrib-watch'); return { scripts: { files: [ diff --git a/package.json b/package.json index 65da303..357edde 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "grunt": "^1.0.2", "grunt-contrib-cssmin": "^2.2.1", "grunt-contrib-uglify-es": "git://github.com/gruntjs/grunt-contrib-uglify.git#harmony", + "grunt-contrib-watch": "^1.0.0", "grunt-eslint": "^20.1.0", "grunt-nodemon": "^0.4.2" }, diff --git a/source/js/aj_logic.js b/source/js/aj_logic.js index 1f80e30..241d38f 100644 --- a/source/js/aj_logic.js +++ b/source/js/aj_logic.js @@ -12,16 +12,13 @@ $(document) }); }; }); - $('.delete-city') - .each((i, elem) => { - elem.onclick = () => { - $.ajax({ - url: `/cities/${elem.getAttribute('_id')}`, - type: 'DELETE', - success() { - location.reload(); - } - }); - }; + $('body .delete-city').click((ev) => { + $.ajax({ + url: `/cities/${$(ev.target).attr('_id')}`, + type: 'DELETE', + success() { + $(ev.target).closest('tr').remove(); + } }); + }); }); From ee88dee4d5c960849eea20ef1a05fc2c22b2abaa Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Sat, 3 Mar 2018 17:31:28 +0300 Subject: [PATCH 5/6] UPDATE logic implemented --- app/core/controllers/cities.js | 11 +++++++++++ app/core/routes/cities.js | 3 ++- app/core/views/cities/index.pug | 10 +++++++--- source/js/aj_logic.js | 30 +++++++++++++++++++----------- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/app/core/controllers/cities.js b/app/core/controllers/cities.js index 210662c..ec94cdc 100644 --- a/app/core/controllers/cities.js +++ b/app/core/controllers/cities.js @@ -42,5 +42,16 @@ module.exports = { } catch (error) { return next(error); } + }, + + update: async (req, res, next) => { + try { + const city = await m.city.findById(req.params.city).exec(); + await city.update(req.body); + return res.status(200) + .end('success'); + } catch (error) { + return next(error); + } } }; diff --git a/app/core/routes/cities.js b/app/core/routes/cities.js index 0dac8c6..6663f40 100644 --- a/app/core/routes/cities.js +++ b/app/core/routes/cities.js @@ -2,6 +2,7 @@ module.exports = (router, controller) => { router.route('/cities/:city?') .get(controller.read) .post(controller.create) - .delete(controller.delete); + .delete(controller.delete) + .put(controller.update); return router; }; diff --git a/app/core/views/cities/index.pug b/app/core/views/cities/index.pug index 28c4540..43330f8 100644 --- a/app/core/views/cities/index.pug +++ b/app/core/views/cities/index.pug @@ -20,12 +20,16 @@ include ../_components/html td № td City name td + td each item in cities - tr - td=n++ - td=item.name + tr(class='row_table') + td=n + td + input(class='city_name_'+n, type='text', name='cityname' value=item.name) td button(class='delete-city', width='100%', height='100%', type='submit', _id=item._id) Delete + td + button(class='update-city', width='100%', height='100%', type='submit', _id=item._id , _idd=n++, _city=item.name) Update .container form(action='/cities', method='post') diff --git a/source/js/aj_logic.js b/source/js/aj_logic.js index 241d38f..ebc13fa 100644 --- a/source/js/aj_logic.js +++ b/source/js/aj_logic.js @@ -1,17 +1,14 @@ $(document) .ready(() => { - $('.delete-user') - .each((i, elem) => { - elem.onclick = () => { - $.ajax({ - url: `/users/${elem.getAttribute('_id')}`, - type: 'DELETE', - success() { - location.reload(); - } - }); - }; + $('body .delete-user').click((ev) => { + $.ajax({ + url: `/users/${$(ev.target).attr('_id')}`, + type: 'DELETE', + success() { + $(ev.target).closest('tr').remove(); + } }); + }); $('body .delete-city').click((ev) => { $.ajax({ url: `/cities/${$(ev.target).attr('_id')}`, @@ -21,4 +18,15 @@ $(document) } }); }); + $('body .update-city').click((ev) => { + const cityId = $(ev.target).attr('_idd'); + const cityname = $(`.city_name_${cityId}`).val(); + $.ajax({ + url: `/cities/${$(ev.target).attr('_id')}`, + type: 'PUT', + data: { + name: cityname + } + }); + }); }); From 00bd0338707070671dbea802dca5fc569aae58a7 Mon Sep 17 00:00:00 2001 From: "viktor.romanyuk" Date: Sun, 4 Mar 2018 13:29:19 +0300 Subject: [PATCH 6/6] notes are taken --- .env.sample | 10 ---------- app/core/controllers/cities.js | 14 ++------------ app/core/controllers/users.js | 2 +- app/core/views/_components/html.pug | 3 +-- app/core/views/cities/index.pug | 4 ++-- app/core/views/home/index.pug | 2 +- app/core/views/users/index.pug | 10 +++++----- grunt/watch.task.js | 1 - 8 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 .env.sample diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 756620f..0000000 --- a/.env.sample +++ /dev/null @@ -1,10 +0,0 @@ -# In order to run your application, make a copy of this file, rename it to .env -# and fill the lines below. All set. -# You can use this to define whatever environment variable your application might need. -# @see /app/config.js - -NODE_ENV=development -PORT=9000 -PRETTY_HTML=true - -MONGO_URI=mongodb://127.0.0.1:27017/boilerplate diff --git a/app/core/controllers/cities.js b/app/core/controllers/cities.js index ec94cdc..7e668df 100644 --- a/app/core/controllers/cities.js +++ b/app/core/controllers/cities.js @@ -14,20 +14,10 @@ module.exports = { } }, - read: async (req, res, next) => { + read: async (req, res) => { if (req.params.city) { - try { - const city = await m.city.findById(req.params.city).exec(); - await city.remove(); - return res.render('cities', { - section: 'Cities', - cities: await m.city.find({ 'meta.status': 'active' }) - }); - } catch (error) { - return next(error); - } + return res.send(await m.city.findById(req.params.city)); } - return res.render('cities', { section: 'Cities', cities: await m.city.find({ 'meta.status': 'active' }) diff --git a/app/core/controllers/users.js b/app/core/controllers/users.js index b19d88b..244fc3b 100644 --- a/app/core/controllers/users.js +++ b/app/core/controllers/users.js @@ -32,7 +32,7 @@ module.exports = { .exec(); await user.remove(); return res.status(200) - .end(); + .end('success'); } catch (error) { return next(error); } diff --git a/app/core/views/_components/html.pug b/app/core/views/_components/html.pug index 9cea9bf..2821266 100644 --- a/app/core/views/_components/html.pug +++ b/app/core/views/_components/html.pug @@ -9,7 +9,6 @@ mixin head() meta(http-equiv='X-UA-Compatible', content='IE=Edge') meta(content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no', name='viewport') link(href='https://fonts.googleapis.com/css?family=Lato' rel='stylesheet') - link(href='/css/home.min.css', rel='stylesheet') link(href='/css/boilerplate.min.css', rel='stylesheet') title Express boilerplate @@ -17,4 +16,4 @@ mixin body() body block script(src='https://code.jquery.com/jquery-3.3.1.min.js', integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=', crossorigin='anonymous') - script(src='/js/aj_logic.min.js', type='text/javascript') + script(src='/js/boilerplate.min.js', type='text/javascript') diff --git a/app/core/views/cities/index.pug b/app/core/views/cities/index.pug index 43330f8..f81d055 100644 --- a/app/core/views/cities/index.pug +++ b/app/core/views/cities/index.pug @@ -11,7 +11,7 @@ include ../_components/html a(href='/users') Users br - -let n=1; + -let n = 1; .container table(id='list-cities' width='20%' border='1') @@ -23,7 +23,7 @@ include ../_components/html td each item in cities tr(class='row_table') - td=n + td= n td input(class='city_name_'+n, type='text', name='cityname' value=item.name) td diff --git a/app/core/views/home/index.pug b/app/core/views/home/index.pug index 7b2298c..e468c89 100644 --- a/app/core/views/home/index.pug +++ b/app/core/views/home/index.pug @@ -5,7 +5,7 @@ include ../_components/html +body() .container h3 Express boilerplate - p=message + p= message .container.actions p Try creating some |   diff --git a/app/core/views/users/index.pug b/app/core/views/users/index.pug index 0abd742..9043f7c 100644 --- a/app/core/views/users/index.pug +++ b/app/core/views/users/index.pug @@ -11,7 +11,7 @@ include ../_components/html a(href='/cities') Cities br - -let n=1; + -let n = 1; b User information: .container @@ -24,9 +24,9 @@ include ../_components/html td each item in users tr(class='user-info') - td=n++ - td=item.username - td=item.email + td= n++ + td= item.username + td= item.email td button(class='delete-user', width='100%', height='100%' , _id=item._id ) Delete br @@ -38,7 +38,7 @@ include ../_components/html input(type='email', name='email' placeholder='enter user email') select(id='city-list', name='city', form='create-form') each item in cities - option(value=item._id)=item.name + option(value=item._id)= item.name input(type='submit' value='Create') diff --git a/grunt/watch.task.js b/grunt/watch.task.js index a469586..6374cbd 100644 --- a/grunt/watch.task.js +++ b/grunt/watch.task.js @@ -1,5 +1,4 @@ module.exports = (grunt, path) => { - grunt.loadNpmTasks('grunt-contrib-watch'); return { scripts: { files: [