From edff54f591ad7034e324ba2c2aba3d6a8c852635 Mon Sep 17 00:00:00 2001 From: David Url Date: Tue, 14 Feb 2023 17:48:01 +0100 Subject: [PATCH] SHARE-539 Improve feedback for download project button --- assets/js/custom/Program.js | 26 +++++++++++++++++++ .../Controller/Project/ProgramController.php | 4 ++- templates/Program/program.html.twig | 12 +++++++-- ...program_download_disabled_button.html.twig | 18 +++++++++++++ .../project-details/project_download.feature | 4 ++- .../project_download_disabled.feature | 25 ++++++++++++++++++ translations/catroweb.en.yaml | 1 + 7 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 templates/Program/program_download_disabled_button.html.twig create mode 100644 tests/BehatFeatures/web/project-details/project_download_disabled.feature diff --git a/assets/js/custom/Program.js b/assets/js/custom/Program.js index 0393da5342..72ecad8603 100644 --- a/assets/js/custom/Program.js +++ b/assets/js/custom/Program.js @@ -45,6 +45,13 @@ export const Program = function (projectId, projectName, userRole, myProgram, st ) }) + $($('.js-btn-project-download-disabled').on('click', (e) => { + downloadDisabled( + $(e.currentTarget).data('redirect-url') + // $(e.currentTarget).data('alert-text') + ) + })) + $('.js-btn-project-apk-download').on('click', (e) => { download( $(e.currentTarget).data('path-url'), @@ -120,6 +127,25 @@ export const Program = function (projectId, projectName, userRole, myProgram, st }) } + function downloadDisabled (redirectUrl) { + /* Swal.fire({ + icon: 'error', + title: 'Login', + text: text, + customClass: { + confirmButton: 'btn btn-primary' + }, + buttonsStyling: false, + allowOutsideClick: false, + timer: 5000, + }).then((result) => { + if (result.value) { + window.location.replace(redirectUrl) + } + }); */ + window.location.replace(redirectUrl) + } + function resetDownloadButtonIcon (icon, spinner) { icon.classList.remove('d-none') icon.classList.add('d-inline-block') diff --git a/src/Application/Controller/Project/ProgramController.php b/src/Application/Controller/Project/ProgramController.php index 88ca0f93a1..03828a1689 100644 --- a/src/Application/Controller/Project/ProgramController.php +++ b/src/Application/Controller/Project/ProgramController.php @@ -89,6 +89,7 @@ public function projectAction(Request $request, string $id): Response $active_like_types = $this->program_manager->findProgramLikeTypes($project->getId()); $total_like_count = $this->program_manager->totalLikeCount($project->getId()); $program_comments = $this->findCommentsById($project->getId()); + $login_redirect = $this->generateUrl('login', [], UrlGeneratorInterface::ABSOLUTE_URL); foreach ($program_comments as $program_comment) { $program_comment->setNumberOfReplies($this->countByParentId($program_comment->getId())); @@ -101,6 +102,7 @@ public function projectAction(Request $request, string $id): Response return $this->render('Program/program.html.twig', [ 'program' => $project, + 'login_redirect' => $login_redirect, 'program_details' => $program_details, 'my_program' => $my_program, 'logged_in' => $logged_in, @@ -143,7 +145,7 @@ public function projectLikeAction(Request $request, string $id): Response $user = $this->getUser(); if (!$user) { if ($request->isXmlHttpRequest()) { - return new JsonResponse(['statusCode' => 601], Response::HTTP_UNAUTHORIZED); + return new JsonResponse(['statusCode' => 401], Response::HTTP_UNAUTHORIZED); } $request->getSession()->set('catroweb_login_redirect', $this->generateUrl( diff --git a/templates/Program/program.html.twig b/templates/Program/program.html.twig index 5c93b3b832..222affd8e1 100644 --- a/templates/Program/program.html.twig +++ b/templates/Program/program.html.twig @@ -83,7 +83,11 @@
- {% include 'Program/program_download_button.html.twig' %} + {% if logged_in %} + {% include 'Program/program_download_button.html.twig' %} + {% else %} + {% include 'Program/program_download_disabled_button.html.twig' %} + {% endif %} {% if not isIOS() %}
{% include 'Program/program_apk_generation_buttons.html.twig' %} @@ -110,7 +114,11 @@
- {% include 'Program/program_download_button.html.twig' with {'suffix': '-small'} %} + {% if logged_in %} + {% include 'Program/program_download_button.html.twig' with {'suffix': '-small'} %} + {% else %} + {% include 'Program/program_download_disabled_button.html.twig' with {'suffix': '-small'} %} + {% endif %}
diff --git a/templates/Program/program_download_disabled_button.html.twig b/templates/Program/program_download_disabled_button.html.twig new file mode 100644 index 0000000000..5660a8a5de --- /dev/null +++ b/templates/Program/program_download_disabled_button.html.twig @@ -0,0 +1,18 @@ + diff --git a/tests/BehatFeatures/web/project-details/project_download.feature b/tests/BehatFeatures/web/project-details/project_download.feature index 58c1d65fcc..36793655a4 100644 --- a/tests/BehatFeatures/web/project-details/project_download.feature +++ b/tests/BehatFeatures/web/project-details/project_download.feature @@ -5,13 +5,15 @@ Feature: As a visitor I want to be able to download projects Given there are users: | id | name | | 1 | Catrobat | + | 2 | User | And there are projects: | id | name | downloads | owned by | apk_ready | | 1 | project 1 | 5 | Catrobat | true | | 2 | project 2 | 5 | Catrobat | true | Scenario: I want to download a project via the button - When I am on "/app/project/1" + Given I log in as "Catrobat" + And I am on "/app/project/1" And I wait for the page to be loaded Then the element "#projectDownloadButton-small" should be visible And I click "#projectDownloadButton-small" diff --git a/tests/BehatFeatures/web/project-details/project_download_disabled.feature b/tests/BehatFeatures/web/project-details/project_download_disabled.feature new file mode 100644 index 0000000000..7cddad5a02 --- /dev/null +++ b/tests/BehatFeatures/web/project-details/project_download_disabled.feature @@ -0,0 +1,25 @@ +@web @project_page +Feature: As a visitor I need to login to be able to download projects + + Background: + Given there are users: + | id | name | + | 1 | Catrobat | + And there are projects: + | id | name | downloads | owned by | apk_ready | + | 1 | project 1 | 5 | Catrobat | true | + | 2 | project 2 | 5 | Catrobat | true | + +Scenario: I want to download a project via the button + When I am on "/app/project/1" + And I wait for the page to be loaded + Then the element "#projectDownloadDisabledButton-small" should be visible + And I click "#projectDownloadDisabledButton-small" + Then I am on "/app/login" + And I wait for the page to be loaded + And I fill in "_username" with "Catrobat" + And I fill in "_password" with "123456" + Then I press "Login" + And I wait for the page to be loaded + Then I should be logged in + And I am on "/app/project/1" \ No newline at end of file diff --git a/translations/catroweb.en.yaml b/translations/catroweb.en.yaml index 79c53c27d3..bb8f3c39cd 100644 --- a/translations/catroweb.en.yaml +++ b/translations/catroweb.en.yaml @@ -27,6 +27,7 @@ reportIt: Yes, report it! areYouSure: Are you sure? noWayOfReturn: There is no way to restore your actions! download: Download +downloadDisabledAlert: You must be logged in to download this project name: Name description: Description noDescription: No description available.