Skip to content

Commit f582428

Browse files
committed
feat: add CMP to manage tools
1 parent bc3487b commit f582428

File tree

21 files changed

+907
-14
lines changed

21 files changed

+907
-14
lines changed

_build/gpm.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ plugins:
1717
- OnDocFormDelete
1818
- OnResourceUndelete
1919
- modAIOnContextProviderRegister
20+
- modAIOnToolRegister
2021

2122
systemSettings:
2223
- key: cache.lit

_build/scripts/custom_events.gpm.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function __invoke(&$modx, $action)
2323

2424
$events = [
2525
'modAIOnContextProviderRegister',
26+
'modAIOnToolRegister',
2627
];
2728

2829
if ($this->action === \xPDO\Transport\xPDOTransport::ACTION_UNINSTALL) {

assets/components/modai/mgr/js/context_provider/page.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
modAIAdmin.page.Element = function (config) {
1+
modAIAdmin.page.ContextProvider = function (config) {
22
config = config || {};
33

44
config.isUpdate = (MODx.request.id) ? true : false;
@@ -34,7 +34,7 @@ modAIAdmin.page.Element = function (config) {
3434
}
3535
]
3636
});
37-
modAIAdmin.page.Element.superclass.constructor.call(this, config);
37+
modAIAdmin.page.ContextProvider.superclass.constructor.call(this, config);
3838
};
39-
Ext.extend(modAIAdmin.page.Element, MODx.Component);
40-
Ext.reg('modai-page-context_provider', modAIAdmin.page.Element);
39+
Ext.extend(modAIAdmin.page.ContextProvider, MODx.Component);
40+
Ext.reg('modai-page-context_provider', modAIAdmin.page.ContextProvider);

assets/components/modai/mgr/js/context_provider/panel.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ modAIAdmin.panel.ContextProvider = function (config) {
2121
cls: 'desc-under'
2222
});
2323
}));
24+
25+
if (configItems.length === 0) {
26+
configItems.push({
27+
html: _('modai.admin.context_provider.no_config')
28+
});
29+
}
30+
2431
} else {
2532
configItems.push({
26-
html: 'Select Context Provider Class to configure it.'
33+
html: _('modai.admin.context_provider.select_class_for_config')
2734
});
2835
}
2936

3037

3138
this.configSection = new Ext.Panel({
32-
title: "Config",
39+
title: _('modai.admin.context_provider.config'),
3340
headerCfg: {
3441
cls: 'modai-admin-section_header x-panel-header',
3542
},
@@ -124,7 +131,7 @@ Ext.extend(modAIAdmin.panel.ContextProvider, MODx.FormPanel, {
124131
},
125132
items: [
126133
{
127-
title: "Context Provider",
134+
title: _('modai.admin.context_provider.context_provider'),
128135
headerCfg: {
129136
cls: 'modai-admin-section_header x-panel-header',
130137
},
@@ -139,13 +146,14 @@ Ext.extend(modAIAdmin.panel.ContextProvider, MODx.FormPanel, {
139146
hideMode: 'offsets',
140147
items: [
141148
{
142-
fieldLabel: 'Context Provider Class',
149+
fieldLabel: _('modai.admin.context_provider.class'),
143150
xtype: 'modai-combo-context_provider_class',
144151
value: config.record.class,
145152
listeners: {
146153
select: (self, record) => {
147154
this.configSection.removeAll();
148-
Object.entries(record.data.config).forEach(([key, config]) => {
155+
const configOptions = Object.entries(record.data.config);
156+
configOptions.forEach(([key, config]) => {
149157
this.configSection.add({
150158
fieldLabel: config.name,
151159
allowBlank: !config.required,
@@ -160,28 +168,34 @@ Ext.extend(modAIAdmin.panel.ContextProvider, MODx.FormPanel, {
160168
});
161169
})
162170

171+
if (configOptions.length === 0) {
172+
this.configSection.add({
173+
html: _('modai.admin.context_provider.no_config')
174+
});
175+
}
176+
163177
this.configSection.doLayout();
164178
}
165179
}
166180
},
167181
{
168-
fieldLabel: 'Name',
182+
fieldLabel: _('modai.admin.context_provider.name'),
169183
xtype: 'textfield',
170184
name: 'name',
171185
msgTarget: 'under',
172186
allowBlank: false,
173187
value: config.record.name,
174188
},
175189
{
176-
fieldLabel: 'Description',
190+
fieldLabel: _('modai.admin.context_provider.description'),
177191
xtype: 'textarea',
178192
name: 'description',
179193
msgTarget: 'under',
180194
value: config.record.description,
181195
allowBlank: true
182196
},
183197
{
184-
fieldLabel: 'Enabled',
198+
fieldLabel: _('modai.admin.context_provider.enabled'),
185199
xtype: 'modai-combo-boolean',
186200
useInt: true,
187201
name: 'enabled',

assets/components/modai/mgr/js/home/panel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ Ext.extend(modAIAdmin.panel.Home, MODx.Panel, {
5252

5353
output.push({
5454
title: _('modai.admin.home.tools'),
55-
items: []
55+
items: [
56+
{
57+
xtype: 'modai-grid-tools',
58+
preventRender: true,
59+
cls: 'main-wrapper'
60+
}
61+
]
5662
});
5763

5864
output.push({
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
modAIAdmin.grid.Tools = function (config) {
2+
config = config || {};
3+
4+
Ext.applyIf(config, {
5+
url: MODx.config.connector_url,
6+
baseParams: {
7+
action: 'modAI\\Processors\\Tools\\GetList',
8+
},
9+
save_action: 'modAI\\Processors\\Tools\\UpdateFromGrid',
10+
autosave: true,
11+
preventSaveRefresh: false,
12+
fields: ['id', 'name', 'default', 'enabled'],
13+
paging: true,
14+
remoteSort: true,
15+
emptyText: _('modai.admin.global.no_records'),
16+
columns: [
17+
{
18+
header: _('id'),
19+
dataIndex: 'id',
20+
width: 0.05,
21+
sortable: true,
22+
hidden: true
23+
},
24+
{
25+
header: _('modai.admin.tool.name'),
26+
dataIndex: 'name',
27+
width: 0.8,
28+
sortable: true,
29+
hidden: false,
30+
editor: {
31+
xtype: 'textfield',
32+
}
33+
},
34+
{
35+
header: _('modai.admin.tool.default'),
36+
dataIndex: 'default',
37+
width: 0.1,
38+
hidden: false,
39+
editor: {
40+
xtype: 'modx-combo-boolean',
41+
renderer: true,
42+
}
43+
},
44+
{
45+
header: _('modai.admin.tool.enabled'),
46+
dataIndex: 'enabled',
47+
width: 0.1,
48+
hidden: false,
49+
editor: {
50+
xtype: 'modx-combo-boolean',
51+
renderer: true,
52+
}
53+
}
54+
],
55+
tbar: this.getTbar(config)
56+
});
57+
modAIAdmin.grid.Tools.superclass.constructor.call(this, config);
58+
};
59+
Ext.extend(modAIAdmin.grid.Tools, MODx.grid.Grid, {
60+
61+
getMenu: function () {
62+
var m = [];
63+
64+
m.push({
65+
text: _('modai.admin.tool.update'),
66+
handler: this.updateTool
67+
});
68+
69+
if (m.length > 0) {
70+
m.push('-');
71+
}
72+
73+
m.push({
74+
text: _('modai.admin.tool.remove'),
75+
handler: this.removeTool
76+
});
77+
78+
return m;
79+
},
80+
81+
getTbar: function(config) {
82+
return [
83+
{
84+
text: _('modai.admin.tool.create'),
85+
handler: this.createTool
86+
},
87+
'->',
88+
{
89+
xtype: 'textfield',
90+
emptyText: _('modai.admin.tool.search'),
91+
listeners: {
92+
change: {
93+
fn: this.search,
94+
scope: this
95+
},
96+
render: {
97+
fn: function (cmp) {
98+
new Ext.KeyMap(cmp.getEl(), {
99+
key: Ext.EventObject.ENTER,
100+
fn: function () {
101+
this.blur();
102+
return true;
103+
},
104+
scope: cmp
105+
});
106+
},
107+
scope: this
108+
}
109+
}
110+
},
111+
{
112+
xtype: 'modai-combo-extended_boolean',
113+
dataLabel: _('modai.admin.tool.default'),
114+
emptyText: _('modai.admin.tool.default'),
115+
filterName: 'default',
116+
useInt: true,
117+
listeners: {
118+
select: this.filterCombo,
119+
scope: this
120+
}
121+
},
122+
{
123+
xtype: 'modai-combo-extended_boolean',
124+
dataLabel: _('modai.admin.tool.enabled'),
125+
emptyText: _('modai.admin.tool.enabled'),
126+
filterName: 'enabled',
127+
useInt: true,
128+
listeners: {
129+
select: this.filterCombo,
130+
scope: this
131+
}
132+
}
133+
];
134+
},
135+
136+
createTool: function(btn, e) {
137+
modAIAdmin.loadPage('tool/create');
138+
},
139+
140+
updateTool: function (btn, e) {
141+
modAIAdmin.loadPage('tool/update', { id: this.menu.record.id });
142+
},
143+
144+
removeTool: function (btn, e) {
145+
if (!this.menu.record) return false;
146+
147+
MODx.msg.confirm({
148+
title: _('modai.admin.tool.remove'),
149+
text: _('modai.admin.tool.remove_confirm', { name: this.menu.record.name }),
150+
url: this.config.url,
151+
params: {
152+
action: 'modAI\\Processors\\Tools\\Remove',
153+
id: this.menu.record.id
154+
},
155+
listeners: {
156+
success: {
157+
fn: function (r) {
158+
this.refresh();
159+
},
160+
scope: this
161+
}
162+
}
163+
});
164+
165+
return true;
166+
},
167+
168+
filterCombo: function (combo, record) {
169+
const s = this.getStore();
170+
s.baseParams[combo.filterName] = record.data[combo.valueField];
171+
this.getBottomToolbar().changePage(1);
172+
},
173+
174+
search: function (field, value) {
175+
const s = this.getStore();
176+
s.baseParams.search = value;
177+
this.getBottomToolbar().changePage(1);
178+
}
179+
});
180+
Ext.reg('modai-grid-tools', modAIAdmin.grid.Tools);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
modAIAdmin.page.Tool = function (config) {
2+
config = config || {};
3+
4+
config.isUpdate = (MODx.request.id) ? true : false;
5+
6+
Ext.applyIf(config, {
7+
formpanel: 'modai-panel-tool',
8+
buttons: [
9+
{
10+
text: _('save'),
11+
method: 'remote',
12+
cls:'primary-button',
13+
process: config.isUpdate ? 'modAI\\Processors\\Tools\\Update' : 'modAI\\Processors\\Tools\\Create',
14+
keys: [
15+
{
16+
key: MODx.config.keymap_save || 's',
17+
ctrl: true
18+
}
19+
]
20+
},
21+
{
22+
text: _('cancel'),
23+
params: {
24+
a: 'home',
25+
namespace: 'modai'
26+
}
27+
}
28+
],
29+
components: [
30+
{
31+
xtype: 'modai-panel-tool',
32+
isUpdate: config.isUpdate,
33+
record: config.record || {},
34+
}
35+
]
36+
});
37+
modAIAdmin.page.Tool.superclass.constructor.call(this, config);
38+
};
39+
Ext.extend(modAIAdmin.page.Tool, MODx.Component);
40+
Ext.reg('modai-page-tool', modAIAdmin.page.Tool);

0 commit comments

Comments
 (0)