[AAE-3925] Add support for date type searchable properties in attach … (#6274)

* [AAE-3925] Add support for date type searchable properties in attach file widget

* Fix comments
This commit is contained in:
arditdomi 2020-10-22 14:17:53 +01:00 committed by GitHub
parent 5b75f7abbe
commit 37fef5a1b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 122 additions and 9 deletions

View File

@ -33,7 +33,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { SearchQueryBuilderService } from '../search';
import { mockQueryBody } from '../mock/search-query.mock';
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { mockContentModelProperty } from '../mock/content-model.mock';
import { mockContentModelTextProperty } from '../mock/content-model.mock';
const fakeResultSetPaging: ResultSetPaging = {
list: {
@ -1179,7 +1179,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
});
it ('should search panel be collapsed by default and expand when clicking the filter button', async() => {
contentNodeSelectorPanelService.customModels = [mockContentModelProperty];
contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty];
fixture.detectChanges();
expect(component.searchPanelExpanded).toEqual(false);
@ -1203,7 +1203,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
});
it('should filter button be present only when there are custom models', () => {
contentNodeSelectorPanelService.customModels = [mockContentModelProperty];
contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty];
fixture.detectChanges();
const toggleFiltersPanelButton = fixture.debugElement.query(By.css('[data-automation-id="adf-toggle-search-panel-button"]'));

View File

@ -0,0 +1,53 @@
/*!
* @license
* Copyright 2019 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 { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { mockContentModelDateProperty, mockContentModelTextProperty, mockConvertedSearchCategoriesFromModels } from '../mock/content-model.mock';
describe('ContentNodeSelectorPanelService', () => {
const contentNodeSelectorPanelService = new ContentNodeSelectorPanelService();
it('should support text type', () => {
expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:text')).toEqual('text');
expect(contentNodeSelectorPanelService.isTypeSupported('d:text')).toEqual(true);
});
it('should support date type', () => {
expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap.get('d:date')).toEqual('date-range');
expect(contentNodeSelectorPanelService.isTypeSupported('d:date')).toEqual(true);
});
it('should return false for an unsupported type', () => {
expect(contentNodeSelectorPanelService.isTypeSupported('d:unsupported')).toEqual(false);
});
it('should modelPropertyTypeToSearchFilterTypeMap contain only the supported types', () => {
const expectedSupportedTypesMap = new Map<string, string> ();
expectedSupportedTypesMap.set('d:text', 'text');
expectedSupportedTypesMap.set('d:date', 'date-range');
expect(contentNodeSelectorPanelService.modelPropertyTypeToSearchFilterTypeMap).toEqual(expectedSupportedTypesMap);
});
it('should search config contain the correct filters converted from the custom content model properties', () => {
contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty, mockContentModelDateProperty];
const expectedConvertedPropertiesToSearchCategories = contentNodeSelectorPanelService.convertCustomModelPropertiesToSearchCategories();
expect(expectedConvertedPropertiesToSearchCategories).toEqual(mockConvertedSearchCategoriesFromModels);
});
});

View File

@ -16,17 +16,24 @@
*/
import { Injectable } from '@angular/core';
import { SearchCategory } from '../search';
import { SearchCategory } from '../search/search-category.interface';
@Injectable({
providedIn: 'root'
})
export class ContentNodeSelectorPanelService {
propertyTypes = ['d:text', 'd:date'];
modelPropertyTypeToSearchFilterTypeMap = new Map<string, string> ();
customModels: any[];
convertCustomModelPropertiesToSearchCategories(): any[] {
const searchConfig = [];
constructor() {
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[0], 'text');
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[1], 'date-range');
}
convertCustomModelPropertiesToSearchCategories(): SearchCategory[] {
const searchConfig: SearchCategory[] = [];
this.customModels?.forEach( (propertyModel) => {
searchConfig.push(this.convertModelPropertyIntoSearchFilter(propertyModel));
});
@ -36,14 +43,14 @@ export class ContentNodeSelectorPanelService {
convertModelPropertyIntoSearchFilter(modelProperty: any): SearchCategory {
let filterSearch: SearchCategory;
if (modelProperty.dataType === 'd:text') {
if (this.isTypeSupported(modelProperty.dataType)) {
filterSearch = {
id : modelProperty.prefixedName,
name: modelProperty.prefixedName,
expanded: false,
enabled: true,
component: {
selector: 'text',
selector: this.modelPropertyTypeToSearchFilterTypeMap.get(modelProperty.dataType),
settings: {
pattern: `${modelProperty.prefixedName}:'(.*?)'`,
field: `${modelProperty.prefixedName}`,
@ -55,4 +62,8 @@ export class ContentNodeSelectorPanelService {
return filterSearch;
}
isTypeSupported(dataType: string): boolean {
return this.propertyTypes.includes(dataType);
}
}

View File

@ -15,7 +15,9 @@
* limitations under the License.
*/
export const mockContentModelProperty = {
import { SearchCategory } from '../search/search-category.interface';
export const mockContentModelTextProperty = {
name: 'name',
prefixedName: 'account:name',
title: 'name',
@ -30,3 +32,50 @@ export const mockContentModelProperty = {
indexTokenisationMode: '',
constraints: []
};
export const mockContentModelDateProperty = {
name: 'creation',
prefixedName: 'account:creation',
title: 'creation',
description: '',
dataType: 'd:date',
multiValued: false,
mandatory: false,
defaultValue: '',
mandatoryEnforced: false,
indexed: false,
facetable: 'FALSE',
indexTokenisationMode: '',
constraints: []
};
export const mockConvertedSearchCategoriesFromModels: SearchCategory[] = [
{
id: 'account:name',
name: 'account:name',
expanded: false,
enabled: true,
component: {
selector: 'text',
settings: {
pattern: `account:name:'(.*?)'`,
field: `account:name`,
placeholder: `Enter the name`
}
}
},
{
id: 'account:creation',
name: 'account:creation',
expanded: false,
enabled: true,
component: {
selector: 'date-range',
settings: {
pattern: `account:creation:'(.*?)'`,
field: `account:creation`,
placeholder: `Enter the creation`
}
}
}
];