Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT-24698] Add aspect name to the title when there are duplicated aspect titles #10374

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
import { AppConfigService } from '@alfresco/adf-core';
import { ClassesApi, Node } from '@alfresco/js-api';
import { TestBed } from '@angular/core/testing';
import { ContentMetadataService } from './content-metadata.service';
import { of } from 'rxjs';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces';
import { PropertyGroup } from '../interfaces/property-group.interface';
import { ContentMetadataService } from './content-metadata.service';
import { ContentTypePropertiesService } from './content-type-property.service';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { PropertyDescriptorsService } from './property-descriptors.service';

const fakeNode: Node = {
Expand Down Expand Up @@ -130,6 +131,62 @@ describe('ContentMetaDataService', () => {
}
};

const aspect1Group: OrganisedPropertyGroup = {
name: 'test:aspect1',
title: 'Test Aspect',
properties: [
{
title: 'Property 1',
name: 'test:property1',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};

const aspect2Group: OrganisedPropertyGroup = {
name: 'test:aspect2',
title: 'Test Aspect',
properties: [
{
title: 'Property 2',
name: 'test:property2',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};

const aspect3Group: OrganisedPropertyGroup = {
name: 'test:aspect3',
title: undefined,
properties: [
{
title: 'Property 3',
name: 'test:property3',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};

const aspect4Group: OrganisedPropertyGroup = {
name: 'test:aspect4',
title: 'test:aspect3',
properties: [
{
title: 'Property 4',
name: 'test:property4',
dataType: 'd:text',
mandatory: false,
multiValued: false
}
]
};

const setConfig = (presetName, presetConfig) => {
appConfig.config['content-metadata'] = {
presets: {
Expand Down Expand Up @@ -176,6 +233,20 @@ describe('ContentMetaDataService', () => {
});
});

it('should distinguish aspects with same title', () => {
const groupedProperties = service.setTitleToNameIfNotSet([aspect1Group, aspect2Group]);
expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('Test Aspect');
expect(groupedProperties[1].title).toEqual('Test Aspect (test:aspect2)');
});

it('should distinguish aspect without title from other aspect with title equals to its name', () => {
const groupedProperties = service.setTitleToNameIfNotSet([aspect3Group, aspect4Group]);
expect(groupedProperties.length).toEqual(2);
expect(groupedProperties[0].title).toEqual('test:aspect3');
expect(groupedProperties[1].title).toEqual('test:aspect3 (test:aspect4)');
});

describe('AspectOriented preset', () => {
it('should return response with exif property', async () => {
setConfig('default', { 'exif:exif': '*' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import { ContentTypePropertiesService } from './content-type-property.service';
providedIn: 'root'
})
export class ContentMetadataService {

error = new Subject<{ statusCode: number; message: string }>();

constructor(private basicPropertiesService: BasicPropertiesService,
private contentMetadataConfigFactory: ContentMetadataConfigFactory,
private propertyGroupTranslatorService: PropertyGroupTranslatorService,
private propertyDescriptorsService: PropertyDescriptorsService,
private contentTypePropertyService: ContentTypePropertiesService) {
}
constructor(
private basicPropertiesService: BasicPropertiesService,
private contentMetadataConfigFactory: ContentMetadataConfigFactory,
private propertyGroupTranslatorService: PropertyGroupTranslatorService,
private propertyDescriptorsService: PropertyDescriptorsService,
private contentTypePropertyService: ContentTypePropertiesService
) {}

getBasicProperties(node: Node): Observable<CardViewItem[]> {
return of(this.basicPropertiesService.getProperties(node));
Expand All @@ -63,9 +63,7 @@ export class ContentMetadataService {
contentMetadataConfig = this.contentMetadataConfigFactory.createConfig(preset);
}

const groupNames = node.aspectNames
.concat(node.nodeType)
.filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName));
const groupNames = node.aspectNames.concat(node.nodeType).filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName));

if (groupNames.length > 0) {
groupedProperties = this.propertyDescriptorsService.load(groupNames).pipe(
Expand All @@ -74,7 +72,8 @@ export class ContentMetadataService {
() => contentMetadataConfig.isIncludeAllEnabled(),
of(contentMetadataConfig.appendAllPreset(groups).concat(contentMetadataConfig.reorganiseByConfig(groups))),
of(contentMetadataConfig.reorganiseByConfig(groups))
)),
)
),
map((groups) => contentMetadataConfig.filterExcludedPreset(groups)),
map((groups) => this.filterEmptyPreset(groups)),
map((groups) => this.setTitleToNameIfNotSet(groups)),
Expand All @@ -87,13 +86,26 @@ export class ContentMetadataService {
}

setTitleToNameIfNotSet(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] {
const propertyGroupsTitles = [];
propertyGroups.map((propertyGroup) => {
propertyGroup.title = propertyGroup.title || propertyGroup.name;
const title = propertyGroup.title;
const name = propertyGroup.name;
if (title) {
if (propertyGroupsTitles.includes(title)) {
propertyGroup.title = name ? `${title} (${name})` : title;
} else {
propertyGroup.title = title;
}
propertyGroupsTitles.push(title);
} else {
propertyGroup.title = name;
swapnil-verma-gl marked this conversation as resolved.
Show resolved Hide resolved
propertyGroupsTitles.push(name);
}
});
return propertyGroups;
}

filterEmptyPreset(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] {
filterEmptyPreset(propertyGroups: OrganisedPropertyGroup[]): OrganisedPropertyGroup[] {
return propertyGroups.filter((props) => props.properties.length);
}
}
Loading