mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[ACS-4985] Revert test fix for e2e execution. Updated search.config.ts for e2e test cases Testing global install of webdriver-manager for e2e webdriver fix [ACS-4985] Resolved e2e test failures [ACS-4985] Increased value for drag emulation to account for increased width of the side filters panel in demo-shell search results window. [ACS-4985] Resolved unit test failures [ACS-4985] Resolved lint issues [ACS-4985] Moved new components to v6.2.0 in versionIndex.md [ACS-4985] Added documentation to versionIndex.md and README.md [ACS-4985] Moved inLast input field back to input type number. [ACS-4985] Resolved issue where typing a special character after adding some numbers in the 'In the last' input field would clear out the field [ACS-4985] Updated test cases after query generation changes [ACS-4985] Added missing null check when generating query [ACS-4985] Added *ngFor back to the search-date-range-advanced-tabbed.component.html [ACS-4985] Updated query generation logic. Now both 'In the last' and 'Between' options use the start date to end date query format [ACS-4985] Removed ANY case from switch (will be handled by default case) [ACS-4985] Split declarations into multiple lines [ACS-4985] Fixed code smell in regex [ACS-4985] Updated dates in documentation [ACS-4985] Updated documentation [ACS-4985] Added link for AngularMaterial bug for CSS workaround [ACS-4985] Added test cases for end date validation. Fixed minor issue when setting invalid date error on between date form fields [ACS-4985] Added validation when user manually enters the start and end dates [ACS-4985] Added borders to inputs [ACS-4985] Updated test cases for SearchDateRangeAdvancedTabbedComponent [ACS-4985] Transferred business logic from SearchDateRangeAdvancedComponent and SearchFilterTabbedComponent to SearchDateRangeAdvancedTabbedComponent. Updated test cases accordingly [ACS-4985] Resolved PR review comments [ACS-4985] Removed unused code from base-query-builder.service.ts [ACS-4985] Resolved linting and unit test issues [ACS-4985] Resolved minor issues where switching between tabs could sometime cause the tab content to not show up [ACS-4985] Resolved minor issues with display label creation [ACS-4985] Updated component to use MatDateFnsAdapter. BetweenStartDate and BetweenEndDate are now formatted when selected from the calender [ACS-4985] Resolved issue where clear button would not clear the values properly [ACS-4985] Added @angular/material-date-fns-adapter package [ACS-4985] Added image for updated documentation [ACS-4985] Added validation to SearchDateRangeAdvancedComponent [ACS-4985] Updated documentation for components [ACS-4985] Removed disableUpdateOnSubmit flag from search widgets [ACS-4985] Updated the documentation for the components [ACS-4985] Added test cases for SearchDateRangeAdvancedTabbedComponent. Moved pending logic from template to typescript [ACS-4985] Added clear and apply button to SearchDateRangeAdvancedTabbedComponent. Moved logic from template to typescript file [ACS-4985] Updated test cases for SearchFilterTabbedComponent. Added safety checks to component [ACS-4985] Added field validation to test case [ACS-4985] Updated SearchDateRangeAdvancedTabbed component to no longer use getters and setters [ACS-4985] Updated test cases for SearchDateRangeAdvancedComponent. Minor updates to the component template and logic. Component no longer uses getters and setters in template [ACS-4985] Updated SearchDateRangeAdvancedTabbed component to use variables instead of getters and setters [ACS-4985] Updated app.cconfig for demo-shell to use new date-range-advanced configuration ACS-4985 Fixed issue with nx build, some clean ups, using changes in configuration [ACS-4985] Updated test cases for changed date format [ACS-4985] Updated date formats for SearchDateRangeAdvancedComponent [ACS-4985] Removed fdescribe test cases for SearchDateRangeAdvancedComponent. [ACS-4985] Fixed test cases for SearchDateRangeAdvancedComponent. [ACS-4985] Fixed erroneous imports [ACS-4985] Added license headers and re-ordered imports [ACS-4985] Updated test cases for SearchDateRangeAdvancedComponent from moment.js to date-fns [ACS-4985] Migrated SearchDateRangeAdvancedComponent from moment.js to date-fns Added import for BaseQueryBuilderService in public-api.ts. Fixes #8647 [ACS-4985] Updated imports in test cases [ACS-4985] Added exports for SearchDateRangeAdvanced and SearchFilterTabbed components to public-api.ts. Updated imports in both components [ACS-4985] Resolved minor issue where the reset method would still trigger multiple api calls when used with the TabbedComponent [ACS-4985] Added test cases for SearchDateRangeAdvancedComponent. Minor update to test cases for SearchFilterTabbedComponent [ACS-4985] Updated Labels for 'In last' date range option [ACS-4985] Updated SearchModule declarations. Fixed minor typo in SearchFilterTabbedComponent [ACS-4985] Added test cases for SearchFilterTabbedComponent. Added test case placeholders for SearchDateRangeAdvancedComponent [ACS-4985] Added data-automation-id to search-date-range-advanced.component.html [ACS-4985] Added test cases for SearchFilterTabbedComponent [ACS-4985] Removed vertical mode from SearchFilterTabbedComponent [ACS-4985] Updated UI for search filters. Minor fixes [ACS-4985] Added documentation for SearchFilterTabbedComponent and SearchDateRangeAdvancedComponent [ACS-4985] Added compatibility of all search filters/facets with SearchFilterTabbedComponent [ACS-4985] Using widget-composite component now correctly updates the search query on submit. Added optional property to disable update on submit button click for widget-composite. [ACS-4985] Added SearchFilterTabbedComponent and SearchDateRangeAdvancedComponent. Added config for using the new components
172 lines
6.8 KiB
TypeScript
172 lines
6.8 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
|
|
*
|
|
* 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 { Component, OnInit, ViewEncapsulation } from '@angular/core';
|
|
import { Subject } from 'rxjs';
|
|
import { SearchDateRangeAdvanced } from './search-date-range-advanced/search-date-range-advanced';
|
|
import { DateRangeType } from './search-date-range-advanced/date-range-type';
|
|
import { SearchWidget } from '../../models/search-widget.interface';
|
|
import { SearchWidgetSettings } from '../../models/search-widget-settings.interface';
|
|
import { SearchQueryBuilderService } from '../../services/search-query-builder.service';
|
|
import { InLastDateType } from './search-date-range-advanced/in-last-date-type';
|
|
import { TranslationService } from '@alfresco/adf-core';
|
|
import {
|
|
endOfDay,
|
|
endOfToday,
|
|
format,
|
|
formatISO,
|
|
startOfDay,
|
|
startOfMonth,
|
|
startOfWeek,
|
|
subDays,
|
|
subMonths,
|
|
subWeeks
|
|
} from 'date-fns';
|
|
|
|
@Component({
|
|
selector: 'adf-search-date-range-advanced-tabbed',
|
|
templateUrl: './search-date-range-advanced-tabbed.component.html',
|
|
encapsulation: ViewEncapsulation.None
|
|
})
|
|
export class SearchDateRangeAdvancedTabbedComponent implements SearchWidget, OnInit {
|
|
displayValue$ = new Subject<string>();
|
|
id: string;
|
|
startValue: SearchDateRangeAdvanced = {
|
|
dateRangeType: DateRangeType.ANY,
|
|
inLastValueType: InLastDateType.DAYS,
|
|
inLastValue: undefined,
|
|
betweenStartDate: undefined,
|
|
betweenEndDate: undefined
|
|
};
|
|
settings?: SearchWidgetSettings;
|
|
context?: SearchQueryBuilderService;
|
|
fields: string[];
|
|
tabsValidity: { [key: string]: boolean } = {};
|
|
combinedQuery: string;
|
|
combinedDisplayValue: string;
|
|
|
|
private value: { [key: string]: Partial<SearchDateRangeAdvanced> } = {};
|
|
private queryMapByField: Map<string, string> = new Map<string, string>();
|
|
private displayValueMapByField: Map<string, string> = new Map<string, string>();
|
|
|
|
constructor(private translateService: TranslationService) {}
|
|
|
|
ngOnInit(): void {
|
|
this.fields = this.settings?.field.split(',').map(field => field.trim());
|
|
}
|
|
|
|
getCurrentValue(): { [key: string]: Partial<SearchDateRangeAdvanced> } {
|
|
return this.value;
|
|
}
|
|
|
|
hasValidValue(): boolean {
|
|
return Object.values(this.tabsValidity).every((valid) => valid);
|
|
}
|
|
|
|
reset() {
|
|
this.combinedQuery = '';
|
|
this.combinedDisplayValue = '';
|
|
this.startValue = {
|
|
...this.startValue
|
|
};
|
|
this.submitValues();
|
|
}
|
|
|
|
setValue(value: { [key: string]: SearchDateRangeAdvanced }) {
|
|
this.value = value;
|
|
}
|
|
|
|
submitValues() {
|
|
this.context.queryFragments[this.id] = this.combinedQuery;
|
|
this.displayValue$.next(this.combinedDisplayValue);
|
|
if (this.id && this.context) {
|
|
this.context.update();
|
|
}
|
|
}
|
|
onDateRangedValueChanged(value: Partial<SearchDateRangeAdvanced>, field: string) {
|
|
this.value[field] = value;
|
|
this.updateQuery(value, field);
|
|
this.updateDisplayValue(value, field);
|
|
}
|
|
|
|
private generateQuery(value: Partial<SearchDateRangeAdvanced>, field: string): string {
|
|
let query = '';
|
|
let startDate: Date;
|
|
let endDate: Date;
|
|
if (value.dateRangeType === DateRangeType.IN_LAST) {
|
|
if (value.inLastValue) {
|
|
switch(value.inLastValueType) {
|
|
case InLastDateType.DAYS:
|
|
startDate = startOfDay(subDays(new Date(), parseInt(value.inLastValue, 10)));
|
|
break;
|
|
case InLastDateType.WEEKS:
|
|
startDate = startOfWeek(subWeeks(new Date(), parseInt(value.inLastValue, 10)));
|
|
break;
|
|
case InLastDateType.MONTHS:
|
|
startDate = startOfMonth(subMonths(new Date(), parseInt(value.inLastValue, 10)));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
endDate = endOfToday();
|
|
} else if (value.dateRangeType === DateRangeType.BETWEEN) {
|
|
if (value.betweenStartDate && value.betweenEndDate) {
|
|
startDate = startOfDay(value.betweenStartDate);
|
|
endDate = endOfDay(value.betweenEndDate);
|
|
}
|
|
}
|
|
if (startDate && endDate) {
|
|
query = `${field}:['${formatISO(startDate)}' TO '${formatISO(endDate)}']`;
|
|
}
|
|
return query;
|
|
}
|
|
|
|
private generateDisplayValue(value: Partial<SearchDateRangeAdvanced>): string {
|
|
let displayValue = '';
|
|
if (value.dateRangeType === DateRangeType.IN_LAST && value.inLastValue) {
|
|
displayValue = this.translateService.instant(`SEARCH.DATE_RANGE_ADVANCED.IN_LAST_DISPLAY_LABELS.${value.inLastValueType}`, {
|
|
value: value.inLastValue
|
|
});
|
|
} else if (value.dateRangeType === DateRangeType.BETWEEN && value.betweenStartDate && value.betweenEndDate) {
|
|
displayValue = `${format(startOfDay(value.betweenStartDate), this.settings.dateFormat)} - ${format(endOfDay(value.betweenEndDate), this.settings.dateFormat)}`;
|
|
}
|
|
return displayValue;
|
|
}
|
|
|
|
private updateQuery(value: Partial<SearchDateRangeAdvanced>, field: string) {
|
|
this.combinedQuery = '';
|
|
this.queryMapByField.set(field, this.generateQuery(value, field));
|
|
this.queryMapByField.forEach((query: string) => {
|
|
if (query) {
|
|
this.combinedQuery = this.combinedQuery ? `${this.combinedQuery} AND ${query}` : `${query}`;
|
|
}
|
|
});
|
|
}
|
|
|
|
private updateDisplayValue(value: Partial<SearchDateRangeAdvanced>, field: string) {
|
|
this.combinedDisplayValue = '';
|
|
this.displayValueMapByField.set(field, this.generateDisplayValue(value));
|
|
this.displayValueMapByField.forEach((displayValue: string, fieldForDisplayLabel: string) => {
|
|
if (displayValue) {
|
|
const displayLabelForField = `${this.translateService.instant(this.settings.displayedLabelsByField[fieldForDisplayLabel]).toUpperCase()}: ${displayValue}`;
|
|
this.combinedDisplayValue = this.combinedDisplayValue ? `${this.combinedDisplayValue} ${displayLabelForField}` : `${displayLabelForField}`;
|
|
}
|
|
});
|
|
}
|
|
}
|