Skip to content

Commit

Permalink
Много рефакторинга по админке, все датагриды (таблицы данных в админк…
Browse files Browse the repository at this point in the history
…е) переведены на единую точку обслуживания, вывод на vueJS.
  • Loading branch information
fuzegit committed Apr 17, 2023
1 parent fbeebde commit aa7c54d
Show file tree
Hide file tree
Showing 177 changed files with 21,189 additions and 8,170 deletions.
4 changes: 4 additions & 0 deletions credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Third-party plugins, libraries and resources included in InstantCMS:
by Twitter, Inc
https://getbootstrap.com

VueJS
by TEvan You && Core Team
https://vuejs.org/

Font Awesome Free
by Fonticons, Inc.
https://fontawesome.com
Expand Down
5 changes: 4 additions & 1 deletion install/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ function get_templates() {
continue;
}

$list[$dir . '/' . $next] = $next;
// не даём выбрать устаревший шаблон
if($next !== 'default'){
$list[$dir . '/' . $next] = $next;
}
}

return $list;
Expand Down
1 change: 0 additions & 1 deletion install/languages/en/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA
(151, 'images_before_upload', 'typograph', 151, 1),
(152, 'engine_start', 'content', 152, 1),
(153, 'content_category_after_update', 'subscriptions', 153, 1),
(154, 'grid_admin_content_items_args', 'admin', 154, 1),
(155, 'user_notify_types', 'rating', 155, 1),
(156, 'content_before_item', 'comments', 156, 1),
(157, 'content_before_item', 'rating', 157, 1),
Expand Down
1 change: 0 additions & 1 deletion install/languages/ru/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,6 @@ INSERT INTO `{#}events` (`id`, `event`, `listener`, `ordering`, `is_enabled`) VA
(151, 'images_before_upload', 'typograph', 151, 1),
(152, 'engine_start', 'content', 152, 1),
(153, 'content_category_after_update', 'subscriptions', 153, 1),
(154, 'grid_admin_content_items_args', 'admin', 154, 1),
(155, 'user_notify_types', 'rating', 155, 1),
(156, 'content_before_item', 'comments', 156, 1),
(157, 'content_before_item', 'rating', 157, 1),
Expand Down
6 changes: 1 addition & 5 deletions system/controllers/activity/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ public function __construct(cmsRequest $request) {
});
}

public function actionIndex() {
$this->redirectToAction('options');
}

public function getBackendMenu() {
return [
[
'title' => LANG_OPTIONS,
'url' => href_to($this->root_url, 'options'),
'url' => href_to($this->root_url),
'options' => [
'icon' => 'cog'
]
Expand Down
10 changes: 4 additions & 6 deletions system/controllers/activity/backend/grids/grid_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ function grid_types($controller) {
'title' => LANG_EVENTS_LISTENER,
'width' => 200,
'class' => 'd-none d-lg-table-cell',
'filter' => 'like',
'filter' => 'exact',
'filter_select' => [
'items' => function($name){
$admin_model = cmsCore::getModel('admin');
$admin_model->join('activity_types', 'e', 'e.controller = i.name');
$controllers = $admin_model->groupBy('i.id')->getInstalledControllers();
$items = ['' => ''];
$items = ['' => LANG_ALL];
foreach($controllers as $controller){
$items[$controller['name']] = $controller['title'];
}
Expand Down Expand Up @@ -57,7 +57,7 @@ function grid_types($controller) {
$columns[$name] = [
'title' => LANG_ACTIVITY_DESC.' ['.$lang.']',
'editable' => [
'save_action' => href_to('admin', 'inline_save', [urlencode('activity_types'), '{id}', 1])
'language_context' => true
]
];
}
Expand All @@ -66,9 +66,7 @@ function grid_types($controller) {

$columns['description'] = [
'title' => LANG_ACTIVITY_DESC,
'editable' => [
'table' => 'activity_types'
]
'editable' => []
];
}

Expand Down
209 changes: 161 additions & 48 deletions system/controllers/admin/actions/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,190 @@
*/
class actionAdminContent extends cmsAction {

public function run($do = false) {

$ctype_id = 0;
$ctype = [];

// если нужно, передаем управление другому экшену
if ($do) {
if (!is_numeric($do)) {
$this->runExternalAction('content_' . $do, array_slice($this->params, 1));
return;
} else {
$ctype_id = $do;
}
}
use icms\traits\oneable;

$ctypes = $this->model_backend_content->getContentTypesFiltered();
use icms\traits\controllers\actions\listgrid {
getListItemsGridHtml as private traitGetListItemsGridHtml;
}

$key_path = '/1.1';
private $ctype = [];

// Сохранённый путь дерева
$tree_path = cmsUser::getCookie('content_tree_path');
private $tree_path_key = '';

if ($tree_path) {
$tree_path = explode('/', trim($tree_path, '/'));
private $category_id = 1;

public function __construct($controller, $params = []) {

parent::__construct($controller, $params);

$this->external_action_prefix = 'content_';

$this->toolbar_hook = 'admin_content_toolbar';
}

public function prepareRun() {

$this->loadCtype(($this->params[0] ?? 0), ($this->params[1] ?? false));

$category = $this->model_backend_content->getCategory($this->ctype['name'], $this->category_id);
if (!$category) {
return cmsCore::error404();
}

// Если $ctype_id передан, формируем $key_path
if ($ctype_id) {
$this->table_name = $this->model->getContentTypeTableName($this->ctype['name']);
$this->grid_name = 'content_items';
$this->grid_args = [$this->ctype];
$this->ups_key = $this->ctype['name'].'.';

$this->tool_buttons = [
[
'class' => 'menu d-xl-none',
'data' => [
'toggle' =>'quickview',
'toggle-element' => '#left-quickview'
],
'title' => LANG_MENU
],
[
'class' => 'settings',
'title' => LANG_CONFIG,
'href' => null
],
[
'class' => 'logs',
'title' => LANG_MODERATION_LOGS,
'href' => null
],
[
'class' => 'folder',
'childs_count' => 4,
'title' => LANG_CATEGORIES
],
[
'class' => 'add_folder',
'level' => 2,
'title' => LANG_CP_CONTENT_CATS_ADD
],
[
'class' => 'edit_folder',
'level' => 2,
'title' => LANG_EDIT
],
[
'class' => 'delete_folder',
'level' => 2,
'title' => LANG_DELETE_CATEGORY,
'confirm' => LANG_DELETE_CATEGORY_CONFIRM
],
[
'class' => 'tree_folder',
'level' => 2,
'title' => LANG_CP_CONTENT_CATS_ORDER,
'onclick' => 'return contentCatsReorder($(this))'
],
[
'class' => 'add add_site',
'title' => LANG_CP_CONTENT_ITEM_ADD
],
[
'class' => 'add add_cpanel',
'title' => LANG_CP_CONTENT_ITEM_ADD_CP
]
];

$this->list_callback = function ($model) use($category) {

$model->filterCategory($this->ctype['name'], $category, true, !empty($this->ctype['options']['is_cats_multi']));

$model->joinUser();

$model->joinLeft(
'moderators_logs',
'mlog',
"mlog.target_id = i.id AND mlog.target_controller = 'content' AND mlog.target_subject = '{$this->ctype['name']}' AND mlog.date_expired IS NOT NULL"
);
$model->select('mlog.date_expired', 'trash_date_expired');

$model->joinModerationsTasks($this->ctype['name']);

return $model;
};
}

$key_path = '/' . $ctype_id . '.1';
public function getListItemsGridHtml() {

// дополняем его категориями, если в куках этот тип контента
if ($tree_path && '/' . $tree_path[0] === $key_path) {
$key_path = '/' . implode('/', $tree_path);
}
} else {
$ctypes = $this->getOnce($this->model_backend_content)->getContentTypesFiltered();

// Иначе, берём id типа контента из кук и формируем $key_path
if ($tree_path) {
$grid_html = $this->traitGetListItemsGridHtml();

$ctype_id = (int) $tree_path[0];
return $this->cms_template->renderInternal($this, 'content', [
'key_path' => $this->tree_path_key,
'ctype' => $this->ctype,
'ctypes' => $ctypes,
'grid_html' => $grid_html
]);
}

$key_path = '/' . implode('/', $tree_path);
}
private function loadCtype($ctype_id, $category_id) {

if ($category_id !== false) {
$this->category_id = $category_id;
}

// Если передан из урл
if ($ctype_id) {

$ctype = $this->model_backend_content->getContentType($ctype_id);
$this->ctype = $this->model_backend_content->getContentType($ctype_id);

if (!$ctype && $do) {
if (!$this->ctype) {
return cmsCore::error404();
}
}

if (!empty($ctype)) {
$grid = $this->loadDataGrid('content_items', $ctype['name'], 'admin.grid_filter.content.' . $ctype['name']);
} else {
$grid = $this->loadDataGrid('content_items');
// Сохранённый путь дерева
$tree_path = cmsUser::getCookie('content_tree_path');

if ($tree_path) {

$tree_path = ltrim($tree_path, '/');

if (preg_match('/^([0-9\/\.]+)$/i', $tree_path)) {

$this->tree_path_key = $tree_path;

$tree_keys = explode('/', $tree_path);

$tree_key = explode('.', end($tree_keys));

$ctype_id = (int)($tree_key[0] ?? 0);

// если не передан из урла, берём из куки
if (!$this->ctype) {
$this->ctype = $this->model_backend_content->getContentType($ctype_id);
}

if ($this->ctype) {

if ($category_id === false) {
$this->category_id = (int)($tree_key[1] ?? $this->category_id);
}

return;
}
}
}

$diff_order = cmsUser::getUPS('admin.grid_filter.content.diff_order');
// Иначе первый из списка
if (!$this->ctype) {

return $this->cms_template->render('content', [
'key_path' => $key_path,
'ctype' => $ctype,
'ctype_id' => $ctype_id,
'ctypes' => $ctypes,
'grid' => $grid,
'diff_order' => $diff_order
]);
$ctypes = $this->getOnce($this->model_backend_content)->getContentTypesFiltered();

$this->ctype = reset($ctypes);

$this->tree_path_key = $this->ctype['id'].'.'.$this->category_id;
}

return;
}

}
17 changes: 8 additions & 9 deletions system/controllers/admin/actions/content_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ public function run($ctype_id) {
return cmsCore::error404();
}

$datasets = $this->model_backend_content->getContentDatasets($ctype_id);

$fields = $this->model_backend_content->getContentFields($ctype['name']);

$fields = cmsEventsManager::hook('ctype_content_fields', $fields);
Expand Down Expand Up @@ -41,16 +39,17 @@ public function run($ctype_id) {
];
}

$fields[] = [
'title' => LANG_CP_SHOW_ONLY_IN_TRASH,
'name' => 'is_deleted',
'handler' => new fieldCheckbox('is_deleted')
];

list($fields, $ctype) = cmsEventsManager::hook('admin_content_filter', [$fields, $ctype]);
list($fields, $ctype) = cmsEventsManager::hook('admin_content_' . $ctype['name'] . '_filter', [$fields, $ctype]);

$diff_order = cmsUser::getUPS('admin.grid_filter.content.diff_order');

return $this->cms_template->render('content_filter', [
'ctype' => $ctype,
'datasets' => $datasets,
'fields' => $fields,
'diff_order' => $diff_order
return $this->cms_template->render('grid_advanced_filter', [
'fields' => $fields
]);
}

Expand Down

0 comments on commit aa7c54d

Please sign in to comment.