From 58e0e8b22cd58c6c7e75d0c281f6fe5f6eed14d8 Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Wed, 14 Jul 2021 10:49:42 +0300 Subject: [PATCH] Add enable debug info --- resources/pot/retailcrm-es_ES.pot | 2 + resources/pot/retailcrm-ru_RU.pot | 4 + src/assets/css/debug-info.css | 7 ++ src/assets/css/debug-info.min.css | 1 + src/assets/js/retailcrm-cron-info.js | 49 ++++++++++ .../class-wc-retailcrm-abstracts-settings.php | 45 +++------- src/include/class-wc-retailcrm-base.php | 85 +++++++++++++++++- src/languages/retailcrm-es_ES.mo | Bin 8416 -> 8469 bytes src/languages/retailcrm-ru_RU.mo | Bin 10310 -> 10386 bytes 9 files changed, 160 insertions(+), 33 deletions(-) create mode 100644 src/assets/css/debug-info.css create mode 100644 src/assets/css/debug-info.min.css create mode 100644 src/assets/js/retailcrm-cron-info.js diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index 23a3f66..9def175 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -274,3 +274,5 @@ msgstr "Introduce el número de teléfono correcto" msgid "You can export all orders and customers from CMS to Simla.com by clicking the «Upload» button. This process can take much time and before it is completed, you need to keep the tab open." msgstr "Presionando el botón «Exportar» puedes descargar a todos los pedidos y clientes de CMS a Simla.com. Este proceso puede llevar mucho tiempo y es necesario mantener abierta la pestaña hasta que termine el proceso." +msgid "Debug information" +msgstr "Información Debug" diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 78c86ec..db5fc0b 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -283,4 +283,8 @@ msgstr "Введите корректный номер телефона" msgid "You can export all orders and customers from CMS to Simla.com by clicking the «Upload» button. This process can take much time and before it is completed, you need to keep the tab open." msgstr "Вы можете экспортировать все заказы и клиентов из CMS в Simla.com, нажав кнопку «Выгрузить». Этот процесс может занять много времени, и до его завершения необходимо держать вкладку открытой." +msgid "Debug information" +msgstr "Отладочная информация" + + diff --git a/src/assets/css/debug-info.css b/src/assets/css/debug-info.css new file mode 100644 index 0000000..5a7d4c5 --- /dev/null +++ b/src/assets/css/debug-info.css @@ -0,0 +1,7 @@ +.retail-cron-info { + padding: 5px 30px !important; +} + +.retail-cron-info-title { + font-weight: bold; +} diff --git a/src/assets/css/debug-info.min.css b/src/assets/css/debug-info.min.css new file mode 100644 index 0000000..e533148 --- /dev/null +++ b/src/assets/css/debug-info.min.css @@ -0,0 +1 @@ +.retail-cron-info{padding:5px 30px!important}.retail-cron-info-title{font-weight:700} \ No newline at end of file diff --git a/src/assets/js/retailcrm-cron-info.js b/src/assets/js/retailcrm-cron-info.js new file mode 100644 index 0000000..e13189f --- /dev/null +++ b/src/assets/js/retailcrm-cron-info.js @@ -0,0 +1,49 @@ +jQuery(function () { + function RetailcrmCronInfo() + { + this.title = jQuery('h2[id="woocommerce_integration-retailcrm_16"]').get(0); + + if (typeof this.title === 'undefined') { + return false; + } + + this.history = 0; + this.icml = 0; + this.inventories = 0; + + let _this = this; + + jQuery.ajax({ + url: window.location.origin + '/wp-admin/admin-ajax.php?action=cron_info', + method: "POST", + timeout: 0, + data: {ajax: 1}, + dataType: "json" + }) + .done(function (response) { + _this.history = response.history; + _this.icml = response.icml; + _this.inventories = response.inventories; + + _this.displayInfoAboutCron(); + + }) + } + + RetailcrmCronInfo.prototype.displayInfoAboutCron = function () { + this.table = jQuery(this.title).next(); + this.table.append(''); + this.infoTable = jQuery('tbody[class="retail-debug-info"]').get(0); + + jQuery(this.infoTable).append("" + "Cron launches:" + ""); + jQuery(this.infoTable).append("" + "History: " + this.history + ""); + jQuery(this.infoTable).append("" + "Icml: " + this.icml + ""); + jQuery(this.infoTable).append("" + "Inventories: " + this.inventories + ""); + } + + window.RetailcrmCronInfo = RetailcrmCronInfo; + + if (!(typeof RetailcrmCronInfo === 'undefined')) { + new window.RetailcrmCronInfo(); + } +}); diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index 3e3a035..05dc1a0 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -36,37 +36,6 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ) { add_action('init', array($this, 'init_settings_fields'), 99); } - - // Include js scripts - $this->includeJsScripts(); - - // Include css file - $this->includeCssFile(); - - }//end __construct() - - - /** - * In this method we include JS scripts. - * - * @return void - */ - private function includeJsScripts() - { - wp_register_script('retailcrm-export', plugins_url() . '/woo-retailcrm/assets/js/retailcrm-export.js'); - wp_enqueue_script('retailcrm-export'); - } - - - /** - * In this method we include CSS file - * - * @return void - */ - private function includeCssFile() - { - wp_register_style('retailcrm-orders-export', plugins_url() . '/woo-retailcrm/assets/css/progress-bar.min.css', false, '0.1'); - wp_enqueue_style('retailcrm-orders-export'); } @@ -89,6 +58,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'checkbox' ); - /* + /** * Upload single order */ $this->form_field[] = array( @@ -561,6 +532,16 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration 'class' => 'checkbox', 'type' => 'checkbox' ); + + /** + * Debug information + */ + $this->form_fields[] = array( + 'title' => __('Debug information', 'retailcrm'), + 'type' => 'heading', + 'description' => '', + 'id' => 'cron_info_options' + ); } } } diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index 51405ea..d409db6 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -88,6 +88,7 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('retailcrm_icml', array($this, 'generate_icml')); add_action('retailcrm_inventories', array($this, 'load_stocks')); add_action('wp_ajax_do_upload', array($this, 'upload_to_crm')); + add_action('wp_ajax_cron_info', array($this, 'get_cron_info'), 99); add_action('wp_ajax_content_upload', array($this, 'count_upload_data'), 99); add_action('wp_ajax_generate_icml', array($this, 'generate_icml')); add_action('wp_ajax_order_upload', array($this, 'order_upload')); @@ -103,6 +104,7 @@ if (!class_exists('WC_Retailcrm_Base')) { add_action('wp_enqueue_scripts', array($this, 'include_whatsapp_icon_style'), 101); add_action('wp_print_footer_scripts', array($this, 'initialize_whatsapp'), 101); add_action('wp_print_footer_scripts', array($this, 'send_analytics'), 99); + add_action('admin_enqueue_scripts', array($this, 'include_files_for_admin'), 101); add_action('woocommerce_new_order', array($this, 'create_order'), 11, 1); if ( @@ -415,6 +417,54 @@ if (!class_exists('WC_Retailcrm_Base')) { } + /** + * In this method we include files in admin WP + * + * @return void + */ + public function include_files_for_admin() + { + $this->include_css_files_for_admin(); + $this->include_js_scripts_for_admin(); + } + + + /** + * In this method we include CSS file + * + * @return void + */ + private function include_css_files_for_admin() + { + $path = plugins_url() . '/woo-retailcrm/assets/css/'; + + // Include style for export + wp_register_style('retailcrm-export-style', $path . 'progress-bar.min.css', false, '0.1'); + wp_enqueue_style('retailcrm-export-style'); + + // Include style for debug info + wp_register_style('retailcrm-debug-info-style', $path . 'debug-info.min.css', false, '0.1'); + wp_enqueue_style('retailcrm-debug-info-style'); + } + + + /** + * In this method we include JS scripts. + * + * @return void + */ + private function include_js_scripts_for_admin() + { + $path = plugins_url() . '/woo-retailcrm/assets/js/'; + + wp_register_script('retailcrm-export', $path . 'retailcrm-export.js'); + wp_enqueue_script('retailcrm-export', $path . 'retailcrm-export.js', '', '', true); + + wp_register_script('retailcrm-cron-info', $path . 'retailcrm-cron-info.js'); + wp_enqueue_script('retailcrm-cron-info', $path . 'retailcrm-export.js', '', '', true); + } + + /** * Include style for WhatsApp icon */ @@ -445,7 +495,7 @@ if (!class_exists('WC_Retailcrm_Base')) { /** - * Rerurn count upload data + * Return count upload data */ public function count_upload_data() { @@ -460,6 +510,38 @@ if (!class_exists('WC_Retailcrm_Base')) { } + /** + * Return time work next cron + */ + public function get_cron_info() { + $icml = 'This option is disabled'; + $history = 'This option is disabled'; + $inventories = 'This option is disabled'; + + if (isset($this->settings['history']) && $this->settings['history'] == static::YES) { + $history = date("H:i:s d-m-Y", wp_next_scheduled('retailcrm_history')); + } + + if (isset($this->settings['icml']) && $this->settings['icml'] == static::YES) { + $icml = date("H:i:s d-m-Y", wp_next_scheduled('retailcrm_icml')); + } + + if (isset($this->settings['sync']) && $this->settings['sync'] == static::YES) { + $inventories = date("H:i:s d-m-Y ", wp_next_scheduled('retailcrm_inventories')); + } + + echo json_encode( + array( + 'history' => $history, + 'icml' => $icml, + 'inventories' => $inventories + ) + ); + + wp_die(); + } + + /** * Get retailcrm api client * @@ -522,3 +604,4 @@ if (!class_exists('WC_Retailcrm_Base')) { } } } + diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index e1f8f91f250c1b5866a92598f0f8795889112f86..ddc6e3817ac63b92858a83cd967895b2dd2ab947 100644 GIT binary patch delta 2011 zcmYk-YfMjZ9LMo5;;*EXDSEHW4fP*yE z4H_EoAx^~?7>D7Z-T+CcKUjpCU=0q#-57-@Fan!#G+xC7e2SX*Cnn=GR=*k7;zWFa z0d4gMjTCPDMNN>xwzTpB%)l*JjLkS0zoQlu#;W^c97f`JYb03Cpkp^Km4r8G#i@ zTG;_4cy{ zHb(F+YNA49lU9QR@u=T#LLJ35T!n9OBxVx^nvSieq0rQzR(jCyx1o~f5iZ5gxDjWO z!U}aW@@=u}s0rKr`;Spc{0<3@eL*E%Zw6D=N1-A&3}f{E7tzpbvJRD87qApNaRDZ? zT%F-gR2J8xBGibCZ7rye<$YA79-@-?Jt{H*&Lay`kv-T}oQa2Vv_qqvhC=rdpW`1? zPILyn(0xLZ*v$*AT+y0FEu{9MmQYivN+_MNUPUcbi(f`%ICo<@K2FVjWfj3$R7Yp7 zLSEQ(x8;R>A#HuNRHk^i*NJ{R&sU*U(Soz7i>YN)Ht!a_-bGYJ@PAPrtnfOH%N(vj zYM9&O!-5LkY^p-01kI!>kyI4+?nTF;kgDjzqvKOiREyn~cS!>sjf!$6N9VuN?Rx)I z)C}?aN*)y@nO+%{To3mRP|kEO1>HJ2ZzY?`3=j8pOQOBR@6W|hotd)xf0;)kgBnj& zQt`d9*w%xAt{#!)yEX+Yt17B@Y+F}TSzXn-FZ5}6bfI@+edXQOs^I*MJkweddo1i9 DK8Ucz delta 1960 zcmXxkU1*kN7zgls=69Mp=SP;c)HG{unahu9v#s@EEwj`XcqXaTfuPob5WN`%6C^Y+ z3Jr!RAw+>ADypL(q7E`CM3^E`5EK-25Ce^V|Mz`%v-|m7&%?9(Gk@r*@@z z{PCg<=(p-WjVq)GCYRFB zP0ai6a89QBK#&2y;!1wUTX>BbVE&ZGKdfga=;s3N=1n}rJ9v~!c#fIyBHK92s$XO` z@8MZmQ~8bXKH?dQi za5%NWUzx-@V1&@xnK`ld5n+q96NZO`?*3zt>h51zzf{K z%glretp09xaSeCz8NSbKPEQ#9{!3qR#9PFA`}@m}V; zeT|uLuzG%yDc+AL8Ravk*v>Q6KEh<~H#)sC&m{Re+F1Yo_X(c$V2F?KU*_z(Ej!iw zJd>e4G)8%u`Eh)k$<(_{@qWx?<^tF8I_;sXaXuTkl{t!|OyWBG_vw%6H|ROn>?rMNJwGy8=)-z4XWshf+0Mm!jw2b&B68+w$yBGF`RlvN z4@GvJmUAC#*-=_jmX_3}Wx?5Hzn<(#TD|4FenL-`kF^28*0CFQ>-L;NuFqeu_#Lg_+4d?{uON{+?I(qSN9v4LVc>b551|#d|oM_6jko$3?HBL SU(@iJDL+mdK0Nox)c*nXOP%%r diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 55142233b51205542202718d75121c8946ab8ba7..83db6ec5c35978d2a598122542811b252185fc27 100644 GIT binary patch delta 2081 zcmY+_drXye9LMo5$X$ga%0)3bCYH&85HEn3M2JR;2^3e?B9Vp&Zi=(K9VsVs>DX*+ z$}Im#Yvw;PYO?`N=e(7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