Skip to content

Commit 23cc847

Browse files
committed
feat: Init the project
0 parents  commit 23cc847

File tree

17 files changed

+454
-0
lines changed

17 files changed

+454
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
core/components/modai/vendor

_build/gpm.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: modAI
2+
version: 1.0.0-pl
3+
lowCaseName: modai
4+
namespace: modAI
5+
author: 'John Peca'
6+
plugins:
7+
- name: modAI
8+
file: modai.php
9+
events:
10+
- OnManagerPageBeforeRender
11+
systemSettings:
12+
- key: chatgpt.key
13+
type: text-password
14+
area: chatgpt
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Styling for the magic wand emoji icon */
2+
#autosummary-wand {
3+
font-size: 24px; /* Adjust font size as needed */
4+
cursor: pointer;
5+
margin-left: 5px;
6+
vertical-align: middle;
7+
transition: transform 0.2s ease;
8+
}
9+
10+
/* Hover effect for the wand icon */
11+
#autosummary-wand:hover {
12+
transform: rotate(20deg);
13+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Ext.onReady(function() {
2+
3+
Ext.defer(function() {
4+
5+
const labelEl = Ext.select('label[for="modx-resource-introtext"]').first();
6+
if (!labelEl) {
7+
return;
8+
}
9+
10+
const introText = Ext.getCmp('modx-resource-introtext');
11+
if (!introText) return;
12+
13+
const wandEl = document.createElement('span');
14+
wandEl.style.cursor = 'pointer';
15+
wandEl.style.marginLeft = '5px';
16+
wandEl.style.verticalAlign = 'middle';
17+
wandEl.style.fontSize = '24px';
18+
wandEl.innerText = '🪄'
19+
20+
introText.label.appendChild(wandEl);
21+
22+
wandEl.addEventListener('click', () => {
23+
Ext.Msg.wait('Generating summary...', 'Please wait');
24+
25+
MODx.Ajax.request({
26+
url: MODx.config.connector_url,
27+
params: {
28+
action: 'modAI\\Processors\\Prompt\\Summarize',
29+
id: MODx.request.id
30+
},
31+
listeners: {
32+
success: {
33+
fn: (r) => {
34+
introText.setValue(r.object.summary);
35+
Ext.Msg.hide();
36+
37+
}
38+
},
39+
failure: {
40+
fn: function() {
41+
console.log('fail');
42+
} ,
43+
scope: this
44+
}
45+
}
46+
});
47+
});
48+
}, 500);
49+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var ModAI = function (config) {
2+
config = config || {};
3+
ModAI.superclass.constructor.call(this, config);
4+
};
5+
Ext.extend(ModAI, Ext.Component, {
6+
7+
page: {},
8+
window: {},
9+
grid: {},
10+
tree: {},
11+
panel: {},
12+
combo: {},
13+
field: {},
14+
config: {},
15+
16+
});
17+
Ext.reg('modai', ModAI);
18+
modAI = new ModAI();

config.core.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
define('MODX_CORE_PATH', '/var/www/html/modx/core/');
3+
define('MODX_CONFIG_KEY', 'config');
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* @var \MODX\Revolution\modX $modx
4+
* @var array $namespace
5+
*/
6+
7+
// Include autoloader generated by your composer
8+
require_once $namespace['path'] . 'vendor/autoload.php';
9+
10+
if (!$modx->services->has('modai')) {
11+
// Register base class in the service container
12+
$modx->services->add('modai', function($c) use ($modx) {
13+
return new \modAI\modAI($modx);
14+
});
15+
16+
// Load packages model, uncomment if you have DB tables
17+
//$modx->addPackage('Modgpt\Model', $namespace['path'] . 'src/', null, 'Modgpt\\');
18+
}
19+
20+
// More about this file: https://docs.modx.com/3.x/en/extending-modx/namespaces#bootstrapping-services
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"modAI\\": "src/"
5+
}
6+
}
7+
}

core/components/modai/composer.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
require_once dirname(dirname(__FILE__)) . '/index.class.php';
3+
4+
class modAIManageManagerController extends modAIBaseManagerController
5+
{
6+
7+
public function process(array $scriptProperties = []): void
8+
{
9+
}
10+
11+
public function getPageTitle(): string
12+
{
13+
return $this->modx->lexicon('modgpt');
14+
}
15+
16+
public function loadCustomCssJs(): void
17+
{
18+
$this->addLastJavascript($this->modgpt->getOption('jsUrl') . 'mgr/widgets/manage.panel.js');
19+
$this->addLastJavascript($this->modgpt->getOption('jsUrl') . 'mgr/sections/manage.js');
20+
21+
$this->addHtml(
22+
'
23+
<script type="text/javascript">
24+
Ext.onReady(function() {
25+
MODx.load({ xtype: "modgpt-page-manage"});
26+
});
27+
</script>
28+
'
29+
);
30+
}
31+
32+
public function getTemplateFile(): string
33+
{
34+
return $this->modgpt->getOption('templatesPath') . 'manage.tpl';
35+
}
36+
37+
}

0 commit comments

Comments
 (0)