Skip to content

Commit

Permalink
fix dncrews#7: date format parsed from query to builder - eslinted - …
Browse files Browse the repository at this point in the history
…v1.5.5
  • Loading branch information
oguennec committed Jul 13, 2016
1 parent 923822b commit eedeef2
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 119 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ It's still pretty early on, as it doesn't support a whole lot of use-cases, but
Notice: this plugin requires:
- the [Angular Recursion](https://github.com/marklagendijk/angular-recursion) module.
- the [Angular directives for Bootstrap](https://github.com/angular-ui/bootstrap) module to display the Calendar (ui.bootstrap.datepicker)
- the [Angular Moment](https://github.com/urish/angular-moment) module.

### Installation
First you'll need to download the [dist](https://github.com/dncrews/angular-elastic-builder/tree/master/dist) files and include this JS file to your app (don't forget to substitute `x.x.x` with the current version number), along with the RecursionHelper, if you're not already using it.
```html
<script type="text/javascript" src="angular-ui-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="moment/moment.js"></script>
<script src="angular-moment/angular-moment.js"></script>
<script type="text/javascript" src="angular-recursion/angular-recursion.min.js"></script>
<script type="text/javascript" src="angular-elastic-builder/angular-elastic-builder.min.js"></script>
```
Expand Down
29 changes: 24 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
{
"name": "angular-elastic-builder",
"homepage": "https://github.com/dncrews/angular-elastic-builder",
"name": "angular-elastic-builder-oguennec",
"version": "1.5.5",
"description": "Angular Module for building an Elasticsearch Query",
"homepage": "https://github.com/oguennec/angular-elastic-builder",
"authors": [
"Dan Crews <[email protected]>"
{
"name": "Dan Crews",
"email": "[email protected]"
},
{
"name": "Olivier Guennec",
"email": "[email protected]"
}
],
"description": "Angular Module for building an Elasticsearch Query",
"repository": {
"type": "git",
"url": "https://github.com/oguennec/angular-elastic-builder.git"
},
"main": "dist/angular-elastic-builder.js",
"keywords": [
"elasticsearch",
Expand All @@ -17,5 +29,12 @@
"bower_components",
"test",
"tests"
]
],
"devDependencies": {
"angular-moment": "^0.10.3",
"angular-recursion": "^1.0.5",
"angular-ui-bootstrap": "^1.3.3",
"express": "^4.13.4",
"moment": "^2.13.0"
}
}
154 changes: 103 additions & 51 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.

2 changes: 2 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ <h3>Query</h3>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="angular-ui-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="moment/moment.js"></script>
<script src="angular-moment/angular-moment.js"></script>
<script src="angular-recursion/angular-recursion.min.js"></script>
<script src="js/angular-elastic-builder.js"></script>
<script src="js/exampleApp.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ app.use(express.static(__dirname));
app.use('/js', express.static(path.join(__dirname, '../dist')));
app.use('/angular-recursion', express.static(path.join(__dirname, '../node_modules/angular-recursion')));
app.use('/angular-ui-bootstrap', express.static(path.join(__dirname, '../node_modules/angular-ui-bootstrap/dist')));
app.use('/moment', express.static(path.join(__dirname, '../node_modules/moment')));
app.use('/angular-moment', express.static(path.join(__dirname, '../node_modules/angular-moment')));

app.listen(process.env.PORT || 3000, function() {
console.log('listening on ' + ( process.env.PORT || 3000));
Expand Down
12 changes: 7 additions & 5 deletions examples/js/exampleApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'and': [
{
'term': {
'test.date': '2016-04-08T09:16:48'
"test.date": "2016-04-07T23:59:59",
"format": "yyyy-MM-ddTHH:mm:ss"
}
},
{
Expand All @@ -25,8 +26,9 @@
},
{
'range': {
'test.number': {
'lt': 850
'test.otherdate': {
"lt": "2016/04/07",
"format": "yyyy/MM/dd"
}
}
}
Expand Down Expand Up @@ -59,8 +61,8 @@
{
'range': {
'test.otherdate': {
'gte': 'now',
'lte': 'now+7d'
"gte": "now-7d",
"lte": "now"
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
{
"name": "angular-elastic-builder",
"version": "1.5.1",
"name": "angular-elastic-builder-oguennec",
"version": "1.5.5",
"description": "Angular Module for building an Elasticsearch Query",
"author": "Dan Crews <[email protected]>",
"contributors": [{
"name": "Olivier Guennec",
"email": "[email protected]"
}],
"license": "MIT",
"keywords": [
"angular",
"elasticsearch"
],
"repository": {
"type": "git",
"url": "https://github.com/dncrews/angular-elastic-builder.git"
"url": "https://github.com/oguennec/angular-elastic-builder.git"
},
"devDependencies": {
"angular-moment": "^0.10.3",
"angular-recursion": "^1.0.5",
"angular-ui-bootstrap": "^1.2.5",
"del": "^1.2.1",
Expand All @@ -24,7 +29,8 @@
"gulp-eslint": "^2.0.0",
"gulp-header": "^1.2.2",
"gulp-rename": "^1.2.2",
"gulp-uglifyjs": "^0.6.1"
"gulp-uglifyjs": "^0.6.1",
"moment": "^2.13.0"
},
"scripts": {
"example": "node examples",
Expand Down
45 changes: 33 additions & 12 deletions src/directives/RuleTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

app.directive('elasticType', [

function() {
'$filter', 'moment',
function($filter, moment) {
return {
scope: {
type: '=elasticType',
Expand Down Expand Up @@ -60,18 +61,13 @@
return ~needs.indexOf(scope.rule.subType);
};

scope.today = function() {
scope.rule.date = new Date();
};
scope.today();

scope.clear = function() {
scope.rule.date = null;
};

scope.dateOptions = {
dateDisabled: disabled,
formatYear: 'yy',
formatYear: 'yyyy',
maxDate: new Date(2018, 1, 13),
minDate: new Date(),
startingDay: 1,
Expand All @@ -88,20 +84,45 @@
scope.popup1.opened = true;
};

scope.setDate = function(year, month, day) {
scope.rule.date = new Date(year, month - 1, day);

scope.formatDate = function (date) {
if (scope.rule.format) {
var inputFormat = scope.rule.format;
//moment requires yyyy and DD in upper case but ui.datepicker and Elastic require lower case
var momentFormat = inputFormat.replace(/(yyyy|yy|d|dd|ddd)/g, function(str) {
return str.toUpperCase();
});

var fDate = moment(date, momentFormat);

return fDate.toDate(momentFormat);

}
};

scope.formatDate($filter, scope.rule.value);

scope.setDate = function() {
if (scope.rule.format) {
scope.rule.date = scope.formatDate(scope.rule.value);
scope.date = scope.rule.date;
}
};

scope.setDate();

scope.formats = [
'yyyy-MM-ddTHH:mm:ss',
'yyyy-MM-ddTHH:mm:ssZ',
'yyyy-MM-dd',
'yyyyMMdd',
'dd-MMMM-yyyy',
'yyyy/MM/dd',
'shortDate',
];
scope.rule.dateFormat = scope.formats[0];
scope.format = scope.rule.dateFormat;

if (scope.rule.hasOwnProperty('format')) {
scope.format = scope.rule.format;
}

scope.altInputFormats = ['M!/d!/yyyy'];

Expand Down
2 changes: 2 additions & 0 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
angular.module('angular-elastic-builder', [
'RecursionHelper',
'ui.bootstrap',
'angularMoment',
]);
//angular.module('angular-elastic-builder').constant('moment', require('moment-timezone'));

})(window.angular);
Loading

0 comments on commit eedeef2

Please sign in to comment.