Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AAE-3967] Add datetime-range search filter component #6297

Merged
merged 6 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,7 +7,7 @@ Last reviewed: 2018-06-11

# [Search date range component](../../../lib/content-services/src/lib/search/components/search-date-range/search-date-range.component.ts "Defined in search-date-range.component.ts")

Implements a date range [widget](../../../lib/testing/src/lib/core/pages/form/widgets/widget.ts) for the [Search Filter component](search-filter.component.md).
Implements a [search widget](../../../lib/content-services/src/lib/search/search-widget.interface.ts) for the [Search Filter component](search-filter.component.md).

![Date Range Widget](../../docassets/images/search-date-range.png)

Expand Down
@@ -0,0 +1,85 @@
---
Title: Search datetime range component
Added: v4.2.0
Status: Active
Last reviewed: 2020-11-02
---

# [Search datetime range component](../../../lib/content-services/src/lib/search/components/search-datetime-range/search-datetime-range.component.ts "Defined in search-datetime-range.component.ts")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be search-datetime-range.component.ts instead of search-date-range.component.ts?

Implements a [search widget](../../../lib/content-services/src/lib/search/search-widget.interface.ts) for the [Search Filter component](search-filter.component.md).

![Date Range Widget](../../docassets/images/search-datetime-range.png)

## Basic usage

```json
{
"search": {
"categories": [
{
"id": "createdDatetimeRange",
"name": "Created Datetime (range)",
"enabled": true,
"component": {
"selector": "datetime-range",
"settings": {
"field": "cm:created"
}
}
}
]
}
}
```

### Settings

| Name | Type | Description |
| ---- | ---- | ----------- |
| field | string | Field to apply the query to. Required value |
| datetimeFormat | string | Datetime format. Datetime formats used by the datetime picker are [Moment.js](https://momentjs.com/docs/#/parsing/string-format/) instances, so you can use any datetime format supported by Moment. Default is 'DD/MM/YYYY HH:mm'. |
| maxDatetime | string | A fixed datetime that will set the maximum searchable datetime. Default is no maximum. |

## Details

This component lets the user select a range between two dates and times based on the particular `field`.
See the [Search filter component](search-filter.component.md) for full details of how to use widgets
in a search query.

### Custom datetime format

You can set the datetime range picker to work with any datetime format your app requires. You can use
any datetime format supported by [Moment.js](https://momentjs.com/docs/#/parsing/string-format/)
in the `datetimeFormat` and in the `maxDatetime` setting:

```json
{
"search": {
"categories": [
{
"id": "createdDateTimeRange",
"name": "Created Datetime (range)",
"enabled": true,
"component": {
"selector": "datetime-range",
"settings": {
"field": "cm:created",
"datetimeFormat": "DD-MMM-YY HH:mm:ss",
"maxDatetime": "10-Mar-20 20:00"
}
}
}
]
}
}
```

## See also

- [Search filter component](search-filter.component.md)
- [Search check list component](search-check-list.component.md)
- [Search number range component](search-number-range.component.md)
- [Search radio component](search-radio.component.md)
- [Search slider component](search-slider.component.md)
- [Search text component](search-text.component.md)
Binary file added docs/docassets/images/search-datetime-range.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -40,6 +40,7 @@ describe('ContentNodeSelectorPanelService', () => {
const expectedSupportedTypesMap = new Map<string, string> ();
expectedSupportedTypesMap.set('d:text', 'text');
expectedSupportedTypesMap.set('d:date', 'date-range');
expectedSupportedTypesMap.set('d:datetime', 'datetime-range');

expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap).toEqual(expectedSupportedTypesMap);
});
Expand Down
Expand Up @@ -23,13 +23,14 @@ import { SearchCategory } from '../search/search-category.interface';
})
export class ContentNodeSelectorPanelService {

propertyTypes = ['d:text', 'd:date'];
propertyTypes = ['d:text', 'd:date', 'd:datetime'];
modelPropertyTypeToSearchFilterTypeMap = new Map<string, string> ();
customModels: any[];

constructor() {
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[0], 'text');
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[1], 'date-range');
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[2], 'datetime-range');
}

convertCustomModelPropertiesToSearchCategories(): SearchCategory[] {
Expand Down
4 changes: 3 additions & 1 deletion lib/content-services/src/lib/i18n/en.json
Expand Up @@ -251,7 +251,9 @@
"NO-DAYS": "No days selected.",
"INVALID-FORMAT": "Invalid Format",
"INVALID-DATE": "Invalid date. The date must be in the format '{{ requiredFormat }}'",
"BEYOND-MAX-DATE": "The date is beyond the maximum date."
"BEYOND-MAX-DATE": "The date is beyond the maximum date.",
"INVALID-DATETIME": "Invalid datetime. The datetime must be in the format '{{ requiredFormat }}'",
"BEYOND-MAX-DATETIME": "The datetime is beyond the maximum datetime."
}
},
"ICONS": {
Expand Down
Expand Up @@ -12,7 +12,7 @@
<mat-datepicker-toggle matSuffix [for]="fromDatepicker" data-automation-id="date-range-from-date-toggle"></mat-datepicker-toggle>
<mat-datepicker #fromDatepicker color="accent"></mat-datepicker>
<mat-error *ngIf="from.invalid" data-automation-id="date-range-from-error">
{{ getFromValidationMessage() | translate: { requiredFormat: datePickerDateFormat } }}
{{ getFromValidationMessage() | translate: { requiredFormat: datePickerFormat } }}
</mat-error>
</mat-form-field>

Expand All @@ -30,7 +30,7 @@
<mat-datepicker-toggle matSuffix [for]="toDatepicker" data-automation-id="date-range-to-date-toggle"></mat-datepicker-toggle>
<mat-datepicker #toDatepicker color="accent"></mat-datepicker>
<mat-error *ngIf="to.invalid" data-automation-id="date-range-to-error">
{{ getToValidationMessage() | translate: { requiredFormat: datePickerDateFormat } }}
{{ getToValidationMessage() | translate: { requiredFormat: datePickerFormat } }}
</mat-error>
</mat-form-field>

Expand Down