Skip to content

Commit 6de9736

Browse files
authored
Merge pull request #48 from modx-pro/dev/notifications
Реализован центр уведомлений
2 parents 8e8b146 + ea299dc commit 6de9736

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4106
-618
lines changed

_build/config.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'name_lower' => 'minishop3',
1414
'name_short' => 'ms3',
1515
'version' => '1.0.0',
16-
'release' => 'alpha.2',
16+
'release' => 'alpha.3',
1717
// Install package to site right after build
1818
'install' => false,
1919
// Which elements should be updated on package upgrade

_build/elements/events.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@
6161
'msOnVendorUpdate',
6262
'msOnBeforeVendorDelete',
6363
'msOnVendorDelete',
64+
// Notification events
65+
'msOnBeforeSendNotification',
66+
'msOnAfterSendNotification',
67+
'msOnRegisterNotificationChannels',
6468
];

_build/elements/menus.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@
1818
'menuindex' => 0,
1919
'action' => 'mgr/customers',
2020
],
21+
'ms3_notifications' => [
22+
'description' => 'ms3_notifications_desc',
23+
'parent' => 'miniShop3',
24+
'menuindex' => 1,
25+
'action' => 'mgr/notifications',
26+
],
2127
'ms3_settings' => [
2228
'description' => 'ms3_settings_desc',
2329
'parent' => 'miniShop3',
24-
'menuindex' => 1,
30+
'menuindex' => 2,
2531
'action' => 'mgr/settings',
2632
],
2733
'ms3_system_settings' => [
2834
'description' => 'ms3_system_settings_desc',
2935
'parent' => 'miniShop3',
30-
'menuindex' => 2,
36+
'menuindex' => 3,
3137
'namespace' => 'core',
3238
'permissions' => 'settings',
3339
'action' => 'system/settings',
@@ -36,13 +42,13 @@
3642
'ms3_help' => [
3743
'description' => 'ms3_help_desc',
3844
'parent' => 'miniShop3',
39-
'menuindex' => 3,
45+
'menuindex' => 4,
4046
'action' => 'mgr/help',
4147
],
4248
'ms3_utilities' => [
4349
'description' => 'ms3_utilities_desc',
4450
'parent' => 'miniShop3',
45-
'menuindex' => 4,
51+
'menuindex' => 5,
4652
'action' => 'mgr/utilities',
4753
],
4854
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* HTML wrapper для Vue приложения Notification Center
3+
*
4+
* Создает контейнер для монтирования Vue приложения
5+
*/
6+
7+
// Создаем простой компонент для MODX
8+
Ext.reg('ms3-notifications-vue-wrapper', Ext.extend(Ext.Component, {
9+
initComponent: function() {
10+
Ext.apply(this, {
11+
html: '<div id="ms3-notifications-vue-wrapper" class="vueApp" style="padding: 20px; height: 100%;"></div>'
12+
});
13+
14+
this.constructor.superclass.initComponent.call(this);
15+
}
16+
}));

assets/components/minishop3/js/mgr/settings/status/grid.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ Ext.extend(ms3.grid.Status, ms3.grid.Default, {
2424

2525
getFields: function () {
2626
return [
27-
'id', 'name', 'description', 'color', 'email_user', 'email_manager',
28-
'subject_user', 'subject_manager', 'body_user', 'body_manager', 'active',
27+
'id', 'name', 'description', 'color', 'active',
2928
'final', 'fixed', 'position', 'editable', 'actions'
3029
];
3130
},
@@ -34,8 +33,6 @@ Ext.extend(ms3.grid.Status, ms3.grid.Default, {
3433
return [
3534
{header: _('ms3_id'), dataIndex: 'id', width: 30},
3635
{header: _('ms3_name'), dataIndex: 'name', width: 50, renderer: ms3.utils.renderBadge},
37-
{header: _('ms3_email_user'), dataIndex: 'email_user', width: 50, renderer: this._renderBoolean},
38-
{header: _('ms3_email_manager'), dataIndex: 'email_manager', width: 50, renderer: this._renderBoolean},
3936
{header: _('ms3_status_final'), dataIndex: 'final', width: 50, renderer: this._renderBoolean},
4037
{header: _('ms3_status_fixed'), dataIndex: 'fixed', width: 50, renderer: this._renderBoolean},
4138
{header: _('ms3_rank'), dataIndex: 'position', width: 35, hidden: true},

assets/components/minishop3/js/mgr/settings/status/window.js

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -35,75 +35,6 @@ Ext.extend(ms3.window.CreateStatus, ms3.window.Default, {
3535
}
3636
}
3737
},
38-
}, {
39-
layout: 'column',
40-
items: [{
41-
columnWidth: .5,
42-
layout: 'form',
43-
items: [{
44-
xtype: 'xcheckbox',
45-
id: config.id + '-email-user',
46-
boxLabel: _('ms3_email_user'),
47-
name: 'email_user',
48-
listeners: {
49-
check: {
50-
fn: function (checkbox) {
51-
this.handleStatusFields(checkbox);
52-
}, scope: this
53-
},
54-
afterrender: {
55-
fn: function (checkbox) {
56-
this.handleStatusFields(checkbox);
57-
}, scope: this
58-
}
59-
},
60-
}, {
61-
xtype: 'textfield',
62-
id: config.id + '-subject-user',
63-
fieldLabel: _('ms3_subject_user'),
64-
name: 'subject_user',
65-
anchor: '99%'
66-
}, {
67-
xtype: 'textfield',
68-
fieldLabel: _('ms3_body_user'),
69-
name: 'body_user',
70-
id: config.id + '-body-user',
71-
anchor: '99%'
72-
}],
73-
}, {
74-
columnWidth: .5,
75-
layout: 'form',
76-
items: [{
77-
xtype: 'xcheckbox',
78-
id: config.id + '-email-manager',
79-
boxLabel: _('ms3_email_manager'),
80-
name: 'email_manager',
81-
listeners: {
82-
check: {
83-
fn: function (checkbox) {
84-
this.handleStatusFields(checkbox);
85-
}, scope: this
86-
},
87-
afterrender: {
88-
fn: function (checkbox) {
89-
this.handleStatusFields(checkbox);
90-
}, scope: this
91-
}
92-
},
93-
}, {
94-
xtype: 'textfield',
95-
id: config.id + '-subject-manager',
96-
fieldLabel: _('ms3_subject_manager'),
97-
name: 'subject_manager',
98-
anchor: '99%'
99-
}, {
100-
xtype: 'textfield',
101-
id: config.id + '-body-manager',
102-
fieldLabel: _('ms3_body_manager'),
103-
name: 'body_manager',
104-
anchor: '99%'
105-
}],
106-
}]
10738
}, {
10839
xtype: 'textarea',
10940
id: config.id + '-description',
@@ -139,20 +70,6 @@ Ext.extend(ms3.window.CreateStatus, ms3.window.Default, {
13970
];
14071
},
14172

142-
handleStatusFields: function (checkbox) {
143-
const type = checkbox.name.replace(/(^.*?_)/, '');
144-
145-
const subject = Ext.getCmp(this.config.id + '-subject-' + type);
146-
const body = Ext.getCmp(this.config.id + '-body-' + type);
147-
if (checkbox.checked) {
148-
subject.enable().show();
149-
body.enable().show();
150-
} else {
151-
subject.hide().disable();
152-
body.hide().disable();
153-
}
154-
},
155-
15673
});
15774
Ext.reg('ms3-window-status-create', ms3.window.CreateStatus);
15875

core/components/minishop3/config/routes/manager.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,60 @@
463463
new PermissionMiddleware($modx, 'view_document') // TODO: создать специфичное право ms3_grid_config_manage
464464
]);
465465

466+
// ============================================
467+
// NOTIFICATIONS API (Центр уведомлений)
468+
// ============================================
469+
$router->group('/notifications', function($router) use ($modx) {
470+
471+
// GET /api/mgr/notifications/references - получить справочники для формы
472+
$router->get('/references', function($params) use ($modx) {
473+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
474+
return $controller->getReferences();
475+
});
476+
477+
// GET /api/mgr/notifications - получить список настроек уведомлений
478+
$router->get('', function($params) use ($modx) {
479+
$allParams = array_merge($_GET, $params);
480+
481+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
482+
return $controller->getList($allParams);
483+
});
484+
485+
// GET /api/mgr/notifications/{id} - получить конкретную настройку
486+
$router->get('/{id}', function($params) use ($modx) {
487+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
488+
return $controller->get($params);
489+
});
490+
491+
// POST /api/mgr/notifications - создать новую настройку
492+
$router->post('', function($params) use ($modx) {
493+
$input = file_get_contents('php://input');
494+
$data = json_decode($input, true) ?: [];
495+
496+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
497+
return $controller->create($data);
498+
});
499+
500+
// PUT /api/mgr/notifications/{id} - обновить настройку
501+
$router->put('/{id}', function($params) use ($modx) {
502+
$input = file_get_contents('php://input');
503+
$data = json_decode($input, true) ?: [];
504+
$data['id'] = $params['id'] ?? null;
505+
506+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
507+
return $controller->update($data);
508+
});
509+
510+
// DELETE /api/mgr/notifications/{id} - удалить настройку
511+
$router->delete('/{id}', function($params) use ($modx) {
512+
$controller = new \MiniShop3\Controllers\Api\Manager\NotificationsController($modx);
513+
return $controller->delete($params);
514+
});
515+
516+
}, [
517+
new PermissionMiddleware($modx, 'mssetting_save') // Требуется право на управление настройками
518+
]);
519+
466520
}, [
467521
// Middleware для всей группы /api/mgr
468522
new AuthMiddleware($modx, 'mgr')
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
if (!class_exists('msManagerController')) {
4+
require_once dirname(__FILE__, 2) . '/manager.class.php';
5+
}
6+
7+
class MiniShop3MgrNotificationsManagerController extends msManagerController
8+
{
9+
/**
10+
* @return string
11+
*/
12+
public function getPageTitle()
13+
{
14+
return $this->modx->lexicon('ms3_notifications') . ' | MiniShop3';
15+
}
16+
17+
18+
/**
19+
* @return array
20+
*/
21+
public function getLanguageTopics()
22+
{
23+
return array('minishop3:default', 'minishop3:notifications', 'minishop3:manager', 'minishop3:vue');
24+
}
25+
26+
27+
/**
28+
*
29+
*/
30+
public function loadCustomCssJs()
31+
{
32+
$this->addCss($this->ms3->config['cssUrl'] . 'mgr/bootstrap.buttons.css');
33+
$this->addCss($this->ms3->config['cssUrl'] . 'mgr/main.css');
34+
$this->addJavascript($this->ms3->config['jsUrl'] . 'mgr/minishop3.js');
35+
36+
// Wrapper для монтирования Vue вместо ExtJS
37+
$this->addJavascript($this->ms3->config['jsUrl'] . 'mgr/notifications/notifications.wrapper.js');
38+
39+
$config = $this->ms3->config;
40+
41+
// ВАЖНО: Сначала конфигурация, потом Vue модули
42+
$this->addHtml('<script>Object.assign(ms3.config, ' . json_encode($config) . ');</script>');
43+
44+
$this->addHtml(
45+
'<link rel="stylesheet" href="' . $this->ms3->config['assetsUrl'] . 'css/mgr/vue-dist/useLexicon.min.css">
46+
<link rel="stylesheet" href="' . $this->ms3->config['assetsUrl'] . 'css/mgr/vue-dist/notifications.min.css">
47+
<script type="module" src="' . $this->ms3->config['assetsUrl'] . 'js/mgr/vue-dist/notifications.min.js"></script>
48+
<script>
49+
Ext.onReady(function() {
50+
MODx.add({xtype: "ms3-notifications-vue-wrapper"});
51+
});
52+
</script>'
53+
);
54+
55+
$this->modx->invokeEvent('msOnManagerCustomCssJs', array(
56+
'controller' => $this,
57+
'page' => 'notifications',
58+
));
59+
}
60+
}

core/components/minishop3/elements/snippets/ms3_product_options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717

1818
$product = !empty($product) && $product != $modx->resource->id
19-
? $modx->getObject('msProduct', ['id' => $product])
19+
? $modx->getObject(msProduct::class, ['id' => $product])
2020
: $modx->resource;
2121
if (!($product instanceof msProduct)) {
2222
return $modx->lexicon('ms3_err_options_is_not_msproduct', [

core/components/minishop3/elements/tasks/sendEmail.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)