mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-19610] Add specific date range settings to search filter (#9250)
* [AAE-19610] add specific date range settings to search filter * [AAE-19610] remove unnecessary properties * [AAE-19610] fix missing property bug * [AAE-19610] fix lint issues
This commit is contained in:
@@ -32,6 +32,11 @@ describe('ContentNodeSelectorPanelService', () => {
|
||||
expect(contentNodeSelectorPanelService.isTypeSupported('d:date')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should support datetime type', () => {
|
||||
expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:datetime')).toEqual('datetime-range');
|
||||
expect(contentNodeSelectorPanelService.isTypeSupported('d:datetime')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should return false for an unsupported type', () => {
|
||||
expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false);
|
||||
});
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*!
|
||||
* @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 { SearchCategory } from '../search/models/search-category.interface';
|
||||
|
||||
export const mockSearchFilterWithoutDisplayedLabelsByField: SearchCategory = {
|
||||
id : 'test',
|
||||
name: 'test',
|
||||
expanded: false,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'date-range',
|
||||
settings: {
|
||||
pattern: `test:'(.*?)'`,
|
||||
field: 'test',
|
||||
placeholder: 'test placeholder'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const mockSearchFilterWithWrongDisplayedLabelsByField: SearchCategory = {
|
||||
id : 'test',
|
||||
name: 'test',
|
||||
expanded: false,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'date-range',
|
||||
settings: {
|
||||
pattern: `test:'(.*?)'`,
|
||||
field: 'test',
|
||||
placeholder: 'test placeholder',
|
||||
displayedLabelsByField: {
|
||||
'wrong-test': 'test-tab-label'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const mockSearchFilterWithDisplayedLabelsByField: SearchCategory = {
|
||||
id : 'test',
|
||||
name: 'test',
|
||||
expanded: false,
|
||||
enabled: true,
|
||||
component: {
|
||||
selector: 'date-range',
|
||||
settings: {
|
||||
pattern: `test:'(.*?)'`,
|
||||
field: 'test',
|
||||
placeholder: 'test placeholder',
|
||||
displayedLabelsByField: {
|
||||
'test': 'test-tab-label'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
@@ -23,3 +23,4 @@ export * from './search-filter-mock';
|
||||
export * from './sites-dropdown.component.mock';
|
||||
export * from './search-query.mock';
|
||||
export * from './new-version-uploader.service.mock';
|
||||
export * from './date-range-search-filter.mock';
|
||||
|
@@ -20,6 +20,7 @@ import { NgModule } from '@angular/core';
|
||||
import { NodeNameTooltipPipe } from './node-name-tooltip.pipe';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { IsIncludedPipe } from './is-included.pipe';
|
||||
import { TabLabelsPipe } from './tab-labels.pipe';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -28,15 +29,18 @@ import { IsIncludedPipe } from './is-included.pipe';
|
||||
],
|
||||
declarations: [
|
||||
NodeNameTooltipPipe,
|
||||
IsIncludedPipe
|
||||
IsIncludedPipe,
|
||||
TabLabelsPipe
|
||||
],
|
||||
providers: [
|
||||
NodeNameTooltipPipe,
|
||||
IsIncludedPipe
|
||||
IsIncludedPipe,
|
||||
TabLabelsPipe
|
||||
],
|
||||
exports: [
|
||||
NodeNameTooltipPipe,
|
||||
IsIncludedPipe
|
||||
IsIncludedPipe,
|
||||
TabLabelsPipe
|
||||
]
|
||||
})
|
||||
export class ContentPipeModule {
|
||||
|
@@ -17,4 +17,5 @@
|
||||
|
||||
export * from './node-name-tooltip.pipe';
|
||||
export * from './is-included.pipe';
|
||||
export * from './tab-labels.pipe';
|
||||
export * from './content-pipe.module';
|
||||
|
43
lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts
Normal file
43
lib/content-services/src/lib/pipes/tab-labels.pipe.spec.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/*!
|
||||
* @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 { TabLabelsPipe } from './tab-labels.pipe';
|
||||
import {
|
||||
mockSearchFilterWithoutDisplayedLabelsByField,
|
||||
mockSearchFilterWithWrongDisplayedLabelsByField,
|
||||
mockSearchFilterWithDisplayedLabelsByField
|
||||
} from '../mock/date-range-search-filter.mock';
|
||||
|
||||
describe('TabLabelsPipe', () => {
|
||||
const pipe = new TabLabelsPipe();
|
||||
|
||||
it('should default to field name when there are no settings available', () => {
|
||||
expect(pipe.transform('test', null)).toBe('test');
|
||||
});
|
||||
|
||||
it('should default to field name when settings do not contain "displayedLabelsByField" property', () => {
|
||||
expect(pipe.transform('test', mockSearchFilterWithoutDisplayedLabelsByField.component.settings)).toBe('test');
|
||||
});
|
||||
|
||||
it('should default to field name when settings with "displayedLabelsByField" property are available but do not contain field', () => {
|
||||
expect(pipe.transform('test', mockSearchFilterWithWrongDisplayedLabelsByField.component.settings)).toBe('test');
|
||||
});
|
||||
|
||||
it('should display correct label when settings with "displayedLabelsByField" property are available and do contain field', () => {
|
||||
expect(pipe.transform('test', mockSearchFilterWithDisplayedLabelsByField.component.settings)).toBe('test-tab-label');
|
||||
});
|
||||
});
|
30
lib/content-services/src/lib/pipes/tab-labels.pipe.ts
Normal file
30
lib/content-services/src/lib/pipes/tab-labels.pipe.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* @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 { Pipe, PipeTransform } from '@angular/core';
|
||||
import { SearchWidgetSettings } from '../search/models/search-widget-settings.interface';
|
||||
|
||||
@Pipe({
|
||||
name: 'tabLabels'
|
||||
})
|
||||
export class TabLabelsPipe implements PipeTransform {
|
||||
|
||||
transform(field: string, settings?: SearchWidgetSettings): string {
|
||||
return settings && settings.displayedLabelsByField && settings.displayedLabelsByField[field] ? settings.displayedLabelsByField[field] : field;
|
||||
}
|
||||
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
<adf-search-filter-tabbed>
|
||||
<ng-container *ngFor="let field of fields">
|
||||
<adf-search-date-range
|
||||
*adf-search-filter-tab="settings.displayedLabelsByField[field]"
|
||||
*adf-search-filter-tab="field | tabLabels: settings"
|
||||
[dateFormat]="settings.dateFormat"
|
||||
[maxDate]="settings.maxDate"
|
||||
[field]="field"
|
||||
|
@@ -37,6 +37,8 @@ import {
|
||||
subWeeks
|
||||
} from 'date-fns';
|
||||
|
||||
const DEFAULT_DATE_DISPLAY_FORMAT = 'dd-MMM-yy';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-search-date-range-tabbed',
|
||||
templateUrl: './search-date-range-tabbed.component.html',
|
||||
@@ -67,6 +69,13 @@ export class SearchDateRangeTabbedComponent implements SearchWidget, OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.fields = this.settings?.field.split(',').map(field => field.trim());
|
||||
this.setDefaultDateFormatSettings();
|
||||
}
|
||||
|
||||
private setDefaultDateFormatSettings() {
|
||||
if (this.settings && !this.settings.dateFormat) {
|
||||
this.settings.dateFormat = DEFAULT_DATE_DISPLAY_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
getCurrentValue(): { [key: string]: Partial<SearchDateRange> } {
|
||||
@@ -163,9 +172,13 @@ export class SearchDateRangeTabbedComponent implements SearchWidget, OnInit {
|
||||
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}`;
|
||||
const displayLabelForField = `${this.translateService.instant(this.getDisplayLabelForField(fieldForDisplayLabel)).toUpperCase()}: ${displayValue}`;
|
||||
this.combinedDisplayValue = this.combinedDisplayValue ? `${this.combinedDisplayValue} ${displayLabelForField}` : `${displayLabelForField}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getDisplayLabelForField(fieldForDisplayLabel: string): string {
|
||||
return this.settings && this.settings.displayedLabelsByField && this.settings.displayedLabelsByField[fieldForDisplayLabel] ? this.settings.displayedLabelsByField[fieldForDisplayLabel] : fieldForDisplayLabel;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user