From 08b9ccef621f871544941cee331f2ea17de8608f Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 13 Nov 2019 21:47:34 +0200 Subject: [PATCH 01/20] Lecture notes --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 86d5cadc7..3411980e9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ ![](https://avatars0.githubusercontent.com/u/4995607?v=3&s=100) +# Naudingos nuorodos + +https://github.com/aurelijusb/kickstart/pull/90 + NFQ Akademija ============ From 02d2606b875738fa45287d9dfc71baa48ed2129e Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 13 Nov 2019 09:00:40 +0200 Subject: [PATCH 02/20] Pridedam React'ui reikalingas JavaScript bibliotekas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/frontend.sh yarn add @babel/preset-react --dev yarn add react react-dom prop-types Dokumentacija: https://symfony.com/doc/current/frontend/encore/reactjs.html Jei paimate pavyzdį, tai scripts/frontend.sh yarn --- package.json | 6 +++ yarn.lock | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index fbd40f7ec..151e728ef 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "devDependencies": { + "@babel/preset-react": "^7.7.0", "@symfony/webpack-encore": "^0.28.0", "bootstrap": "^4.3.1", "core-js": "^3.0.0", @@ -17,5 +18,10 @@ "dev": "encore dev", "watch": "encore dev --watch", "build": "encore production --progress" + }, + "dependencies": { + "prop-types": "^15.7.2", + "react": "^16.11.0", + "react-dom": "^16.11.0" } } diff --git a/yarn.lock b/yarn.lock index 47fd30502..418eec27a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -54,6 +54,14 @@ "@babel/helper-explode-assignable-expression" "^7.1.0" "@babel/types" "^7.0.0" +"@babel/helper-builder-react-jsx@^7.7.0": + version "7.7.0" + resolved "https://registry.yarnpkg.com/@babel/helper-builder-react-jsx/-/helper-builder-react-jsx-7.7.0.tgz#c6b8254d305bacd62beb648e4dea7d3ed79f352d" + integrity sha512-LSln3cexwInTMYYoFeVLKnYPPMfWNJ8PubTBs3hkh7wCu9iBaqq1OOyW+xGmEdLxT1nhsl+9SJ+h2oUDYz0l2A== + dependencies: + "@babel/types" "^7.7.0" + esutils "^2.0.0" + "@babel/helper-call-delegate@^7.4.4": version "7.4.4" resolved "https://registry.yarnpkg.com/@babel/helper-call-delegate/-/helper-call-delegate-7.4.4.tgz#87c1f8ca19ad552a736a7a27b1c1fcf8b1ff1f43" @@ -288,6 +296,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-syntax-jsx@^7.2.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.2.0.tgz#0b85a3b4bc7cdf4cc4b8bf236335b907ca22e7c7" + integrity sha512-VyN4QANJkRW6lDBmENzRszvZf3/4AXaj9YR7GwrWeeN9tEBPuXbmDYVU9bYBN0D70zCWVwUy0HWq2553VCb6Hw== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-object-rest-spread@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" @@ -488,6 +503,38 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" +"@babel/plugin-transform-react-display-name@^7.0.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.2.0.tgz#ebfaed87834ce8dc4279609a4f0c324c156e3eb0" + integrity sha512-Htf/tPa5haZvRMiNSQSFifK12gtr/8vwfr+A9y69uF0QcU77AVu4K7MiHEkTxF7lQoHOL0F9ErqgfNEAKgXj7A== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + +"@babel/plugin-transform-react-jsx-self@^7.0.0": + version "7.2.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.2.0.tgz#461e21ad9478f1031dd5e276108d027f1b5240ba" + integrity sha512-v6S5L/myicZEy+jr6ielB0OR8h+EH/1QFx/YJ7c7Ua+7lqsjj/vW6fD5FR9hB/6y7mGbfT4vAURn3xqBxsUcdg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + +"@babel/plugin-transform-react-jsx-source@^7.0.0": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.5.0.tgz#583b10c49cf057e237085bcbd8cc960bd83bd96b" + integrity sha512-58Q+Jsy4IDCZx7kqEZuSDdam/1oW8OdDX8f+Loo6xyxdfg1yF0GE2XNJQSTZCaMol93+FBzpWiPEwtbMloAcPg== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + +"@babel/plugin-transform-react-jsx@^7.7.0": + version "7.7.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.7.0.tgz#834b0723ba78cd4d24d7d629300c2270f516d0b7" + integrity sha512-mXhBtyVB1Ujfy+0L6934jeJcSXj/VCg6whZzEcgiiZHNS0PGC7vUCsZDQCxxztkpIdF+dY1fUMcjAgEOC3ZOMQ== + dependencies: + "@babel/helper-builder-react-jsx" "^7.7.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-syntax-jsx" "^7.2.0" + "@babel/plugin-transform-regenerator@^7.4.5": version "7.4.5" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.4.5.tgz#629dc82512c55cee01341fb27bdfcb210354680f" @@ -604,6 +651,17 @@ js-levenshtein "^1.1.3" semver "^5.5.0" +"@babel/preset-react@^7.7.0": + version "7.7.0" + resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.7.0.tgz#8ab0c4787d98cf1f5f22dabf115552bf9e4e406c" + integrity sha512-IXXgSUYBPHUGhUkH+89TR6faMcBtuMW0h5OHbMuVbL3/5wK2g6a2M2BBpkLa+Kw0sAHiZ9dNVgqJMDP/O4GRBA== + dependencies: + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-transform-react-display-name" "^7.0.0" + "@babel/plugin-transform-react-jsx" "^7.7.0" + "@babel/plugin-transform-react-jsx-self" "^7.0.0" + "@babel/plugin-transform-react-jsx-source" "^7.0.0" + "@babel/template@^7.1.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0": version "7.6.0" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6" @@ -637,6 +695,15 @@ lodash "^4.17.13" to-fast-properties "^2.0.0" +"@babel/types@^7.7.0": + version "7.7.2" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.7.2.tgz#550b82e5571dcd174af576e23f0adba7ffc683f7" + integrity sha512-YTf6PXoh3+eZgRCBzzP25Bugd2ngmpQVrk7kXX0i5N9BO7TFBtIgZYs7WtxtOGs8e6A4ZI7ECkbBCEHeXocvOA== + dependencies: + esutils "^2.0.2" + lodash "^4.17.13" + to-fast-properties "^2.0.0" + "@symfony/webpack-encore@^0.28.0": version "0.28.0" resolved "https://registry.yarnpkg.com/@symfony/webpack-encore/-/webpack-encore-0.28.0.tgz#75f24034602cfca35eea95400e88926821a1d7dc" @@ -2517,7 +2584,7 @@ estraverse@^4.1.0, estraverse@^4.1.1: resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.3.0.tgz#398ad3f3c5a24948be7725e83d11a7de28cdbd1d" integrity sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== -esutils@^2.0.2: +esutils@^2.0.0, esutils@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64" integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== @@ -3921,7 +3988,7 @@ loglevel@^1.6.4: resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.4.tgz#f408f4f006db8354d0577dcf6d33485b3cb90d56" integrity sha512-p0b6mOGKcGa+7nnmKbpzR6qloPbrgLcnio++E+14Vo/XffOGwZtRpUhr8dTH/x2oCMmEoIU0Zwm3ZauhvYD17g== -loose-envify@^1.0.0: +loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== @@ -5251,6 +5318,15 @@ promise-inflight@^1.0.1: resolved "https://registry.yarnpkg.com/promise-inflight/-/promise-inflight-1.0.1.tgz#98472870bf228132fcbdd868129bad12c3c029e3" integrity sha1-mEcocL8igTL8vdhoEputEsPAKeM= +prop-types@^15.6.2, prop-types@^15.7.2: + version "15.7.2" + resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" + integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ== + dependencies: + loose-envify "^1.4.0" + object-assign "^4.1.1" + react-is "^16.8.1" + proxy-addr@~2.0.5: version "2.0.5" resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.5.tgz#34cbd64a2d81f4b1fd21e76f9f06c8a45299ee34" @@ -5396,6 +5472,30 @@ rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" +react-dom@^16.11.0: + version "16.11.0" + resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.11.0.tgz#7e7c4a5a85a569d565c2462f5d345da2dd849af5" + integrity sha512-nrRyIUE1e7j8PaXSPtyRKtz+2y9ubW/ghNgqKFHHAHaeP0fpF5uXR+sq8IMRHC+ZUxw7W9NyCDTBtwWxvkb0iA== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + scheduler "^0.17.0" + +react-is@^16.8.1: + version "16.11.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.11.0.tgz#b85dfecd48ad1ce469ff558a882ca8e8313928fa" + integrity sha512-gbBVYR2p8mnriqAwWx9LbuUrShnAuSCNnuPGyc7GJrMVQtPDAh8iLpv7FRuMPFb56KkaVZIYSz1PrjI9q0QPCw== + +react@^16.11.0: + version "16.11.0" + resolved "https://registry.yarnpkg.com/react/-/react-16.11.0.tgz#d294545fe62299ccee83363599bf904e4a07fdbb" + integrity sha512-M5Y8yITaLmU0ynd0r1Yvfq98Rmll6q8AxaEe88c8e7LxO8fZ2cNgmFt0aGAS9wzf1Ao32NKXtCl+/tVVtkxq6g== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + prop-types "^15.6.2" + read-pkg-up@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" @@ -5750,6 +5850,14 @@ sax@^1.2.4, sax@~1.2.4: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== +scheduler@^0.17.0: + version "0.17.0" + resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.17.0.tgz#7c9c673e4ec781fac853927916d1c426b6f3ddfe" + integrity sha512-7rro8Io3tnCPuY4la/NuI5F2yfESpnfZyT6TtkXnSWVkcu0BCDJ+8gk5ozUaFaxpIyNuWAPXrH0yFcSi28fnDA== + dependencies: + loose-envify "^1.1.0" + object-assign "^4.1.1" + schema-utils@^0.4.5: version "0.4.7" resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187" From c70edb7b6bb4888dfe1a647b65fba821ee1d0110 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 11 Apr 2018 22:35:27 +0300 Subject: [PATCH 03/20] =?UTF-8?q?Pajungiame,=20kad=20kompiliuot=C5=B3=20Re?= =?UTF-8?q?act'o=20JSX=20failus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iš assets/js eis į build/js/app.js, nes taip parašėme webpack.config.js scripts/frontend.sh yarn watch Rezultato ieškoti: build/js/app.js Dokumentacija: https://symfony.com/doc/current/frontend/encore/reactjs.html https://yarnpkg.com/lang/en/docs/package-json/#toc-scripts --- assets/js/react.jsx | 1 + webpack.config.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 assets/js/react.jsx diff --git a/assets/js/react.jsx b/assets/js/react.jsx new file mode 100644 index 000000000..9d7684786 --- /dev/null +++ b/assets/js/react.jsx @@ -0,0 +1 @@ +let here = 'will be more code'; diff --git a/webpack.config.js b/webpack.config.js index ca8c7037b..0ae15dc06 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -23,7 +23,10 @@ Encore * Each entry will result in one JavaScript file (e.g. app.js) * and one CSS file (e.g. app.css) if your JavaScript imports CSS. */ - .addEntry('app', './assets/js/app.js') + .addEntry('app', [ + './assets/js/app.js', + './assets/js/react.jsx' + ]) //.addEntry('page1', './assets/js/page1.js') //.addEntry('page2', './assets/js/page2.js') @@ -55,6 +58,7 @@ Encore // enables Sass/SCSS support .enableSassLoader() + .enableReactPreset() // uncomment if you use TypeScript //.enableTypeScriptLoader() From 8d99df994536f75252e93581b563bab27fa2bf12 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 13 Nov 2019 17:17:14 +0200 Subject: [PATCH 04/20] Sukuriame Controller patogesniam testavimui Sugeneruota su scripts/backend.sh bin/console make:controller People Patikrinimui: * http://127.0.0.1:8000/people Dokumentacija: * https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html --- src/Controller/PeopleController.php | 19 +++++++++++++++++++ templates/people/index.html.twig | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/Controller/PeopleController.php create mode 100644 templates/people/index.html.twig diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php new file mode 100644 index 000000000..c85b90746 --- /dev/null +++ b/src/Controller/PeopleController.php @@ -0,0 +1,19 @@ +render('people/index.html.twig', [ + 'controller_name' => 'PeopleController', + ]); + } +} diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig new file mode 100644 index 000000000..f3aeb3871 --- /dev/null +++ b/templates/people/index.html.twig @@ -0,0 +1,20 @@ +{% extends 'base.html.twig' %} + +{% block title %}Hello PeopleController!{% endblock %} + +{% block body %} + + +
+

Hello {{ controller_name }}! ✅

+ + This friendly message is coming from: + +
+{% endblock %} From 6824312d7568a918526d6a39008f4aa791fe7534 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 11 Apr 2018 22:45:49 +0300 Subject: [PATCH 05/20] Bandome React Hello world, bet neveikia Patikrinimui: http://127.0.0.1:8000/people Dokumentacija: https://reactjs.org/docs/hello-world.html --- assets/js/react.jsx | 5 ++++- templates/people/index.html.twig | 16 ++-------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/assets/js/react.jsx b/assets/js/react.jsx index 9d7684786..29cf2f43b 100644 --- a/assets/js/react.jsx +++ b/assets/js/react.jsx @@ -1 +1,4 @@ -let here = 'will be more code'; +ReactDOM.render( +

Hello, world!

, + document.getElementById('root') +); diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index f3aeb3871..c5739b1a5 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -3,18 +3,6 @@ {% block title %}Hello PeopleController!{% endblock %} {% block body %} - - -
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: - -
+
Loading...
+ {% endblock %} From 6f02df35a4da3a361627d6a3bcb5236c9a82e469 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 11 Apr 2018 22:54:25 +0300 Subject: [PATCH 06/20] =?UTF-8?q?Pataisome,=20kad=20veikt=C5=B3=20React=20?= =?UTF-8?q?Hello=20world=20pavyzdys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Klaidą buvo galima patyti per Naršyklės konsolę: ReferenceError: ReactDOM is not defined Esmė: React'ą turėjome node_modules (prsiminkime yarn... komandą), bet WebPack Encore nežinojo, kad reikia jį įtraukti. Dokumentacija (neatsimenu, kur radau, bet čia geras pavyzdys): https://artemzhuravlev.com/blog/symfony-reactjs-using-encore/ Bonus per konsole siūlo (ir programuoti padės): Download the React DevTools for a better development experience: https://fb.me/react-devtools --- assets/js/react.jsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/assets/js/react.jsx b/assets/js/react.jsx index 29cf2f43b..24b8859c1 100644 --- a/assets/js/react.jsx +++ b/assets/js/react.jsx @@ -1,3 +1,6 @@ +const React = require('react'); +const ReactDOM = require('react-dom'); + ReactDOM.render(

Hello, world!

, document.getElementById('root') From b395b707ac4065d37125db40fb16e802d5abf300 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 13 Nov 2019 20:01:21 +0200 Subject: [PATCH 07/20] =?UTF-8?q?Panaudokime=20kieno=20nors=20kito=20bibli?= =?UTF-8?q?otek=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit scripts/frontend.sh yarn add axios yarn watch Pridėta į app.js, kad būtų galima patikrinti: public/build/js/app.js Dokumentacija: https://www.npmjs.com/package/axios https://yarnpkg.com/lang/en/docs/cli/add/ https://yarnpkg.com/lang/en/docs/cli/run/ Jei naudojamas commit'as kaip pavyzdys, scripts/frontend.sh yarn --- assets/js/app.js | 2 ++ package.json | 1 + yarn.lock | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/assets/js/app.js b/assets/js/app.js index 468ca96e6..32a9b5e7b 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -15,3 +15,5 @@ require('bootstrap'); $(document).ready(function() { $('[data-toggle="popover"]').popover(); }); + +const axios = require('axios'); diff --git a/package.json b/package.json index 151e728ef..b381fcaae 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "build": "encore production --progress" }, "dependencies": { + "axios": "^0.19.0", "prop-types": "^15.7.2", "react": "^16.11.0", "react-dom": "^16.11.0" diff --git a/yarn.lock b/yarn.lock index 418eec27a..10934a295 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1193,6 +1193,14 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ== +axios@^0.19.0: + version "0.19.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8" + integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ== + dependencies: + follow-redirects "1.5.10" + is-buffer "^2.0.2" + babel-loader@^8.0.0: version "8.0.6" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.6.tgz#e33bdb6f362b03f4bb141a0c21ab87c501b70dfb" @@ -2163,6 +2171,13 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3: dependencies: ms "2.0.0" +debug@=3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261" + integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g== + dependencies: + ms "2.0.0" + debug@^3.0.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6: version "3.2.6" resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b" @@ -2839,6 +2854,13 @@ flush-write-stream@^1.0.0: inherits "^2.0.3" readable-stream "^2.3.6" +follow-redirects@1.5.10: + version "1.5.10" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a" + integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ== + dependencies: + debug "=3.1.0" + follow-redirects@^1.0.0: version "1.9.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f" @@ -3553,6 +3575,11 @@ is-buffer@^1.1.5: resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w== +is-buffer@^2.0.2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.4.tgz#3e572f23c8411a5cfd9557c849e3665e0b290623" + integrity sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A== + is-callable@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75" From f1cff084b08094809e80595a93176b112c228acc Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 11 Apr 2018 23:43:52 +0300 Subject: [PATCH 08/20] =?UTF-8?q?Padarom=20AJAX=20u=C5=BEklaus=C4=85=20nau?= =?UTF-8?q?dojant=20axios=20bibliotek=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Čia viena iš pavyzdžių, kaip galima panaudoti išorinę bilbioteką, kad mūsų kodas būtų paprastesnis. Kad kodas veiktų, paleidžiame per scripts/frontend.sh yarn watch Patirikrinimui: http://127.0.0.1:8000/people Patirkinimui, atsidarome Naršyklės console langą Turėtų būti kažkas į Object { "build/app.css": "/build/app.css", "build/app.js": "/build/app.js", "build/runtime.js": "/build/runtime.js", "build/vendors~app.js": "/build/vendors~app.js" } Dokumentacija: https://www.npmjs.com/package/axios --- assets/js/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/js/app.js b/assets/js/app.js index 32a9b5e7b..897bba512 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -17,3 +17,10 @@ $(document).ready(function() { }); const axios = require('axios'); +axios.get('/build/manifest.json') + .then(function(response) { + console.log(response.data); + }) + .catch(function (error) { + console.error(error); + }); From bc78d6f807d495e8cb5fc265a232296d27bb0f96 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Wed, 11 Apr 2018 23:49:56 +0300 Subject: [PATCH 09/20] Atvaizduojame duomenis puslapyje MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pradedame nuo "...", nes užsikrauna ne iš karto, kad naudotoja matytų, jog pasikeis. Kodo generavimu paleisti per scripts/frontend.sh yarn watch Rezultatas matysis atsidarius pusplaį: http://127.0.0.1:8000/people Patikrinimui pabandykite (manifest.json reikšmė pasikeis): yarn dev yarn build Dokumentacija: https://www.w3schools.com/jsref/prop_html_innerhtml.asp https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById https://developer.mozilla.org/en-US/docs/Web/API/Node/innerText https://symfony.com/doc/current/frontend/encore/versioning.html https://yarnpkg.com/lang/en/docs/cli/run/ --- assets/js/app.js | 5 +++-- templates/people/index.html.twig | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 897bba512..e733368e2 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -17,10 +17,11 @@ $(document).ready(function() { }); const axios = require('axios'); +let versionedFileElement = document.getElementById('versionedFile'); axios.get('/build/manifest.json') .then(function(response) { - console.log(response.data); + versionedFileElement.innerText = response.data['build/app.js']; }) .catch(function (error) { - console.error(error); + versionedFileElement.innerText = 'Error: ' . error; }); diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index c5739b1a5..c47f17545 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -5,4 +5,7 @@ {% block body %}
Loading...
+
+ Versijuojamas JavaScript failas: ... +
{% endblock %} From 0c8b3b8ccf60b271fdb4d3d2c9854f7fd672e961 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:03:03 +0300 Subject: [PATCH 10/20] =?UTF-8?q?Perduokime=20duomenis=20i=C5=A1=20Twig'o?= =?UTF-8?q?=20=C4=AF=20JavaScript'=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problema: naudojame React ir axious kodą tik People puslapyje, bet JavaScript įkraunamas visur. Taigi Pagrindiniame puslapyje Console'je metamos klaidos. Sprendimas: įterpti JavaScript dalį, kuri būtų virš. Naudojami globalūs JavaScript kintamieji ("var", bet ne "let") Gerosios praktikos: naudoti data-... parametrus Geresnis sprendimas: patikrinti ar elementas egzistuoja Kodas sukeneruotas per scripts/frontend.sh yarn watch Patikrinimui, ar veikia: Tiek pagrindiniame, tiek /people puslapyje Naršyklės Console nerodo klaidos Dokumentacija: https://symfony.com/doc/current/frontend/encore/server-data.html https://www.w3schools.com/js/js_datatypes.asp --- assets/js/app.js | 18 ++++++++++-------- assets/js/react.jsx | 10 ++++++---- templates/people/index.html.twig | 8 ++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index e733368e2..f0bafb1df 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -17,11 +17,13 @@ $(document).ready(function() { }); const axios = require('axios'); -let versionedFileElement = document.getElementById('versionedFile'); -axios.get('/build/manifest.json') - .then(function(response) { - versionedFileElement.innerText = response.data['build/app.js']; - }) - .catch(function (error) { - versionedFileElement.innerText = 'Error: ' . error; - }); +if (typeof usingVersionedFileJs !== "undefined") { + let versionedFileElement = document.getElementById('versionedFile'); + axios.get('/build/manifest.json') + .then(function (response) { + versionedFileElement.innerText = response.data['build/app.js']; + }) + .catch(function (error) { + versionedFileElement.innerText = 'Error: '.error; + }); +} diff --git a/assets/js/react.jsx b/assets/js/react.jsx index 24b8859c1..15267e86d 100644 --- a/assets/js/react.jsx +++ b/assets/js/react.jsx @@ -1,7 +1,9 @@ const React = require('react'); const ReactDOM = require('react-dom'); -ReactDOM.render( -

Hello, world!

, - document.getElementById('root') -); +if (typeof usingReactApp !== "undefined") { + ReactDOM.render( +

Hello, world!

, + document.getElementById('root') + ); +} diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index c47f17545..1bf98c380 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -9,3 +9,11 @@ Versijuojamas JavaScript failas: ... {% endblock %} + +{% block javascripts %} + + {{ parent() }} +{% endblock %} From d0288b0bec8e0bd084d5ace635dcc219805fe6d2 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:15:19 +0300 Subject: [PATCH 11/20] =?UTF-8?q?Prisimename=20navigacij=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nes jau sunku per puslapius vaikščioti. Patrikrinimui (viršuje turėtų būti navigacijos juosta): http://127.0.0.1:8000/people http://127.0.0.1:8000/ Gali prireikti per scripts/backend.sh bin/console cache:clear Dokumentacija: https://symfony.com/doc/current/reference/twig_reference.html https://twig.symfony.com/doc/2.x/tags/extends.html https://getbootstrap.com/docs/4.3/components/navbar/ --- templates/base.html.twig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/base.html.twig b/templates/base.html.twig index e06313d52..cfd34354b 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -10,6 +10,18 @@ {% endblock %} + {% block body %}{% endblock %} {% block javascripts %} {{ encore_entry_script_tags('app') }} From 6d7da6765f99061f971fb4702f910684a2d27564 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:23:32 +0300 Subject: [PATCH 12/20] =?UTF-8?q?Pridedame=20atskir=C4=85=20JavaScript=20f?= =?UTF-8?q?ail=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kuris bus naudojamas tik viename puslapyje Nes jau nebereikia mokintis parametrų perdavimo. Priminimui: CSS failai yra įtraukiami iškviečiant require('../css/app.scss') ar pan. Kodas sugeneruojamas per scripts/frontend.sh yarn watch Patikrinimui, žiūrėti sugeneruotą: public/build/validation.js (Gali tekti iš naujo paleisti "yarn watch") Dokumentacija: https://symfony.com/doc/current/frontend/encore/shared-entry.html https://symfony.com/doc/current/frontend/encore/split-chunks.html --- assets/js/validation.js | 1 + webpack.config.js | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 assets/js/validation.js diff --git a/assets/js/validation.js b/assets/js/validation.js new file mode 100644 index 000000000..a5d95686a --- /dev/null +++ b/assets/js/validation.js @@ -0,0 +1 @@ +// Here will be validation in Frontend diff --git a/webpack.config.js b/webpack.config.js index 0ae15dc06..bc33ef528 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -27,6 +27,9 @@ Encore './assets/js/app.js', './assets/js/react.jsx' ]) + .addEntry('validation', + './assets/js/validation.js' + ) //.addEntry('page1', './assets/js/page1.js') //.addEntry('page2', './assets/js/page2.js') From 488b744a8a32cb08ffe4148b1c5ef03098e8f75d Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:34:28 +0300 Subject: [PATCH 13/20] =?UTF-8?q?Paprastas=20JavaScript=20reaguojantis=20?= =?UTF-8?q?=C4=AF=20=C4=AFvest=C4=85=20laukel=C4=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pridedame validacijos failą tik People puslapyje. Kodo sugeneruojamas (nukopijuojamas į build katalogą) node konteineryje: yarn watch Lyginant su senesnėmis Symfony/Encore versijomis buvo naudojama asset komanda, kurią dabar pakeičia gudresnė encore_entry_script_tags. Patikrinimui, ar veikia: http://127.0.0.1:8000/people keičiant teksta su klaviatūra, turi šalia rodyti --- assets/js/validation.js | 9 ++++++++- templates/people/index.html.twig | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/js/validation.js b/assets/js/validation.js index a5d95686a..7538ea218 100644 --- a/assets/js/validation.js +++ b/assets/js/validation.js @@ -1 +1,8 @@ -// Here will be validation in Frontend +let name = document.getElementById('name'); +let validationResult = document.getElementById('validation-result'); +const validateName = function () { + validationResult.innerText = 'Įrašėte: ' + name.value; +}; + +name.onkeyup = validateName; +name.onchange = validateName; diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index 1bf98c380..7b014b6d6 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -8,6 +8,8 @@
Versijuojamas JavaScript failas: ...
+ + {% endblock %} {% block javascripts %} @@ -15,5 +17,6 @@ var usingVersionedFileJs = true; var usingReactApp = true; + {{ encore_entry_script_tags('validation') }} {{ parent() }} {% endblock %} From 2026641e8abda2011e40ede07397fab0b5195911 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:48:54 +0300 Subject: [PATCH 14/20] =?UTF-8?q?Pasidarome=20prieig=C4=85=20AJAX=20u?= =?UTF-8?q?=C5=BEklausoms=20(sud=C4=97tingesnis=20tak=C5=B3=20pavyzdys)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Symfony turi galingą takų (angl. route) sistemą, tai galima perduoti argumentus užklausoje, kaip argumentus į funkciją. Pasidarome apribojimą, kad būtų galima kviesti tik per POST metodą. Vis dar nėra kaip pilnai ištestuoti. Galima tik patikrinti per scripts/backend.sh bin/console debug:router bin/console debug:router validatePerson Arba iš Linux: curl -X POST http://127.0.0.1:8000/validate/name curl -X POST http://127.0.0.1:8000/validate/labas Dokumentacija: https://symfony.com/doc/current/routing.html https://symfony.com/doc/current/routing.html#matching-http-methods --- README.md | 2 +- src/Controller/PeopleController.php | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3411980e9..1cb9ae129 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Plačiau žr. [MySql GUI dokumentacijoje](https://github.com/nfqakademija/docker * **Kaip pasileisti xDebug?** Trumpai: `./scripts/backend.sh /enable_xdebug.sh ` -Plačiau žr. [xDebug dokumentacijoje](https://github.com/nfqakademija/docker/blob/master/docs/setup-xdebug.md) +Plačiau žr. [xDebug dokumentacijoje](https://github.com/nfqakadmija/docker/blob/master/docs/setup-xdebug.md) * **Turių daugiau techninių klausimų?** Google ir StackOverflow yra geriausi tavo draugai. diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index c85b90746..1b7f0d52f 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -2,7 +2,10 @@ namespace App\Controller; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class PeopleController extends AbstractController @@ -16,4 +19,21 @@ public function index() 'controller_name' => 'PeopleController', ]); } + + /** + * @Route( + * "/validate/{element}", + * name="validatePerson", + * methods={"POST"} + * ) + */ + public function validate(string $element) + { + switch ($element) { + case 'name': + return new JsonResponse(['valid' => true]); + } + + return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST); + } } From bb86ad6f4c39208aed62fd58b91ba3d530329d32 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 00:50:32 +0300 Subject: [PATCH 15/20] =?UTF-8?q?Perduodame=20adres=C4=85=20=C4=AF=20JavaS?= =?UTF-8?q?cript'=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Path irgi gali priimti parametrus Javascript pergeneravimui iš scripts/frontend.sh yarn watch Patirkinimui: http://127.0.0.1:8000/people keičiant tekstą, rodo: "Validuosiu su: /validate/name" Dokumentacija: https://symfony.com/doc/current/frontend/encore/server-data.html https://symfony.com/doc/current/routing/generate_url_javascript.html --- assets/js/validation.js | 2 +- templates/people/index.html.twig | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/js/validation.js b/assets/js/validation.js index 7538ea218..1a37c632d 100644 --- a/assets/js/validation.js +++ b/assets/js/validation.js @@ -1,7 +1,7 @@ let name = document.getElementById('name'); let validationResult = document.getElementById('validation-result'); const validateName = function () { - validationResult.innerText = 'Įrašėte: ' + name.value; + validationResult.innerText = 'Validuosiu su: ' + validationResult.dataset.path; }; name.onkeyup = validateName; diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index 7b014b6d6..cd18cf87f 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -9,7 +9,8 @@ Versijuojamas JavaScript failas: ... - + + {% endblock %} {% block javascripts %} From 9f3814085aca920910d3fe7490a3dde2d12f04d7 Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 01:01:39 +0300 Subject: [PATCH 16/20] =?UTF-8?q?Si=C5=B3n=C4=8Diame=20AJAX=20u=C5=BEklaus?= =?UTF-8?q?=C4=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keičiant laukelio turinį, grąžina ":)" Rankomis galima pasibandyti pakeisti, ar pagauna ir klaidas. Bet jau turime sujungtą Frontend'ą su Backend'u. Dokumentacija: https://www.npmjs.com/package/axios --- assets/js/validation.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/assets/js/validation.js b/assets/js/validation.js index 1a37c632d..1881c8a67 100644 --- a/assets/js/validation.js +++ b/assets/js/validation.js @@ -1,7 +1,20 @@ +const axios = require('axios'); + let name = document.getElementById('name'); let validationResult = document.getElementById('validation-result'); const validateName = function () { - validationResult.innerText = 'Validuosiu su: ' + validationResult.dataset.path; + validationResult.innerText = '...'; + axios.post(validationResult.dataset.path, {input: name.value}) + .then(function(response) { + if (response.data.valid) { + validationResult.innerHTML = ":)"; + } else { + validationResult.innerHTML = ":("; + } + }) + .catch(function (error) { + validationResult.innerText = 'Error: ' + error; + }); }; name.onkeyup = validateName; From 923ca9d4cadbc61ca3a5e9ee2b669862e101128f Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 01:18:14 +0300 Subject: [PATCH 17/20] =?UTF-8?q?Pasiruo=C5=A1iame=20testinius=20duomenis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Nesinori parodyti spendimo pirmam namų darbui, tai dėl paprastumo tiesiog įdedama į PHP failą. --- src/Controller/PeopleController.php | 199 +++++++++++++++++++++++++++- 1 file changed, 198 insertions(+), 1 deletion(-) diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index 1b7f0d52f..fa16da82d 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -2,7 +2,6 @@ namespace App\Controller; -use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; @@ -36,4 +35,202 @@ public function validate(string $element) return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST); } + + private function getStorage() + { + return /** @lang json */ + '{ + "team1": { + "name": "Team1", + "mentors": [ + "Mantas" + ], + "students": [ + "Tadas", + "Gytis", + "Ričardas" + ] + }, + "baltichalatai": { + "name": "BaltiChalatai", + "mentors": [ + "Lukas" + ], + "students": [ + "Vytas", + "Lukas", + "Diana" + ] + }, + "nnizer": { + "name": "ePacientas", + "mentors": [ + "Tadas" + ], + "students": [ + "Kornelijus", + "Dominykas", + "Miglė" + ] + }, + "activegen": { + "name": "ActiveGen", + "mentors": [ + "Arnoldas" + ], + "students": [ + "Andrius", + "Nojus", + "Martynas", + "Edvinas" + ] + }, + "mms": { + "name": "Membership-management-system", + "mentors": [ + "Mindaugas" + ], + "students": [ + "Erika", + "Rokas", + "Valentinas", + "Eligijus" + ] + }, + "pamainos": { + "name": "NFQ pamainu sistema", + "mentors": [ + "Paulius" + ], + "students": [ + "Liudas", + "Justina", + "Andrius" + ] + }, + "receptai": { + "name": "Receptai", + "mentors": [ + "Mantas" + ], + "students": [ + "Arnoldas", + "Arentas", + "Tautvydas" + ] + }, + "pulse": { + "name": "NFQ pulse", + "mentors": [ + "Lorenas" + ], + "students": [ + "Arvydas", + "Titas", + "Kristijonas", + "Andrius" + ] + }, + "lita": { + "name": "NFQ Petro atrankos problema akademijai", + "mentors": [ + "Paulius" + ], + "students": [ + "Kristina", + "Indrė", + "Dmitri" + ] + }, + "myfleet": { + "name": "MyFleet", + "mentors": [ + "Laurynas" + ], + "students": [ + "Artūras", + "Ignas", + "Jonas" + ] + }, + "career": { + "name": "NFQ Career Criteria Assessment", + "mentors": [ + "Erikas" + ], + "students": [ + "Matas", + "Andrius", + "Ainis" + ] + }, + "carparking": { + "name": "NFQ Car parking", + "mentors": [ + "Andrejus" + ], + "students": [ + "Kęstas", + "Lukas", + "Lukas" + ] + }, + "podcast": { + "name": "Krepšinio podcastai", + "mentors": [ + "Eligijus" + ], + "students": [ + "Edvardas", + "Nerijus", + "Kazimieras" + ] + }, + "Barakas": { + "name": "barakas", + "mentors": [ + "Armandas" + ], + "students": [ + "Raimondas", + "Mantas", + "Tomas" + ] + }, + "devcollab": { + "name": "Education sharing platform", + "mentors": [ + "Viktoras" + ], + "students": [ + "Karolis", + "Arnas", + "Evaldas", + "Algirdas" + ] + }, + "hacker\'is po .mySubdomain &project=123": { + "name": "\' OR 1 -- DROP DATABASE", + "mentors": [ + "Ponas Programišius" + ], + "students": [ + "Aurelijus", + "Ir jo \"geras\" draug\'as" + ] + } + }'; + } + + private function getStudents(): array + { + $students = []; + $storage = json_decode($this->getStorage(), true); + foreach ($storage as $teamData) { + foreach ($teamData['students'] as $student) { + $students[] = $student; + } + } + return $students; + } } From 96cb2785b679a97d5cdede9afebc500d446d3c8a Mon Sep 17 00:00:00 2001 From: Aurelijus Banelis Date: Thu, 12 Apr 2018 01:34:22 +0300 Subject: [PATCH 18/20] =?UTF-8?q?Turime=20veikian=C4=8Di=C4=85=20AJAX=20va?= =?UTF-8?q?lidacij=C4=85=20(teisingos=20reik=C5=A1m=C4=97s=20patikrinim?= =?UTF-8?q?=C4=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patikrinimui: Įvesti egzistuojantį vardą (pvz. Lukas) ir bus matoma laiminga šypsenėlė ":)" Bandome apsisaugoti nuo netinkamų laukų pavadinimų. JavaScript pergeneravimui per scripts/frontend.sh yarn watch Dokumentacija: https://symfony.com/doc/current/create_framework/http_kernel_controller_resolver.html --- src/Controller/PeopleController.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index fa16da82d..bb86b5f8e 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -2,8 +2,10 @@ namespace App\Controller; +use Exception; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; @@ -26,11 +28,18 @@ public function index() * methods={"POST"} * ) */ - public function validate(string $element) + public function validate(Request $request, string $element) { + try { + $input = json_decode($request->getContent(), true)['input']; + } catch (Exception $e) { + return new JsonResponse(['error' => 'Invalid method'], Response::HTTP_BAD_REQUEST); + } + + $students = $this->getStudents(); switch ($element) { case 'name': - return new JsonResponse(['valid' => true]); + return new JsonResponse(['valid' => in_array(strtolower($input), $students)]); } return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST); @@ -228,7 +237,7 @@ private function getStudents(): array $storage = json_decode($this->getStorage(), true); foreach ($storage as $teamData) { foreach ($teamData['students'] as $student) { - $students[] = $student; + $students[] = strtolower($student); } } return $students; From e02e0cf0ff9be75f307465f907963db60998b3b6 Mon Sep 17 00:00:00 2001 From: Erika Radziulyte Date: Thu, 21 Nov 2019 19:42:19 +0200 Subject: [PATCH 19/20] Symfony Homework Part 2 --- assets/js/validation.js | 26 ++++++++++++++++---------- src/Controller/PeopleController.php | 22 ++++++++++++++-------- templates/people/index.html.twig | 10 +++++++--- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/assets/js/validation.js b/assets/js/validation.js index 1881c8a67..126f82db2 100644 --- a/assets/js/validation.js +++ b/assets/js/validation.js @@ -1,21 +1,27 @@ const axios = require('axios'); -let name = document.getElementById('name'); -let validationResult = document.getElementById('validation-result'); -const validateName = function () { - validationResult.innerText = '...'; - axios.post(validationResult.dataset.path, {input: name.value}) +const validateType = (validate, type) => { + validate.innerText = '...'; + axios.post(validate.dataset.path, {input: type.value}) .then(function(response) { if (response.data.valid) { - validationResult.innerHTML = ":)"; + validate.innerHTML = ":)"; } else { - validationResult.innerHTML = ":("; + validate.innerHTML = ":("; } }) .catch(function (error) { - validationResult.innerText = 'Error: ' + error; + validate.innerText = 'Error: ' + error; }); }; -name.onkeyup = validateName; -name.onchange = validateName; +let name = document.getElementById('name'); +let validateName= document.getElementById('validation-result-name'); +name.onkeyup = () => validateType(validateName, name); +name.onchange = () => validateType(validateName, name); + + +let team = document.getElementById('team'); +let validateTeam = document.getElementById('validation-result-team'); +team.onkeyup = () => validateType(validateTeam, team); +team.onchange = () => validateType(validateTeam, team); \ No newline at end of file diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index bb86b5f8e..d51eac438 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -1,7 +1,5 @@ 'PeopleController', ]); } - /** * @Route( * "/validate/{element}", @@ -35,20 +32,21 @@ public function validate(Request $request, string $element) } catch (Exception $e) { return new JsonResponse(['error' => 'Invalid method'], Response::HTTP_BAD_REQUEST); } - $students = $this->getStudents(); + $teams = $this->getTeams(); switch ($element) { case 'name': return new JsonResponse(['valid' => in_array(strtolower($input), $students)]); + case 'team': + return new JsonResponse(['valid' => in_array(strtolower($input), $teams)]); } - return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST); } private function getStorage() { return /** @lang json */ - '{ + '{ "team1": { "name": "Team1", "mentors": [ @@ -230,7 +228,6 @@ private function getStorage() } }'; } - private function getStudents(): array { $students = []; @@ -242,4 +239,13 @@ private function getStudents(): array } return $students; } -} + private function getTeams(): array + { + $teams = []; + $storage = json_decode($this->getStorage(), true); + foreach ($storage as $teamData => $teamInfo) { + $teams[] = $teamData; + } + return $teams; + } +} \ No newline at end of file diff --git a/templates/people/index.html.twig b/templates/people/index.html.twig index cd18cf87f..71deb4ce6 100644 --- a/templates/people/index.html.twig +++ b/templates/people/index.html.twig @@ -8,9 +8,13 @@
Versijuojamas JavaScript failas: ...
- + Vardas: - + +
+ Komanda: + + {% endblock %} {% block javascripts %} @@ -20,4 +24,4 @@ {{ encore_entry_script_tags('validation') }} {{ parent() }} -{% endblock %} +{% endblock %} \ No newline at end of file From fb15c1a01cee57d6dddacb2157dc4ee3ce1bb19f Mon Sep 17 00:00:00 2001 From: Erika Radziulyte Date: Thu, 21 Nov 2019 19:58:41 +0200 Subject: [PATCH 20/20] added blank line after namespace --- src/Controller/PeopleController.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Controller/PeopleController.php b/src/Controller/PeopleController.php index d51eac438..50b0d1546 100644 --- a/src/Controller/PeopleController.php +++ b/src/Controller/PeopleController.php @@ -1,5 +1,7 @@ 'PeopleController', ]); } + /** * @Route( * "/validate/{element}", @@ -25,6 +28,7 @@ public function index() * methods={"POST"} * ) */ + public function validate(Request $request, string $element) { try { @@ -228,6 +232,7 @@ private function getStorage() } }'; } + private function getStudents(): array { $students = []; @@ -239,6 +244,7 @@ private function getStudents(): array } return $students; } + private function getTeams(): array { $teams = []; @@ -248,4 +254,4 @@ private function getTeams(): array } return $teams; } -} \ No newline at end of file +}