From 3184f761013f17f3d781e8e7026166e6d3560af5 Mon Sep 17 00:00:00 2001 From: luisddm Date: Fri, 7 Dec 2018 22:56:02 +0100 Subject: [PATCH] Reorganize views --- app.js | 6 ++--- load.js | 2 +- package.json | 2 +- public/favicon.ico | Bin 0 -> 32038 bytes routes/{end.js => done.js} | 3 +-- routes/index.js | 4 +-- routes/vote.js | 1 - test/{end.test.js => done.test.js} | 14 +++++----- views/index.ejs | 36 ------------------------- views/pages/done.ejs | 10 +++++++ views/{ => pages}/error.ejs | 4 +++ views/pages/index.ejs | 27 +++++++++++++++++++ views/pages/vote.ejs | 29 ++++++++++++++++++++ views/partials/foot.ejs | 3 +++ views/{end.ejs => partials/head.ejs} | 12 ++------- views/vote.ejs | 38 --------------------------- 16 files changed, 89 insertions(+), 102 deletions(-) create mode 100644 public/favicon.ico rename routes/{end.js => done.js} (93%) rename test/{end.test.js => done.test.js} (66%) delete mode 100644 views/index.ejs create mode 100644 views/pages/done.ejs rename views/{ => pages}/error.ejs (56%) create mode 100644 views/pages/index.ejs create mode 100644 views/pages/vote.ejs create mode 100644 views/partials/foot.ejs rename views/{end.ejs => partials/head.ejs} (56%) delete mode 100644 views/vote.ejs diff --git a/app.js b/app.js index 85d04e3..9b2ef67 100644 --- a/app.js +++ b/app.js @@ -6,12 +6,12 @@ const logger = require('morgan') const voteRouter = require('./routes/vote') const indexRouter = require('./routes/index') -const endRouter = require('./routes/end') +const doneRouter = require('./routes/done') const app = express() // view engine setup -app.set('views', path.join(__dirname, 'views')) +app.set('views', path.join(__dirname, 'views/pages')) app.set('view engine', 'ejs') app.use(logger('dev')) @@ -22,7 +22,7 @@ app.use(express.static(path.join(__dirname, 'public'))) app.use('/', indexRouter) app.use('/vote', voteRouter) -app.use('/end', endRouter) +app.use('/done', doneRouter) // catch 404 and forward to error handler app.use(function (req, res, next) { diff --git a/load.js b/load.js index ddc18e4..34b7449 100644 --- a/load.js +++ b/load.js @@ -21,7 +21,7 @@ if (DATA_FILE) { }) rl.question( - `The Census table will be dropped and created again with the new data (${censusArray.length} entries). Proceed? (y/N) `, + `The tables will be dropped and created again with the new data (${censusArray.length} entries for the census). Proceed? (y/N) `, async function (answer) { if (answer === 'y') { try { diff --git a/package.json b/package.json index a7651bf..2b0c527 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vote", - "version": "0.5.0", + "version": "0.10.0", "private": true, "scripts": { "start:dev": "NODE_ENV=development node ./bin/www", diff --git a/public/favicon.ico b/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9fbac92f2599b27d4ebaf347ce0241e4a9b14a76 GIT binary patch literal 32038 zcmeHQ36vDY86FN_;(_9Ycq5A9i4hfHSLLY>j|k+wyqCO0jEHAq5{*&7D=KO{KtZ__ zS?*(55F(%gE4P3ga;=<;vMPrQvK+h1a!vpFzV4}+p1yl_X5C$>_j-G#x4Y{5zW=Yk zs;jGOB9S_g`jLhWBiJ{IJX${zX%~q^nlv%K=i>N89J~7J*!O0U$RAFRMB27BzBj)m z64Ba3BF%9PPDKvJaqJ?<)|SK}9Xu%V+;f_obyifSOwk<9a6feDkVwy-nw)S#R3ee6 zJocC-M~=9kZ~hO)MM~nu;hJq5MHWvK*=5dDh^UrJ2pg~l4E%{FUOyu|XiZsA!b(f1gSR}HWdHjUT=8Z%i{gU!{ z=_QetEk&-pk~R}5D-&5#fbX+JBFm5mwnvIIDLoQJ9zP(DQ6kg&i+nLw|Gpp41`H6n z=_Zk^ERok<6Di$?(@I4y`5JjF6=}4zLRPI?C2|--{jf%4((5AQUly6#Tjxr^*fC(%YBac&;?3aR><0QIbnrPEe*!vHO$=#6;dz*f{gBNTs!zN5#%LD4jU)M{xXl89FhEdSlMLe)x|qyN8W!;*Fxkd zMYSjTs`*+e-z}mr>*ey=pm)#6y&kv$` z`5wd>GyowJHSg2Mx$K4~YjS5Vk#BI0XWCONvM^6%b$%!eUS*$pswUT8D{^KZk#^sR ze2ezoF|q6gTvah=i?OhhiN7EWX`+oy17@7TR!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kZ$6d+6co4QOP=h&mrO+!;1Fi||)Gj#lN885tU%7Un8(;Hro%<6ppHGdu!ml(4 z(m&ui{4Ix^98@)*VmBW|pV~o#u{QrF_g=<(s9y11@z-NrdbleMxPCwVz)J)EkH3Y% z-=g5}Nd!q;8@mJUo6LTY%)c_+gT=ZaIC+lp1GahA_R!3|98FW0#I?CQLIV{K68tN} z-N*UD05qLT4XiOyaqrs~x7#7PtE{;;xYEGj-#@(14~5TfU>lbi?h30}1I3*_pDK5i zFEwCY7&9jy+}{jW-`U3TH%~ImU16mLeBYJzy+2GZ_e;{YuxynkE=NUGjOjYQ~TxSb$ZPl-9FbQ?(EO= zx2<>|=f>B3{3!P-jdgZsP1BKsX1fQBb$n;8w$%5qKCid$RoBL)$;$R@80+TaozyV( zUFW_Cd1bb5V+Wh&BRcmKVjbszRZ-t2&5RS-rNkX$R<(h<-p1kiT^OI|S}wJLJ3WA7 zFkJsC=>0p_B-!|7&G&ib{hYhXxjOo9?6{0ivya2RO>N_@G~m1pFAWs;!o|3vhR1ou z*}8YrAc?#6qFVNy&mcLUmz>Q$U$_KBYpLC>Ce$^+^Broy-=Ny`3*xS{*oOxU{9R*x S&6ldPyJb0mqhEhv3j7~g9@6Ci literal 0 HcmV?d00001 diff --git a/routes/end.js b/routes/done.js similarity index 93% rename from routes/end.js rename to routes/done.js index 80820c8..a2044c4 100644 --- a/routes/end.js +++ b/routes/done.js @@ -26,8 +26,7 @@ router.post('/', async function (req, res, next) { error = e } - res.render('end', { - title: 'FrontFest Vote', + res.render('done', { selectedOption, error }) diff --git a/routes/index.js b/routes/index.js index 73a62c2..e0eb892 100644 --- a/routes/index.js +++ b/routes/index.js @@ -4,9 +4,7 @@ const router = express.Router() /* GET home page. */ router.get('/', function (req, res, next) { - res.render('index', { - title: 'FrontFest Vote' - }) + res.render('index') }) module.exports = router diff --git a/routes/vote.js b/routes/vote.js index c372cbf..51d84f2 100644 --- a/routes/vote.js +++ b/routes/vote.js @@ -34,7 +34,6 @@ router.post('/', async function (req, res, next) { } res.render('vote', { - title: 'FrontFest Vote', options, ticketId, error diff --git a/test/end.test.js b/test/done.test.js similarity index 66% rename from test/end.test.js rename to test/done.test.js index 7579abe..30f7e6d 100644 --- a/test/end.test.js +++ b/test/done.test.js @@ -3,26 +3,26 @@ const request = require('supertest') const app = require('../app') const db = require('../db') -describe('end route', () => { +describe('done route', () => { let response beforeEach(async () => { await db.sequelize.sync({ force: true }) }) - it('end: code does not exist', async () => { + it('done: code does not exist', async () => { await db.census.create({ code: 'abcde' }) - response = await request(app).post('/end').send({ ticketId: 'random_code', selectedOption: 'OPT1' }) + response = await request(app).post('/done').send({ ticketId: 'random_code', selectedOption: 'OPT1' }) expect(response.statusCode).toBe(200) expect(response.text).toContain('No existe el localizador.') }) - it('end: already voted', async () => { + it('done: already voted', async () => { await db.census.create({ code: 'abcde', voted: true }) - response = await request(app).post('/end').send({ ticketId: 'abcde', selectedOption: 'OPT1' }) + response = await request(app).post('/done').send({ ticketId: 'abcde', selectedOption: 'OPT1' }) expect(response.statusCode).toBe(200) expect(response.text).toContain('Lo siento, ya has votado.') }) - it('end: voted ok', async () => { + it('done: voted ok', async () => { await db.census.create({ code: 'abcde' }) - response = await request(app).post('/end').send({ ticketId: 'abcde', selectedOption: 'OPT1' }) + response = await request(app).post('/done').send({ ticketId: 'abcde', selectedOption: 'OPT1' }) expect(response.statusCode).toBe(200) expect(response.text).toContain('¡Gracias! Has votado por OPT1.') const vote = await db.votes.findOne({ where: { result: 'OPT1' } }) diff --git a/views/index.ejs b/views/index.ejs deleted file mode 100644 index 20bb858..0000000 --- a/views/index.ejs +++ /dev/null @@ -1,36 +0,0 @@ - - - - <%= title %> - - - - - - -
-
- -
-
-
- - - -

- Puedes encontrar el localizador bajo el código QR en el PDF de Koliseo. -

-

- El localizador se utilizará únicamente para comprobar que se posee una entrada válida y evitar la duplicidad del voto. - No se relacionará en ningún caso con la opción elegida, manteniendo anónimo el sentido del voto. -

-

- Más información sobre esta app y código fuente aquí. -

-
-
-
- - diff --git a/views/pages/done.ejs b/views/pages/done.ejs new file mode 100644 index 0000000..3126046 --- /dev/null +++ b/views/pages/done.ejs @@ -0,0 +1,10 @@ +<% include ../partials/head %> + +<% if (!error) { %> +

¡Gracias! Has votado por <%= selectedOption %>.

+<% } else { %> +

<%= error %>

+<% } %> + +<% include ../partials/foot %> + diff --git a/views/error.ejs b/views/pages/error.ejs similarity index 56% rename from views/error.ejs rename to views/pages/error.ejs index 7cf94ed..77558f3 100644 --- a/views/error.ejs +++ b/views/pages/error.ejs @@ -1,3 +1,7 @@ +<% include ../partials/head %> +

<%= message %>

<%= error.status %>

<%= error.stack %>
+ +<% include ../partials/foot %> diff --git a/views/pages/index.ejs b/views/pages/index.ejs new file mode 100644 index 0000000..168076d --- /dev/null +++ b/views/pages/index.ejs @@ -0,0 +1,27 @@ +<% include ../partials/head %> + +
+ +
+
+
+ + + +

+ Puedes encontrar el localizador bajo el código QR en el PDF de Koliseo. +

+

+ El localizador se utilizará únicamente para comprobar que se posee una entrada válida y evitar la duplicidad del voto. + No se relacionará en ningún caso con la opción elegida, manteniendo anónimo el sentido del voto. +

+

+ Más información sobre esta app y código fuente aquí. +

+
+
+ +<% include ../partials/foot %> + diff --git a/views/pages/vote.ejs b/views/pages/vote.ejs new file mode 100644 index 0000000..8e9c989 --- /dev/null +++ b/views/pages/vote.ejs @@ -0,0 +1,29 @@ +<% include ../partials/head %> + +<% if (!error) { %> +
+
+

<%= ticketId %>

+
+
+ +
+ + + + +
+ +
+<% } else { %> +

<%= error %>

+<% } %> + +<% include ../partials/foot %> + diff --git a/views/partials/foot.ejs b/views/partials/foot.ejs new file mode 100644 index 0000000..5b6e2d6 --- /dev/null +++ b/views/partials/foot.ejs @@ -0,0 +1,3 @@ + + + diff --git a/views/end.ejs b/views/partials/head.ejs similarity index 56% rename from views/end.ejs rename to views/partials/head.ejs index 64eb3a9..33382ba 100644 --- a/views/end.ejs +++ b/views/partials/head.ejs @@ -1,19 +1,11 @@ - <%= title %> + FrontFest Vote - +
- <% if (!error) { %> -

¡Gracias! Has votado por <%= selectedOption %>.

- <% } else { %> -

<%= error %>

- <% } %> -
- - diff --git a/views/vote.ejs b/views/vote.ejs deleted file mode 100644 index 590a1ee..0000000 --- a/views/vote.ejs +++ /dev/null @@ -1,38 +0,0 @@ - - - - <%= title %> - - - - - - -
- <% if (!error) { %> -
-
-

<%= ticketId %>

-
-
- -
- - - - -
- -
- <% } else { %> -

<%= error %>

- <% } %> -
- -