kanaui 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/kanaui/kiddo/axes.js +25 -25
- data/app/assets/javascripts/kanaui/kiddo/charts/line_chart.js +12 -7
- data/app/assets/javascripts/kanaui/kiddo/charts/utils/mouse_over.js +67 -39
- data/app/assets/javascripts/kanaui/kiddo/kiddo_initialize.js +19 -11
- data/app/assets/javascripts/kanaui/kiddo/renderer.js +7 -2
- data/app/assets/javascripts/kanaui/kiddo/settings.js +1 -1
- data/app/assets/stylesheets/kanaui/reports.css +1 -1
- data/app/controllers/kanaui/dashboard_controller.rb +82 -22
- data/app/controllers/kanaui/engine_controller.rb +10 -0
- data/app/controllers/kanaui/reports_controller.rb +60 -0
- data/app/helpers/kanaui/dashboard_helper.rb +28 -2
- data/app/views/kanaui/dashboard/index.html.erb +90 -15
- data/app/views/kanaui/reports/_form.html.erb +49 -0
- data/app/views/kanaui/reports/_reports_table.html.erb +60 -0
- data/app/views/kanaui/reports/edit.html.erb +10 -0
- data/app/views/kanaui/reports/index.html.erb +17 -0
- data/app/views/kanaui/reports/new.html.erb +10 -0
- data/config/routes.rb +5 -1
- data/lib/kanaui/version.rb +1 -1
- metadata +121 -121
- data/app/assets/javascripts/kanaui/killbill.js +0 -1114
- data/app/assets/javascripts/kanaui/purl.js +0 -271
- data/app/assets/javascripts/kanaui/reports.graphs.js +0 -190
- data/app/assets/javascripts/kanaui/reports.js +0 -201
- data/app/assets/javascripts/kanaui/reports.urls.js +0 -44
- data/app/assets/javascripts/kanaui/tests.js +0 -2
@@ -1,201 +0,0 @@
|
|
1
|
-
function Reports() {
|
2
|
-
this.protocol = 'http';
|
3
|
-
this.host = '127.0.0.1';
|
4
|
-
this.port = 8080;
|
5
|
-
this.basePath = '/plugins/killbill-analytics/static/analytics.html';
|
6
|
-
|
7
|
-
this.startDate = moment().subtract('months', 3).format('YYYY[-]MM[-]DD');
|
8
|
-
this.endDate = moment().format('YYYY[-]MM[-]DD');
|
9
|
-
// Map position -> report names
|
10
|
-
this.reports = {};
|
11
|
-
// Map position -> smoothing function
|
12
|
-
this.smoothingFunctions = {};
|
13
|
-
|
14
|
-
// Standard sets of reports
|
15
|
-
this.ANALYTICS_REPORTS = {
|
16
|
-
reports: {
|
17
|
-
1: ['trial_starts_count_daily'],
|
18
|
-
2: ['cancellations_count_daily'],
|
19
|
-
3: ['active_by_product_term_monthly'],
|
20
|
-
4: ['invoices_balance_daily']
|
21
|
-
}
|
22
|
-
};
|
23
|
-
this.SYSTEM_REPORTS = {
|
24
|
-
reports: {
|
25
|
-
1: ['system_report_payments_per_day'],
|
26
|
-
2: ['system_report_notifications_per_queue_name'],
|
27
|
-
3: ['system_report_notifications_per_queue_name_late'],
|
28
|
-
4: ['system_report_payments'],
|
29
|
-
5: ['system_report_control_tag_no_test']
|
30
|
-
}
|
31
|
-
};
|
32
|
-
|
33
|
-
// Debugging
|
34
|
-
this.loadFromFilePath = false;
|
35
|
-
}
|
36
|
-
|
37
|
-
Reports.prototype.init = function() {
|
38
|
-
var url = $.url();
|
39
|
-
// Infer Kill Bill's address by looking at the current address,
|
40
|
-
// except if we're loading the file directly (file:///).
|
41
|
-
if (url.attr('protocol') != 'file') {
|
42
|
-
this.protocol = url.attr('protocol');
|
43
|
-
this.host = url.attr('host');
|
44
|
-
this.port = url.attr('port');
|
45
|
-
} else {
|
46
|
-
this.loadFromFilePath = true;
|
47
|
-
}
|
48
|
-
this.basePath = url.attr('path');
|
49
|
-
|
50
|
-
var params = url.param();
|
51
|
-
for (var key in params) {
|
52
|
-
if (key == 'startDate') {
|
53
|
-
this.startDate = params[key];
|
54
|
-
} else if (key == 'endDate') {
|
55
|
-
this.endDate = params[key];
|
56
|
-
} else if (key.startsWith('smooth')) {
|
57
|
-
var position = key.split('smooth')[1];
|
58
|
-
this.smoothingFunctions[position] = params[key];
|
59
|
-
} else if (key.startsWith('report')) {
|
60
|
-
var position = key.split('report')[1];
|
61
|
-
if (!(params[key] instanceof Array)) {
|
62
|
-
this.reports[position] = [params[key]];
|
63
|
-
} else {
|
64
|
-
this.reports[position] = params[key];
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
}
|
69
|
-
|
70
|
-
Reports.prototype.hasReport = function(val) {
|
71
|
-
var found = false;
|
72
|
-
|
73
|
-
var that = this;
|
74
|
-
$.each(Object.keys(this.reports), function(i, position) {
|
75
|
-
$.each(that.reports[position], function(j, reportName) {
|
76
|
-
if (reportName === val) {
|
77
|
-
found = true;
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
});
|
81
|
-
});
|
82
|
-
|
83
|
-
return found;
|
84
|
-
}
|
85
|
-
|
86
|
-
Reports.prototype.availableReports = function(callback) {
|
87
|
-
var available_report_path = Routes.kanaui_engine_available_reports_path({format: "json"});
|
88
|
-
var url = this.buildBaseURL(available_report_path);
|
89
|
-
this.doGet(url, function(allReports) { callback(allReports); });
|
90
|
-
}
|
91
|
-
|
92
|
-
Reports.prototype.getDataForReport = function(position, callback) {
|
93
|
-
var url = this.buildDataURL(position);
|
94
|
-
|
95
|
-
return this.doGet(url,
|
96
|
-
function(data) {
|
97
|
-
callback(position, data);
|
98
|
-
},
|
99
|
-
function(jqXHR, textStatus, errorThrown) {
|
100
|
-
if (jqXHR.responseText) {
|
101
|
-
try {
|
102
|
-
errors = $.parseJSON(jqXHR.responseText);
|
103
|
-
if (errors['message']) {
|
104
|
-
displayError('Error generating report nb. ' + position + ':\n' + errors['message']);
|
105
|
-
} else {
|
106
|
-
displayError('Error generating report nb. ' + position + ':\n' + errors);
|
107
|
-
}
|
108
|
-
} catch (err) {
|
109
|
-
displayError('Error generating report nb. ' + position + ':\n' + jqXHR.responseText);
|
110
|
-
}
|
111
|
-
} else {
|
112
|
-
if (errorThrown) {
|
113
|
-
displayError('Error generating report nb. ' + position + ':\n' + errorThrown);
|
114
|
-
} else {
|
115
|
-
displayError('Error generating report nb. ' + position + ':\n' + textStatus + ' (status '+ jqXHR.status + ')');
|
116
|
-
}
|
117
|
-
}
|
118
|
-
});
|
119
|
-
}
|
120
|
-
|
121
|
-
Reports.prototype.getDataForReports = function(callback) {
|
122
|
-
// Array of all deferreds
|
123
|
-
var futures = []
|
124
|
-
// Array of all the data, the index being the report position (starts at zero)
|
125
|
-
var futuresData = new Array(Object.keys(this.reports).length);
|
126
|
-
|
127
|
-
for (var position in this.reports) {
|
128
|
-
// Fetch the data
|
129
|
-
var future = this.getDataForReport(position, function(zePosition, reportsData) {
|
130
|
-
if (!(reportsData instanceof Array) || reportsData.length == 0 || reportsData[0].data.length == 0) {
|
131
|
-
log.debug('Report at position ' + (zePosition - 1) + ' has not data')
|
132
|
-
// Skip, to avoid confusing the graphing library
|
133
|
-
} else {
|
134
|
-
log.debug('Got data for report at position ' + (zePosition - 1));
|
135
|
-
log.trace(reportsData);
|
136
|
-
futuresData[zePosition - 1] = reportsData[0];
|
137
|
-
}
|
138
|
-
});
|
139
|
-
futures.push(future);
|
140
|
-
}
|
141
|
-
|
142
|
-
// Apply callback on join (and remove skipped reports, with no data)
|
143
|
-
$.when.apply(null, futures).done(function() { callback($.grep(futuresData, function(e) { return e; })); });
|
144
|
-
}
|
145
|
-
|
146
|
-
Reports.prototype.buildRefreshURLForNewSmooth = function(position, newSmooth) {
|
147
|
-
var newReports = $.extend(true, {}, this);
|
148
|
-
newReports.smoothingFunctions[position] = newSmooth;
|
149
|
-
return newReports.buildRefreshURL();
|
150
|
-
}
|
151
|
-
|
152
|
-
Reports.prototype.buildRefreshURL = function() {
|
153
|
-
|
154
|
-
console.log("buildRefreshURL : StartDate = " + this.startDate + "EndDate = " + this.endDate);
|
155
|
-
|
156
|
-
var newReports = this.reports;
|
157
|
-
var url = !this.loadFromFilePath ? this.buildBaseURL(this.basePath) : this.basePath;
|
158
|
-
url += '?startDate=' + this.startDate;
|
159
|
-
url += '&endDate=' + this.endDate;
|
160
|
-
|
161
|
-
for (var position in newReports) {
|
162
|
-
var joinKey = '&report' + position + '=';
|
163
|
-
url += joinKey + newReports[position].join(joinKey);
|
164
|
-
if (this.smoothingFunctions[position]) {
|
165
|
-
url += '&smooth' + position + '=' + this.smoothingFunctions[position];
|
166
|
-
}
|
167
|
-
}
|
168
|
-
|
169
|
-
return url;
|
170
|
-
};
|
171
|
-
|
172
|
-
Reports.prototype.buildDataURL = function(position, format) {
|
173
|
-
var reports_path = Routes.kanaui_engine_reports_path({format: "json"});
|
174
|
-
var url = this.buildBaseURL(reports_path);
|
175
|
-
url += '?format=' + (format ? format : 'json')
|
176
|
-
url += '&startDate=' + this.startDate;
|
177
|
-
url += '&endDate=' + this.endDate;
|
178
|
-
url += '&name=' + this.reports[position].join('&name=');
|
179
|
-
if (this.smoothingFunctions[position]) {
|
180
|
-
url += '&smooth=' + this.smoothingFunctions[position]
|
181
|
-
}
|
182
|
-
|
183
|
-
return url;
|
184
|
-
}
|
185
|
-
|
186
|
-
Reports.prototype.buildBaseURL = function(path) {
|
187
|
-
return this.protocol + '://' + this.host + ':' + this.port + path;
|
188
|
-
}
|
189
|
-
|
190
|
-
Reports.prototype.doGet = function(url, doneCallback, failCallback) {
|
191
|
-
var apiKey = $.url().param('apiKey') || 'bob';
|
192
|
-
var apiSecret = $.url().param('apiSecret') || 'lazar';
|
193
|
-
|
194
|
-
return $.ajax({
|
195
|
-
type: 'GET',
|
196
|
-
contentType: 'application/json',
|
197
|
-
headers: { 'X-Killbill-ApiKey': apiKey, 'X-Killbill-ApiSecret': apiSecret },
|
198
|
-
dataType: 'json',
|
199
|
-
url: url
|
200
|
-
}).done(doneCallback).fail(failCallback);
|
201
|
-
}
|
@@ -1,44 +0,0 @@
|
|
1
|
-
function ReportsUrls(reportName) {
|
2
|
-
this.url = reportName;
|
3
|
-
|
4
|
-
// See com.ning.billing.osgi.bundles.analytics.reports.ReportSpecification
|
5
|
-
this.reportSpecificationsSeparator = '^';
|
6
|
-
this.reportSpecificationSeparator = ':';
|
7
|
-
|
8
|
-
// See com.ning.billing.osgi.bundles.analytics.reports.sql.Cases
|
9
|
-
this.groupsSeparator = '|';
|
10
|
-
}
|
11
|
-
|
12
|
-
ReportsUrls.prototype.addDimension = function(dimension, groups) {
|
13
|
-
var dimensionWithGroups = dimension;
|
14
|
-
|
15
|
-
var that = this;
|
16
|
-
$.each(groups || [], function(i, group) {
|
17
|
-
if (i == 0) {
|
18
|
-
dimensionWithGroups += '(';
|
19
|
-
}
|
20
|
-
|
21
|
-
dimensionWithGroups += groups[i];
|
22
|
-
|
23
|
-
if (i == groups.length - 1) {
|
24
|
-
dimensionWithGroups += ')';
|
25
|
-
} else {
|
26
|
-
dimensionWithGroups += that.groupsSeparator;
|
27
|
-
}
|
28
|
-
});
|
29
|
-
|
30
|
-
return this.addSpecification('dimension', dimensionWithGroups);
|
31
|
-
}
|
32
|
-
|
33
|
-
ReportsUrls.prototype.addMetric = function(metric) {
|
34
|
-
return this.addSpecification('metric', metric);
|
35
|
-
}
|
36
|
-
|
37
|
-
ReportsUrls.prototype.addFilter = function(filter) {
|
38
|
-
return this.addSpecification('filter', filter);
|
39
|
-
}
|
40
|
-
|
41
|
-
ReportsUrls.prototype.addSpecification = function(specificationString, specificationValue) {
|
42
|
-
this.url += this.reportSpecificationsSeparator + specificationString + this.reportSpecificationSeparator + encodeURIComponent(specificationValue);
|
43
|
-
return this;
|
44
|
-
}
|