From fefd214d8f7ec3249651e5b437024c20013e2c0e Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 11:55:44 +0100 Subject: [PATCH 01/11] Update index.html --- app/public/zadanie01/index.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/public/zadanie01/index.html b/app/public/zadanie01/index.html index c116dfd..0c3a3d5 100644 --- a/app/public/zadanie01/index.html +++ b/app/public/zadanie01/index.html @@ -1 +1,19 @@ - \ No newline at end of file + + + + + + + Coders Lab + + + +

Czy B jest dzielnikiem A?

+
+ Liczba A:
+ Liczba B:
+ +
+ + From a37f7f1218567f0f1bb4ec06c36f75044b774508 Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 11:56:34 +0100 Subject: [PATCH 02/11] Update zadanie01.js --- app/zadanie01.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..3409aba 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,17 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const bodyParser = require('body-parser'); +const app = express(); +app.use(bodyParser.urlencoded({ + extended: true //body-parser deprecated undefined extended: provide extended option +})); +app.use(express.static('./public/zadanie01/')); + +app.post('/result', (req, res) => { + const {a, b} = req.body; + let is = parseInt(a) % parseInt(b) === 0 ? '' : ' nie'; + res.send('Liczba ' + b + is + ' jest dzielnikiem liczby ' + a); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); From 8e3a3d687d1520758f95860ca8cbc7cba323d583 Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 12:15:58 +0100 Subject: [PATCH 03/11] Update zadanie02.js --- app/zadanie02.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..1d1d0a9 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,29 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const cookieParser = require('cookie-parser'); +const bodyParser = require('body-parser'); +const app = express(); +app.use(cookieParser()); +app.use(bodyParser.urlencoded({ + extended: true +})); +app.use(express.static('./public/zadanie02/')); + +app.post('/cookie/set', (req, res) => { + res.cookie('cookieName', req.body.name, { + maxAge : 2628000000, + }); + res.send('Zapisano imię: ' + req.body.name); +}); + +app.get('/cookie/show', (req, res) => { + res.send('Zapisane imię: ' + req.cookies.cookieName); +}); + +app.get('/cookie/check', (req, res) => { + let is = req.cookies.cookieName === undefined ? 'nie' : ''; + res.send('Imię '+ is + ' zostało zapisane w ciastku.'); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); From e2d8e369b0a18b99420de91c8429d0d877ddc93a Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 12:16:18 +0100 Subject: [PATCH 04/11] Update index.html --- app/public/zadanie02/index.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/public/zadanie02/index.html b/app/public/zadanie02/index.html index c116dfd..983c088 100644 --- a/app/public/zadanie02/index.html +++ b/app/public/zadanie02/index.html @@ -1 +1,18 @@ - \ No newline at end of file + + + + + + + Coders Lab + + +
+ Imię:
+ +
+ Pokaż imię + Sprawdź imię + + From d7776b9d4b6f19bf48e40aaf307a7e7a7776668d Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:21:30 +0100 Subject: [PATCH 05/11] Create add.html --- app/public/zadanieDnia/add.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/public/zadanieDnia/add.html diff --git a/app/public/zadanieDnia/add.html b/app/public/zadanieDnia/add.html new file mode 100644 index 0000000..cca2eab --- /dev/null +++ b/app/public/zadanieDnia/add.html @@ -0,0 +1,16 @@ + + + + + + + Add comment + + +
+
+ +
+ + From acf25500db2d22f1cf475067e9d29362caa1340b Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:22:25 +0100 Subject: [PATCH 06/11] Delete index.html --- app/public/zadanieDnia/index.html | 1 - 1 file changed, 1 deletion(-) delete mode 100644 app/public/zadanieDnia/index.html diff --git a/app/public/zadanieDnia/index.html b/app/public/zadanieDnia/index.html deleted file mode 100644 index c116dfd..0000000 --- a/app/public/zadanieDnia/index.html +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 3bf767624d46a3ab80bb3eb4f59501fc511a04ee Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:23:37 +0100 Subject: [PATCH 07/11] Update zadanieDnia.js --- app/zadanieDnia.js | 55 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..b8fff5f 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,54 @@ -//Twój kod \ No newline at end of file +const express = require('express'); +const cookieParser = require('cookie-parser'); +const bodyParser = require('body-parser'); +const app = express(); +app.use(cookieParser()); +app.use(bodyParser.urlencoded({ + extended: true +})); +app.use(express.static('./public/zadanieDnia/')); + +app.get('/remove', (req, res) => { + res.clearCookie('comments'); + res.send('Komentarze usunięte!'); +}); + +app.get('/', (req, res) => { + const comments = readComments(req.cookies.comments); + res.send(comments + '
Dodaj nowy komentarz'); +}); + +app.post('/save', (req, res) => { + let comments = addComment(req.cookies.comments, req.body.comment); + res.cookie('comments', comments, { + maxAge: 2628000000, + }); + res.send('Zapisano nowy komentarz. Zobacz komentarze'); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); + +// Funkcje pomocnicze + +/** + * Ta funkcja pobiera string dotychczasowego ciastka, dodaje nowy komentarz i zwraca nowy string - taki z jakim należy nadpisać to ciasto. + * @param {string} commentsCookieValue Wartość dotychczasowego ciastka przechowującego komentarze + * @param {string} newComment Nowy komentarz + * @return {string} Nowy string z komentarzami do zapisania w ciastku + */ +function addComment(commentsCookieValue, newComment) { + const comments = readComments(commentsCookieValue); + comments.push(newComment); + return JSON.stringify(comments); +} + +/** + * Ta funkcja odczytuje już dodane komentarze i zwraca je w postaci tablicy. + * @param {string} commentsCookieValue Wartość dotychczasowego ciastka przechowującego komentarze + * @return {Array} Tablica z komentarzami + */ +function readComments(commentsCookieValue) { + return commentsCookieValue ? JSON.parse(commentsCookieValue) : []; +} From 17115f6ea10e01c8b6899c1f9ef25949ce0a6846 Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:38:05 +0100 Subject: [PATCH 08/11] const --- app/zadanieDnia.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index b8fff5f..67ee643 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -19,7 +19,7 @@ app.get('/', (req, res) => { }); app.post('/save', (req, res) => { - let comments = addComment(req.cookies.comments, req.body.comment); + const comments = addComment(req.cookies.comments, req.body.comment); res.cookie('comments', comments, { maxAge: 2628000000, }); From bd4eab318c40c6f3a79890f67b0d09d77c115862 Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:41:50 +0100 Subject: [PATCH 09/11] const --- app/zadanie01.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 3409aba..d463d20 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -8,7 +8,7 @@ app.use(express.static('./public/zadanie01/')); app.post('/result', (req, res) => { const {a, b} = req.body; - let is = parseInt(a) % parseInt(b) === 0 ? '' : ' nie'; + const is = parseInt(a) % parseInt(b) === 0 ? '' : ' nie'; res.send('Liczba ' + b + is + ' jest dzielnikiem liczby ' + a); }); From 6644e27fcc0a981b14b6d7ac258d0ef5142b22b1 Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:42:09 +0100 Subject: [PATCH 10/11] const --- app/zadanie02.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 1d1d0a9..4aab2bc 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -20,7 +20,7 @@ app.get('/cookie/show', (req, res) => { }); app.get('/cookie/check', (req, res) => { - let is = req.cookies.cookieName === undefined ? 'nie' : ''; + const is = req.cookies.cookieName === undefined ? 'nie' : ''; res.send('Imię '+ is + ' zostało zapisane w ciastku.'); }); From c1c077c85225afc9a5d0ff05ec3d67f1045aa41c Mon Sep 17 00:00:00 2001 From: Greg Herbowicz Date: Sat, 3 Feb 2018 13:43:32 +0100 Subject: [PATCH 11/11] no styles --- app/public/zadanie01/index.html | 1 - 1 file changed, 1 deletion(-) diff --git a/app/public/zadanie01/index.html b/app/public/zadanie01/index.html index 0c3a3d5..32f01bf 100644 --- a/app/public/zadanie01/index.html +++ b/app/public/zadanie01/index.html @@ -6,7 +6,6 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> Coders Lab -

Czy B jest dzielnikiem A?