Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Новый раздел с утилитами. Обновление превью изображений #868

Merged
merged 3 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions _build/data/transport.menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
'menuindex' => 3,
'action' => 'mgr/help',
],
'ms2_utilites' => [
'description' => 'ms2_utilites_desc',
'parent' => 'minishop2',
'menuindex' => 4,
'action' => 'mgr/utilites',
],
];

foreach ($tmp as $k => $v) {
Expand Down
36 changes: 36 additions & 0 deletions assets/components/minishop2/css/mgr/utilites/gallery.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ms-utility-gallery-range_outer{
position: relative;
padding: 20px 0 0;
visibility: hidden;
}

.ms-utility-gallery-labels{
position: absolute;
top: 0;
right: 0;
left: 0;

font-weight: bold;
}

#ms-utility-gallery-iteration{
position: absolute;
top: 0;
right: 0;
}

#ms-utility-gallery-progress{
position: relative;
height: 5px;
background-color: #ddd;
}

#ms-utility-gallery-progress-bar{
position: absolute;
top: 0;
left: 0;

height: 100%;

background-color: #32AB9A;
}
135 changes: 135 additions & 0 deletions assets/components/minishop2/js/mgr/utilites/gallery/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
miniShop2.panel.UtilitesGallery = function (config) {
config = config || {};

Ext.apply(config, {
cls: 'container form-with-labels',
autoHeight: true,
url: miniShop2.config.connector_url,
saveMsg: _('ms2_utilites_gallery_updating'),

progress:true,
baseParams: {
action: 'mgr/utilites/gallery/update'
},
items: [{
layout: 'form',
cls: 'main-wrapper',
labelWidth: 200,
labelAlign: 'left',
border: false,
buttonAlign: 'left',
style: 'padding: 0 0 0 7px',
items: [
{
html: String.format(
_('ms2_utilites_gallery_information'),
miniShop2.config.utility_gallery_source_name,
miniShop2.config.utility_gallery_source_id,
miniShop2.config.utility_gallery_total_products,
miniShop2.config.utility_gallery_total_products_files
),
},
{
xtype: 'fieldset',
title: _('ms2_utilites_params'),
id: 'ms2-utilites-gallery-params',
cls: 'x-fieldset-checkbox-toggle',
style: 'margin: 5px 0 15px ',
collapsible: true,
collapsed: true,
stateful: true,
labelAlign: 'top',
stateEvents: ['collapse', 'expand'],
items: [
{
html: miniShop2.config.utility_gallery_thumbnails
},
]
},
{
name: 'limit',
xtype: 'numberfield',
value: 10,
width: 80,
fieldLabel: _('ms2_utilites_gallery_for_step')
},
{
name: 'offset',
xtype: 'numberfield',
value: 0,
hidden: true,
},
{
xtype: 'button',
style: 'margin: 15px 0 0 2px',
text: '<i class="icon icon-refresh"></i> &nbsp;' + _('ms2_utilites_gallery_refresh'),
handler: function() {
var form = this.getForm();
form.setValues({
offset: 0
});
this.submit(this);
}, scope: this
},
{
style: 'padding: 15px 0',
html: '\
<div id="ms-utility-gallery-range_outer">\
<div class="ms-utility-gallery-labels"><span id="ms-utility-gallery-label">0%</span><span id="ms-utility-gallery-iteration"></span></div>\
<div id="ms-utility-gallery-progress"><span id="ms-utility-gallery-progress-bar"></span></div>\
</div>\
'
}
]
}],
listeners: {
success: {fn: function(response) {
var data = response.result.object;
var form = this.getForm();
this.updateProgress(data);

if (!data.done) {
form.setValues({
offset: Number(data.offset)
});
this.submit(this);
}
else {
MODx.msg.status({
title: _('ms2_utilites_gallery_done'),
message: _('ms2_utilites_gallery_done_message'),
delay: 5
});
}
},scope: this}
}
});
miniShop2.panel.UtilitesGallery.superclass.constructor.call(this, config);
};

Ext.extend(miniShop2.panel.UtilitesGallery, MODx.FormPanel,{

updateProgress: function (data) {
const progressblock = document.getElementById('ms-utility-gallery-range_outer');
const progresslabel = document.getElementById('ms-utility-gallery-label');
const progressbar = document.getElementById('ms-utility-gallery-progress-bar');
const progressiteration = document.getElementById('ms-utility-gallery-iteration');
progressblock.style.visibility = 'visible';

if(data.done) {
progresslabel.innerHTML = '100%';
progressbar.style.width = '100%';
progressiteration.style.visibility = 'hidden';
} else {
let progress = (parseFloat((data.offset/data.total) * 100)).toFixed(2);
progresslabel.innerHTML = progress + '%';
progressbar.style.width = progress + '%';

// count iterations
const totalIterations = Math.ceil(data.total/data.limit);
const currentIteration = data.offset/data.limit;
progressiteration.innerHTML = currentIteration + "/" + totalIterations;
}
}
});
Ext.reg('minishop2-utilites-gallery', miniShop2.panel.UtilitesGallery);
51 changes: 51 additions & 0 deletions assets/components/minishop2/js/mgr/utilites/panel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
miniShop2.panel.Utilites = function (config) {
config = config || {};
Ext.apply(config, {
cls: 'container',
items: [{
html: '<h2>' + _('minishop2') + ' :: ' + _('ms2_utilites') + '</h2>',
cls: 'modx-page-header',
}, {
xtype: 'modx-tabs',
id: 'minishop2-utilites-tabs',
stateful: true,
stateId: 'minishop2-utilites-tabs',
stateEvents: ['tabchange'],
cls: 'minishop2-panel',
getState: function () {
return {
activeTab: this.items.indexOf(this.getActiveTab())
};
},
items: [{
title: _('ms2_utilites_gallery'),
layout: 'anchor',
items: [{
html: _('ms2_utilites_gallery_intro'),
bodyCssClass: 'panel-desc',
}, {
xtype: 'minishop2-utilites-gallery',
cls: 'main-wrapper',
}]
},
/*
// todo
{
title: _('ms2_utilites_import'),
layout: 'anchor',
items: [{
html: _('ms2_utilites_import_intro'),
bodyCssClass: 'panel-desc',
}, {
xtype: 'minishop2-utilites-import',
cls: 'main-wrapper',
}]
}*/
]
}]

});
miniShop2.panel.Utilites.superclass.constructor.call(this, config);
};
Ext.extend(miniShop2.panel.Utilites, MODx.Panel);
Ext.reg('minishop2-utilites', miniShop2.panel.Utilites);
67 changes: 67 additions & 0 deletions core/components/minishop2/controllers/mgr/utilites.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

if (!class_exists('msManagerController')) {
require_once dirname(__FILE__, 2) . '/manager.class.php';
}

class Minishop2MgrUtilitesManagerController extends msManagerController
{
/**
* @return string
*/
public function getPageTitle()
{
return $this->modx->lexicon('ms2_utilites') . ' | miniShop2';
}

/**
* @return array
*/
public function getLanguageTopics()
{
return ['minishop2:default', 'minishop2:product', 'minishop2:manager'];
}

/**
*
*/
public function loadCustomCssJs()
{

$this->addCss($this->miniShop2->config['cssUrl'] . 'mgr/utilites/gallery.css');

$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/minishop2.js');
$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/utilites/panel.js');
$this->addJavascript($this->miniShop2->config['jsUrl'] . 'mgr/utilites/gallery/panel.js');

$config = $this->miniShop2->config;

// get source properties
$productSource = $this->getOption('ms2_product_source_default', null, 1);
if ($source = $this->modx->getObject('modMediaSource', $productSource)) {
$config['utility_gallery_source_id'] = $productSource;
$config['utility_gallery_source_name'] = $source->get('name');

$properties = $source->get('properties');
$propertiesString = '';
foreach (json_decode($properties['thumbnails']['value'], true) as $key => $value) {
$propertiesString .= "<strong>$key: </strong>" . json_encode($value) . "<br>";
}
$config['utility_gallery_thumbnails'] = $propertiesString;
}

// get information about products and files
$config['utility_gallery_total_products'] = $this->modx->getCount('msProduct', ['class_key' => 'msProduct']);
$config['utility_gallery_total_products_files'] = $this->modx->getCount('msProductFile', ['parent' => 0]);

$this->addHtml(
'<script>
miniShop2.config = ' . json_encode($config) . ';

Ext.onReady(function() {
MODx.add({xtype: "minishop2-utilites"});
});
</script>'
);
}
}
2 changes: 2 additions & 0 deletions core/components/minishop2/lexicon/ru/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,7 @@
$_lang['ms2_system_settings'] = 'Системные настройки';
$_lang['ms2_system_settings_desc'] = 'Системные настройки miniShop2';
$_lang['ms2_type'] = 'Тип';
$_lang['ms2_utilites'] = 'Утилиты';
$_lang['ms2_utilites_desc'] = 'Инструменты разработчика';
$_lang['ms2_vendors'] = 'Производители товаров';
$_lang['ms2_vendors_intro'] = 'Список возможных производителей товаров. То, что вы сюда добавите, можно выбрать в поле "vendor" товара.';
10 changes: 10 additions & 0 deletions core/components/minishop2/lexicon/ru/manager.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@
$_lang['ms2_updatedon'] = 'Дата изменения';
$_lang['ms2_user'] = 'Пользователь';
$_lang['ms2_username'] = 'Логин';
$_lang['ms2_utilites_gallery'] = 'Галерея';
$_lang['ms2_utilites_gallery_done'] = 'Завершено';
$_lang['ms2_utilites_gallery_done_message'] = 'Обновление превью изображений успешно завершено.';
$_lang['ms2_utilites_gallery_err_noproducts'] = 'В каталоге нет товаров';
$_lang['ms2_utilites_gallery_for_step'] = 'Обработать товаров за 1 шаг';
$_lang['ms2_utilites_gallery_information'] = 'Выбранный источник файлов: <strong>{0}</strong> <a href="?a=source/update&id={1}" target="_blank"><i class="icon icon-cog"></i></a><br>Всего товаров: <strong>{2} шт.</strong> <br> Изображений: <strong>{3} шт.</strong> ';
$_lang['ms2_utilites_gallery_intro'] = 'Обновление всех изображений товаров согласно указанным параметрам. <br>Данная операция является трудозатратной, поэтому не указывайте большое число для одной итерации.';
$_lang['ms2_utilites_gallery_refresh'] = 'Обновить';
$_lang['ms2_utilites_gallery_updating'] = 'Обновлению превью';
$_lang['ms2_utilites_params'] = 'Параметры ';
$_lang['ms2_weight'] = 'Вес';
$_lang['ms2_weight_price'] = 'Стоимость ед/вес';
$_lang['ms2_weight_price_help'] = 'Добавочная стоимость доставки за единицу веса. <br>Может быть использовано в кастомных классах.';