-
Notifications
You must be signed in to change notification settings - Fork 24
Feed the Symfony dashboard's Zone One hook with KPIs and a chart, add a settings page #63
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: dev
Are you sure you want to change the base?
Changes from all commits
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,12 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8" ?> | ||
| <module> | ||
| <name>dashactivity</name> | ||
| <displayName><![CDATA[Dashboard Activity]]></displayName> | ||
| <version><![CDATA[2.1.2]]></version> | ||
| <description><![CDATA[]]></description> | ||
| <author><![CDATA[PrestaShop]]></author> | ||
| <tab><![CDATA[dashboard]]></tab> | ||
| <is_configurable>0</is_configurable> | ||
| <need_instance>1</need_instance> | ||
| <limited_countries></limited_countries> | ||
| </module> | ||
| <name>dashactivity</name> | ||
| <displayName><![CDATA[Dashboard Activity]]></displayName> | ||
| <version><![CDATA[2.2.0]]></version> | ||
| <description><![CDATA[Check at a glance what is happening on your store with a list of KPIs on your dashboard.]]></description> | ||
| <author><![CDATA[PrestaShop]]></author> | ||
| <tab><![CDATA[administration]]></tab> | ||
| <is_configurable>0</is_configurable> | ||
| <need_instance>1</need_instance> | ||
| </module> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| dashactivity_configuration: | ||
| path: /dashactivity/configuration | ||
| methods: [GET, POST] | ||
| defaults: | ||
| _controller: PrestaShop\Module\DashActivity\Controller\ConfigurationController::indexAction | ||
| _legacy_controller: AdminDashactivityConfiguration | ||
| _legacy_link: AdminDashactivityConfiguration |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| services: | ||
| PrestaShop\Module\DashActivity\Controller\ConfigurationController: | ||
| public: true | ||
| autowire: true | ||
| autoconfigure: true | ||
|
|
||
| PrestaShop\Module\DashActivity\Type\ConfigurationType: | ||
| tags: ['form.type'] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\DashActivity\Controller; | ||
|
|
||
| use Configuration; | ||
| use PrestaShop\Module\DashActivity\Type\ConfigurationType; | ||
| use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| class ConfigurationController extends FrameworkBundleAdminController | ||
| { | ||
| private const FIELDS = [ | ||
| 'DASHACTIVITY_CART_ACTIVE', | ||
| 'DASHACTIVITY_VISITOR_ONLINE', | ||
| 'DASHACTIVITY_CART_ABANDONED_MIN', | ||
| 'DASHACTIVITY_CART_ABANDONED_MAX', | ||
| ]; | ||
|
|
||
| public function indexAction(Request $request): Response | ||
|
Contributor
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. No ACL check here. The admin firewall only requires #[AdminSecurity("is_granted('read', request.get('_legacy_controller'))")]
public function indexAction(Request $request): ResponseWorth guarding the write branch with |
||
| { | ||
| $data = []; | ||
| foreach (self::FIELDS as $field) { | ||
| $data[$field] = (int) Configuration::get($field); | ||
| } | ||
|
|
||
| $form = $this->createForm(ConfigurationType::class, $data); | ||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted() && $form->isValid()) { | ||
| foreach ($form->getData() as $field => $value) { | ||
| Configuration::updateValue($field, (int) $value); | ||
| } | ||
| $this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success')); | ||
|
|
||
| return $this->redirectToRoute('dashactivity_configuration'); | ||
| } | ||
|
|
||
| return $this->render('@Modules/dashactivity/views/templates/admin/configuration.html.twig', [ | ||
| 'configurationForm' => $form->createView(), | ||
| 'enableSidebar' => true, | ||
| 'help_link' => $this->generateSidebarLink('AdminDashactivityConfiguration'), | ||
| ]); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
| /** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
| * that is bundled with this package in the file LICENSE.md. | ||
| * It is also available through the world-wide-web at this URL: | ||
| * https://opensource.org/licenses/AFL-3.0 | ||
| * | ||
| * @author PrestaShop SA and Contributors <contact@prestashop.com> | ||
| * @copyright Since 2007 PrestaShop SA and Contributors | ||
| * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PrestaShop\Module\DashActivity\Type; | ||
|
|
||
| use Symfony\Component\Form\AbstractType; | ||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
| use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||
| use Symfony\Component\Form\FormBuilderInterface; | ||
| use Symfony\Component\OptionsResolver\OptionsResolver; | ||
| use Symfony\Component\Validator\Constraints\GreaterThan; | ||
| use Symfony\Component\Validator\Constraints\NotBlank; | ||
|
|
||
| /** | ||
| * Plain AbstractType: labels/help are translated via translation_domain, no need for | ||
| * TranslatorAwareType's translator/locales injection. | ||
| */ | ||
| class ConfigurationType extends AbstractType | ||
| { | ||
| private const DELAY_CHOICES = [15, 30, 45, 60, 90, 120]; | ||
|
|
||
| public function buildForm(FormBuilderInterface $builder, array $options): void | ||
| { | ||
| $delayChoices = array_combine(self::DELAY_CHOICES, self::DELAY_CHOICES); | ||
|
|
||
| $builder | ||
| ->add('DASHACTIVITY_CART_ACTIVE', ChoiceType::class, [ | ||
| 'label' => 'Active cart', | ||
| 'help' => 'How long (in minutes) a cart is to be considered as active after the last recorded change.', | ||
| 'choices' => $delayChoices, | ||
| ]) | ||
| ->add('DASHACTIVITY_VISITOR_ONLINE', ChoiceType::class, [ | ||
| 'label' => 'Online visitor', | ||
| 'help' => 'How long (in minutes) a visitor is to be considered as online after their last action.', | ||
| 'choices' => $delayChoices, | ||
| ]) | ||
| ->add('DASHACTIVITY_CART_ABANDONED_MIN', IntegerType::class, [ | ||
| 'label' => 'Abandoned cart (min)', | ||
| 'help' => 'How long (in hours) after the last action a cart is to be considered as abandoned.', | ||
| 'constraints' => [new NotBlank(), new GreaterThan(0)], | ||
| ]) | ||
| ->add('DASHACTIVITY_CART_ABANDONED_MAX', IntegerType::class, [ | ||
| 'label' => 'Abandoned cart (max)', | ||
| 'help' => 'How long (in hours) after the last action a cart is no longer to be considered as abandoned.', | ||
| 'constraints' => [new NotBlank(), new GreaterThan(0)], | ||
| ]) | ||
| ; | ||
| } | ||
|
|
||
| public function configureOptions(OptionsResolver $resolver): void | ||
| { | ||
| $resolver->setDefaults([ | ||
| 'required' => true, | ||
| 'translation_domain' => 'Modules.Dashactivity.Admin', | ||
| ]); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| {#** | ||
| * Copyright since 2007 PrestaShop SA and Contributors | ||
| * PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
| * | ||
| * This source file is subject to the Academic Free License 3.0 (AFL-3.0). | ||
| * It is also available through the world-wide-web at this URL: https://opensource.org/licenses/AFL-3.0 | ||
| *#} | ||
| {% extends '@PrestaShop/Admin/layout.html.twig' %} | ||
|
|
||
| {% block content %} | ||
| {{ form_start(configurationForm) }} | ||
| <div class="row justify-content-center"> | ||
| <div class="col-xl-10"> | ||
| <div class="card"> | ||
| <h3 class="card-header"> | ||
| <i class="material-icons">settings</i> | ||
| {{ 'Activity overview settings'|trans({}, 'Modules.Dashactivity.Admin') }} | ||
| </h3> | ||
| <div class="card-body"> | ||
| {{ form_widget(configurationForm) }} | ||
| </div> | ||
| <div class="card-footer"> | ||
| <div class="d-flex justify-content-end"> | ||
| <button class="btn btn-primary">{{ 'Save'|trans({}, 'Admin.Actions') }}</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {{ form_end(configurationForm) }} | ||
| {% endblock %} |
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.
The trailing newline is gone (
\ No newline at end of file), and the file also switches from tabs to spaces and drops<limited_countries>. All unrelated to the feature, worth restoring to keep the diff focused.