Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
magenizr committed Oct 7, 2022
1 parent f73a5e5 commit 0b4e7b4
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 32 deletions.
44 changes: 37 additions & 7 deletions Controller/Adminhtml/Reset/Index.php
Expand Up @@ -30,7 +30,7 @@ class Index extends \Magento\Backend\App\Action
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;

/**
* Index constructor.
*
Expand All @@ -39,20 +39,23 @@ class Index extends \Magento\Backend\App\Action
* @param \Magento\Ui\Model\ResourceModel\BookmarkRepository $bookmarkRepository
* @param \Magento\Framework\Controller\ResultFactory $resultFactory
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\User\Model\UserFactory $userFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Ui\Api\Data\BookmarkInterfaceFactory $bookmarkFactory,
\Magento\Ui\Model\ResourceModel\BookmarkRepository $bookmarkRepository,
\Magento\Framework\Controller\ResultFactory $resultFactory,
\Magento\Framework\App\RequestInterface $request
\Magento\Framework\App\RequestInterface $request,
\Magento\User\Model\UserFactory $userFactory
) {
parent::__construct($context);

$this->bookmarkFactory = $bookmarkFactory;
$this->bookmarkRepository = $bookmarkRepository;
$this->resultFactory = $resultFactory;
$this->request = $request;
$this->userFactory = $userFactory;
}

/**
Expand All @@ -62,16 +65,32 @@ public function __construct(
*/
public function execute()
{
$system = true;
$params = $this->request->getParam('magenizr_resetuibookmarks');

$userId = $this->_auth->getUser()->getId();


if (!empty($params['userId'])) {

$system = false;
$userId = $params['userId'];
}

$user = $this->userFactory->create()->load($userId);

$redirect = $this->resultRedirectFactory->create();
$redirect->setPath('adminhtml/system_account/index');
$redirect->setPath('adminhtml/user/edit', ['user_id' => $userId]);

if ($system) {
$redirect->setPath('adminhtml/system_account/index');
}

try {
$collection = $this->bookmarkFactory->create()->getCollection();
$collection->addFieldToFilter('user_id', ['eq' => $userId]);

switch ($this->request->getParam('identifier')) {
switch ($params['identifier']) {
case 'saved-only':
$collection->addFieldToFilter('identifier', ['like' => '_%']);
break;
Expand All @@ -80,11 +99,22 @@ public function execute()
break;
}

foreach ($collection->getItems() as $bookmark) {
$this->bookmarkRepository->deleteById($bookmark->getBookmarkId());
$message = __('No UI Bookmarks found for user (%1).', $user->getEmail());

if (!empty($collection->getItems())) {

foreach ($collection->getItems() as $bookmark) {
$this->bookmarkRepository->deleteById($bookmark->getBookmarkId());
}

$message = __('The UI Bookmarks for user (%1) have been cleared successfully.', $user->getEmail());

if ($system) {
$message = __('Your UI Bookmarks were cleared successfully.');
}
}

$this->messageManager->addSuccessMessage(__('Your UI Bookmarks were cleared successfully.'));
$this->messageManager->addSuccessMessage($message);

return $redirect;
} catch (\Exception $e) {
Expand Down
50 changes: 50 additions & 0 deletions Plugin/Block/Adminhtml/User/Edit/Tab/ResetUiBookmarks.php
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace Magenizr\ResetUiBookmarks\Plugin\Block\Adminhtml\User\Edit\Tab;

class ResetUiBookmarks
{
/**
* Add fieldset for reset ui bookmarks
*
* @param \Magento\User\Block\User\Edit\Tab\Main $subject
* @param \Closure $proceed
* @return mixed
*/
public function aroundGetFormHtml(
\Magento\User\Block\User\Edit\Tab\Main $subject,
\Closure $proceed
) {
$form = $subject->getForm();
if (is_object($form)) {
$fieldset = $form->getElement('base_fieldset');
$userId = 0;

foreach ($fieldset->getElements() as $element) {

if ($element->getId() === 'user_id') {
$userId = $element->getValue();
}
}

$fieldset = $form->addFieldset('magenizr_resetuibookmarks', ['legend' => __('Bookmarks')]);

$fieldset->addField(
'reset_ui_bookmarks',
'label',
[
'container_id' => 'reset_ui_bookmarks',
'after_element_html' => $subject->getLayout()
->getBlock('magenizr.resetuibookmarks.system.account')
->setData('userId', $userId)
->toHtml()
]
);

$subject->setForm($form);
}

return $proceed();
}
}
28 changes: 16 additions & 12 deletions README.md
@@ -1,7 +1,8 @@
# Reset Ui Bookmarks
Reset UI Bookmarks becomes an invaluable tool while working daily in the admin panel, especially on Magento® instances with a large catalogue. The regular use of grid filters, applied sorting ( e.g `Sales > Orders or Catalog > Product` ) or other options provided by third party integrations can cause server time-outs ( depending on the filter combinations ) and make the grid tables unusable. With Reset UI Bookmarks any admin user can reset their filters back to default without having an agency support team involved.

![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/24/58/jH70l3Si_o.png)
![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/a3/7b/Nzdq7r9y_o.png)
![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/74/23/EprsvLRC_o.png)

## Business Value
Usually a technical person ( e.g developer ) is required to reset those filters back to default. This can be annoying for a client and create unnecessarily noise for a developer team. Here are the advantages of Reset UI Bookmarks.
Expand All @@ -16,15 +17,15 @@ Usually a technical person ( e.g developer ) is required to reset those filters

## Installation (Composer)

1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.1.2" --no-update`
2. Install dependencies and update your composer.lock `composer update --lock`
1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.2.0" --no-update`
2. Install dependencies and update your composer.lock `composer update magenizr/magento2-resetuibookmarks --lock`

```
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing magenizr/magento2-resetuibookmarks (1.1.2): Downloading (100%)
- Installing magenizr/magento2-resetuibookmarks (1.2.0): Downloading (100%)
Writing lock file
Generating autoload files
```
Expand All @@ -38,13 +39,13 @@ php bin/magento setup:upgrade

## Installation (Composer 2)

1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.1.2" --no-update`
2. Use `composer update --no-install` to update your composer.lock file.
1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.2.0" --no-update`
2. Use `composer update magenizr/magento2-resetuibookmarks --no-install` to update your composer.lock file.

```
Updating dependencies
Lock file operations: 1 install, 1 update, 0 removals
- Locking magenizr/magento2-resetuibookmarks (1.1.2)
- Locking magenizr/magento2-resetuibookmarks (1.2.0)
```

3. And then `composer install` to install the package.
Expand All @@ -53,7 +54,7 @@ Lock file operations: 1 install, 1 update, 0 removals
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 1 install, 0 update, 0 removals
- Installing magenizr/magento2-resetuibookmarks (1.1.2): Extracting archive
- Installing magenizr/magento2-resetuibookmarks (1.2.0): Extracting archive
```

4. Enable the module and clear static content.
Expand All @@ -65,7 +66,7 @@ php bin/magento setup:upgrade

## Installation (Manually)
1. Download the code.
2. Extract the downloaded tar.gz file. Example: `tar -xzf Magenizr_ResetUiBookmarks_1.1.2.tar.gz`.
2. Extract the downloaded tar.gz file. Example: `tar -xzf Magenizr_ResetUiBookmarks_1.2.0.tar.gz`.
3. Copy the code into `./app/code/Magenizr/ResetUiBookmarks/`.
4. Enable the module and clear static content.

Expand All @@ -75,12 +76,12 @@ php bin/magento setup:upgrade
```

## Features
* A red button `Reset UI Bookmarks` is available on the `Account Settings` page for each admin user.
* A red button `Reset UI Bookmarks` within your `Account Settings` page as well as on `System > Permissions > All Users > {User} > User Info`.
* Once a admin user hits the button `Reset UI Bookmarks`, it will clear the history of state of filters, column positions or applied sorting which are stored in the MySQL table `ui_bookmark`.
* Choose between the options `All Bookmarks`, `Saved Filters Only` and `Keep Saved Filters`

## Usage
Go to your `Account Settings` and hit the button `Reset UI Bookmarks` to clear the bookmarks and wait for the confirmation `Your UI bookmarks were cleared successfully`. After that all filters and grid settings are set back to default. More details are available in the attached user guide.
Simply hit the button `Reset UI Bookmarks` to clear the bookmarks and wait for the confirmation `Your UI bookmarks were cleared successfully`. After that all filters and grid settings are set back to default. More details are available in the attached user guide.

## Support
If you experience any issues, don't hesitate to open an issue on [Github](https://github.com/magenizr/Magenizr_Debugger/issues). For a custom build, don't hesitate to contact us on [Magento Marketplace](https://marketplace.magento.com/partner/magenizr).
Expand All @@ -92,8 +93,11 @@ This module is available for free on [GitHub](https://github.com/magenizr). If y
Follow us on [GitHub](https://github.com/magenizr), [Twitter](https://twitter.com/magenizr) and [Facebook](https://www.facebook.com/magenizr).

## History
===== 1.2.0 =====
* ResetUiBookmarks Button added to `System > Permissions > All Users > {User} > User Info` so that bookmarks can be cleared for non-administrator users.

===== 1.1.2 =====
- `setup_version=""` removed from module.xml
* `setup_version=""` removed from module.xml

===== 1.1.1 =====
* 2.4.x compatibility added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "magenizr/magento2-resetuibookmarks",
"description": "This Magento 2 module allows you to reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.",
"type": "magento2-module",
"version": "1.1.2",
"version": "1.2.0",
"license": [
"OSL-3.0"
],
Expand Down
6 changes: 6 additions & 0 deletions etc/adminhtml/di.xml
@@ -0,0 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\User\Block\User\Edit\Tab\Main">
<plugin name="admin_user_image" type="Magenizr\ResetUiBookmarks\Plugin\Block\Adminhtml\User\Edit\Tab\ResetUiBookmarks" sortOrder="1"/>
</type>
</config>
3 changes: 2 additions & 1 deletion i18n/de_DE.csv
@@ -1,7 +1,8 @@
"Reset UI Bookmarks","UI Bookmarks zurücksetzen"
"This will reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","Damit werden benutzerdefinierte Filtereinstellungen zurückgesetzt. Zum Beispiel die Positionen der Spalten in Tabellen und Sortierungen."
"This will reset UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","Damit werden benutzerdefinierte Filtereinstellungen zurückgesetzt. Zum Beispiel die Positionen der Spalten in Tabellen und Sortierungen."
"Your UI Bookmarks were cleared successfully.","Deine UI Bookmarks wurden erfolgreich zurückgesetzt."
"We were unable to submit your request. Please try again!","Es ist ein Fehler aufgetreten. Bitte versuche es noch einmal."
"No UI Bookmarks found for user (%1).","Keine UI Bookmarks für Benutzer (%1) gefunden."
"All Bookmarks","Alle Bookmarks"
"Saved Filters Only","Nur gespeicherte Filter"
"Keep Saved Filters","Gespeicherte Filter behalten"
3 changes: 2 additions & 1 deletion i18n/en_US.csv
@@ -1,7 +1,8 @@
"Reset UI Bookmarks","Reset UI Bookmarks"
"This will reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","This will reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on."
"This will reset UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","This will reset UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on."
"Your UI Bookmarks were cleared successfully.","Your UI Bookmarks were cleared successfully."
"We were unable to submit your request. Please try again.","We were unable to submit your request. Please try again."
"No UI Bookmarks found for user (%1).","No UI Bookmarks found for user (%1)."
"All Bookmarks","All Bookmarks"
"Saved Filters Only","Saved Filters Only"
"Keep Saved Filters","Keep Saved Filters"
3 changes: 2 additions & 1 deletion i18n/fr_FR.csv
@@ -1,7 +1,8 @@
"Reset UI Bookmarks","Réinitialiser UI Bookmarks "
"This will reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","Cela réinitialisera vos signets d'interface utilisateur tels que l'état des filtres, les positions des colonnes, le tri des tables, la pagination, etc."
"This will reset UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.","Cela réinitialisera vos signets d'interface utilisateur tels que l'état des filtres, les positions des colonnes, le tri des tables, la pagination, etc."
"Your UI Bookmarks were cleared successfully.","Vos signets d'interface utilisateur ont été effacés avec succès."
"We were unable to submit your request. Please try again.","Nous n'avons pas pu soumettre votre demande. Veuillez réessayer."
"No UI Bookmarks found for user (%1).","Aucun signet d'interface utilisateur trouvé pour l'utilisateur administrateur (%1)."
"All Bookmarks","Tous les signets"
"Saved Filters Only","Filtres enregistrés uniquement"
"Keep Saved Filters","Conserver les filtres enregistrés"
4 changes: 1 addition & 3 deletions view/adminhtml/layout/adminhtml_system_account_index.xml
Expand Up @@ -14,11 +14,9 @@
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Backend\Block\System\Account\Edit"
name="adminhtml.system.account.edit"/>
<block class="Magento\Framework\View\Element\Template"
name="magenizr.resetuibookmarks.adminhtml.system.account.edit"
template="Magenizr_ResetUiBookmarks::system/account/resetuibookmarks.phtml"/>
</referenceContainer>
</body>
</page>
</page>
20 changes: 20 additions & 0 deletions view/adminhtml/layout/adminhtml_user_edit.xml
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="Magenizr_ResetUiBookmarks::css/style.css"/>
</head>
<body>
<referenceContainer name="left">
<block class="Magento\User\Block\User\Edit\Tabs" name="adminhtml.user.edit.tabs">
<block class="Magento\Backend\Block\Template" name="magenizr.resetuibookmarks.system.account" template="Magenizr_ResetUiBookmarks::system/account/resetuibookmarks.phtml"/>
</block>
</referenceContainer>
</body>
</page>
19 changes: 13 additions & 6 deletions view/adminhtml/templates/system/account/resetuibookmarks.phtml
Expand Up @@ -9,30 +9,37 @@
<div class="magenizr-resetuibookmarks">
<div class="divider"></div>
<fieldset class="fieldset admin__fieldset " id="magenizr_resetuibookmarks">
<legend class="admin__legend">

<legend class="admin__legend hide">
<span><?= $escaper->escapeHtml(__('Reset UI Bookmarks')) ?></span>
</legend><br>

<div class="admin__field">
<label class="label admin__field-label"></label>
<div class="admin__field-control control">

<form action="<?= $escaper->escapeUrl($block->getUrl('magenizr_resetuibookmarks/reset/index', ['_current' => true, '_use_rewrite' => true])) ?>" method="get">
<label class="label admin__field-label hide"></label>

<div class="admin__field-control control ml0 w100">

<form action="<?= $escaper->escapeUrl($block->getUrl(
'magenizr_resetuibookmarks/reset/index',
['_current' => true, '_use_rewrite' => true]
)) ?>" method="get">

<button id="save" title="Save Account" type="submit" class="action-default scalable button-danger" role="button" aria-disabled="false">
<span><?= $escaper->escapeHtml(__('Reset UI Bookmarks')) ?></span>
</button>

<select id="identifier" name="identifier" title="Identifier" class="select select admin__control-select">
<select id="identifier" name="magenizr_resetuibookmarks[identifier]" title="Identifier" class="select select admin__control-select">
<option value="saved-exclude"><?= $escaper->escapeHtml(__('Keep Saved Filters')) ?></option>
<option value="saved-only"><?= $escaper->escapeHtml(__('Saved Filters Only')) ?></option>
<option value="all"><?= $escaper->escapeHtml(__('All Bookmarks')) ?></option>
</select>

<input type="hidden" name="magenizr_resetuibookmarks[userId]" value="<?= $escaper->escapeHtml($block->getData('userId')); ?>" />
</form>

<span class="hint">
<?= $escaper->escapeHtml(__('This will reset your UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.')) ?>
<?= $escaper->escapeHtml(__('This will reset UI bookmarks such as state of filters, column positions, grid sorting, pagination and so on.')) ?>
</span>
</div>
</div>
Expand Down
23 changes: 23 additions & 0 deletions view/adminhtml/web/css/style.less
Expand Up @@ -40,3 +40,26 @@
margin-left: 0.5em;
}
}

#reset_ui_bookmarks {

.divider {
display: none;
}

.hide {
display: none !important;
}

.ml0 {
margin-left: 0 !important;
}

.w100 {
width: 100% !important;
}

.admin__field {
margin-left: 0 !important;
}
}

0 comments on commit 0b4e7b4

Please sign in to comment.