Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
67bc07a
Done.
diana-v Nov 17, 2019
2d0a210
Code style fixes.
diana-v Nov 17, 2019
cc9effe
Solving conflicts
aurelijusb Dec 14, 2019
21f42c3
Merge branch 'homework-2019-11-14' into diana-sf2-hw
aurelijusb Dec 14, 2019
3380cbb
Merge branch 'homework-2019-11-14' into diana-sf2-hw
aurelijusb Dec 15, 2019
dc572bf
Merge branch 'homework-2019-11-14' into diana-sf2-hw
aurelijusb Dec 15, 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
4 changes: 4 additions & 0 deletions 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
45 changes: 37 additions & 8 deletions assets/js/validation.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
const axios = require('axios');

let name = document.getElementById('name');
let validationResult = document.getElementById('validation-result');
let team = document.getElementById('team');
let validateNameResult = document.getElementById('validation-result-name');
let validateTeamResult = document.getElementById('validation-result-team');
const validateName = function () {
validationResult.innerText = '...';
axios.post(validationResult.dataset.path, {input: name.value})
validateNameResult.innerText = '...';
axios.post(validateNameResult.dataset.path, {input: name.value})
.then(function(response) {
if (response.data.valid) {
validationResult.innerHTML = ":)";
validateNameResult.innerHTML = ":)";
} else {
validationResult.innerHTML = ":(";
validateNameResult.innerHTML = ":(";
}
})
.catch(function (error) {
validationResult.innerText = 'Error: ' + error;
validateNameResult.innerText = 'Error: ' + error;
});
};
const validateTeam = function () {
validateTeamResult.innerText = '...';
axios.post(validateTeamResult.dataset.path, {input: name.value, input2: team.value})
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per paskaitą lig minėjau, kad jie neturi būti priklausomi.

Tada kodas būtų daug paprastesnis.

.then(function(response) {
if (response.data.valid) {
validateTeamResult.innerHTML = ":)";
} else {
validateTeamResult.innerHTML = ":(";
}
})
.catch(function (error) {
validateTeamResult.innerText = 'Error: ' + error;
});
};

name.onkeyup = () => {pleaseWork([validateName, validateTeam])};
name.onchange = () => {pleaseWork([validateName, validateTeam])};
team.onkeyup = () => {pleaseWork([validateTeam])};
team.onchange = () => {pleaseWork([validateTeam])};

name.onkeyup = validateName;
name.onchange = validateName;
var timeout;
function pleaseWork (funcs) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kažkas čia ne į tą pausę.

Namų darbų įvykdymui nereikėjo jokių focus arba timeout

clearTimeout(timeout);
executor = (funcs) => {
for (var i=0; i<funcs.length; i-=-1) {
funcs[i]()
}
}
timeout = setTimeout(()=>{executor(funcs)} , 200)
}
46 changes: 34 additions & 12 deletions src/Controller/PeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

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

/**
* @Route(
* "/validate/{element}",
* name="validatePerson",
* methods={"POST"}
* )
*/
/**
* @Route(
* "/validate/{element}",
* name="validatePerson",
* methods={"POST"}
* )
*/
public function validate(Request $request, string $element)
{
try {
Expand All @@ -40,14 +40,23 @@ public function validate(Request $request, string $element)
switch ($element) {
case 'name':
return new JsonResponse(['valid' => in_array(strtolower($input), $students)]);
case 'team':
$studentTeam = $this->getStudentTeam($input);
$input2 = json_decode($request->getContent(), true)['input2'];
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Geriau būtų šitą vietą iškelti į viršų

$isValidTeam = false;
if ($input) {
$isValidTeam = (strtolower($input2) === $studentTeam);
}
return new JsonResponse(['valid' => $isValidTeam]);
}

return new JsonResponse(['error' => 'Invalid arguments'], Response::HTTP_BAD_REQUEST);
}

private function getStorage()
{
return /** @lang json */
return
/** @lang json */
'{
"team1": {
"name": "Team1",
Expand Down Expand Up @@ -242,4 +251,17 @@ private function getStudents(): array
}
return $students;
}

private function getStudentTeam(string $student_name)
{
$storage = json_decode($this->getStorage(), true);
foreach ($storage as $teamData) {
foreach ($teamData['students'] as $student) {
if (strtolower($student_name) == strtolower($student)) {
return strtolower($teamData['name']);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atidumo. Pavyzdys buvo ne toks
image

}
}
}
return null;
}
}
5 changes: 4 additions & 1 deletion templates/people/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
</div>

<input type="text" id="name"/>
<span id="validation-result" data-path="{{ path('validatePerson', {'element': 'name'}) }}"></span>
<span id="validation-result-name" data-path="{{ path('validatePerson', {'element': 'name'}) }}"></span>
<br>
<input type="text" id="team"/>
<span id="validation-result-team" data-path="{{ path('validatePerson', {'element': 'team'}) }}"></span>
{% endblock %}

{% block javascripts %}
Expand Down