2016-07-27 19:57:05 -04:00
|
|
|
const $ = window.$ = require('jquery');
|
|
|
|
/* eslint no-unused-vars: 0 */
|
|
|
|
const jQuery = window.jQuery = $;
|
2016-03-24 17:11:29 -04:00
|
|
|
require('../stylesheets/welcome.css');
|
|
|
|
require('bootstrap');
|
2016-04-04 19:12:28 -04:00
|
|
|
require('datatables.net-bs');
|
|
|
|
require('../node_modules/datatables-bootstrap3-plugin/media/css/datatables-bootstrap3.css');
|
2016-03-24 17:11:29 -04:00
|
|
|
require('../node_modules/cal-heatmap/cal-heatmap.css');
|
2016-07-27 19:57:05 -04:00
|
|
|
const d3 = require('d3');
|
|
|
|
const CalHeatMap = require('cal-heatmap');
|
2016-04-13 20:26:44 -04:00
|
|
|
function modelViewTable(selector, modelView, orderCol, order) {
|
2016-03-24 17:11:29 -04:00
|
|
|
// Builds a dataTable from a flask appbuilder api endpoint
|
2016-07-27 19:57:05 -04:00
|
|
|
let url = '/' + modelView.toLowerCase() + '/api/read';
|
2016-04-13 20:26:44 -04:00
|
|
|
url += '?_oc_' + modelView + '=' + orderCol;
|
2016-07-27 19:57:05 -04:00
|
|
|
url += '&_od_' + modelView + '=' + order;
|
2016-04-13 20:26:44 -04:00
|
|
|
$.getJSON(url, function (data) {
|
2016-07-27 19:57:05 -04:00
|
|
|
const tableData = $.map(data.result, function (el) {
|
|
|
|
const row = $.map(data.list_columns, function (col) {
|
|
|
|
return el[col];
|
|
|
|
});
|
|
|
|
return [row];
|
2016-03-24 17:11:29 -04:00
|
|
|
});
|
2016-07-27 19:57:05 -04:00
|
|
|
const cols = $.map(data.list_columns, function (col) {
|
2016-03-26 00:55:28 -04:00
|
|
|
return { sTitle: data.label_columns[col] };
|
2016-03-24 17:11:29 -04:00
|
|
|
});
|
2016-07-27 19:57:05 -04:00
|
|
|
const panel = $(selector).parents('.panel');
|
|
|
|
panel.find('img.loading').remove();
|
2016-03-24 17:11:29 -04:00
|
|
|
$(selector).DataTable({
|
|
|
|
aaData: tableData,
|
|
|
|
aoColumns: cols,
|
2016-04-04 19:12:28 -04:00
|
|
|
bPaginate: true,
|
|
|
|
pageLength: 10,
|
|
|
|
bLengthChange: false,
|
|
|
|
aaSorting: [],
|
2016-04-04 19:56:06 -04:00
|
|
|
searching: true,
|
2016-07-21 00:32:20 -04:00
|
|
|
bInfo: false,
|
2016-03-24 17:11:29 -04:00
|
|
|
});
|
2016-04-04 23:47:12 -04:00
|
|
|
// Hack to move the searchbox in the right spot
|
2016-07-27 19:57:05 -04:00
|
|
|
const search = panel.find('.dataTables_filter input');
|
2016-04-04 19:12:28 -04:00
|
|
|
search.addClass('form-control').detach();
|
2016-07-27 19:57:05 -04:00
|
|
|
search.appendTo(panel.find('.search'));
|
2016-04-04 19:12:28 -04:00
|
|
|
panel.find('.dataTables_filter').remove();
|
2016-04-04 23:47:12 -04:00
|
|
|
// Hack to display the page navigator properly
|
|
|
|
panel.find('.col-sm-5').remove();
|
2016-07-27 19:57:05 -04:00
|
|
|
const nav = panel.find('.col-sm-7');
|
2016-04-04 23:47:12 -04:00
|
|
|
nav.removeClass('col-sm-7');
|
|
|
|
nav.addClass('col-sm-12');
|
2016-04-04 19:12:28 -04:00
|
|
|
$(selector).slideDown();
|
2016-03-24 17:11:29 -04:00
|
|
|
$('[data-toggle="tooltip"]').tooltip({ container: 'body' });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$(document).ready(function () {
|
2016-05-17 00:22:38 -04:00
|
|
|
d3.json('/caravel/activity_per_day', function (json) {
|
2016-07-27 19:57:05 -04:00
|
|
|
const ext = d3.extent(d3.values(json));
|
|
|
|
const cal = new CalHeatMap();
|
|
|
|
const range = 10;
|
|
|
|
const legendBounds = [];
|
|
|
|
const step = (ext[1] - ext[0]) / (range - 1);
|
|
|
|
for (let i = 0; i < range; i++) {
|
2016-05-17 00:22:38 -04:00
|
|
|
legendBounds.push(i * step + ext[0]);
|
|
|
|
}
|
|
|
|
cal.init({
|
|
|
|
start: new Date().setFullYear(new Date().getFullYear() - 1),
|
|
|
|
range: 13,
|
|
|
|
data: json,
|
|
|
|
legend: legendBounds,
|
2016-07-27 19:57:05 -04:00
|
|
|
legendColors: [
|
|
|
|
'#D6E685',
|
|
|
|
'#1E6823',
|
|
|
|
],
|
|
|
|
domain: 'month',
|
|
|
|
subDomain: 'day',
|
|
|
|
itemName: 'action',
|
2016-07-21 00:32:20 -04:00
|
|
|
tooltip: true,
|
2016-08-08 13:55:03 -04:00
|
|
|
cellSize: 10,
|
|
|
|
cellPadding: 2,
|
|
|
|
domainGutter: 22,
|
2016-05-17 00:22:38 -04:00
|
|
|
});
|
2016-03-24 17:11:29 -04:00
|
|
|
});
|
2016-04-13 20:26:44 -04:00
|
|
|
modelViewTable('#dash_table', 'DashboardModelViewAsync', 'changed_on', 'desc');
|
2016-03-24 17:11:29 -04:00
|
|
|
});
|