Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
08b9cce
Lecture notes
aurelijusbanelis Nov 13, 2019
02d2606
Pridedam React'ui reikalingas JavaScript bibliotekas
aurelijusbanelis Nov 13, 2019
c70edb7
Pajungiame, kad kompiliuotų React'o JSX failus
aurelijusbanelis Apr 11, 2018
8d99df9
Sukuriame Controller patogesniam testavimui
aurelijusbanelis Nov 13, 2019
6824312
Bandome React Hello world, bet neveikia
aurelijusbanelis Apr 11, 2018
6f02df3
Pataisome, kad veiktų React Hello world pavyzdys
aurelijusbanelis Apr 11, 2018
b395b70
Panaudokime kieno nors kito biblioteką
aurelijusbanelis Nov 13, 2019
f1cff08
Padarom AJAX užklausą naudojant axios biblioteką
aurelijusbanelis Apr 11, 2018
bc78d6f
Atvaizduojame duomenis puslapyje
aurelijusbanelis Apr 11, 2018
0c8b3b8
Perduokime duomenis iš Twig'o į JavaScript'ą
aurelijusbanelis Apr 11, 2018
d0288b0
Prisimename navigaciją
aurelijusbanelis Apr 11, 2018
6d7da67
Pridedame atskirą JavaScript failą
aurelijusbanelis Apr 11, 2018
488b744
Paprastas JavaScript reaguojantis į įvestą laukelį
aurelijusbanelis Apr 11, 2018
2026641
Pasidarome prieigą AJAX užklausoms (sudėtingesnis takų pavyzdys)
aurelijusbanelis Apr 11, 2018
bb86ad6
Perduodame adresą į JavaScript'ą
aurelijusbanelis Apr 11, 2018
9f38140
Siųnčiame AJAX užklausą
aurelijusbanelis Apr 11, 2018
923ca9d
Pasiruošiame testinius duomenis
aurelijusbanelis Apr 11, 2018
96cb278
Turime veikiančią AJAX validaciją (teisingos reikšmės patikrinimą)
aurelijusbanelis Apr 11, 2018
e02e0cf
Symfony Homework Part 2
erirad Nov 21, 2019
fb15c1a
added blank line after namespace
erirad Nov 21, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
============

Expand Down Expand Up @@ -119,7 +123,7 @@ Plačiau žr. [MySql GUI dokumentacijoje](https://github.com/nfqakademija/docker

* **Kaip pasileisti xDebug?**
Trumpai: `./scripts/backend.sh /enable_xdebug.sh <TAVO_KOMPO_IP_ADRESAS>`
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.
Expand Down
12 changes: 12 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ require('bootstrap');
$(document).ready(function() {
$('[data-toggle="popover"]').popover();
});

const axios = require('axios');
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;
});
}
9 changes: 9 additions & 0 deletions assets/js/react.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const React = require('react');
const ReactDOM = require('react-dom');

if (typeof usingReactApp !== "undefined") {
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
}
27 changes: 27 additions & 0 deletions assets/js/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const axios = require('axios');

const validateType = (validate, type) => {
validate.innerText = '...';
axios.post(validate.dataset.path, {input: type.value})
.then(function(response) {
if (response.data.valid) {
validate.innerHTML = ":)";
} else {
validate.innerHTML = ":(";
}
})
.catch(function (error) {
validate.innerText = 'Error: ' + error;
});
};

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);
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -17,5 +18,11 @@
"dev": "encore dev",
"watch": "encore dev --watch",
"build": "encore production --progress"
},
"dependencies": {
"axios": "^0.19.0",
"prop-types": "^15.7.2",
"react": "^16.11.0",
"react-dom": "^16.11.0"
}
}
257 changes: 257 additions & 0 deletions src/Controller/PeopleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
<?php

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;

class PeopleController extends AbstractController
{
/**
* @Route("/people", name="people")
*/
public function index()
{
return $this->render('people/index.html.twig', [
'controller_name' => 'PeopleController',
]);
}

/**
* @Route(
* "/validate/{element}",
* name="validatePerson",
* methods={"POST"}
* )
*/

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();
$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": [
"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"
]
},
"hack<b>er</b>\'is po .mySubdomain &project=123": {
"name": "\' OR 1 -- DROP DATABASE",
"mentors": [
"<b>Ponas</b> Programišius"
],
"students": [
"Aurelijus",
"<b>Ir</b> 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[] = strtolower($student);
}
}
return $students;
}

private function getTeams(): array
{
$teams = [];
$storage = json_decode($this->getStorage(), true);
foreach ($storage as $teamData => $teamInfo) {
$teams[] = $teamData;
}
return $teams;
}
}
12 changes: 12 additions & 0 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
{% endblock %}
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{{ path('home') }}">Pagrindinis</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ path('people') }}">Žmonės</a>
</li>
</ul>
</div>
</nav>
{% block body %}{% endblock %}
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
Expand Down
27 changes: 27 additions & 0 deletions templates/people/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% extends 'base.html.twig' %}

{% block title %}Hello PeopleController!{% endblock %}

{% block body %}
<div id="root">Loading...</div>
<noscript>To use this app, enable JavaScript</noscript>
<div>
Versijuojamas JavaScript failas: <b id="versionedFile">...</b>
</div>
Vardas:
<input type="text" id="name"/>
<span id="validation-result-name" data-path="{{ path('validatePerson', {'element': 'name'}) }}"></span>
<br>
Komanda:
<input type="text" id="team"/>
<span id="validation-result-team" data-path="{{ path('validatePerson', {'element': 'team'}) }}"></span>
{% endblock %}

{% block javascripts %}
<script>
var usingVersionedFileJs = true;
var usingReactApp = true;
</script>
{{ encore_entry_script_tags('validation') }}
{{ parent() }}
{% endblock %}
Loading