From f1bc86fcaa84da0bf16087d2f3716c5ea806ea05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:54:07 +0100 Subject: [PATCH 1/6] Zadanie 01 - done --- app/zadanie01.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app/zadanie01.js b/app/zadanie01.js index 8c20173..b7b5c3a 100644 --- a/app/zadanie01.js +++ b/app/zadanie01.js @@ -1 +1,23 @@ -//Twój kod \ No newline at end of file +//Twój kod + +const express = require('express'); +const bodyParser = require('body-parser'); +const app = express(); +app.use(bodyParser.urlencoded({ extended: false })); + +app.use(express.static('./public/zadanie01/')); + +app.post('/result', (req, res) => { + const {numberA, numberB} = req.body; + let information = ''; + if (parseInt(numberA) % parseInt(numberB) === 0) { + information = `Tak! Liczba ${numberB} jest dzielnikiem liczby ${numberA}`; + } else { + information = `Nie! Liczba ${numberB} nie jest dzielnikiem liczby ${numberA}`; + } + res.send(`

${information}

`); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file From 9d20e92d6b6987336072f80d289ecce13ca46e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:54:36 +0100 Subject: [PATCH 2/6] Zadanie 01 - done --- app/public/zadanie01/index.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/public/zadanie01/index.html b/app/public/zadanie01/index.html index c116dfd..727abd5 100644 --- a/app/public/zadanie01/index.html +++ b/app/public/zadanie01/index.html @@ -1 +1,21 @@ - \ No newline at end of file + + + + + + + + + Coders Lab + + + +

Chcesz wiedzieć czy liczba B jest dzielnikiem liczby A?

+
+ Liczba A:
+ Liczba B:
+ +
+ + \ No newline at end of file From 096e9f80221de727e63ddea312853ea6eb589615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:54:53 +0100 Subject: [PATCH 3/6] Zadanie 02 - done --- app/zadanie02.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/zadanie02.js b/app/zadanie02.js index 8c20173..63d6a76 100644 --- a/app/zadanie02.js +++ b/app/zadanie02.js @@ -1 +1,31 @@ -//Twój kod \ No newline at end of file +//Twój kod + +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: false })); + +app.use(express.static('./public/zadanie02/')); + +app.post('/cookie/set', (req, res) => { + const {name} = req.body; + res.cookie('nameSaved', name, { + maxAge : 2592000000, + }); + res.send(`Zapisano imię: ${name}`); +}); + +app.get('/cookie/show', (req, res) => { + res.send(`Zapisane imię: ${req.cookies.nameSaved}`); +}); + +app.get('/cookie/check', (req, res) => { + let information = req.cookies.nameSaved === undefined ? 'Nie zapisano imienia.' : 'Imię zapisane.'; + res.send(information); +}); + +app.listen(3000, () => { + console.log('Serwer uruchomiony na porcie 3000'); +}); \ No newline at end of file From 648c258fd138364dd7d3c48d04b752c09b760dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:55:09 +0100 Subject: [PATCH 4/6] Zadanie 02 - done --- app/public/zadanie02/index.html | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/public/zadanie02/index.html b/app/public/zadanie02/index.html index c116dfd..494cfc4 100644 --- a/app/public/zadanie02/index.html +++ b/app/public/zadanie02/index.html @@ -1 +1,20 @@ - \ No newline at end of file + + + + + + + + + Coders Lab + + + +

Jak masz na imię?

+
+ Imię:
+ +
+ + \ No newline at end of file From f74f235a042c00d1b7b3d2932fde2f1268ecb1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:55:28 +0100 Subject: [PATCH 5/6] Zadanie Dnia - done --- app/zadanieDnia.js | 52 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/app/zadanieDnia.js b/app/zadanieDnia.js index 8c20173..5d23ce7 100644 --- a/app/zadanieDnia.js +++ b/app/zadanieDnia.js @@ -1 +1,51 @@ -//Twój kod \ No newline at end of file +//Twój kod + +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: false })); + +app.use(express.static('./public/zadanieDnia/')); + +app.post('/save', (req, res) => { + const comments = addComment(req.cookies.commentSaved, req.body.comment) + + res.cookie('commentSaved', comments, { + maxAge : 2592000000, + }); + res.send('Zapisano komentarz Powrót do strony głównej'); +}); + +app.get('/', (req, res) => { + const comments = readComments(req.cookies.commentSaved); + res.send(`${comments}
Dodaj nowy komentarz`); +}); + +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) : []; +} \ No newline at end of file From 849ecd4d960aeb36e3cff5522a8762f824c0293b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Godzi=C5=84ski?= Date: Sat, 3 Feb 2018 18:56:06 +0100 Subject: [PATCH 6/6] Zadanie Dnia - done --- app/public/zadanieDnia/add.html | 20 ++++++++++++++++++++ app/public/zadanieDnia/index.html | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 app/public/zadanieDnia/add.html delete mode 100644 app/public/zadanieDnia/index.html diff --git a/app/public/zadanieDnia/add.html b/app/public/zadanieDnia/add.html new file mode 100644 index 0000000..9f797b8 --- /dev/null +++ b/app/public/zadanieDnia/add.html @@ -0,0 +1,20 @@ + + + + + + + + + Coders Lab + + + +

Napisz komentarz:

+
+ + +
+ + \ No newline at end of file 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