From d10a339542f808ca9df76915657bd23ec1f75634 Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Mon, 2 Sep 2013 14:47:47 +0200 Subject: [PATCH] //kevin special commit --- .../dashboard/helpers/view/view.tpl | 29 ++++++++++++ classes/Hook.php | 2 +- .../admin/AdminDashboardController.php | 10 +++++ js/admin-dashboard.js | 45 +++++++++++++++++++ modules/dashactivity/dashactivity.php | 27 ++++++++++- modules/dashproducts/dashproducts.php | 8 +++- modules/dashtrends/dashtrends.php | 7 ++- 7 files changed, 124 insertions(+), 4 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl index 156e7f008..8b2848702 100644 --- a/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl +++ b/admin-dev/themes/default/template/controllers/dashboard/helpers/view/view.tpl @@ -1,3 +1,32 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + + +

{l s='Dashboard'} diff --git a/classes/Hook.php b/classes/Hook.php index 451b3b31b..fe2b80819 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -465,7 +465,7 @@ class HookCore extends ObjectModel $output .= self::wrapLiveEdit($display, $moduleInstance, $array['id_hook']); } else if ($array_return) - $output[] = $display; + $output[$moduleInstance->name] = $display; else $output .= $display; } diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php index 7d5ef4e17..6adc71247 100644 --- a/controllers/admin/AdminDashboardController.php +++ b/controllers/admin/AdminDashboardController.php @@ -56,4 +56,14 @@ class AdminDashboardControllerCore extends AdminController ); return parent::renderView(); } + + public function ajaxProcessRefreshDashboard() + { + $id_module = null; + if ($module = Tools::getValue('module')) + $id_module = Module::getInstanceByName($module)->id; + + $datas = Hook::exec('dashboardDatas', array(), $id_module, true); + die(Tools::jsonEncode($datas)); + } } \ No newline at end of file diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js index ada0abf9d..1aeb1b97a 100644 --- a/js/admin-dashboard.js +++ b/js/admin-dashboard.js @@ -21,3 +21,48 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ + +$(document).ready( function () { + refreshDashbard(); +}); + + +function refreshDashbard() +{ + datas = { + ajax:true, + action:'refreshDashboard' + }; + $.ajax({ + url : dashboard_ajax_url, + data : datas, + dataType: 'json', + success : function(widgets){ + for (var name in widgets) + for (data_type in widgets[name]) + window[data_type](widgets[name][data_type]); + }, + error : function(data){ + alert("[TECHNICAL ERROR]"); + } + }); +} + +function data_value(datas) +{ + for (var data_id in datas) + $('#'+data_id).html(datas[data_id]); +} + +function data_trends(datas) +{ + for (var data_id in datas) + { + $('#'+data_id).html(datas[data_id]['value']); + if (datas[data_id]['value'] == 'down') + $('#'+data_id).parent().removeClass('dash_trend_up').addClass('dash_trend_down'); + else + $('#'+data_id).parent().removeClass('dash_trend_down').addClass('dash_trend_up'); + } + +} \ No newline at end of file diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php index ffb2981da..13205e299 100644 --- a/modules/dashactivity/dashactivity.php +++ b/modules/dashactivity/dashactivity.php @@ -42,7 +42,7 @@ class Dashactivity extends Module public function install() { - if (!parent::install() || !$this->registerHook('dashboardZoneOne')) + if (!parent::install() || !$this->registerHook('dashboardZoneOne') || !$this->registerHook('dashboardDatas')) return false; return true; } @@ -51,4 +51,29 @@ class Dashactivity extends Module { return $this->display(__FILE__, 'dashboard_zone_one.tpl'); } + + public function hookDashboardDatas($params) + { + return array( + 'data_value' => array( + 'order_nbr' => 365, + 'pending_orders' => 120, + 'return_exchanges' => 35, + 'abandoned_cart' => 12, + 'products_out_of_stock' => 4, + 'new_messages' => 42, + 'order_inquires' => 13, + 'product_reviews' => 56, + 'new_customers' => 42, + 'online_visitor' => 200, + 'new_registrations' => 125, + 'total_suscribers' => 13500, + 'visits' => 10000, + 'unique_visitors' => 3500, + ), + 'data_trends' => array( + 'orders_trends' => array('way' => 'down', 'value' => 0.66), + ) + ); + } } \ No newline at end of file diff --git a/modules/dashproducts/dashproducts.php b/modules/dashproducts/dashproducts.php index 150583f09..5f099f99a 100644 --- a/modules/dashproducts/dashproducts.php +++ b/modules/dashproducts/dashproducts.php @@ -42,7 +42,7 @@ class Dashproducts extends Module public function install() { - if (!parent::install() || !$this->registerHook('dashboardZoneTwo')) + if (!parent::install() || !$this->registerHook('dashboardZoneTwo') || !$this->registerHook('dashboardDatas')) return false; return true; } @@ -51,4 +51,10 @@ class Dashproducts extends Module { return $this->display(__FILE__, 'dashboard_zone_two.tpl'); } + + public function hookDashboardDatas($params) + { + return array(); + } + } \ No newline at end of file diff --git a/modules/dashtrends/dashtrends.php b/modules/dashtrends/dashtrends.php index 1d4c11c45..f4c59f8a2 100644 --- a/modules/dashtrends/dashtrends.php +++ b/modules/dashtrends/dashtrends.php @@ -42,7 +42,7 @@ class Dashtrends extends Module public function install() { - if (!parent::install() || !$this->registerHook('dashboardZoneTwo')) + if (!parent::install() || !$this->registerHook('dashboardZoneTwo') || !$this->registerHook('dashboardDatas')) return false; return true; } @@ -51,4 +51,9 @@ class Dashtrends extends Module { return $this->display(__FILE__, 'dashboard_zone_two.tpl'); } + + public function hookDashboardDatas($params) + { + return array(); + } } \ No newline at end of file