mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2846] new facets (#3251)
* schema and configuration improvements * check list search widget * "Clear all" button to reset the list * page size and "show more" for response facet fields * test fixes * fix tests * fix pagination bug (skipCount reseting) * integrate date range picker from #3248 * i18n support for date and number range * some docs for search filter * docs update * docs update * cleanup code as per review
This commit is contained in:
committed by
Eugenio Romano
parent
bb664a283b
commit
dbe88a5efc
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { OnInit, Component, ViewEncapsulation } from '@angular/core';
|
||||
import { FormControl, Validators, FormGroup } from '@angular/forms';
|
||||
import { SearchWidget } from '../../search-widget.interface';
|
||||
import { SearchWidgetSettings } from '../../search-widget-settings.interface';
|
||||
import { SearchQueryBuilderService } from '../../search-query-builder.service';
|
||||
import { LiveErrorStateMatcher } from '../../forms/live-error-state-matcher';
|
||||
import moment from 'moment-es6';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-search-date-range',
|
||||
templateUrl: './search-date-range.component.html',
|
||||
styleUrls: ['./search-date-range.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None,
|
||||
host: { class: 'adf-search-date-range' }
|
||||
})
|
||||
export class SearchDateRangeComponent implements SearchWidget, OnInit {
|
||||
|
||||
from: FormControl;
|
||||
to: FormControl;
|
||||
|
||||
form: FormGroup;
|
||||
matcher = new LiveErrorStateMatcher();
|
||||
|
||||
id: string;
|
||||
settings?: SearchWidgetSettings;
|
||||
context?: SearchQueryBuilderService;
|
||||
maxFrom: any;
|
||||
|
||||
ngOnInit() {
|
||||
const validators = Validators.compose([
|
||||
Validators.required
|
||||
]);
|
||||
|
||||
this.from = new FormControl('', validators);
|
||||
this.to = new FormControl('', validators);
|
||||
|
||||
this.form = new FormGroup({
|
||||
from: this.from,
|
||||
to: this.to
|
||||
});
|
||||
|
||||
this.maxFrom = moment().startOf('day');
|
||||
}
|
||||
|
||||
apply(model: { from: string, to: string }, isValid: boolean) {
|
||||
if (isValid && this.id && this.context && this.settings && this.settings.field) {
|
||||
const start = moment(model.from).startOf('day').format();
|
||||
const end = moment(model.to).endOf('day').format();
|
||||
|
||||
this.context.queryFragments[this.id] = `${this.settings.field}:['${start}' TO '${end}']`;
|
||||
this.context.update();
|
||||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.form.reset({
|
||||
from: '',
|
||||
to: ''
|
||||
});
|
||||
if (this.id && this.context) {
|
||||
this.context.queryFragments[this.id] = '';
|
||||
this.context.update();
|
||||
}
|
||||
}
|
||||
|
||||
hasSelectedDays(from: string, to: string): boolean {
|
||||
if (from && to) {
|
||||
const start = moment(from).startOf('day');
|
||||
const end = moment(to).endOf('day');
|
||||
|
||||
return start.isBefore(end);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user