forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the json generator for basic aggregations
- Loading branch information
Showing
6 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var jsonGenerator = require("./modules/json_generator"); | ||
|
||
$(document).ready(function () { | ||
$('#convertButton').click(function () { | ||
var expression = $('#expression').val().trim(); | ||
var parse_tree = jsonGenerator.parse(expression); | ||
console.log(parse_tree); | ||
$('#json').val(JSON.stringify(parse_tree)); | ||
$(this).closest('.modal').modal('hide'); | ||
}); | ||
$('#json_gen_modal').on('shown.bs.modal', function () { | ||
$('#expression').focus(); | ||
}); | ||
|
||
var showJsonGenModal = function () { | ||
$('#json_gen_modal').modal('show'); | ||
}; | ||
|
||
$.extend(window, { | ||
showJsonGenModal: showJsonGenModal | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
var jsep = require("jsep"); | ||
|
||
var typeMap = { | ||
sum: 'doubleSum', | ||
doubleSum: 'doubleSum', | ||
longSum: 'longSum', | ||
}; | ||
|
||
var capitalize = function (string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
}; | ||
|
||
var convertFuncCall = function (node) { | ||
var funcName = node.callee.name; | ||
var fieldName = node.arguments[0].name; | ||
if (!funcName) return; | ||
var m = funcName.toLowerCase().match(/^(double|long)?(sum|min|max)$/); | ||
if (!m) return; | ||
|
||
var varType = m[1] || 'double'; // default to double | ||
var funcType = m[2]; | ||
|
||
var type = varType + capitalize(funcType); | ||
|
||
return { | ||
type: type, | ||
name: fieldName, | ||
fieldName: fieldName, | ||
}; | ||
}; | ||
|
||
var parse = function (expression) { | ||
expression = expression.trim(); | ||
var parse_tree = jsep(expression); | ||
parse_tree = convertFuncCall(parse_tree); | ||
return parse_tree; | ||
}; | ||
|
||
module.exports = { | ||
parse: parse | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{% extends "appbuilder/general/model/edit.html" %} | ||
|
||
{% block content %} | ||
{{ super() }} | ||
<div class="modal fade" id="json_gen_modal" tabindex="-1" role="dialog"> | ||
<div class="modal-dialog" role="document"> | ||
<div class="modal-content css"> | ||
<div class="modal-header"> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> | ||
<h4 class="modal-title" id="myModalLabel">JSON Generator</h4> | ||
<h6><strong>Enter the algebraic expression to convert. E.g. longSum(price), doubleMin(price)</strong></h6> | ||
</div> | ||
<div class="modal-body"> | ||
<textarea id="expression" rows="5" cols="60"></textarea> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-default" data-dismiss="modal"> | ||
Close | ||
</button> | ||
<button type="button" class="btn btn-default" id="convertButton"> | ||
Convert to Json | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block tail_js %} | ||
{{ super() }} | ||
<script src="/static/assets/javascripts/dist/datasource.entry.js"></script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters