From ecb57b3985df3f5e95dab586017a6a3fc594e463 Mon Sep 17 00:00:00 2001 From: edumoreira1506 Date: Thu, 15 Aug 2019 15:02:33 -0300 Subject: [PATCH 1/8] =?UTF-8?q?Instalando=20depend=C3=AAncias?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 6a376a7..2ccdd38 100644 --- a/package.json +++ b/package.json @@ -26,5 +26,11 @@ "homepage": "https://github.com/insideoutprojectbr/mulheres-palestrantes#readme", "devDependencies": { "http-server": "^0.11.1" + }, + "dependencies": { + "body-parser": "^1.19.0", + "consign": "^0.1.6", + "express": "^4.17.1", + "fs": "0.0.1-security" } } From fd5b985fd8fa3597ed859a82f735f75a1191b0f7 Mon Sep 17 00:00:00 2001 From: edumoreira1506 Date: Thu, 15 Aug 2019 15:16:47 -0300 Subject: [PATCH 2/8] Instalando modulo ejs --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 2ccdd38..b1c512c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "dependencies": { "body-parser": "^1.19.0", "consign": "^0.1.6", + "ejs": "^2.6.2", "express": "^4.17.1", "fs": "0.0.1-security" } From 05889e0b0e00d46bc76cef436a1aa9fc4219d9df Mon Sep 17 00:00:00 2001 From: edumoreira1506 Date: Thu, 15 Aug 2019 15:25:05 -0300 Subject: [PATCH 3/8] Alterando a estrutura de pastas para suportar o novo formulario de cadastro --- app/controllers/womans.js | 8 ++ app/views/template/footer.ejs | 3 + app/views/template/header.ejs | 31 +++++ app/views/template/scripts.ejs | 32 +++++ app/views/womans/index.ejs | 51 ++++++++ config/routes.js | 3 + config/server.js | 18 +++ index.html | 116 ------------------ index.js | 6 + {css => public/css}/font-awesome.min.css | 0 {css => public/css}/style.css | 0 ...Brn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 | Bin .../fonts}/fontawesome-webfont.woff2 | Bin {img => public/img}/favicon-16x16.png | Bin {img => public/img}/favicon-32x32.png | Bin {img => public/img}/fork-me.png | Bin {img => public/img}/js4girls.png | Bin {img => public/img}/logo.png | Bin {img => public/img}/logoMP.png | Bin {img => public/img}/placeholder-female.jpg | Bin app.js => public/js/app.js | 0 mulheres.json => public/mulheres.json | 0 22 files changed, 152 insertions(+), 116 deletions(-) create mode 100644 app/controllers/womans.js create mode 100644 app/views/template/footer.ejs create mode 100644 app/views/template/header.ejs create mode 100644 app/views/template/scripts.ejs create mode 100644 app/views/womans/index.ejs create mode 100644 config/routes.js create mode 100644 config/server.js delete mode 100644 index.html create mode 100644 index.js rename {css => public/css}/font-awesome.min.css (100%) rename {css => public/css}/style.css (100%) rename {fonts => public/fonts}/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 (100%) rename {fonts => public/fonts}/fontawesome-webfont.woff2 (100%) rename {img => public/img}/favicon-16x16.png (100%) rename {img => public/img}/favicon-32x32.png (100%) rename {img => public/img}/fork-me.png (100%) rename {img => public/img}/js4girls.png (100%) rename {img => public/img}/logo.png (100%) rename {img => public/img}/logoMP.png (100%) rename {img => public/img}/placeholder-female.jpg (100%) rename app.js => public/js/app.js (100%) rename mulheres.json => public/mulheres.json (100%) diff --git a/app/controllers/womans.js b/app/controllers/womans.js new file mode 100644 index 0000000..1616551 --- /dev/null +++ b/app/controllers/womans.js @@ -0,0 +1,8 @@ +module.exports = app => { + + const index = (req, res) => { + res.render('womans/index') + } + + return { index } +} \ No newline at end of file diff --git a/app/views/template/footer.ejs b/app/views/template/footer.ejs new file mode 100644 index 0000000..a4d0328 --- /dev/null +++ b/app/views/template/footer.ejs @@ -0,0 +1,3 @@ +
+ js4girls logo +
\ No newline at end of file diff --git a/app/views/template/header.ejs b/app/views/template/header.ejs new file mode 100644 index 0000000..9c9ff2f --- /dev/null +++ b/app/views/template/header.ejs @@ -0,0 +1,31 @@ + + + + + + Mulheres Palestrantes + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/views/template/scripts.ejs b/app/views/template/scripts.ejs new file mode 100644 index 0000000..26f78c2 --- /dev/null +++ b/app/views/template/scripts.ejs @@ -0,0 +1,32 @@ + + + + + + + + \ No newline at end of file diff --git a/app/views/womans/index.ejs b/app/views/womans/index.ejs new file mode 100644 index 0000000..131037d --- /dev/null +++ b/app/views/womans/index.ejs @@ -0,0 +1,51 @@ +<%- include ../template/header.ejs %> + + Ir para conteúdo principal (Alt + 1) + + + Fork me on GitHub + + +
+

Mulheres Palestrantes

+

Quero meu nome aqui! :)
Como posso fazer isso?

+
+ +
+
+

Procurando mulheres para palestrar em seu evento?

+

O Mulheres Palestrantes é uma lista de mulheres que falam sobre assuntos relacionados a programação, design, empreendedorismo e tecnologia num geral.

+
+ +

Hoje temos um total de mulheres cadastradas.

+ + + + + +
+ +

+

Área de interesse para palestras

+
    +
  • +
+
+

+ +
+
+
+ <%- include ../template/footer.ejs %> +<%- include ../template/scripts.ejs %> + diff --git a/config/routes.js b/config/routes.js new file mode 100644 index 0000000..1f2e5e0 --- /dev/null +++ b/config/routes.js @@ -0,0 +1,3 @@ +module.exports = app => { + app.get('/', app.app.controllers.womans.index) +} \ No newline at end of file diff --git a/config/server.js b/config/server.js new file mode 100644 index 0000000..69e8589 --- /dev/null +++ b/config/server.js @@ -0,0 +1,18 @@ +const express = require('express'); +const consign = require('consign'); +const bodyParser = require('body-parser'); + +const app = express(); + +app.set('view engine', 'ejs'); +app.set('views', 'app/views'); + +app.use(express.static('public')); +app.use(bodyParser.urlencoded({extended: true})); + +consign() + .include('app/controllers') + .then('config/routes.js') + .into(app); + +module.exports = app; \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index 53162a2..0000000 --- a/index.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - Mulheres Palestrantes - - - - - - - - - - - - - - - - - - - - - - - - - - - - Ir para conteúdo principal (Alt + 1) - - - Fork me on GitHub - - -
-

Mulheres Palestrantes

-

Quero meu nome aqui! :)
Como posso fazer isso?

-
- -
-
-

Procurando mulheres para palestrar em seu evento?

-

O Mulheres Palestrantes é uma lista de mulheres que falam sobre assuntos relacionados a programação, design, empreendedorismo e tecnologia num geral.

-
- -

Hoje temos um total de mulheres cadastradas.

- - - - - -
- -

-

Área de interesse para palestras

-
    -
  • -
-
-

- -
-
-
- -
- js4girls logo -
- - - - - - - - - \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..4f263a6 --- /dev/null +++ b/index.js @@ -0,0 +1,6 @@ +const app = require('./config/server'); +const port = 80; + +const server = app.listen(port, function(){ + console.log(`Servidor online na porta ${port}`); +}); diff --git a/css/font-awesome.min.css b/public/css/font-awesome.min.css similarity index 100% rename from css/font-awesome.min.css rename to public/css/font-awesome.min.css diff --git a/css/style.css b/public/css/style.css similarity index 100% rename from css/style.css rename to public/css/style.css diff --git a/fonts/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 b/public/fonts/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 similarity index 100% rename from fonts/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 rename to public/fonts/cJZKeOuBrn4kERxqtaUH3ZBw1xU1rKptJj_0jans920.woff2 diff --git a/fonts/fontawesome-webfont.woff2 b/public/fonts/fontawesome-webfont.woff2 similarity index 100% rename from fonts/fontawesome-webfont.woff2 rename to public/fonts/fontawesome-webfont.woff2 diff --git a/img/favicon-16x16.png b/public/img/favicon-16x16.png similarity index 100% rename from img/favicon-16x16.png rename to public/img/favicon-16x16.png diff --git a/img/favicon-32x32.png b/public/img/favicon-32x32.png similarity index 100% rename from img/favicon-32x32.png rename to public/img/favicon-32x32.png diff --git a/img/fork-me.png b/public/img/fork-me.png similarity index 100% rename from img/fork-me.png rename to public/img/fork-me.png diff --git a/img/js4girls.png b/public/img/js4girls.png similarity index 100% rename from img/js4girls.png rename to public/img/js4girls.png diff --git a/img/logo.png b/public/img/logo.png similarity index 100% rename from img/logo.png rename to public/img/logo.png diff --git a/img/logoMP.png b/public/img/logoMP.png similarity index 100% rename from img/logoMP.png rename to public/img/logoMP.png diff --git a/img/placeholder-female.jpg b/public/img/placeholder-female.jpg similarity index 100% rename from img/placeholder-female.jpg rename to public/img/placeholder-female.jpg diff --git a/app.js b/public/js/app.js similarity index 100% rename from app.js rename to public/js/app.js diff --git a/mulheres.json b/public/mulheres.json similarity index 100% rename from mulheres.json rename to public/mulheres.json From 44223a0220a13e6974f2947fb88893ace953d49b Mon Sep 17 00:00:00 2001 From: edumoreira1506 Date: Thu, 15 Aug 2019 15:26:24 -0300 Subject: [PATCH 4/8] Importando o sweetalert --- app/views/template/scripts.ejs | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/template/scripts.ejs b/app/views/template/scripts.ejs index 26f78c2..029364d 100644 --- a/app/views/template/scripts.ejs +++ b/app/views/template/scripts.ejs @@ -1,6 +1,7 @@ + + + + <%- include ../template/scripts.ejs %> + diff --git a/config/routes.js b/config/routes.js index 1f2e5e0..c73a66a 100644 --- a/config/routes.js +++ b/config/routes.js @@ -1,3 +1,5 @@ module.exports = app => { app.get('/', app.app.controllers.womans.index) + + app.get('/cadastrar', app.app.controllers.womans.register) } \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index 13db0b0..a194f6b 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -109,6 +109,69 @@ header h1 { box-shadow: inset 0 1px 1px rgba(0,0,0,.075); } +.half{ + display: inline-block; +} + +#register-new-quality{ + background-color: #f284ff; + display: inline-block; + color: #fff; + border: 1px solid #ddd; + border-radius: 0.3rem; + font-size: 32px; + height: 46px; + -webkit-transition: ease-in-out .2s; + -o-transition: ease-in-out .2s; + transition: ease-in-out .2s; + width: 100%; + margin: 20px 0 20px 0; +} + +#qualitys-list{ + text-align: left; +} + +.quality-item{ + height: 45px; + width: auto; + border: 1px solid #ddd; + border-radius: 0.3rem; + box-shadow: inset 0 1px 1px rgba(0,0,0,.075); + padding: 0.8rem 1rem; + display: inline-block; +} + +.quality-item h3{ + color: #555; + font-size: 0.9rem; + display: inline-block; +} + +.quality-item span{ + margin-left: 12px; + cursor: pointer; + color: #ffffff; + background: #f284ff; + border-radius: 2px; + padding: 0 7px 0 7px; + -webkit-transition: ease-in-out .2s; + -o-transition: ease-in-out .2s; + transition: ease-in-out .2s; +} + +.quality-item span:hover{ + color: #f284ff; + background: #ffffff; + outline: #f284ff 1px solid; +} + +#register-new-quality:hover{ + color: #f284ff; + border: 1px solid #f284ff; + background-color: #fff; +} + .card { background: #fff; border: solid 1px #eee; diff --git a/public/js/register.js b/public/js/register.js new file mode 100644 index 0000000..7b962cc --- /dev/null +++ b/public/js/register.js @@ -0,0 +1,50 @@ +const qualitys = [] + +const removeQuality = position => { + qualitys.splice(position, 1); + updateQualitysList() +} + +const updateQualitysList = () => { + let html = '' + + for(i in qualitys){ + html += ` +
+

${qualitys[i]}

+ X +
+ ` + } + + $('#qualitys-list').html(html) +} + +const addNewQuality = quality => { + $('.half').val('') + qualitys.push(quality) + updateQualitysList() +} + +$(document).ready(function(){ + + $('.half').keyup(function(e){ + if(e.keyCode == 13) { + addNewQuality(this.value) + } + }) + + $('#register-new-quality').click(function(e){ + e.preventDefault() + + let newQuality = $(".half").val() + + if(qualitys.includes(newQuality)){ + swal('Ops','Você já inseriu essa qualidade na lista','error') + }else{ + addNewQuality(newQuality) + } + + }) + +}) From 013a89156b88a34628b207ac435a9253f245842a Mon Sep 17 00:00:00 2001 From: edumoreira1506 Date: Thu, 15 Aug 2019 17:28:56 -0300 Subject: [PATCH 8/8] Fazendo o cadastro via ajax no arquivo mulheres.json --- app/controllers/womans.js | 48 ++++++++++++++++++++++++++++-- app/views/womans/new.ejs | 5 ++-- config/routes.js | 2 ++ public/css/style.css | 2 ++ public/js/register.js | 61 +++++++++++++++++++++++++++++---------- 5 files changed, 97 insertions(+), 21 deletions(-) diff --git a/app/controllers/womans.js b/app/controllers/womans.js index cf3d669..6b30905 100644 --- a/app/controllers/womans.js +++ b/app/controllers/womans.js @@ -1,12 +1,54 @@ module.exports = app => { const index = (req, res) => { - res.render('womans/index') + res.render('womans/index') } const register = (req, res) => { res.render('womans/new') } - return { index, register } -} \ No newline at end of file + const create = (req, res) => { + + if (!req.body.name || !req.body.email) { + res.send({ + status: false, + message: 'Nome e e-mail são obrigatórios!' + }) + } else { + const fs = require('fs') + const jsonPath = '././public/mulheres.json' + + fs.exists(jsonPath, function (exists) { + fs.readFile(jsonPath, function readFileCallback(err, data) { + let array = JSON.parse(data); + array.mulheres.push({ + "name": req.body.name, + "interests": req.body.qualitys, + "location": req.body.location, + "photo": req.body.name, + "email": req.body.email, + "linkedin": req.body.linkeDin, + "github": req.body.gitHub, + "twitter": req.body.twitter, + "fb": req.body.faceBook, + "behance": req.body.behance, + "site": req.body.site + }) + let json = JSON.stringify(array); + fs.writeFile(jsonPath, json); + }); + }); + + res.send({ + status: true + }) + } + } + + return { + index, + register, + create + } +} diff --git a/app/views/womans/new.ejs b/app/views/womans/new.ejs index 0785e29..e693308 100644 --- a/app/views/womans/new.ejs +++ b/app/views/womans/new.ejs @@ -12,11 +12,12 @@
- + - + + diff --git a/config/routes.js b/config/routes.js index c73a66a..c8d3309 100644 --- a/config/routes.js +++ b/config/routes.js @@ -2,4 +2,6 @@ module.exports = app => { app.get('/', app.app.controllers.womans.index) app.get('/cadastrar', app.app.controllers.womans.register) + + app.post('/woman', app.app.controllers.womans.create) } \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css index a194f6b..00c6ca8 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1,3 +1,5 @@ + + * { box-sizing: border-box; margin: 0 auto; diff --git a/public/js/register.js b/public/js/register.js index 7b962cc..2ecfaa9 100644 --- a/public/js/register.js +++ b/public/js/register.js @@ -1,14 +1,14 @@ const qualitys = [] const removeQuality = position => { - qualitys.splice(position, 1); + qualitys.splice(position, 1); updateQualitysList() } const updateQualitysList = () => { let html = '' - for(i in qualitys){ + for (i in qualitys) { html += `

${qualitys[i]}

@@ -21,30 +21,59 @@ const updateQualitysList = () => { } const addNewQuality = quality => { - $('.half').val('') - qualitys.push(quality) - updateQualitysList() + if (quality == undefined || quality == null || quality == '') { + swal('Ops', 'Q qualidade não pode ser nula', 'error') + } else { + $('.half').val('') + qualitys.push(quality) + updateQualitysList() + } } -$(document).ready(function(){ +$(document).ready(function () { - $('.half').keyup(function(e){ - if(e.keyCode == 13) { - addNewQuality(this.value) - } + $('#register-form').submit(function (e) { + e.preventDefault() + + let inputs = $('.search') + + $.ajax({ + url: `http://localhost/woman`, + method: 'POST', + data: { + name: inputs[0].value, + location: inputs[1].value, + imageUrl: inputs[2].value, + email: inputs[3].value, + linkeDin: inputs[4].value, + gitHub: inputs[5].value, + twitter: inputs[6].value, + faceBook: inputs[7].value, + site: inputs[8].value, + qualitys: qualitys + }, + dataType: 'json', + success: function (serverResopnse) { + if (serverResopnse.status) swal('Boa!', 'Seus dados foram cadastrados e agora todos podem te achar!', 'success').then(() => { + location.reload() + }) + else + swal('Ops',serverResopnse.message,'error') + } + }) }) - $('#register-new-quality').click(function(e){ + $('#register-new-quality').click(function (e) { e.preventDefault() let newQuality = $(".half").val() - - if(qualitys.includes(newQuality)){ - swal('Ops','Você já inseriu essa qualidade na lista','error') - }else{ + + if (qualitys.includes(newQuality)) { + swal('Ops', 'Você já inseriu essa qualidade na lista', 'error') + } else { addNewQuality(newQuality) } - + }) })