Skip to content

Commit

Permalink
Merge pull request #908 from ga-devfront/feat/add-page-params
Browse files Browse the repository at this point in the history
Feat: new UI add page params
  • Loading branch information
Quetzacoalt91 authored Sep 27, 2024
2 parents 8eb4787 + 408730c commit 171b40d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 42 deletions.
9 changes: 7 additions & 2 deletions controllers/admin/AdminSelfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,13 @@ public function initContent()
$request = Request::createFromGlobals();
$this->addNewUIAssets($request);

// TODO: In the future, the router will return an object instead of a string depending on controller called.
$this->content = (new Router($this->upgradeContainer))->handle($request);
$response = (new Router($this->upgradeContainer))->handle($request);

if ($response instanceof \Symfony\Component\HttpFoundation\Response) {
$response->send();
exit;
}
$this->content = $response;

return parent::initContent();
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/admin/self-managed/AbstractPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace PrestaShop\Module\AutoUpgrade\Controller;

use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

abstract class AbstractPageController extends AbstractGlobalController
Expand Down Expand Up @@ -69,11 +70,11 @@ public function renderPage(string $page, array $params): string
/**
* @param Request $request
*
* @return string
* @return RedirectResponse|string
*
* @throws \Exception
*/
public function index(Request $request): string
public function index(Request $request)
{
return $this->renderPage(
$this::CURRENT_PAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ protected function getParams(Request $request): array

return array_merge(
$updateSteps->getStepParams($this::CURRENT_STEP),
[]
[
// TODO
'default_backup_files_and_database' => true,
'default_include_images' => false,
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ protected function getParams(Request $request): array

return array_merge(
$updateSteps->getStepParams($this::CURRENT_STEP),
[]
[
// TODO
'backlog_link' => 'https://myshop.com/my-backlog.txt',
]
);
}
}
9 changes: 9 additions & 0 deletions controllers/admin/self-managed/UpdatePageUpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

namespace PrestaShop\Module\AutoUpgrade\Controller;

use PrestaShop\Module\AutoUpgrade\Router\Router;
use PrestaShop\Module\AutoUpgrade\Twig\UpdateSteps;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
Expand All @@ -38,6 +40,13 @@ class UpdatePageUpdateController extends AbstractPageController
const CURRENT_STEP = UpdateSteps::STEP_UPDATE;
const CURRENT_PAGE = 'update';

public function index(Request $request): RedirectResponse
{
return new RedirectResponse(
str_replace(Router::UPDATE_PAGE_UPDATE, Router::UPDATE_PAGE_BACKUP, $request->getUri())
);
}

/**
* @param Request $request
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ protected function getParams(Request $request): array

return array_merge(
$updateSteps->getStepParams($this::CURRENT_STEP),
[]
[
// TODO
'default_deactive_non_native_modules' => true,
'default_regenerate_email_templates' => true,
'switch_the_theme' => '1',
'disable_all_overrides' => false,
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getParams(Request $request): array

if (!$isLastVersion) {
$updateType = VersionUtils::getUpdateType($this->getPsVersion(), $this->upgradeContainer->getUpgrader()->getDestinationVersion());
$releaseNote = VersionUtils::getUpdateType($this->getPsVersion(), $this->upgradeContainer->getUpgrader()->getOnlineDestinationRelease()->getReleaseNoteUrl());
$releaseNote = $this->upgradeContainer->getUpgrader()->getOnlineDestinationRelease()->getReleaseNoteUrl();
} else {
$updateType = null;
$releaseNote = null;
Expand All @@ -87,20 +87,25 @@ protected function getParams(Request $request): array
default:
$updateLabel = null;
}
$archiveRepository = $this->upgradeContainer->getLocalArchiveRepository();

return array_merge(
$updateSteps->getStepParams($this::CURRENT_STEP),
[
'upToDate' => $isLastVersion,
'noLocalArchive' => !$this->upgradeContainer->getLocalArchiveRepository()->hasLocalArchive(),
'assetsBasePath' => $this->upgradeContainer->getAssetsEnvironment()->getAssetsBaseUrl($request),
'currentPrestashopVersion' => $this->getPsVersion(),
'currentPhpVersion' => VersionUtils::getHumanReadableVersionOf(PHP_VERSION_ID),
'nextRelease' => [
'up_to_date' => $isLastVersion,
'no_local_archive' => !$this->upgradeContainer->getLocalArchiveRepository()->hasLocalArchive(),
'assets_base_path' => $this->upgradeContainer->getAssetsEnvironment()->getAssetsBaseUrl($request),
'current_prestashop_version' => $this->getPsVersion(),
'current_php_version' => VersionUtils::getHumanReadableVersionOf(PHP_VERSION_ID),
'local_archives' => [
'zip' => $archiveRepository->getZipLocalArchive(),
'xml' => $archiveRepository->getXmlLocalArchive(),
],
'next_release' => [
'version' => $this->upgradeContainer->getUpgrader()->getDestinationVersion(),
'badgeLabel' => $updateLabel,
'badgeStatus' => $updateType,
'releaseNote' => $releaseNote,
'badge_label' => $updateLabel,
'badge_status' => $updateType,
'release_note' => $releaseNote,
],
]
);
Expand Down
2 changes: 1 addition & 1 deletion storybook/stories/components/RadioCard.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Archive = {
checked: true,
title: "Local archive",
message:
"Save the archive file of the version you want to update to in the following directory: /admin/autoUpdate/download/",
"Save the archive file of the version you want to update to in the following directory: /admin/autoupgrade/download/",
disabled: false,
disabledMessage: "No backup file found on your store.",
badgeLabel: "",
Expand Down
4 changes: 2 additions & 2 deletions views/templates/steps/backup.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
BoolName: "PS_AUTOUP_BACKUP_FILES_DB",
BoolId: "PS_AUTOUP_BACKUP_FILES_DB",
val: true,
val: default_backup_files_and_database,
} %}

{% include "@ModuleAutoUpgrade/components/render-bool.html.twig" with {
Expand All @@ -40,7 +40,7 @@
},
BoolName: "PS_AUTOUP_BACKUP_WITH_IMAGES",
BoolId: "PS_AUTOUP_BACKUP_WITH_IMAGES",
val: false,
val: default_include_images,
} %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion views/templates/steps/post-update.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</div>

<div class="content__section">
<a class="link" href="#">
<a class="link" href="{{ backlog_link }}" download>
{{ 'Download update logs'|trans({}) }}
<i class="material-icons">file_upload</i>
</a>
Expand Down
8 changes: 4 additions & 4 deletions views/templates/steps/update-options.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
BoolName: "PS_AUTOUP_CUSTOM_MOD_DESACT",
BoolId: "PS_AUTOUP_CUSTOM_MOD_DESACT",
val: true
val: default_deactive_non_native_modules
} %}

{% include "@ModuleAutoUpgrade/components/render-bool.html.twig" with {
Expand All @@ -34,7 +34,7 @@
},
BoolName: "PS_AUTOUP_REGEN_EMAIL",
BoolId: "PS_AUTOUP_REGEN_EMAIL",
val: true
val: default_regenerate_email_templates
} %}

{% include "@ModuleAutoUpgrade/components/render-select.html.twig" with {
Expand All @@ -53,7 +53,7 @@
disabled: false
},
key: "PS_AUTOUP_SWITCH_THEME",
val: "1"
val: switch_the_theme
} %}

{% include "@ModuleAutoUpgrade/components/render-bool.html.twig" with {
Expand All @@ -69,7 +69,7 @@
},
BoolName: "PS_AUTOUP_DISABLE_OVERRIDE",
BoolId: "PS_AUTOUP_DISABLE_OVERRIDE",
val: false
val: disable_all_overrides
} %}
</div>
{% endblock %}
Expand Down
40 changes: 23 additions & 17 deletions views/templates/steps/version-choice.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@
{% endblock %}

{% block content %}
{% if upToDate %}
<div class="up-to-date {% if noLocalArchive %} up-to-date--no-archive {% endif %}">
{% if noLocalArchive %}
{% if up_to_date %}
<div class="up-to-date {% if no_local_archive %} up-to-date--no-archive {% endif %}">
{% if no_local_archive %}
<img class="up-to-date__img"
src="{{ assetsBasePath }}/img/up_to_date.svg"
src="{{ assets_base_path }}/img/up_to_date.svg"
width="243"
height="203"
alt=""
/>
{% endif %}

<p class="up-to-date__title text-success {% if noLocalArchive %} h2 {% else %} h3 {% endif %}">
<p class="up-to-date__title text-success {% if no_local_archive %} h2 {% else %} h3 {% endif %}">
<i class="material-icons">check_circle</i>
{{ 'You\'re up to date'|trans({}) }}
</p>

<p class="up-to-date__message">
{{ 'Current PrestaShop version:'|trans({}) }}
{{ currentPrestashopVersion }}
{{ current_prestashop_version }}
<br />
{{ 'Current PHP version:'|trans({}) }}
{{ currentPhpVersion }}
{{ current_php_version }}
</p>
</div>
{% if noLocalArchive %}
{% if no_local_archive %}
{% include "@ModuleAutoUpgrade/components/alert.html.twig" with {
message: "Unlock the local update feature and manually update your store to your preferred upgrade by saving the archive and XML files of the PrestaShop version in the following directory on your server: %pathToLocalArchive%"|trans({
'%pathToLocalArchive%': '<b>/admin/autoupgrade/download/</b>'
Expand Down Expand Up @@ -66,13 +66,13 @@

<p class="not-up-to-date__message">
{{ 'Current PrestaShop version:'|trans({}) }}
{{ currentPrestashopVersion }}
{{ current_prestashop_version }}
<br />
{{ 'Current PHP version:'|trans({}) }}
{{ currentPhpVersion }}
{{ current_php_version }}
</p>

{% if not noLocalArchive %}
{% if not no_local_archive %}
<p>
<strong>
{{ 'Select version:'|trans({}) }}
Expand All @@ -88,17 +88,19 @@
<div class="version-page__card-list">
{% include "@ModuleAutoUpgrade/components/radio-card.html.twig" with {
radioCardId: "",
radioName: "canal_choice",
radioValue: "online",
checked: true,
title: "PrestaShop %version%"|trans({'%version%': nextRelease.version}),
title: "PrestaShop %version%"|trans({'%version%': next_release.version}),
disabled: false,
badgeLabel: nextRelease.badgeLabel,
badgeStatus: nextRelease.badgeStatus,
releaseNote: nextRelease.releaseNote,
badgeLabel: next_release.badge_label,
badgeStatus: next_release.badge_status,
releaseNote: next_release.release_note,
archiveCard: false,
checkRequirements: false,
} %}

{% if noLocalArchive %}
{% if no_local_archive %}
{% include "@ModuleAutoUpgrade/components/alert.html.twig" with {
message: "Unlock the local update feature and manually update your store to your preferred upgrade by saving the archive and XML files of the PrestaShop version in the following directory on your server: %pathToLocalArchive%"|trans({
'%pathToLocalArchive%': '<b>/admin/autoupgrade/download/</b>'
Expand All @@ -110,14 +112,18 @@
{% else %}
{% include "@ModuleAutoUpgrade/components/radio-card.html.twig" with {
radioCardId: "",
radioName: "canal_choice",
radioValue: "local",
checked: false,
title: "Local archive"|trans({}),
message: "Save the archive file of the version you want to update to in the following directory: /admin/autoUpdate/download/",
message: "Save the archive file of the version you want to update to in the following directory: /admin/autoupgrade/download/",
disabled: false,
disabledMessage: "",
badgeLabel: "",
releaseNote: "",
archiveCard: true,
archiveFiles: local_archives.zip,
xmlFiles: local_archives.xml,
} %}
{% endif %}
</div>
Expand Down

0 comments on commit 171b40d

Please sign in to comment.