mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
[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:
parent
5b75f7abbe
commit
37fef5a1b6
@ -33,7 +33,7 @@ import { TranslateModule } from '@ngx-translate/core';
|
|||||||
import { SearchQueryBuilderService } from '../search';
|
import { SearchQueryBuilderService } from '../search';
|
||||||
import { mockQueryBody } from '../mock/search-query.mock';
|
import { mockQueryBody } from '../mock/search-query.mock';
|
||||||
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
|
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 = {
|
const fakeResultSetPaging: ResultSetPaging = {
|
||||||
list: {
|
list: {
|
||||||
@ -1179,7 +1179,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it ('should search panel be collapsed by default and expand when clicking the filter button', async() => {
|
it ('should search panel be collapsed by default and expand when clicking the filter button', async() => {
|
||||||
contentNodeSelectorPanelService.customModels = [mockContentModelProperty];
|
contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.searchPanelExpanded).toEqual(false);
|
expect(component.searchPanelExpanded).toEqual(false);
|
||||||
@ -1203,7 +1203,7 @@ describe('ContentNodeSelectorPanelComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should filter button be present only when there are custom models', () => {
|
it('should filter button be present only when there are custom models', () => {
|
||||||
contentNodeSelectorPanelService.customModels = [mockContentModelProperty];
|
contentNodeSelectorPanelService.customModels = [mockContentModelTextProperty];
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
const toggleFiltersPanelButton = fixture.debugElement.query(By.css('[data-automation-id="adf-toggle-search-panel-button"]'));
|
const toggleFiltersPanelButton = fixture.debugElement.query(By.css('[data-automation-id="adf-toggle-search-panel-button"]'));
|
||||||
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
@ -16,17 +16,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { SearchCategory } from '../search';
|
import { SearchCategory } from '../search/search-category.interface';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class ContentNodeSelectorPanelService {
|
export class ContentNodeSelectorPanelService {
|
||||||
|
|
||||||
|
propertyTypes = ['d:text', 'd:date'];
|
||||||
|
modelPropertyTypeToSearchFilterTypeMap = new Map<string, string> ();
|
||||||
customModels: any[];
|
customModels: any[];
|
||||||
|
|
||||||
convertCustomModelPropertiesToSearchCategories(): any[] {
|
constructor() {
|
||||||
const searchConfig = [];
|
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[0], 'text');
|
||||||
|
this.modelPropertyTypeToSearchFilterTypeMap.set(this.propertyTypes[1], 'date-range');
|
||||||
|
}
|
||||||
|
|
||||||
|
convertCustomModelPropertiesToSearchCategories(): SearchCategory[] {
|
||||||
|
const searchConfig: SearchCategory[] = [];
|
||||||
this.customModels?.forEach( (propertyModel) => {
|
this.customModels?.forEach( (propertyModel) => {
|
||||||
searchConfig.push(this.convertModelPropertyIntoSearchFilter(propertyModel));
|
searchConfig.push(this.convertModelPropertyIntoSearchFilter(propertyModel));
|
||||||
});
|
});
|
||||||
@ -36,14 +43,14 @@ export class ContentNodeSelectorPanelService {
|
|||||||
|
|
||||||
convertModelPropertyIntoSearchFilter(modelProperty: any): SearchCategory {
|
convertModelPropertyIntoSearchFilter(modelProperty: any): SearchCategory {
|
||||||
let filterSearch: SearchCategory;
|
let filterSearch: SearchCategory;
|
||||||
if (modelProperty.dataType === 'd:text') {
|
if (this.isTypeSupported(modelProperty.dataType)) {
|
||||||
filterSearch = {
|
filterSearch = {
|
||||||
id : modelProperty.prefixedName,
|
id : modelProperty.prefixedName,
|
||||||
name: modelProperty.prefixedName,
|
name: modelProperty.prefixedName,
|
||||||
expanded: false,
|
expanded: false,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
component: {
|
component: {
|
||||||
selector: 'text',
|
selector: this.modelPropertyTypeToSearchFilterTypeMap.get(modelProperty.dataType),
|
||||||
settings: {
|
settings: {
|
||||||
pattern: `${modelProperty.prefixedName}:'(.*?)'`,
|
pattern: `${modelProperty.prefixedName}:'(.*?)'`,
|
||||||
field: `${modelProperty.prefixedName}`,
|
field: `${modelProperty.prefixedName}`,
|
||||||
@ -55,4 +62,8 @@ export class ContentNodeSelectorPanelService {
|
|||||||
return filterSearch;
|
return filterSearch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isTypeSupported(dataType: string): boolean {
|
||||||
|
return this.propertyTypes.includes(dataType);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const mockContentModelProperty = {
|
import { SearchCategory } from '../search/search-category.interface';
|
||||||
|
|
||||||
|
export const mockContentModelTextProperty = {
|
||||||
name: 'name',
|
name: 'name',
|
||||||
prefixedName: 'account:name',
|
prefixedName: 'account:name',
|
||||||
title: 'name',
|
title: 'name',
|
||||||
@ -30,3 +32,50 @@ export const mockContentModelProperty = {
|
|||||||
indexTokenisationMode: '',
|
indexTokenisationMode: '',
|
||||||
constraints: []
|
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`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user