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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*!
* 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').controller('LocationProviderUpdaterController', LocationProviderUpdaterController);
LocationProviderUpdaterController.$inject = ['piwikApi'];
function LocationProviderUpdaterController(piwikApi) {
// remember to keep controller very simple. Create a service/factory (model) if needed
var self = this;
this.buttonUpdateSaveText = _pk_translate('General_Save');
this.progressUpdateLabel = '';
// geoip database wizard
var downloadNextChunk = function (action, thisId, progressBarId, cont, extraData, callback) {
var data = {};
for (var k in extraData) {
data[k] = extraData[k];
}
piwikApi.withTokenInUrl();
piwikApi.post({
module: 'UserCountry',
action: action,
'continue': cont ? 1 : 0
}, data).then(function (response) {
if (!response || response.error) {
callback(response);
} else {
// update progress bar
var newProgressVal = Math.ceil((response.current_size / response.expected_file_size) * 100);
self[progressBarId] = Math.min(newProgressVal, 100);
// if incomplete, download next chunk, otherwise, show updater manager
if (newProgressVal < 100) {
downloadNextChunk(action, thisId, progressBarId, true, extraData, callback);
} else {
callback(response);
}
}
}, function () {
callback({error: _pk_translate('UserCountry_FatalErrorDuringDownload')});
});
};
this.startDownloadFreeGeoIp = function () {
this.showFreeDownload = true;
this.showPiwikNotManagingInfo = false;
this.progressFreeDownload = 0;
// start download of free dbs
downloadNextChunk(
'downloadFreeGeoIPDB',
'geoipdb-screen2-download',
'progressFreeDownload',
false,
{},
function (response) {
if (response.error) {
$('#geoipdb-update-info').html(response.error);
self.geoipDatabaseInstalled = true;
} else {
self.showGeoIpUpdateInfo();
}
}
);
};
this.startAutomaticUpdateGeoIp = function () {
this.buttonUpdateSaveText = _pk_translate('General_Continue');
this.showGeoIpUpdateInfo();
};
this.showGeoIpUpdateInfo = function () {
this.geoipDatabaseInstalled = true;
// todo we need to replace this the proper way eventually
$('#geoip-db-mangement .card-title').text(_pk_translate('UserCountry_SetupAutomaticUpdatesOfGeoIP'));
}
this.saveGeoIpLinks = function () {
var currentDownloading = null;
var updateGeoIPSuccess = function (response) {
if (response && response.error) {
self.isUpdatingGeoIpDatabase = false;
var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(response.error, {
placeat: '#geoipdb-update-info-error',
context: 'error',
style: {display: 'inline-block'},
id: 'userCountryGeoIpUpdate'
});
} else if (response && response.to_download) {
var continuing = currentDownloading == response.to_download;
currentDownloading = response.to_download;
// show progress bar w/ message
self.progressUpdateDownload = 0;
self.progressUpdateLabel = response.to_download_label;
self.isUpdatingGeoIpDatabase = true;
// start/continue download
downloadNextChunk(
'downloadMissingGeoIpDb', 'geoipdb-update-info', 'progressUpdateDownload',
continuing, {key: response.to_download}, updateGeoIPSuccess);
} else {
self.progressUpdateLabel = '';
self.isUpdatingGeoIpDatabase = false;
var UI = require('piwik/UI');
var notification = new UI.Notification();
notification.show(_pk_translate('General_Done'), {
placeat: '#done-updating-updater',
context: 'success',
noclear: true,
type: 'toast',
style: {display: 'inline-block'},
id: 'userCountryGeoIpUpdate'
});
$('#geoip-updater-next-run-time').html(response.nextRunTime).parent().effect('highlight', {color: '#FFFFCB'}, 2000);
}
};
piwikApi.withTokenInUrl();
piwikApi.post({
period: this.updatePeriod,
module: 'UserCountry',
action: 'updateGeoIPLinks',
}, {
loc_db: this.locationDbUrl,
isp_db: this.ispDbUrl,
org_db: this.orgDbUrl
}).then(updateGeoIPSuccess);
};
}
})();
|