Skip to content

Commit

Permalink
simplified static operand values
Browse files Browse the repository at this point in the history
  • Loading branch information
futurechan committed May 28, 2015
1 parent 1df86eb commit 310aba4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-expression-builder",
"version": "0.2.0",
"version": "0.3.0",
"authors": [
"Josh <[email protected]>"
],
Expand Down
23 changes: 6 additions & 17 deletions dist/expression-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ angular.module('expression-builder', ['ui.bootstrap'])
}

$scope.getLeftOperands=function($viewValue){
if($scope.staticLeftOperandProvider)
return $scope.staticLeftOperandProvider();

return ($scope.leftOperandProvider)
? $scope.leftOperandProvider($viewValue)
: [];
}

$scope.getRightOperands=function($viewValue){
if($scope.staticRightOperandProvider)
return $scope.staticRightOperandProvider();

return ($scope.rightOperandProvider)
? $scope.rightOperandProvider($viewValue)
: [];
Expand All @@ -49,10 +43,10 @@ angular.module('expression-builder', ['ui.bootstrap'])
conditions: '=',
booleanOperators: '=?',
comparisonOperators: '=?',
leftOperands: '=?',
leftOperandProvider: '&',
staticLeftOperandProvider: '&',
rightOperandProvider: '&',
staticRightOperandProvider: '&'
rightOperands: '=?',
rightOperandProvider: '&'
},
compile: function (element) {
var contents = element.contents().remove();
Expand All @@ -73,21 +67,16 @@ angular.module('expression-builder', ['ui.bootstrap'])
if(scope.comparisonOperators === undefined)
scope.comparisonOperators = ['=', '<>', '<', '<=', '>', '>=', '[]', '![]'];

if(scope.left)

if(scope.leftOperandProvider)
scope.leftOperandProvider = scope.leftOperandProvider()

if(scope.staticLeftOperandProvider)
scope.staticLeftOperandProvider = scope.staticLeftOperandProvider()

if(scope.rightOperandProvider)
scope.rightOperandProvider = scope.rightOperandProvider()

if(scope.staticRightOperandProvider)
scope.staticRightOperandProvider = scope.staticRightOperandProvider()

};
}
};
})

angular.module("expression-builder").run(["$templateCache", function($templateCache) {$templateCache.put("templates/expressionbuilder.html","<div class=condition-builder><div ng-repeat=\"c in conditions\"><div ng-if=\"$index != 0\" class=\"form-inline bool-op\"><select class=\"form-control input-sm\" ng-options=\"o as o for o in booleanOperators\" ng-model=c.bool></select></div><div ng-if=c.conditions class=condition-group><div class=pull-right><button class=\"btn btn-danger btn-sm\" ng-click=removeAt($index)>&times;</button></div><expression-builder conditions=c.conditions boolean-operators=booleanOperators comparison-operators=comparisonOperators left-operand-provider=leftOperandProvider static-left-operand-provider=staticLeftOperandProvider right-operand-provider=rightOperandProvider static-right-operand-provider=staticRightOperandProvider></expression-builder></div><div ng-if=!c.conditions class=form-inline><div class=form-group-sm><select class=form-control ng-if=staticLeftOperandProvider ng-model=c.leftOperand ng-options=\"operand for operand in getLeftOperands()\"></select><input class=form-control ng-if=!staticLeftOperandProvider ng-model=c.leftOperand placeholder=\"Left Operand\" typeahead=\"operand for operand in getLeftOperands($viewValue)\"><select class=form-control ng-model=c.comparison ng-options=\"o as o for o in comparisonOperators\"></select><select class=form-control ng-if=staticRightOperandProvider ng-model=c.rightOperand ng-options=\"operand for operand in getRightOperands()\"></select><input class=form-control ng-if=!staticRightOperandProvider ng-model=c.rightOperand placeholder=\"Right Operand\" typeahead=\"operand for operand in getRightOperands($viewValue)\"> <button class=\"btn btn-danger btn-sm\" ng-click=removeAt($index)>&times;</button></div></div></div><div class=condition-group-button-row><button class=\"btn btn-default btn-sm\" ng-click=addCondition()><span class=\"glyphicon glyphicon-plus-sign\"></span> Add Condition</button> <button class=\"btn btn-default btn-sm\" ng-click=addGroup()><span class=\"glyphicon glyphicon-plus-sign\"></span> Add Group</button></div></div>");}]);
angular.module("expression-builder").run(["$templateCache", function($templateCache) {$templateCache.put("templates/expressionbuilder.html","<div class=condition-builder><div ng-repeat=\"c in conditions\"><div ng-if=\"$index != 0\" class=\"form-inline bool-op\"><select class=\"form-control input-sm\" ng-options=\"o as o for o in booleanOperators\" ng-model=c.bool></select></div><div ng-if=c.conditions class=condition-group><div class=pull-right><button class=\"btn btn-danger btn-sm\" ng-click=removeAt($index)>&times;</button></div><expression-builder conditions=c.conditions boolean-operators=booleanOperators comparison-operators=comparisonOperators left-operands=leftOperands left-operand-provider=leftOperandProvider right-operands=rightOperands right-operand-provider=rightOperandProvider></expression-builder></div><div ng-if=!c.conditions class=form-inline><div class=form-group-sm><select class=form-control ng-if=leftOperands ng-model=c.leftOperand ng-options=\"operand for operand in leftOperands\"></select><input class=form-control ng-if=!leftOperands ng-model=c.leftOperand placeholder=\"Left Operand\" typeahead=\"operand for operand in getLeftOperands($viewValue)\"><select class=form-control ng-model=c.comparison ng-options=\"o as o for o in comparisonOperators\"></select><select class=form-control ng-if=rightOperands ng-model=c.rightOperand ng-options=\"operand for operand in rightOperands\"></select><input class=form-control ng-if=!rightOperands ng-model=c.rightOperand placeholder=\"Right Operand\" typeahead=\"operand for operand in getRightOperands($viewValue)\"> <button class=\"btn btn-danger btn-sm\" ng-click=removeAt($index)>&times;</button></div></div></div><div class=condition-group-button-row><button class=\"btn btn-default btn-sm\" ng-click=addCondition()><span class=\"glyphicon glyphicon-plus-sign\"></span> Add Condition</button> <button class=\"btn btn-default btn-sm\" ng-click=addGroup()><span class=\"glyphicon glyphicon-plus-sign\"></span> Add Group</button></div></div>");}]);
2 changes: 1 addition & 1 deletion dist/expression-builder.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
.controller("AppController", function($scope){
//$scope.booleanOperators=['AND', 'OR', 'AND NOT'];

var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];

$scope.getStateList = function(){return states;}
$scope.states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Dakota', 'North Carolina', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];

$scope.getStates=function($viewValue){
var results = [];

states.forEach(function(state){
$scope.states.forEach(function(state){
if(state.toLowerCase().indexOf($viewValue.toLowerCase()) > -1)
results.push(state);
})
Expand Down Expand Up @@ -63,7 +61,7 @@

<expression-builder
conditions="conditions" boolean-operators="booleanOperators"
static-left-operand-provider="getStateList"
left-operands="states"
right-operand-provider="getStates"></expression-builder>

<expression-stringer
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-expression-builder",
"version": "0.2.0",
"version": "0.3.0",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
21 changes: 5 additions & 16 deletions src/js/expression-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,12 @@ angular.module('expression-builder', ['ui.bootstrap'])
}

$scope.getLeftOperands=function($viewValue){
if($scope.staticLeftOperandProvider)
return $scope.staticLeftOperandProvider();

return ($scope.leftOperandProvider)
? $scope.leftOperandProvider($viewValue)
: [];
}

$scope.getRightOperands=function($viewValue){
if($scope.staticRightOperandProvider)
return $scope.staticRightOperandProvider();

return ($scope.rightOperandProvider)
? $scope.rightOperandProvider($viewValue)
: [];
Expand All @@ -49,10 +43,10 @@ angular.module('expression-builder', ['ui.bootstrap'])
conditions: '=',
booleanOperators: '=?',
comparisonOperators: '=?',
leftOperands: '=?',
leftOperandProvider: '&',
staticLeftOperandProvider: '&',
rightOperandProvider: '&',
staticRightOperandProvider: '&'
rightOperands: '=?',
rightOperandProvider: '&'
},
compile: function (element) {
var contents = element.contents().remove();
Expand All @@ -73,18 +67,13 @@ angular.module('expression-builder', ['ui.bootstrap'])
if(scope.comparisonOperators === undefined)
scope.comparisonOperators = ['=', '<>', '<', '<=', '>', '>=', '[]', '![]'];

if(scope.left)

if(scope.leftOperandProvider)
scope.leftOperandProvider = scope.leftOperandProvider()

if(scope.staticLeftOperandProvider)
scope.staticLeftOperandProvider = scope.staticLeftOperandProvider()

if(scope.rightOperandProvider)
scope.rightOperandProvider = scope.rightOperandProvider()

if(scope.staticRightOperandProvider)
scope.staticRightOperandProvider = scope.staticRightOperandProvider()

};
}
};
Expand Down
16 changes: 8 additions & 8 deletions src/templates/expressionbuilder.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@
conditions="c.conditions"
boolean-operators="booleanOperators"
comparison-operators="comparisonOperators"
left-operand-provider="leftOperandProvider" static-left-operand-provider="staticLeftOperandProvider"
right-operand-provider="rightOperandProvider" static-right-operand-provider="staticRightOperandProvider">
left-operands="leftOperands" left-operand-provider="leftOperandProvider"
right-operands="rightOperands" right-operand-provider="rightOperandProvider">
</expression-builder>
</div>

<div ng-if="!c.conditions" class="form-inline">
<div class="form-group-sm">

<select class="form-control" ng-if="staticLeftOperandProvider"
<select class="form-control" ng-if="leftOperands"
ng-model="c.leftOperand"
ng-options="operand for operand in getLeftOperands()"></select>
<input class="form-control" ng-if="!staticLeftOperandProvider"
ng-options="operand for operand in leftOperands"></select>
<input class="form-control" ng-if="!leftOperands"
ng-model="c.leftOperand" placeholder="Left Operand"
typeahead="operand for operand in getLeftOperands($viewValue)">

<select class="form-control"
ng-model="c.comparison"
ng-options="o as o for o in comparisonOperators"></select>

<select class="form-control" ng-if="staticRightOperandProvider"
<select class="form-control" ng-if="rightOperands"
ng-model="c.rightOperand"
ng-options="operand for operand in getRightOperands()"></select>
<input class="form-control" ng-if="!staticRightOperandProvider"
ng-options="operand for operand in rightOperands"></select>
<input class="form-control" ng-if="!rightOperands"
ng-model="c.rightOperand" placeholder="Right Operand"
typeahead="operand for operand in getRightOperands($viewValue)">

Expand Down

0 comments on commit 310aba4

Please sign in to comment.