Skip to content

Commit

Permalink
Adding ability to set min and max on number fields
Browse files Browse the repository at this point in the history
  • Loading branch information
dncrews committed Apr 20, 2015
1 parent 127be18 commit 7668265
Show file tree
Hide file tree
Showing 23 changed files with 883 additions and 550 deletions.
573 changes: 336 additions & 237 deletions dist/angular-elastic-builder.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/angular-elastic-builder.min.js

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<title>Angular Elastic Builder</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
</head>
<body data-ng-app="exampleApp">

<div data-ng-controller="BasicController as example">
<div class="container">
<div class="row">
<div class="col-md-6">
<h3>Filters</h3>
<div data-elastic-builder="example.data"></div>
</div>
<div class="col-md-6">
<h3>Query</h3>
<pre data-ng-bind="example.showQuery()"></pre>
</div>
</div>
</div>
</div>

<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="angular/angular-recursion.min.js"></script>
<script src="js/angular-elastic-builder.min.js"></script>
<script src="js/exampleApp.js"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var path = require('path');
var express = require('express');

var app = express();

app.use(express.static(__dirname));
app.use('/js', express.static(path.join(__dirname, '../dist')));
app.use('/angular', express.static(path.join(__dirname, '../node_modules/angular-recursion')));

app.listen(process.env.PORT || 3000, function() {
console.log('listening on ' + ( process.env.PORT || 3000));
});
74 changes: 74 additions & 0 deletions examples/js/exampleApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(function(angular) {

var app = angular.module('exampleApp', [
'angular-elastic-builder',
]);

app.controller('BasicController', function() {

var data = this.data = {};

data.query = [
{
'and': [
{
'range': {
'test.number': {
'gte': 650
}
}
},
{
'range': {
'test.number': {
'lt': 850
}
}
}
]
},
{
'term': {
'test.boolean': 0
}
},
{
'terms': {
'test.state.multi': [ 'AZ', 'CT' ]
}
},
{
'not': {
'filter': {
'term': {
'test.term': 'asdfasdf'
}
}
}
},
{
'exists': {
'field': 'test.term'
}
}
];

data.fields = {
'test.number': { type: 'number', minimum: 650 },
'test.term': { type: 'term' },
'test.boolean': { type: 'term', subType: 'boolean' },
'test.state.multi': { type: 'multi', choices: [ 'AZ', 'CA', 'CT' ]}
};

this.showQuery = function() {
var queryToShow = {
size: 0,
filter: { and : data.query }
};

return JSON.stringify(queryToShow, null, 2);
};

});

})(window.angular);
16 changes: 8 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ var banner = ['/**'
var filename = util.format('%s.js', pkg.name)
, dest = 'dist/' + filename;

gulp.task('build', ['concat', 'header', 'uglify']);
gulp.task('default', ['concat', 'header', 'uglify']);
gulp.task('build', ['uglify']);
gulp.task('default', ['uglify']);


gulp.task('clean', function(done) {
del('./dist', done);
});

gulp.task('concat', [ 'clean', 'templatecache' ], function() {
gulp.task('concat', [ 'templatecache' ], function() {
return gulp.src(['./src/module.js', './src/**/*.js'])
.pipe(concat(filename))
.pipe(gulp.dest('./dist'));
Expand All @@ -49,17 +49,17 @@ gulp.task('header', [ 'concat' ], function() {
.pipe(gulp.dest('./dist'));
});

gulp.task('uglify', [ 'clean', 'concat', 'header' ], function() {
gulp.task('uglify', [ 'header' ], function() {
return gulp.src('./dist/*.js')
.pipe(uglify(dest.replace(/\.js$/, '.min.js')))
.pipe(gulp.dest('./'));
});

gulp.task('templatecache', function() {
gulp.task('templatecache', [ 'clean' ], function() {
var TEMPLATE_HEADER = '(function(angular) {"use strict"; angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {'
, TEMPLATE_FOOTER = '}]);})(window.angular);';

return gulp.src('src/tmpl/*.html')
return gulp.src('src/tmpl/**/*.html')
.pipe(templateCache({
root: 'angular-elastic-builder',
module: 'angular-elastic-builder',
Expand All @@ -71,6 +71,6 @@ gulp.task('templatecache', function() {
});

gulp.task('watch', [ 'templatecache', 'build' ], function() {
gulp.watch('src/tmpl/*.html', [ 'templatecache' ]);
gulp.watch('src/**/**.js', [ 'build' ]);
gulp.watch('src/tmpl/**/*.html', [ 'templatecache', 'build' ]);
gulp.watch(['src/**/**.js','!src/tmpl/ElasticBuilderTemplates.js'], [ 'build' ]);
});
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-elastic-builder",
"version": "1.1.1",
"version": "1.2.0",
"description": "Angular Module for building an Elasticsearch Query",
"author": "Dan Crews <[email protected]>",
"license": "MIT",
Expand All @@ -13,7 +13,9 @@
"url": "https://github.com/dncrews/angular-elastic-builder.git"
},
"devDependencies": {
"angular-recursion": "^1.0.5",
"del": "^1.1.1",
"express": "^4.12.3",
"gulp": "^3.8.11",
"gulp-angular-templatecache": "^1.6.0",
"gulp-concat": "^2.5.2",
Expand All @@ -22,6 +24,7 @@
"gulp-uglifyjs": "^0.6.1"
},
"scripts": {
"example": "node examples",
"test": "echo \"Error: no test specified\" && exit 1"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* angular-elastic-builder
*
* /src/ElasticBuilderDirective.js
* /src/directives/BuilderDirective.js
*
* Angular Directive for injecting a query builder form.
*/
Expand All @@ -11,17 +11,16 @@

angular.module('angular-elastic-builder')
.directive('elasticBuilder', [
'$templateCache',
'elasticBuilderService',
'elasticQueryService',

function EB($templateCache, elasticBuilderService) {
function EB(elasticQueryService) {

return {
scope: {
data: '=elasticBuilder',
},

template: $templateCache.get('angular-elastic-builder/BuilderDirective.html'),
templateUrl: 'angular-elastic-builder/BuilderDirective.html',

link: function(scope) {
var data = scope.data;
Expand Down Expand Up @@ -57,7 +56,7 @@
var unwatcher = scope.$watch('data.query', function(curr) {
if (! curr) return;

scope.filters = elasticBuilderService.toFilters(data.query, scope.data.fields);
scope.filters = elasticQueryService.toFilters(data.query, scope.data.fields);

/* Stop Watching */
unwatcher();
Expand All @@ -69,7 +68,7 @@
scope.$watch('filters', function(curr) {
if (! curr) return;

data.query = elasticBuilderService.toQuery(scope.filters, scope.data.fields);
data.query = elasticQueryService.toQuery(scope.filters, scope.data.fields);
}, true);
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* angular-elastic-builder
*
* /src/ElasticBuilderChooser.js
* /src/directives/Chooser.js
*
* This file is to help recursively, to decide whether to show a group or rule
*/
Expand All @@ -12,10 +12,10 @@
var app = angular.module('angular-elastic-builder');

app.directive('elasticBuilderChooser', [
'$templateCache',
'RecursionHelper',
'groupClassHelper',

function elasticBuilderChooser($templateCache, RH) {
function elasticBuilderChooser(RH, groupClassHelper) {

return {
scope: {
Expand All @@ -24,28 +24,18 @@
onRemove: '&',
},

template: $templateCache.get('angular-elastic-builder/ChooserDirective.html'),
templateUrl: 'angular-elastic-builder/ChooserDirective.html',

compile: function (element) {
return RH.compile(element, function(scope, el, attrs) {
var depth = scope.depth = (+ attrs.depth)
, item = scope.item;

scope.getGroupClassName = function() {
var levels = [
'',
'list-group-item-info',
'list-group-item-success',
'list-group-item-warning',
'list-group-item-danger',
];

var level = depth;
if (item.type === 'group') level++;

level = level % levels.length;

return levels[level];
return groupClassHelper(level);
};
});
}
Expand Down
29 changes: 0 additions & 29 deletions src/directives/ElasticBuilderRule.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* angular-elastic-builder
*
* /src/ElasticBuilderGroup.js
* /src/directives/Group.js
*/

(function(angular) {
Expand All @@ -10,10 +10,10 @@
var app = angular.module('angular-elastic-builder');

app.directive('elasticBuilderGroup', [
'$templateCache',
'RecursionHelper',
'groupClassHelper',

function elasticBuilderGroup($templateCache, RH) {
function elasticBuilderGroup(RH, groupClassHelper) {

return {
scope: {
Expand All @@ -22,11 +22,11 @@
onRemove: '&',
},

template: $templateCache.get('angular-elastic-builder/GroupDirective.html'),
templateUrl: 'angular-elastic-builder/GroupDirective.html',

compile: function(element) {
return RH.compile(element, function(scope, el, attrs) {
scope.depth = (+ attrs.depth);
var depth = scope.depth = (+ attrs.depth);
var group = scope.group;

scope.addRule = function() {
Expand All @@ -43,6 +43,10 @@
scope.removeChild = function(idx) {
group.rules.splice(idx, 1);
};

scope.getGroupClassName = function() {
return groupClassHelper(depth + 1);
};
});
}
};
Expand Down
Loading

0 comments on commit 7668265

Please sign in to comment.