superset/caravel/assets/javascripts/welcome.js

68 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-03-24 17:11:29 -04:00
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;
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-03-26 00:55:28 -04:00
var CalHeatMap = require('cal-heatmap');
2016-03-24 17:11:29 -04:00
2016-04-04 19:12:28 -04:00
function modelViewTable(selector, modelEndpoint) {
2016-03-24 17:11:29 -04:00
// Builds a dataTable from a flask appbuilder api endpoint
$.getJSON(modelEndpoint + '/api/read', function (data) {
2016-03-26 00:55:28 -04:00
var tableData = jQuery.map(data.result, function (el, i) {
var row = $.map(data.list_columns, function (col, i) {
2016-03-24 17:11:29 -04:00
return el[col];
});
return [row];
});
2016-03-26 00:55:28 -04:00
var cols = jQuery.map(data.list_columns, function (col, i) {
return { sTitle: data.label_columns[col] };
2016-03-24 17:11:29 -04:00
});
2016-04-04 19:12:28 -04:00
var 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: [],
searching: true,
bInfo: false
2016-03-24 17:11:29 -04:00
});
2016-04-04 19:12:28 -04:00
// Hack to move the searchbox in the right spot
2016-04-04 19:12:28 -04:00
var search = panel.find(".dataTables_filter input");
search.addClass('form-control').detach();
search.appendTo(panel.find(".search"));
panel.find('.dataTables_filter').remove();
// Hack to display the page navigator properly
panel.find('.col-sm-5').remove();
var nav = panel.find('.col-sm-7');
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 () {
var cal = new CalHeatMap();
cal.init({
start: new Date().setFullYear(new Date().getFullYear() - 1),
range: 13,
2016-03-29 00:55:58 -04:00
data: '/caravel/activity_per_day',
2016-03-26 00:55:28 -04:00
domain: "month",
subDomain: "day",
2016-03-24 17:11:29 -04:00
itemName: "action",
tooltip: true
});
modelViewTable('#dash_table', '/dashboardmodelviewasync');
modelViewTable('#slice_table', '/sliceasync');
});