[Rt-commit] rt branch, lcore, updated. fcd15a60ba8255cb561c58d8d62da0271d7b14db
clkao at bestpractical.com
clkao at bestpractical.com
Fri Oct 9 08:45:56 EDT 2009
The branch, lcore has been updated
via fcd15a60ba8255cb561c58d8d62da0271d7b14db (commit)
via 9579498cd1141bf2d12f7990a5085c5fcf9aa14a (commit)
via 3b29f0900c35e6ffa4a851a396a3df8ddae7eae2 (commit)
via 6c0ca19a9a59fad73691bf61b0738a02cdd00b50 (commit)
via 5bd634cf8f38c605b0a3d2dfdb27722dd66371f6 (commit)
from 7ca1b8b124f0f6e18a2ab28896da73fab656d308 (commit)
Summary of changes:
lib/RT/Model/Rule.pm | 23 ++++++++++++++++++++---
lib/RT/View/Form/Field/RuleTextarea.pm | 27 ++++++++++++++-------------
lib/RT/View/RuleBuilder.pm | 3 ++-
share/web/static/js/rulebuilder.js | 28 +++++++++++++++++++++++-----
4 files changed, 59 insertions(+), 22 deletions(-)
- Log -----------------------------------------------------------------
commit 5bd634cf8f38c605b0a3d2dfdb27722dd66371f6
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 9 14:14:12 2009 +0800
rulebuilder constructor to take expressions.
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index ae5784c..2c879bf 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -1,7 +1,10 @@
-RuleBuilder = function (sel, cb) {
+RuleBuilder = function (sel, expressions, cb) {
this.sel = sel;
/* defaults for now, should use ajax query */
- this.expressions = RuleBuilder.expressions;
+ if (expressions)
+ this.expressions = expressions;
+ else
+ this.expressions = RuleBuilder.expressions;
var that = this;
jQuery.get('/rulebuilder/allfunctions.json', {},
@@ -28,6 +31,7 @@ RuleBuilder.load_and_edit_lambda = function (params, return_type, el) {
jQuery.post('/rulebuilder/parse_lambda.json', { lambda_text: lambda_text },
function(response, status) {
var rb = new RuleBuilder("#expressionbuilder",
+ params,
function () {
this.load_expressions(response, this.top_context);
});
commit 6c0ca19a9a59fad73691bf61b0738a02cdd00b50
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 9 15:58:36 2009 +0800
parse_lambda should serialize parameters as well.
diff --git a/lib/RT/View/RuleBuilder.pm b/lib/RT/View/RuleBuilder.pm
index 39c37b7..ed58810 100644
--- a/lib/RT/View/RuleBuilder.pm
+++ b/lib/RT/View/RuleBuilder.pm
@@ -43,7 +43,8 @@ template 'parse_lambda.json' => sub {
my $env = $l->env;
my $lambda = $l->analyze_it(get('lambda_text'));
- print to_json( $lambda->procedure->body->to_hash );
+ print to_json( { parameters => [map { $_->to_hash} @{ $lambda->procedure->parameters} ],
+ body => $lambda->procedure->body->to_hash } );
};
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 2c879bf..5c94407 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -33,7 +33,7 @@ RuleBuilder.load_and_edit_lambda = function (params, return_type, el) {
var rb = new RuleBuilder("#expressionbuilder",
params,
function () {
- this.load_expressions(response, this.top_context);
+ this.load_expressions(response.body, this.top_context);
});
rb.finalize = function() {
var body = this.top_context.serialize();
commit 3b29f0900c35e6ffa4a851a396a3df8ddae7eae2
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 9 16:25:22 2009 +0800
load named based param into rulebuilder.
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 5c94407..0b63385 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -53,8 +53,21 @@ RuleBuilder.prototype.load_expressions = function (node, ctx) {
var func_name = node.operator.name; // XXX: ensure operator of
// type: variable
ctx.set_application(func_name, this.functions[func_name]);
- for (var i in ctx.children) {
- this.load_expressions(node.operands[i], ctx.children[i]);
+
+ var operands = node.operands;
+ if (operands instanceof Array) {
+ for (var i in ctx.children) {
+ this.load_expressions(node.operands[i], ctx.children[i]);
+ }
+ }
+ else {
+ var names = jQuery.map(this.functions[func_name].parameters,
+ function(param) { return param.name });
+ console.log(names);
+ for (var i in ctx.children) {
+ console.log("setting "+i+" "+names[i]);
+ this.load_expressions(node.operands[names[i]], ctx.children[i]);
+ }
}
}
else if (node.type == 'variable') {
commit 9579498cd1141bf2d12f7990a5085c5fcf9aa14a
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 9 20:32:40 2009 +0800
Make ruletextarea respect individual column's signatures and return_type.
diff --git a/lib/RT/Model/Rule.pm b/lib/RT/Model/Rule.pm
index 2671f19..86feb92 100644
--- a/lib/RT/Model/Rule.pm
+++ b/lib/RT/Model/Rule.pm
@@ -65,9 +65,26 @@ use base qw'RT::Record';
sub table {'Rules'}
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
- column action_code => type is 'text', render as 'RT::View::Form::Field::RuleTextarea';
- column condition_code => type is 'text', render as 'RT::View::Form::Field::RuleTextarea';
- column prepare_code => type is 'text', render as 'RT::View::Form::Field::RuleTextarea';
+ column action_code => type is 'text',
+ signatures is [ { name => 'ticket', type => 'RT::Model::Ticket' },
+ { name => 'transaction', type => 'RT::Model::Transaction' },
+ { name => 'context', type => 'HashRef' },
+ ],
+ return_type is 'Any',
+ render as 'RT::View::Form::Field::RuleTextarea';
+ column condition_code => type is 'text',
+ signatures is [ { name => 'ticket', type => 'RT::Model::Ticket' },
+ { name => 'transaction', type => 'RT::Model::Transaction' },
+],
+ return_type is 'Bool',
+ render as 'RT::View::Form::Field::RuleTextarea';
+ column prepare_code => type is 'text',
+ signatures is [ { name => 'ticket', type => 'RT::Model::Ticket' },
+ { name => 'transaction', type => 'RT::Model::Transaction' },
+ { name => 'context', type => 'HashRef' },
+ ],
+ return_type is 'Any',
+ render as 'RT::View::Form::Field::RuleTextarea';
column description => type is 'text';
};
use Jifty::Plugin::ActorMetadata::Mixin::Model::ActorMetadata map => {
diff --git a/lib/RT/View/Form/Field/RuleTextarea.pm b/lib/RT/View/Form/Field/RuleTextarea.pm
index 3f3db3e..6c1f0da 100644
--- a/lib/RT/View/Form/Field/RuleTextarea.pm
+++ b/lib/RT/View/Form/Field/RuleTextarea.pm
@@ -2,8 +2,13 @@ package RT::View::Form::Field::RuleTextarea;
use warnings;
use strict;
use Jifty::View::Declare;
+use JSON;
use base 'Jifty::Web::Form::Field::Textarea';
+__PACKAGE__->mk_accessors(qw(signatures return_type));
+
+sub accessors { shift->SUPER::accessors(), 'signatures', 'return_type' }
+
sub render_widget {
my $self = shift;
$self->SUPER::render_widget(@_);
@@ -12,19 +17,15 @@ sub render_widget {
}
sub render_rulebuilder_launcher {
- Jifty->web->out('
-<input type="submit" value="Edit!" onClick="RuleBuilder.load_and_edit_lambda([
- { expression: \'ticket\',
- type: \'RT::Model::Ticket\'
- },
- { expression: \'transaction\',
- type: \'RT::Model::Transaction\'
- }
-], \'Bool\', this);"/>
-
-
- ');
-
+ my $self = shift;
+ my $signatures = $self->attributes->{signatures};
+ my $return_type = $self->attributes->{return_type};
+ my $params_json = to_json(
+ [ map { { expression => $_->{name}, type => $_->{type} } }
+ @$signatures ] );
+ Jifty->web->out(qq{
+<input type="submit" value="Edit!" onClick='RuleBuilder.load_and_edit_lambda($params_json, "$return_type", this);' />
+});
}
1;
commit fcd15a60ba8255cb561c58d8d62da0271d7b14db
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Fri Oct 9 20:45:40 2009 +0800
hide "enter a value" prompt after loading self-evaluting expression
diff --git a/share/web/static/js/rulebuilder.js b/share/web/static/js/rulebuilder.js
index 0b63385..30f963e 100644
--- a/share/web/static/js/rulebuilder.js
+++ b/share/web/static/js/rulebuilder.js
@@ -75,6 +75,7 @@ RuleBuilder.prototype.load_expressions = function (node, ctx) {
ctx.set_expression(expressions[0]);
}
else if (node.type == 'self_evaluating') {
+ jQuery('span.enter-value', ctx.element).hide();
jQuery._input_({ 'type': 'text', 'class': 'enter-value', 'value': node.value})
.change(function() { ctx.update_return_type(ctx.return_type_from_val(this.value)) } )
.appendTo(ctx.element).trigger('focus');
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list