Skip to content

Commit

Permalink
Version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magenizr committed Apr 21, 2023
1 parent 25a1702 commit 054d9ec
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 34 deletions.
58 changes: 58 additions & 0 deletions Block/System/Account/ResetUiBookmarks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);

/**
* Magenizr ResetUiBookmarks
* @copyright Copyright (c) 2018 - 2022 Magenizr (https://www.magenizr.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Magenizr\ResetUiBookmarks\Block\System\Account;

class ResetUiBookmarks extends \Magento\Backend\Block\Template
{
/**
* @var \Magento\Ui\Api\Data\BookmarkInterfaceFactory
*/
protected $bookmarkFactory;

/**
* Init Constructor.
*
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Ui\Api\Data\BookmarkInterfaceFactory $bookmarkFactory
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Ui\Api\Data\BookmarkInterfaceFactory $bookmarkFactory,
array $data = []
)
{
parent::__construct($context, $data);
$this->bookmarkFactory = $bookmarkFactory;
}

/**
* Return a list of namespaces from table ui_bookmarks
*
* @return array
*/
public function getNamespaceList()
{
$data = [];
$items = $this->bookmarkFactory->create()
->getCollection()
->addFieldToSelect('namespace')
->addOrder('namespace', \Magento\Framework\DB\Select::SQL_DESC)
->getItems();

if (!empty($items)) {
foreach ($items as $item) {
$data[$item->getData('namespace')] = ucwords(str_replace('_', ' ', $item->getData('namespace')));
}
}

return $data;
}
}
28 changes: 19 additions & 9 deletions Controller/Adminhtml/Reset/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class Index extends \Magento\Backend\App\Action
* @param \Magento\User\Model\UserFactory $userFactory
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Ui\Api\Data\BookmarkInterfaceFactory $bookmarkFactory,
\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\User\Model\UserFactory $userFactory
) {
\Magento\Framework\Controller\ResultFactory $resultFactory,
\Magento\Framework\App\RequestInterface $request,
\Magento\User\Model\UserFactory $userFactory
)
{
parent::__construct($context);

$this->bookmarkFactory = $bookmarkFactory;
Expand All @@ -69,7 +70,7 @@ public function execute()
$params = $this->request->getParam('magenizr_resetuibookmarks');

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

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

$system = false;
Expand All @@ -94,7 +95,16 @@ public function execute()
$collection->addFieldToFilter('identifier', ['like' => '_%']);
break;
case 'saved-exclude':
$collection->addFieldToFilter('identifier', ['in' => ['current','default']]);
$collection->addFieldToFilter('identifier', ['in' => ['current', 'default']]);
break;
}

switch ($params['namespace']) {
case 'all':
$collection->addFieldToFilter('namespace', ['like' => '%']);
break;
default:
$collection->addFieldToFilter('namespace', ['eq' => $params['namespace']]);
break;
}

Expand All @@ -109,7 +119,7 @@ public function execute()
$message = __('The UI Bookmarks for user (%1) have been cleared successfully.', $user->getEmail());

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

Expand Down
9 changes: 8 additions & 1 deletion Plugin/Block/Adminhtml/User/Edit/Tab/ResetUiBookmarks.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?php
declare(strict_types=1);

/**
* Magenizr ResetUiBookmarks
* @copyright Copyright (c) 2018 - 2022 Magenizr (https://www.magenizr.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

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

class ResetUiBookmarks
{

/**
* Add fieldset for reset ui bookmarks
*
Expand Down Expand Up @@ -36,7 +43,7 @@ public function aroundGetFormHtml(
if ($userId === 0) {
return $proceed();
}

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

$fieldset->addField(
Expand Down
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +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/a3/7b/Nzdq7r9y_o.png)
![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/74/23/EprsvLRC_o.png)
![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/13/c1/IWMHIdfk_o.png)
![Magenizr ResetUiBookmarks - Backend](https://images2.imgbox.com/16/f6/Ed7BKH2o_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 @@ -17,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.2.2" --no-update`
1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.3.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.2.2): Downloading (100%)
- Installing magenizr/magento2-resetuibookmarks (1.3.0): Downloading (100%)
Writing lock file
Generating autoload files
```
Expand All @@ -38,13 +38,13 @@ php bin/magento module:enable Magenizr_ResetUiBookmarks

## Installation (Composer 2)

1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.2.2" --no-update`
1. Update your composer.json `composer require "magenizr/magento2-resetuibookmarks":"1.3.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.2.2)
- Locking magenizr/magento2-resetuibookmarks (1.3.0)
```

3. And then `composer install` to install the package.
Expand All @@ -53,7 +53,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.2.2): Extracting archive
- Installing magenizr/magento2-resetuibookmarks (1.3.0): Extracting archive
```

4. Enable the module and clear static content.
Expand All @@ -64,7 +64,7 @@ php bin/magento module:enable Magenizr_ResetUiBookmarks

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

Expand All @@ -77,20 +77,24 @@ php bin/magento setup:upgrade
* 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`
* Select a specific namespace such as `Product Listing` or `Customer Listing`. The dropdown is generated based on namespaces stored in the `ui_bookmark` table.

## Usage
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).
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 via [https://account.magenizr.com](https://account.magenizr.com).

## Purchase
This module is available for free on [GitHub](https://github.com/magenizr). If you purchase the module on [Magenizr Shop](https://shop.magenizr.com) or [Magento Marketplace](https://marketplace.magento.com/partner/magenizr) we offer 60 days free support, 90 days warranty and 12 month free updates.
This module is available for free on [GitHub](https://github.com/magenizr). If you purchase this module on [https://account.magenizr.com](https://account.magenizr.com) offer support and regular updates.

## Contact
Follow us on [GitHub](https://github.com/magenizr), [Twitter](https://twitter.com/magenizr) and [Facebook](https://www.facebook.com/magenizr).

## History
===== 1.3.0 =====
* Namespace added so that you can clear bookmarks for a specific grid table

===== 1.2.2 =====
* 2.4.6 compatibility check
* Code cleanup
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
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.2.2",
"version": "1.3.0",
"license": [
"OSL-3.0"
],
Expand Down
4 changes: 2 additions & 2 deletions view/adminhtml/layout/adminhtml_system_account_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
</head>
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template"
<block class="Magenizr\ResetUiBookmarks\Block\System\Account\ResetUiBookmarks"
name="magenizr.resetuibookmarks.adminhtml.system.account.edit"
template="Magenizr_ResetUiBookmarks::system/account/resetuibookmarks.phtml"/>
</referenceContainer>
</body>
</page>
</page>
2 changes: 1 addition & 1 deletion view/adminhtml/layout/adminhtml_user_edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<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 class="Magenizr\ResetUiBookmarks\Block\System\Account\ResetUiBookmarks" name="magenizr.resetuibookmarks.system.account" template="Magenizr_ResetUiBookmarks::system/account/resetuibookmarks.phtml"/>
</block>
</referenceContainer>
</body>
Expand Down
34 changes: 25 additions & 9 deletions view/adminhtml/templates/system/account/resetuibookmarks.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,31 @@
['_current' => true, '_use_rewrite' => true]
)) ?>" method="get">

<button id="reset" title="Reset UI Bookmarks" 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="magenizr_resetuibookmarks[identifier]" title="Identifier" class="select select admin__control-select ignore-validate">
<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>
<div class="row">
<span class="label"><?= $escaper->escapeHtml(__('Bookmarks')) ?></span>
<select id="identifier" name="magenizr_resetuibookmarks[identifier]" title="Identifier" class="select select admin__control-select ignore-validate">
<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>
</div>

<div class="row">
<span class="label"><?= $escaper->escapeHtml(__('Namespace')) ?></span>
<select id="namespace" name="magenizr_resetuibookmarks[namespace]" title="Namespace" class="select select admin__control-select ignore-validate">
<option value="all"><?= $escaper->escapeHtml(__('All Namespaces')) ?></option>
<?php foreach ($block->getNamespaceList() as $namespace => $name): ?>
<option value="<?= $escaper->escapeHtml($namespace); ?>"><?= $escaper->escapeHtml($name); ?></option>
<?php endforeach; ?>
</select>
</div>

<div class="row">
<span class="label">&nbsp;</span>
<button id="reset" title="Reset UI Bookmarks" type="submit" class="action-default scalable button-danger" role="button" aria-disabled="false">
<span><?= $escaper->escapeHtml(__('Reset UI Bookmarks')) ?></span>
</button>
</div>

<input type="hidden" name="magenizr_resetuibookmarks[userId]" value="<?= $escaper->escapeHtml($block->getData('userId')); ?>" class="ignore-validate" />
</form>
Expand Down
14 changes: 13 additions & 1 deletion view/adminhtml/web/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@
}
}

.label {
text-align: left;
font-weight: bold;
width: 25%;
display: block;
float: left;
}

.row {
margin-bottom: 15px;
}

select {
margin-left: 0.5em;
margin: 0;
}
}

Expand Down

0 comments on commit 054d9ec

Please sign in to comment.