Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 05:38:15 +0400
committerBenaka Moorthi <benaka.moorthi@gmail.com>2013-09-12 05:39:19 +0400
commitd6f94510ca16b4f6b06d5113c97fa206f704b489 (patch)
tree4949e43c3d2f339a5f873fd074e86192274f45ee /plugins/Live
parent94799537f84f0be7a3ad2da3bf289ed2783c3b27 (diff)
Refs #3089, only show map in visitor profile if map is not showing on another part of the screen, load the map through AJAX, and some tweaks to code style.
Diffstat (limited to 'plugins/Live')
-rw-r--r--plugins/Live/API.php30
-rw-r--r--plugins/Live/Controller.php15
-rw-r--r--plugins/Live/javascripts/visitorProfile.js61
-rw-r--r--plugins/Live/stylesheets/visitor_profile.less4
-rw-r--r--plugins/Live/templates/getVisitorProfilePopup.twig5
5 files changed, 77 insertions, 38 deletions
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index c58aefbed0..85ac7c28cd 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -172,17 +172,17 @@ class API
* TODO: check for goals plugin, etc.
*
* @param int $idSite Site ID
- * @param string $idVisitor The ID of the visitor whose profile to retrieve.
+ * @param string $visitorId The ID of the visitor whose profile to retrieve.
* @param string|false $segment
* @return array
*/
- public function getVisitorProfile($idSite, $idVisitor, $segment = false)
+ public function getVisitorProfile($idSite, $visitorId, $segment = false)
{
- if ($idVisitor === false) {
- $idVisitor = $this->getMostRecentVisitorId($idSite, $segment);
+ if ($visitorId === false) {
+ $visitorId = $this->getMostRecentVisitorId($idSite, $segment);
}
- $newSegment = ($segment === false ? '' : $segment . ';') . 'visitorId==' . $idVisitor;
+ $newSegment = ($segment === false ? '' : $segment . ';') . 'visitorId==' . $visitorId;
$visits = $this->getLastVisitsDetails($idSite, $period = false, $date = false, $newSegment,
$filter_limit = self::VISITOR_PROFILE_MAX_VISITS_TO_AGGREGATE,
@@ -309,8 +309,8 @@ class API
// TODO: make sure order of visitor ids is not changed if a returning visitor visits while the user is
// looking at the popup.
$latestVisitTime = reset($rows)->getColumn('lastActionDateTime');
- $result['nextVisitorId'] = $this->getAdjacentVisitorId($idSite, $idVisitor, $latestVisitTime, $segment, $getNext = true);
- $result['prevVisitorId'] = $this->getAdjacentVisitorId($idSite, $idVisitor, $latestVisitTime, $segment, $getNext = false);
+ $result['nextVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = true);
+ $result['prevVisitorId'] = $this->getAdjacentVisitorId($idSite, $visitorId, $latestVisitTime, $segment, $getNext = false);
Piwik_PostEvent(Live::GET_EXTRA_VISITOR_DETAILS_EVENT, array(&$result));
@@ -344,8 +344,8 @@ class API
* in the log_visit table.
*
* @param int $idSite The ID of the site whose visits should be looked at.
- * @param string $idVisitor The ID of the visitor to get an adjacent visitor for.
- * @param string $visitLastActionTime The last action time of the latest visit for $idVisitor.
+ * @param string $visitorId The ID of the visitor to get an adjacent visitor for.
+ * @param string $visitLastActionTime The last action time of the latest visit for $visitorId.
* @param string $segment
* @param bool $getNext Whether to retrieve the next visitor or the previous visitor. The next
* visitor will be the visitor that appears chronologically later in the
@@ -353,7 +353,7 @@ class API
* earlier.
* @return string The hex visitor ID.
*/
- private function getAdjacentVisitorId($idSite, $idVisitor, $visitLastActionTime, $segment, $getNext)
+ private function getAdjacentVisitorId($idSite, $visitorId, $visitLastActionTime, $segment, $getNext)
{
if ($getNext) {
$visitLastActionTimeCondition = "sub.visit_last_action_time <= ?";
@@ -366,7 +366,7 @@ class API
$select = "log_visit.idvisitor, MAX(log_visit.visit_last_action_time) as visit_last_action_time";
$from = "log_visit";
$where = "log_visit.idsite = ? AND log_visit.idvisitor <> UNHEX(?)";
- $whereBind = array($idSite, $idVisitor);
+ $whereBind = array($idSite, $visitorId);
$orderBy = "MAX(log_visit.visit_last_action_time) $orderByDir";
$groupBy = "log_visit.idvisitor";
@@ -379,11 +379,11 @@ class API
LIMIT 1";
$bind = array_merge($queryInfo['bind'], array($visitLastActionTime));
- $idVisitor = Db::fetchOne($sql, $bind);
- if (!empty($idVisitor)) {
- $idVisitor = bin2hex($idVisitor);
+ $visitorId = Db::fetchOne($sql, $bind);
+ if (!empty($visitorId)) {
+ $visitorId = bin2hex($visitorId);
}
- return $idVisitor;
+ return $visitorId;
}
/**
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index 30f56a43d7..b5114679b3 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -10,6 +10,7 @@
*/
namespace Piwik\Plugins\Live;
+use Piwik\Url;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\Piwik;
@@ -146,7 +147,9 @@ class Controller extends \Piwik\Controller
$view->idSite = $idSite;
$view->goals = Goals_API::getInstance()->getGoals($idSite);
$view->visitorData = Request::processRequest('Live.getVisitorProfile');
- $view->userCountryMap = $this->getUserCountryMapForVisitorProfile();
+ if (Common::getRequestVar('showMap', 1) == 1) {
+ $view->userCountryMapUrl = $this->getUserCountryMapUrlForVisitorProfile();
+ }
// TODO: disabled until segmentation issue can be dealt w/ (if enabled, last 24 months of data will be archived w/
// segment every visitor ID)
$view->lastVisitsChart = ''; //$this->getLastVisitsForVisitorProfile();
@@ -193,10 +196,14 @@ class Controller extends \Piwik\Controller
return $result;
}
- private function getUserCountryMapForVisitorProfile()
+ private function getUserCountryMapUrlForVisitorProfile()
{
- $params = array('standalone' => false, 'fetch' => true, 'segment' => self::getSegmentWithVisitorId());
- return FrontController::getInstance()->fetchDispatch('UserCountryMap', 'realtimeMap', $params); // TODO: check if plugin is enabled?
+ $params = array(
+ 'module' => 'UserCountryMap',
+ 'action' => 'realtimeMap',
+ 'segment' => self::getSegmentWithVisitorId()
+ );
+ return Url::getCurrentQueryStringWithParametersModified($params);
}
private static function getSegmentWithVisitorId()
diff --git a/plugins/Live/javascripts/visitorProfile.js b/plugins/Live/javascripts/visitorProfile.js
index 7c1aa9a301..b7e53f8938 100644
--- a/plugins/Live/javascripts/visitorProfile.js
+++ b/plugins/Live/javascripts/visitorProfile.js
@@ -43,7 +43,14 @@
* @param {String} visitorId The string visitor ID.
*/
VisitorProfileControl.showPopover = function (visitorId) {
- var url = 'module=Live&action=getVisitorProfilePopup&idVisitor=' + encodeURIComponent(visitorId);
+ var url = 'module=Live&action=getVisitorProfilePopup&visitorId=' + encodeURIComponent(visitorId);
+
+ // if there is already a map shown on the screen, do not show the map in the popup. kartograph seems
+ // to only support showing one map at a time.
+ if ($('.RealTimeMap').length > 0) {
+ url += '&showMap=0';
+ }
+
Piwik_Popover.createPopupAndLoadUrl(url, '', 'visitor-profile-popup');
};
@@ -105,27 +112,49 @@
$element.on('click', '.visitor-profile-show-map', function (e) {
e.preventDefault();
+ self.toggleMap();
+ return false;
+ });
+ },
- var $map = $('.visitor-profile-map', $element);
- if ($map.is(':hidden')) {
- if ($map.height() < 1) {
- $map.resize();
- }
-
- $map.slideDown('slow');
- var newLabel = 'Live_HideMap_js';
+ toggleMap: function () {
+ var $element = this.$element,
+ $map = $('.visitor-profile-map', $element);
+ if (!$map.children().length) { // if the map hasn't been loaded, load it
+ this._loadMap($map);
+ return;
+ }
- piwikHelper.lazyScrollTo($('.visitor-profile-location', $element)[0], 400);
- } else {
- $map.slideUp('slow');
- var newLabel = 'Live_ShowMap_js';
+ if ($map.is(':hidden')) { // show the map if it is hidden
+ if ($map.height() < 1) {
+ $map.resize();
}
- newLabel = _pk_translate(newLabel).replace(' ', '\xA0');
- $(this).text('(' + newLabel + ')');
+ $map.slideDown('slow');
+ var newLabel = 'Live_HideMap_js';
- return false;
+ piwikHelper.lazyScrollTo($('.visitor-profile-location', $element)[0], 400);
+ } else { // hide the map if it is shown
+ $map.slideUp('slow');
+ var newLabel = 'Live_ShowMap_js';
+ }
+
+ newLabel = _pk_translate(newLabel).replace(' ', '\xA0');
+ $('.visitor-profile-show-map', $element).text('(' + newLabel + ')');
+ },
+
+ _loadMap: function ($map) {
+ var self = this;
+
+ var ajax = new ajaxHelper();
+ ajax.setUrl($map.attr('data-href'));
+ ajax.setCallback(function (response) {
+ $map.html(response);
+ self.toggleMap();
});
+ ajax.setFormat('html');
+ ajax.setLoadingElement($('.visitor-profile-location > p > .loadingPiwik', self.$element));
+ ajax.send();
},
_loadMoreVisits: function () {
diff --git a/plugins/Live/stylesheets/visitor_profile.less b/plugins/Live/stylesheets/visitor_profile.less
index cf1db666da..93abb01404 100644
--- a/plugins/Live/stylesheets/visitor_profile.less
+++ b/plugins/Live/stylesheets/visitor_profile.less
@@ -292,6 +292,10 @@
}
}
+.visitor-profile-location>p>.loadingPiwik {
+ padding:0 0 0 4px;
+}
+
.visitor-profile-pages-visited {
height:unit(@visitor_profile_visits_title_height, px);
overflow-y:auto;
diff --git a/plugins/Live/templates/getVisitorProfilePopup.twig b/plugins/Live/templates/getVisitorProfilePopup.twig
index d57bb58cb0..571f742be4 100644
--- a/plugins/Live/templates/getVisitorProfilePopup.twig
+++ b/plugins/Live/templates/getVisitorProfilePopup.twig
@@ -75,10 +75,9 @@
{% set entryCountry %}<img src="{{ entry.flag }}" title="{{ entry.prettyName }}"/>&nbsp;{{ entry.prettyName }}{% endset %}
{{- 'General_XFromY'|translate(entryVisits, entryCountry)|raw -}}{% if not loop.last %}, {% endif %}
{%- endfor %}
- <a class="visitor-profile-show-map" href="#">({{ 'Live_ShowMap_js'|translate|replace({' ': '&nbsp;'})|raw }})</a>
+ <a class="visitor-profile-show-map" href="#" {% if userCountryMapUrl|default('') is empty %}style="display:none"{% endif %}>({{ 'Live_ShowMap_js'|translate|replace({' ': '&nbsp;'})|raw }})</a> <img class="loadingPiwik" style="display:none;" src="plugins/Zeitgeist/images/loading-blue.gif"/>
</p>
- <div class="visitor-profile-map" style="display:none">
- {{ userCountryMap|raw }}
+ <div class="visitor-profile-map" style="display:none" data-href="{{ userCountryMapUrl|default('') }}">
</div>
</div>
</div>