blob: 53cace77bf851f61d0af6e1501a8199ccc6a4cfe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*!
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
(function () {
angular.module('piwikApp.service').service('piwik', piwikService);
piwikService.$inject = ['piwikPeriods'];
function piwikService(piwikPeriods) {
piwik.helper = piwikHelper;
piwik.broadcast = broadcast;
piwik.updatePeriodParamsFromUrl = updatePeriodParamsFromUrl;
return piwik;
function updatePeriodParamsFromUrl() {
var date = piwik.broadcast.getValueFromHash('date');
var period = piwik.broadcast.getValueFromHash('period');
if (!isValidPeriod(period, date)) {
// invalid data in URL
return;
}
if (piwik.period === period && piwik.currentDateString === date) {
// this period / date is already loaded
return;
}
piwik.period = period;
if (date && date.indexOf(',') > -1) {
var dateParts = date.split(',');
if (dateParts[1]) {
piwik.currentDateString = dateParts[1];
} else if (dateParts[0]) {
piwik.currentDateString = dateParts[0];
}
} else {
piwik.currentDateString = date;
}
var dateRange = piwikPeriods.parse(period, date).getDateRange();
piwik.startDateString = $.datepicker.formatDate('yy-mm-dd', dateRange[0]);
piwik.endDateString = $.datepicker.formatDate('yy-mm-dd', dateRange[1]);
}
function isValidPeriod(periodStr, dateStr) {
try {
piwikPeriods.get(periodStr).parse(dateStr);
return true;
} catch (e) {
return false;
}
}
}
angular.module('piwikApp.service').run(initPiwikService);
initPiwikService.$inject = ['piwik', '$rootScope'];
function initPiwikService(piwik, $rootScope) {
$rootScope.$on('$locationChangeSuccess', piwik.updatePeriodParamsFromUrl);
}
})();
|