Skip to content

Commit

Permalink
index queue backend ui
Browse files Browse the repository at this point in the history
  • Loading branch information
benwalch committed Dec 9, 2024
1 parent f2da7d9 commit ff73612
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 39 deletions.
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
20 changes: 20 additions & 0 deletions config/pimcore/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,26 @@ dynamic_search.controller.admin.get_context_full_configuration:
options:
expose: true

dynamic_search.controller.admin.index_queue.get_info:
path: /admin/dynamic-search/settings/index-queue/info
defaults: { _controller: DynamicSearchBundle\Controller\Admin\SettingsController::indexQueueInfoAction }
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}
defaults: { _controller: DynamicSearchBundle\Controller\SearchController::jsonSearchAction }
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
37 changes: 36 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,38 @@ 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();
}

public function contextFullConfigurationAction(): JsonResponse
{
return $this->json($this->contextFullConfiguration);
}
Expand Down
16 changes: 13 additions & 3 deletions src/Manager/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,22 @@ public function __construct(
)
{}

public function getQueueTableName(): string
{
return $this->tableName;
}

public function getTotalQueuedItems(): int
{
$qb = $this->connection->createQueryBuilder();
$qb->select('COUNT(id)')->from($this->tableName);
return (int)$qb->executeQuery()->fetchOne();
}

public function clearQueue(): void
{
try {
$qb = $this->connection->createQueryBuilder();
$qb->select('COUNT(id)')->from($this->tableName);
$affectedRows = current($qb->executeQuery()->fetchFirstColumn());
$affectedRows = $this->getTotalQueuedItems();
$sql = $this->connection->getDatabasePlatform()->getTruncateTableSQL($this->tableName);
$this->connection->executeStatement($sql);
$this->logger->debug(sprintf('data queue cleared. Affected jobs: %d', $affectedRows), 'queue', 'default');
Expand Down
2 changes: 2 additions & 0 deletions src/Manager/QueueManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

interface QueueManagerInterface
{
public function getQueueTableName(): string;
public function getTotalQueuedItems(): int;
public function clearQueue(): void;
}
1 change: 0 additions & 1 deletion src/Runner/ContextRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function runSingleContextCreation(string $contextName): void
{
$contextDefinition = $this->setupContextDefinition($contextName, ContextDefinitionInterface::CONTEXT_DISPATCH_TYPE_INDEX);

$this->queueManager->clearQueue();
$this->longProcessService->boot();

$this->dispatchContext($contextDefinition);
Expand Down
Loading

0 comments on commit ff73612

Please sign in to comment.