Skip to content

Commit 7668265

Browse files
committed
Adding ability to set min and max on number fields
1 parent 127be18 commit 7668265

23 files changed

+883
-550
lines changed

dist/angular-elastic-builder.js

Lines changed: 336 additions & 237 deletions
Large diffs are not rendered by default.

dist/angular-elastic-builder.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Angular Elastic Builder</title>
5+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
6+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
7+
</head>
8+
<body data-ng-app="exampleApp">
9+
10+
<div data-ng-controller="BasicController as example">
11+
<div class="container">
12+
<div class="row">
13+
<div class="col-md-6">
14+
<h3>Filters</h3>
15+
<div data-elastic-builder="example.data"></div>
16+
</div>
17+
<div class="col-md-6">
18+
<h3>Query</h3>
19+
<pre data-ng-bind="example.showQuery()"></pre>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
25+
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
26+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
27+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
28+
<script src="angular/angular-recursion.min.js"></script>
29+
<script src="js/angular-elastic-builder.min.js"></script>
30+
<script src="js/exampleApp.js"></script>
31+
</body>
32+
</html>

examples/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var path = require('path');
2+
var express = require('express');
3+
4+
var app = express();
5+
6+
app.use(express.static(__dirname));
7+
app.use('/js', express.static(path.join(__dirname, '../dist')));
8+
app.use('/angular', express.static(path.join(__dirname, '../node_modules/angular-recursion')));
9+
10+
app.listen(process.env.PORT || 3000, function() {
11+
console.log('listening on ' + ( process.env.PORT || 3000));
12+
});

examples/js/exampleApp.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
(function(angular) {
2+
3+
var app = angular.module('exampleApp', [
4+
'angular-elastic-builder',
5+
]);
6+
7+
app.controller('BasicController', function() {
8+
9+
var data = this.data = {};
10+
11+
data.query = [
12+
{
13+
'and': [
14+
{
15+
'range': {
16+
'test.number': {
17+
'gte': 650
18+
}
19+
}
20+
},
21+
{
22+
'range': {
23+
'test.number': {
24+
'lt': 850
25+
}
26+
}
27+
}
28+
]
29+
},
30+
{
31+
'term': {
32+
'test.boolean': 0
33+
}
34+
},
35+
{
36+
'terms': {
37+
'test.state.multi': [ 'AZ', 'CT' ]
38+
}
39+
},
40+
{
41+
'not': {
42+
'filter': {
43+
'term': {
44+
'test.term': 'asdfasdf'
45+
}
46+
}
47+
}
48+
},
49+
{
50+
'exists': {
51+
'field': 'test.term'
52+
}
53+
}
54+
];
55+
56+
data.fields = {
57+
'test.number': { type: 'number', minimum: 650 },
58+
'test.term': { type: 'term' },
59+
'test.boolean': { type: 'term', subType: 'boolean' },
60+
'test.state.multi': { type: 'multi', choices: [ 'AZ', 'CA', 'CT' ]}
61+
};
62+
63+
this.showQuery = function() {
64+
var queryToShow = {
65+
size: 0,
66+
filter: { and : data.query }
67+
};
68+
69+
return JSON.stringify(queryToShow, null, 2);
70+
};
71+
72+
});
73+
74+
})(window.angular);

gulpfile.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ var banner = ['/**'
2929
var filename = util.format('%s.js', pkg.name)
3030
, dest = 'dist/' + filename;
3131

32-
gulp.task('build', ['concat', 'header', 'uglify']);
33-
gulp.task('default', ['concat', 'header', 'uglify']);
32+
gulp.task('build', ['uglify']);
33+
gulp.task('default', ['uglify']);
3434

3535

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

40-
gulp.task('concat', [ 'clean', 'templatecache' ], function() {
40+
gulp.task('concat', [ 'templatecache' ], function() {
4141
return gulp.src(['./src/module.js', './src/**/*.js'])
4242
.pipe(concat(filename))
4343
.pipe(gulp.dest('./dist'));
@@ -49,17 +49,17 @@ gulp.task('header', [ 'concat' ], function() {
4949
.pipe(gulp.dest('./dist'));
5050
});
5151

52-
gulp.task('uglify', [ 'clean', 'concat', 'header' ], function() {
52+
gulp.task('uglify', [ 'header' ], function() {
5353
return gulp.src('./dist/*.js')
5454
.pipe(uglify(dest.replace(/\.js$/, '.min.js')))
5555
.pipe(gulp.dest('./'));
5656
});
5757

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

62-
return gulp.src('src/tmpl/*.html')
62+
return gulp.src('src/tmpl/**/*.html')
6363
.pipe(templateCache({
6464
root: 'angular-elastic-builder',
6565
module: 'angular-elastic-builder',
@@ -71,6 +71,6 @@ gulp.task('templatecache', function() {
7171
});
7272

7373
gulp.task('watch', [ 'templatecache', 'build' ], function() {
74-
gulp.watch('src/tmpl/*.html', [ 'templatecache' ]);
75-
gulp.watch('src/**/**.js', [ 'build' ]);
74+
gulp.watch('src/tmpl/**/*.html', [ 'templatecache', 'build' ]);
75+
gulp.watch(['src/**/**.js','!src/tmpl/ElasticBuilderTemplates.js'], [ 'build' ]);
7676
});

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-elastic-builder",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Angular Module for building an Elasticsearch Query",
55
"author": "Dan Crews <crewsd@gmail.com>",
66
"license": "MIT",
@@ -13,7 +13,9 @@
1313
"url": "https://github.com/dncrews/angular-elastic-builder.git"
1414
},
1515
"devDependencies": {
16+
"angular-recursion": "^1.0.5",
1617
"del": "^1.1.1",
18+
"express": "^4.12.3",
1719
"gulp": "^3.8.11",
1820
"gulp-angular-templatecache": "^1.6.0",
1921
"gulp-concat": "^2.5.2",
@@ -22,6 +24,7 @@
2224
"gulp-uglifyjs": "^0.6.1"
2325
},
2426
"scripts": {
27+
"example": "node examples",
2528
"test": "echo \"Error: no test specified\" && exit 1"
2629
}
2730
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* angular-elastic-builder
33
*
4-
* /src/ElasticBuilderDirective.js
4+
* /src/directives/BuilderDirective.js
55
*
66
* Angular Directive for injecting a query builder form.
77
*/
@@ -11,17 +11,16 @@
1111

1212
angular.module('angular-elastic-builder')
1313
.directive('elasticBuilder', [
14-
'$templateCache',
15-
'elasticBuilderService',
14+
'elasticQueryService',
1615

17-
function EB($templateCache, elasticBuilderService) {
16+
function EB(elasticQueryService) {
1817

1918
return {
2019
scope: {
2120
data: '=elasticBuilder',
2221
},
2322

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

2625
link: function(scope) {
2726
var data = scope.data;
@@ -57,7 +56,7 @@
5756
var unwatcher = scope.$watch('data.query', function(curr) {
5857
if (! curr) return;
5958

60-
scope.filters = elasticBuilderService.toFilters(data.query, scope.data.fields);
59+
scope.filters = elasticQueryService.toFilters(data.query, scope.data.fields);
6160

6261
/* Stop Watching */
6362
unwatcher();
@@ -69,7 +68,7 @@
6968
scope.$watch('filters', function(curr) {
7069
if (! curr) return;
7170

72-
data.query = elasticBuilderService.toQuery(scope.filters, scope.data.fields);
71+
data.query = elasticQueryService.toQuery(scope.filters, scope.data.fields);
7372
}, true);
7473
}
7574
};
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* angular-elastic-builder
33
*
4-
* /src/ElasticBuilderChooser.js
4+
* /src/directives/Chooser.js
55
*
66
* This file is to help recursively, to decide whether to show a group or rule
77
*/
@@ -12,10 +12,10 @@
1212
var app = angular.module('angular-elastic-builder');
1313

1414
app.directive('elasticBuilderChooser', [
15-
'$templateCache',
1615
'RecursionHelper',
16+
'groupClassHelper',
1717

18-
function elasticBuilderChooser($templateCache, RH) {
18+
function elasticBuilderChooser(RH, groupClassHelper) {
1919

2020
return {
2121
scope: {
@@ -24,28 +24,18 @@
2424
onRemove: '&',
2525
},
2626

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

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

3434
scope.getGroupClassName = function() {
35-
var levels = [
36-
'',
37-
'list-group-item-info',
38-
'list-group-item-success',
39-
'list-group-item-warning',
40-
'list-group-item-danger',
41-
];
42-
4335
var level = depth;
4436
if (item.type === 'group') level++;
4537

46-
level = level % levels.length;
47-
48-
return levels[level];
38+
return groupClassHelper(level);
4939
};
5040
});
5141
}

src/directives/ElasticBuilderRule.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)