Asterix SDK added syntax and comments; new icon for cherry example
diff --git a/asterix-app/src/main/resources/sdk/static/js/asterix-api-core.js b/asterix-app/src/main/resources/sdk/static/js/asterix-api-core.js
index 6e6fec6..69e6a6e 100644
--- a/asterix-app/src/main/resources/sdk/static/js/asterix-api-core.js
+++ b/asterix-app/src/main/resources/sdk/static/js/asterix-api-core.js
@@ -1,56 +1,114 @@
+// AsterixSDK
+// Core Object for REST API communication
+// Handles callbacks to client applications, communication to REST API, and
+// endpoint selection. Initializes an RPC consumer object.
+//
+// Usage:
+// var a = new AsterixSDK();
function AsterixSDK() {
- // Local RPC Handler for REST API
+ // Asterix SDK request handler initialization
+ // TODO Depending on configuration, may need multiples of these...
this.xhr = new easyXDM.Rpc({
remote: "http://localhost:19101/sdk/static/client.html"
}, {
remote: {
post: {}
}
- });
-}
+ })
+
+ // Asterix SDK => send
+ // Posts a message containing an API endpoint, json data,
+ // and a UI callback function.
+ //
+ // @param handler [Asterix REST Controller], a handler object
+ // that provides REST request information.
+ //
+ // Anticipated Usage:
+ //
+ // var a = AsterixSDK();
+ // var e = Expression;
+ // var h = AsterixRestController.bindExpression(e);
+ // a.send(h);
+ this.send = function(handler) {
+ var api = handler.onSend();
+ this.xhr.post(
+ api["endpoint"],
+ api["apiData"],
+ api["callback"]
+ );
+ };
-
-AsterixSDK.prototype.send = function(handler) {
- var api = handler.onSend();
- this.xhr.post(
- api["endpoint"],
- api["apiData"],
- api["callback"]
- );
-}
-
-
-/**
-* Asterix SDK / requestHandler
-*
-* Talks to
-*/
-AsterixSDK.prototype.requestHandler = function() {
- var rpc = new easyXDM.Rpc({}, {
- local: {
- post: {
- method: function(url, data, fn, fnError){
- $.ajax({
- type : 'GET',
- url : url,
- data : data,
- dataType : "json",
- success : function(res) {
- fn(res);
- }
- });
+ // Asterix SDK => requestHandler
+ // Handlers remote requests to Asterix REST API
+ // using the easyXDM RPC protocol
+ // Usually should only be called by client side, could be overridden
+ // TODO Get rid of jQuery ajax notation in favor of xmlhttprequest pure js
+ this.requestHandler = function() {
+ var rpc = new easyXDM.Rpc({}, {
+ local: {
+ post: {
+ method: function(url, data, fn, fnError){
+ $.ajax({
+ type : 'GET',
+ url : url,
+ data : data,
+ dataType : "json",
+ success : function(res) {
+ fn(res);
+ }
+ });
+ }
}
}
- }
- });
+ });
+ }
}
-
+// Asterix REST Controller
+//
// Asterix REST Controller
// Handles interactions with remote database using a request handler
function AsterixRESTController() {
-
+
+ // bindExpression
+ // Prepares an expression for query the asterix API
+ // TODO: Future expressions will do some kind of parsing on queries, for now
+ // a keyword is used to return the appropriate handler
+ // keywords: ddl, update, query, query_status, query_result
+ //
+ // @param expression [AsterixExpression], an expression or one of its
+ // subclasses
+ // @param handler [AsterixRESTController], a handler to pass to the SDK
+ // remote method call
+ this.bindExpression = function(expression, handler_type) {
+
+ // TODO Expression handler
+
+ // Parse handler, to be replaced with something more elegant
+ switch (handler_type)
+ {
+ case "ddl":
+ break;
+ case "update":
+ break;
+ case "query":
+ break;
+ case "query_status":
+ break;
+ case "query_result":
+ break;
+ default:
+ this.onHandlerInitError();
+ }
+ };
+
+ // onHandlerInitError
+ // Method for handling expression binding errors in the controller.
+ this.onHandlerInitError = function() {
+ alert("AsterixSDK / AsterixRESTController / bindExpressionError: Could not determine api endpoint, incorrect keyword");
+ }
+
// REST DDL API
this.DDL = function(data, callback) {
this.endpoint = "http://localhost:19101/ddl";
@@ -117,17 +175,33 @@
};
-// For expressions
-// TODO Is this correct name?
-// TODO Probably query API
-ForExpression.prototype = new AsterixExpression();
-ForExpression.prototype.constructor = ForExpression;
-function ForExpression() {}
-ForExpression.prototype.onSend = function () {
+// ForClause
+//
+// Grammar:
+// "for" Variable ( "at" Variable )? "in" ( Expression )
+//
+// @param for_variable [String], REQUIRED, first variable in clause
+// @param at_variable [String], NOT REQUIRED, first variable in clause
+// @param expression [AsterixExpression], REQUIRED, expression to evaluate
+//
+// Doesn't need Expression syntax
+// ForExpression.prototype = new AsterixExpression();
+// ForExpression.prototype.constructor = ForExpression;
+function ForClause(for_variable, at_variable, expression) {
+
+ // Parse for and expression
+ this.variable = for_variable;
+ this.expression = expression;
+ // at_variable is optional, check if defined
+ this.at = typeof at_variable ? a : null;
+
+ // TODO Error handling
+ this.toString = function() {
+
+ };
}
-
-//
+
/*
// ************************
diff --git a/asterix-examples/src/main/resources/cherry/examples/cherry.html b/asterix-examples/src/main/resources/cherry/examples/cherry.html
index 8e37cfe..e8facae 100755
--- a/asterix-examples/src/main/resources/cherry/examples/cherry.html
+++ b/asterix-examples/src/main/resources/cherry/examples/cherry.html
@@ -8,7 +8,9 @@
rel="stylesheet" type="text/css"/>
<link href="../css/jquery.dataTables.css" rel="stylesheet" type="text/css"/>
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
-
+
+ <link rel="shortcut icon" type="image/png" href="../img/mobile.png">
+
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"
type="text/javascript"></script>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>