[MNT-22606] Support preset config as input in content-metadata component (#7311)

This commit is contained in:
Pablo Martinez Garcia
2021-10-23 20:25:53 +02:00
committed by GitHub
parent 6861e5320e
commit 9f08d4a3e6
10 changed files with 98 additions and 17 deletions

View File

@@ -48,7 +48,7 @@ Displays and edits metadata related to a node.
| displayEmpty | `boolean` | false | (optional) This flag displays/hides empty metadata fields. | | displayEmpty | `boolean` | false | (optional) This flag displays/hides empty metadata fields. |
| multi | `boolean` | false | (optional) This flag allows the component to display more than one accordion at a time. | | multi | `boolean` | false | (optional) This flag allows the component to display more than one accordion at a time. |
| node | `Node` | | (required) The node entity to fetch metadata about | | node | `Node` | | (required) The node entity to fetch metadata about |
| preset | `string` | | (required) Name of the metadata preset, which defines aspects and their properties. | | preset | `string` or `PresetConfig` | | (required) Name or configuration of the metadata preset, which defines aspects and their properties. |
| readOnly | `boolean` | false | (optional) This flag sets the metadata in read only mode preventing changes. | | readOnly | `boolean` | false | (optional) This flag sets the metadata in read only mode preventing changes. |
| displayDefaultProperties | `boolean` | | (optional) This flag displays/hides the metadata properties. | | displayDefaultProperties | `boolean` | | (optional) This flag displays/hides the metadata properties. |
@@ -57,7 +57,9 @@ Displays and edits metadata related to a node.
The component shows metadata related to a given node. It uses the The component shows metadata related to a given node. It uses the
[Card View component](../../core/components/card-view.component.md) to render the properties of metadata aspects. [Card View component](../../core/components/card-view.component.md) to render the properties of metadata aspects.
The different aspects and their properties to be shown can be configured as application config The different aspects and their properties to be shown can be configured as application config
presets (see below). By default the component only shows the basic properties of the node. presets (see below) or the preset config can be provided directly as
[PresetConfig](../../../lib/content-services/src/lib/content-metadata/interfaces/preset-config.interface.ts "PresetConfig in preset-config.interface.ts").
By default the component only shows the basic properties of the node.
The user can click on the pencil icon at the bottom of the component to edit the metadata The user can click on the pencil icon at the bottom of the component to edit the metadata
properties. properties.

View File

@@ -19,6 +19,7 @@ import { Component, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { ContentService, AllowableOperationsEnum, VersionCompatibilityService } from '@alfresco/adf-core'; import { ContentService, AllowableOperationsEnum, VersionCompatibilityService } from '@alfresco/adf-core';
import { NodeAspectService } from '../../../aspect-list/node-aspect.service'; import { NodeAspectService } from '../../../aspect-list/node-aspect.service';
import { PresetConfig } from '../../interfaces/content-metadata.interfaces';
@Component({ @Component({
selector: 'adf-content-metadata-card', selector: 'adf-content-metadata-card',
templateUrl: './content-metadata-card.component.html', templateUrl: './content-metadata-card.component.html',
@@ -44,11 +45,11 @@ export class ContentMetadataCardComponent implements OnChanges {
@Input() @Input()
displayAspect: string = null; displayAspect: string = null;
/** (required) Name of the metadata preset, which defines aspects /** (required) Name or configuration of the metadata preset, which defines aspects
* and their properties. * and their properties.
*/ */
@Input() @Input()
preset: string; preset: string | PresetConfig;
/** (optional) This flag sets the metadata in read only mode /** (optional) This flag sets the metadata in read only mode
* preventing changes. * preventing changes.

View File

@@ -299,6 +299,30 @@ describe('ContentMetadataComponent', () => {
expect(contentMetadataService.getGroupedProperties).toHaveBeenCalledWith(expectedNode, 'custom-preset'); expect(contentMetadataService.getGroupedProperties).toHaveBeenCalledWith(expectedNode, 'custom-preset');
}); });
it('should load the group properties when preset config is provided on node change', () => {
const presetConfig = [
{
title: 'My custom preset',
items: [
{
type: 'my:type',
properties: '*'
},
{
aspect: 'my:aspect',
properties: '*'
}
]
}
];
component.preset = presetConfig;
spyOn(contentMetadataService, 'getGroupedProperties');
component.ngOnChanges({ node: new SimpleChange(node, expectedNode, false) });
expect(contentMetadataService.getGroupedProperties).toHaveBeenCalledWith(expectedNode, presetConfig);
});
it('should pass through the loaded group properties to the card view', async () => { it('should pass through the loaded group properties to the card view', async () => {
const expectedProperties = []; const expectedProperties = [];
component.expanded = true; component.expanded = true;

View File

@@ -30,7 +30,7 @@ import {
UpdateNotification UpdateNotification
} from '@alfresco/adf-core'; } from '@alfresco/adf-core';
import { ContentMetadataService } from '../../services/content-metadata.service'; import { ContentMetadataService } from '../../services/content-metadata.service';
import { CardViewGroup } from '../../interfaces/content-metadata.interfaces'; import { CardViewGroup, PresetConfig } from '../../interfaces/content-metadata.interfaces';
import { takeUntil, debounceTime, catchError, map } from 'rxjs/operators'; import { takeUntil, debounceTime, catchError, map } from 'rxjs/operators';
@Component({ @Component({
@@ -68,9 +68,9 @@ export class ContentMetadataComponent implements OnChanges, OnInit, OnDestroy {
@Input() @Input()
multi = false; multi = false;
/** Name of the metadata preset, which defines aspects and their properties */ /** Name or configuration of the metadata preset, which defines aspects and their properties */
@Input() @Input()
preset: string; preset: string | PresetConfig;
/** Toggles whether the metadata properties should be shown */ /** Toggles whether the metadata properties should be shown */
@Input() @Input()

View File

@@ -28,4 +28,6 @@ export * from './services/config/indifferent-config.service';
export * from './services/config/layout-oriented-config.service'; export * from './services/config/layout-oriented-config.service';
export * from './services/config/aspect-oriented-config.service'; export * from './services/config/aspect-oriented-config.service';
export * from './interfaces/content-metadata.interfaces';
export * from './content-metadata.module'; export * from './content-metadata.module';

View File

@@ -51,7 +51,7 @@ export class ContentMetadataConfigFactory {
return this.createConfig(presetConfig); return this.createConfig(presetConfig);
} }
private createConfig(presetConfig: PresetConfig): ContentMetadataConfig { public createConfig(presetConfig: PresetConfig): ContentMetadataConfig {
let config: ContentMetadataConfig; let config: ContentMetadataConfig;
if (this.isLayoutOrientedPreset(presetConfig)) { if (this.isLayoutOrientedPreset(presetConfig)) {

View File

@@ -273,5 +273,49 @@ describe('ContentMetaDataService', () => {
expect(classesApi.getClass).toHaveBeenCalledTimes(1); expect(classesApi.getClass).toHaveBeenCalledTimes(1);
expect(classesApi.getClass).toHaveBeenCalledWith('cm_content'); expect(classesApi.getClass).toHaveBeenCalledWith('cm_content');
}); });
}); });
describe('Provided preset config', () => {
it('should create the metadata config on the fly when preset config is provided', async(done) => {
const fakeNode: Node = <Node> { name: 'Node Action', id: 'fake-id', nodeType: 'cm:content', isFile: true, aspectNames: [] } ;
const customLayoutOrientedScheme = [
{
'id': 'app.content.metadata.customGroup',
'title': 'Exif',
'items': [
{
'id': 'app.content.metadata.exifAspect2',
'aspect': 'exif:exif',
'properties': '*'
}
]
},
{
'id': 'app.content.metadata.customGroup2',
'title': 'Properties',
'items': [
{
'id': 'app.content.metadata.content',
'aspect': 'cm:content',
'properties': '*'
}
]
}
];
spyOn(classesApi, 'getClass').and.returnValue(Promise.resolve(contentResponse));
service.getGroupedProperties(fakeNode, customLayoutOrientedScheme).subscribe(
(res) => {
expect(res.length).toEqual(1);
expect(res[0].title).toEqual('Properties');
done();
}
);
expect(classesApi.getClass).toHaveBeenCalledTimes(1);
expect(classesApi.getClass).toHaveBeenCalledWith('cm_content');
});
});
}); });

View File

@@ -21,7 +21,7 @@ import { BasicPropertiesService } from './basic-properties.service';
import { Observable, of, iif, Subject } from 'rxjs'; import { Observable, of, iif, Subject } from 'rxjs';
import { PropertyGroupTranslatorService } from './property-groups-translator.service'; import { PropertyGroupTranslatorService } from './property-groups-translator.service';
import { CardViewItem } from '@alfresco/adf-core'; import { CardViewItem } from '@alfresco/adf-core';
import { CardViewGroup, OrganisedPropertyGroup } from '../interfaces/content-metadata.interfaces'; import { CardViewGroup, OrganisedPropertyGroup, PresetConfig } from '../interfaces/content-metadata.interfaces';
import { ContentMetadataConfigFactory } from './config/content-metadata-config.factory'; import { ContentMetadataConfigFactory } from './config/content-metadata-config.factory';
import { PropertyDescriptorsService } from './property-descriptors.service'; import { PropertyDescriptorsService } from './property-descriptors.service';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
@@ -52,14 +52,20 @@ export class ContentMetadataService {
return this.contentTypePropertyService.openContentTypeDialogConfirm(changedProperties.nodeType); return this.contentTypePropertyService.openContentTypeDialogConfirm(changedProperties.nodeType);
} }
getGroupedProperties(node: Node, presetName: string = 'default'): Observable<CardViewGroup[]> { getGroupedProperties(node: Node, preset: string | PresetConfig = 'default'): Observable<CardViewGroup[]> {
let groupedProperties = of([]); let groupedProperties = of([]);
if (node.aspectNames) { if (node.aspectNames) {
const contentMetadataConfig = this.contentMetadataConfigFactory.get(presetName), let contentMetadataConfig;
groupNames = node.aspectNames if (typeof preset === 'string') {
.concat(node.nodeType) contentMetadataConfig = this.contentMetadataConfigFactory.get(preset);
.filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName)); } else {
contentMetadataConfig = this.contentMetadataConfigFactory.createConfig(preset);
}
const groupNames = node.aspectNames
.concat(node.nodeType)
.filter((groupName) => contentMetadataConfig.isGroupAllowed(groupName));
if (groupNames.length > 0) { if (groupNames.length > 0) {
groupedProperties = this.propertyDescriptorsService.load(groupNames).pipe( groupedProperties = this.propertyDescriptorsService.load(groupNames).pipe(

View File

@@ -18,6 +18,7 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core'; import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { NodesApiService } from '@alfresco/adf-core'; import { NodesApiService } from '@alfresco/adf-core';
import { Node } from '@alfresco/js-api'; import { Node } from '@alfresco/js-api';
import { PresetConfig } from '@alfresco/adf-content-services';
/* tslint:disable:component-selector */ /* tslint:disable:component-selector */
@@ -52,9 +53,9 @@ export class PropertiesViewerWrapperComponent implements OnInit, OnChanges {
@Input() @Input()
multi; multi;
/** Name of the metadata preset, which defines aspects and their properties */ /** Name or configuration of the metadata preset, which defines aspects and their properties */
@Input() @Input()
preset: string; preset: string | PresetConfig;
/** Toggles whether the metadata properties should be shown */ /** Toggles whether the metadata properties should be shown */
@Input() @Input()

View File

@@ -28,6 +28,7 @@ export * from './components/widgets/date/date-cloud.widget';
export * from './components/widgets/dropdown/dropdown-cloud.widget'; export * from './components/widgets/dropdown/dropdown-cloud.widget';
export * from './components/widgets/group/group-cloud.widget'; export * from './components/widgets/group/group-cloud.widget';
export * from './components/widgets/people/people-cloud.widget'; export * from './components/widgets/people/people-cloud.widget';
export * from './components/widgets/properties-viewer/properties-viewer.widget';
export * from './services/content-cloud-node-selector.service'; export * from './services/content-cloud-node-selector.service';
export * from './services/form-cloud.service'; export * from './services/form-cloud.service';