Skip to content
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

index queue backend ui #97

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Upgrade Notes

## 4.0.5
- index queue backend ui [#97](https://github.com/dachcom-digital/pimcore-dynamic-search/pull/97)
## 4.0.4
- provide ds settings in backend ui [#96](https://github.com/dachcom-digital/pimcore-dynamic-search/pull/96)
## 4.0.3
Expand Down
25 changes: 25 additions & 0 deletions config/pimcore/routing.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
dynamic_search.controller.admin.get_state:
path: /admin/dynamic-search/settings/health-state
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::healthStateAction }
options:
expose: true

dynamic_search.controller.admin.get_provider:
path: /admin/dynamic-search/settings/provider
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::providerAction }
options:
expose: true

dynamic_search.controller.admin.get_context_full_configuration:
path: /admin/dynamic-search/settings/context-full-configuration
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::contextFullConfigurationAction }
options:
expose: true

dynamic_search.controller.admin.index_queue.get_info:
path: /admin/dynamic-search/settings/index-queue/info
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::indexQueueInfoAction }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set methods

options:
expose: true

dynamic_search.controller.admin.index_queue.queue_all_data:
path: /admin/dynamic-search/settings/index-queue/queue-all-data
methods: [ POST ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::indexQueueAllDataAction }
options:
expose: true

dynamic_search.controller.admin.index_queue.clear:
path: /admin/dynamic-search/settings/index-queue/clear
methods: [ POST ]
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::clearIndexQueueAction }
options:
expose: true

dynamic_search.controller.json_search:
path: /dynamic-search/{contextName}/j-{outputChannelName}
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\SearchController::jsonSearchAction }
4 changes: 3 additions & 1 deletion config/pimcore/routing/frontend_routing.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
dynamic_search_frontend_search_list:
path: /dynamic-search/{contextName}/{outputChannelName}
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\SearchFrontendController::searchAction }

dynamic_search_frontend_multi_search_list:
path: /dynamic-search/{contextName}/collection/{outputChannelName}
defaults: { _controller: DynamicSearchBundle\Controller\SearchFrontendController::multiSearchAction }
methods: [ GET ]
defaults: { _controller: DynamicSearchBundle\Controller\SearchFrontendController::multiSearchAction }
188 changes: 156 additions & 32 deletions public/js/backend/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ pimcore.plugin.dynamicSearch.settings = Class.create({

panel: null,

healthStateStore: null,
providerStore: null,
queueInfoStore: null,

initialize: function () {
this.buildLayout();
},
Expand All @@ -17,7 +21,7 @@ pimcore.plugin.dynamicSearch.settings = Class.create({

this.panel = Ext.create('Ext.panel.Panel', {
id: 'dynamic_search_settings',
title: t('dynamic_search_settings'),
title: t('dynamic_search.settings'),
iconCls: 'dynamic_search_bundle',
border: false,
bodyPadding: 10,
Expand All @@ -26,9 +30,15 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
align: 'stretch'
},
closable: true,
tbar: [{
xtype: 'button',
iconCls: 'pimcore_icon_reload',
handler: this.reload.bind(this)
}],
items: [
this.buildStatusPanel(),
this.buildProviderGrid()
this.buildProviderGrid(),
this.buildQueueInfoPanel()
]
});

Expand All @@ -48,10 +58,136 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
pimcoreSystemPanel.setActiveItem('dynamic_search_settings');
},

reload: function() {
this.queueInfoStore.reload();
this.healthStateStore.reload();
this.providerStore.reload();
},

buildQueueInfoPanel: function() {
this.queueInfoStore = new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: Routing.generate('dynamic_search.controller.admin.index_queue.get_info'),
reader: {
type: 'json',
transform: {
fn: function(data) {
return [data];
}
}
}
},
fields: ['tableName', 'count']
});

const contexts = Object.keys(pimcore.globalmanager.get('dynamic_search.context.full_configuration') || {});

const performIndexQueueAction = function(action, context) {
Ext.Msg.confirm(
t(`dynamic_search.actions.index_queue.${action}`) + (context ? ': ' + context : ''),
t(`dynamic_search.actions.index_queue.${action}.confirmation.message`),
function (confirmMsg) {

if (confirmMsg !== 'yes') {
return;
}

Ext.Ajax.request({
url: Routing.generate('dynamic_search.controller.admin.index_queue.' + action),
method: 'POST',
params: {
context: context
},
success: function(response) {
if (response.status === 200) {
this.queueInfoStore.reload();
pimcore.helpers.showNotification(t('success'), t(`dynamic_search.actions.index_queue.${action}.success`), 'success');
} else {
pimcore.helpers.showNotification(t('error'), response.responseText, 'error');
}
}.bind(this)
});
}.bind(this)
);
}.bind(this);

return new Ext.grid.Panel({
title: t('dynamic_search.settings.index_queue'),
layout: 'table',
hideHeaders: false,
style: 'margin-bottom: 10px',
store: this.queueInfoStore,
columns: [
{
text: t('dynamic_search.settings.index_queue.table_name'),
sortable: false,
dataIndex: 'tableName',
hidden: false,
flex: 2,
},
{
text: t('dynamic_search.settings.index_queue.total_queued_items'),
sortable: false,
dataIndex: 'count',
hidden: false,
flex: 1,
renderer: function (value, metaData) {
return '<strong>' + value + '</strong>';
}
}
],
bbar: {
items: [
{
xtype: 'button',
scale: 'small',
margin: '0 10 0 0',
text: t('dynamic_search.actions.index_queue.queue_all_data'),
icon: '/bundles/pimcoreadmin/img/flat-color-icons/data_recovery.svg',
menu: contexts.map(function(context) {
return {
text: context,
handler: function() {
performIndexQueueAction('queue_all_data', context)
}
}
})
},
{
xtype: 'button',
scale: 'small',
margin: '0 10 0 0',
text: t('dynamic_search.actions.index_queue.clear'),
icon: '/bundles/pimcoreadmin/img/flat-color-icons/delete_database.svg',
handler: function() {
performIndexQueueAction('clear', null)
}
}
]
}
});
},

buildStatusPanel: function () {
this.healthStateStore = new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: Routing.generate('dynamic_search.controller.admin.get_state'),
reader: {
type: 'json',
rootProperty: 'lines'
}
},
fields: ['module', 'title', 'comment', 'icon']
});

return new Ext.panel.Table({
title: 'Health Status',
title: t('dynamic_search.settings.health_status'),
layout: 'table',
viewType: 'tableview',
style: 'margin-bottom: 10px',
Expand All @@ -63,19 +199,7 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
viewConfig: {
trackOver: false
},
store: new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: Routing.generate('dynamic_search.controller.admin.get_state'),
reader: {
type: 'json',
rootProperty: 'lines'
}
},
fields: ['module', 'title', 'comment', 'icon']
}),
store: this.healthStateStore,
columns: [
{
sortable: false,
Expand Down Expand Up @@ -118,9 +242,22 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
},

buildProviderGrid: function () {
this.providerStore = new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: Routing.generate('dynamic_search.controller.admin.get_provider'),
reader: {
type: 'json',
rootProperty: 'provider'
}
},
fields: ['id', 'path', 'active']
});

return new Ext.grid.GridPanel({
title: 'Provider',
title: t('dynamic_search.settings.provider'),
layout: 'table',
style: 'margin-bottom: 10px',
columnLines: true,
Expand All @@ -129,19 +266,7 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
viewConfig: {
trackOver: false
},
store: new Ext.data.JsonStore({
autoDestroy: true,
autoLoad: true,
proxy: {
type: 'ajax',
url: Routing.generate('dynamic_search.controller.admin.get_provider'),
reader: {
type: 'json',
rootProperty: 'provider'
}
},
fields: ['id', 'path', 'active']
}),
store: this.providerStore,
columns: [

{
Expand All @@ -168,6 +293,5 @@ pimcore.plugin.dynamicSearch.settings = Class.create({
}
]
});

}
});
});
2 changes: 1 addition & 1 deletion public/js/backend/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DynamicSearch {
callback: function() {
searchMenu = new Ext.Action({
id: 'search',
text: t('dynamic_search_settings'),
text: t('dynamic_search.settings'),
iconCls: 'dynamic_search_bundle',
handler: this.openSettingsPanel.bind(this)
});
Expand Down
38 changes: 37 additions & 1 deletion src/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace DynamicSearchBundle\Controller\Admin;

use DynamicSearchBundle\Manager\QueueManagerInterface;
use DynamicSearchBundle\Provider\Extension\ProviderBundleLocator;
use DynamicSearchBundle\Registry\HealthStateRegistryInterface;
use DynamicSearchBundle\Runner\ContextRunnerInterface;
use DynamicSearchBundle\State\HealthStateInterface;
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class SettingsController extends AdminAbstractController
{
Expand Down Expand Up @@ -51,7 +55,39 @@ public function providerAction(ProviderBundleLocator $providerBundleLocator): Js
]);
}

public function contextFullConfigurationAction(ProviderBundleLocator $providerBundleLocator): JsonResponse
public function indexQueueInfoAction(QueueManagerInterface $queueManager): JsonResponse
{
return $this->json([
'tableName' => $queueManager->getQueueTableName(),
'count' => $queueManager->getTotalQueuedItems()
]);
}

public function indexQueueAllDataAction(Request $request, ContextRunnerInterface $contextRunner): Response
{
$contextName = $request->get('context');

if (empty($contextName)) {
return new Response('no context given', 400);
}

try {
$contextRunner->runSingleContextCreation($contextName);
} catch (\Throwable $e) {
return new Response($e->getMessage(), 500);
}

return new Response();
}

public function clearIndexQueueAction(QueueManagerInterface $queueManager): Response
{
$queueManager->clearQueue();

return new Response();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing new line before return

}

public function contextFullConfigurationAction(): JsonResponse
{
return $this->json($this->contextFullConfiguration);
}
Expand Down
Loading
Loading