-
Notifications
You must be signed in to change notification settings - Fork 34
Diana sf2 hw #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: homework-2019-11-14
Are you sure you want to change the base?
Diana sf2 hw #308
Changes from all commits
08b9cce
02d2606
c70edb7
8d99df9
6824312
6f02df3
b395b70
f1cff08
bc78d6f
0c8b3b8
d0288b0
6d7da67
488b744
2026641
bb86ad6
9f38140
923ca9d
96cb278
67bc07a
2d0a210
cc9effe
21f42c3
3380cbb
dc572bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}) | ||
| .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) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kažkas čia ne į tą pausę. Namų darbų įvykdymui nereikėjo jokių |
||
| clearTimeout(timeout); | ||
| executor = (funcs) => { | ||
| for (var i=0; i<funcs.length; i-=-1) { | ||
| funcs[i]() | ||
| } | ||
| } | ||
| timeout = setTimeout(()=>{executor(funcs)} , 200) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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']; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
|
@@ -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']); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||

There was a problem hiding this comment.
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.