[ADF-2311] fix metadata components with folders (#2985)

* fix metadata folders

* remove dead code

* fix check mimetype
This commit is contained in:
Eugenio Romano
2018-02-23 10:41:03 +00:00
committed by GitHub
parent ad3dbd4d0b
commit 7f63b76d37
9 changed files with 142 additions and 26 deletions

View File

@@ -28,7 +28,13 @@ import { BasicPropertiesService } from '../../services/basic-properties.service'
import { PropertyGroupTranslatorService } from '../../services/property-groups-translator.service';
import { PropertyDescriptorsService } from '../../services/property-descriptors.service';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { CardViewBaseItemModel, CardViewComponent, CardViewUpdateService, NodesApiService, LogService } from '@alfresco/adf-core';
import {
CardViewBaseItemModel,
CardViewComponent,
CardViewUpdateService,
NodesApiService,
LogService
} from '@alfresco/adf-core';
import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
import { Observable } from 'rxjs/Observable';
import { ContentMetadataConfigFactory } from '../../services/config/content-metadata-config.factory';
@@ -38,6 +44,7 @@ describe('ContentMetadataComponent', () => {
let component: ContentMetadataComponent,
fixture: ComponentFixture<ContentMetadataComponent>,
node: MinimalNodeEntryEntity,
folderNode: MinimalNodeEntryEntity,
preset = 'custom-preset';
beforeEach(async(() => {
@@ -76,6 +83,14 @@ describe('ContentMetadataComponent', () => {
modifiedByUser: {}
};
folderNode = <MinimalNodeEntryEntity> {
id: 'folder-id',
aspectNames: [],
nodeType: '',
createdByUser: {},
modifiedByUser: {}
};
component.node = node;
component.preset = preset;
fixture.detectChanges();
@@ -101,6 +116,22 @@ describe('ContentMetadataComponent', () => {
});
});
describe('Folder', () => {
it('should show the folder node', () => {
component.expanded = false;
fixture.detectChanges();
component.ngOnChanges({ node: new SimpleChange(node, folderNode, false) });
component.basicProperties$.subscribe(() => {
fixture.detectChanges();
const basicPropertiesComponent = fixture.debugElement.query(By.directive(CardViewComponent)).componentInstance;
expect(basicPropertiesComponent.properties).toBeDefined();
});
});
});
describe('Saving', () => {
it('should save the node on itemUpdate', () => {

View File

@@ -22,9 +22,17 @@ import { CardViewDateItemModel, CardViewTextItemModel, FileSizePipe } from '@alf
@Injectable()
export class BasicPropertiesService {
constructor(private fileSizePipe: FileSizePipe) {}
constructor(private fileSizePipe: FileSizePipe) {
}
getProperties(node: MinimalNodeEntryEntity) {
const sizeInBytes = node.content ? node.content.sizeInBytes : '',
mimeTypeName = node.content ? node.content.mimeTypeName : '',
author = node.properties ? node.properties['cm:author'] : '',
description = node.properties ? node.properties['cm:description'] : '',
title = node.properties ? node.properties['cm:title'] : '';
return [
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.NAME',
@@ -34,7 +42,7 @@ export class BasicPropertiesService {
}),
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.TITLE',
value: node.properties['cm:title'],
value: title,
key: 'properties.cm:title',
editable: true
}),
@@ -52,7 +60,7 @@ export class BasicPropertiesService {
}),
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.SIZE',
value: node.content.sizeInBytes,
value: sizeInBytes,
key: 'content.sizeInBytes',
pipes: [{ pipe: this.fileSizePipe }],
editable: false
@@ -71,19 +79,19 @@ export class BasicPropertiesService {
}),
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.MIMETYPE',
value: node.content.mimeTypeName,
value: mimeTypeName,
key: 'content.mimeTypeName',
editable: false
}),
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.AUTHOR',
value: node.properties['cm:author'],
value: author,
key: 'properties.cm:author',
editable: true
}),
new CardViewTextItemModel({
label: 'CORE.METADATA.BASIC.DESCRIPTION',
value: node.properties['cm:description'],
value: description,
key: 'properties.cm:description',
multiline: true,
editable: true

View File

@@ -28,31 +28,30 @@ import { PropertyDescriptorsService } from './property-descriptors.service';
@Injectable()
export class ContentMetadataService {
constructor(
private basicPropertiesService: BasicPropertiesService,
private contentMetadataConfigFactory: ContentMetadataConfigFactory,
private propertyGroupTranslatorService: PropertyGroupTranslatorService,
private propertyDescriptorsService: PropertyDescriptorsService
) {}
constructor(private basicPropertiesService: BasicPropertiesService,
private contentMetadataConfigFactory: ContentMetadataConfigFactory,
private propertyGroupTranslatorService: PropertyGroupTranslatorService,
private propertyDescriptorsService: PropertyDescriptorsService) {
}
getBasicProperties(node: MinimalNodeEntryEntity): Observable<CardViewItem[]> {
return Observable.of(this.basicPropertiesService.getProperties(node));
}
getGroupedProperties(node: MinimalNodeEntryEntity, presetName: string = 'default'): Observable<CardViewGroup[]> {
const config = this.contentMetadataConfigFactory.get(presetName),
groupNames = node.aspectNames
.concat(node.nodeType)
.filter(groupName => config.isGroupAllowed(groupName));
let groupedProperties = Observable.of([]);
let groupedProperties;
if (node.aspectNames) {
const config = this.contentMetadataConfigFactory.get(presetName),
groupNames = node.aspectNames
.concat(node.nodeType)
.filter(groupName => config.isGroupAllowed(groupName));
if (groupNames.length > 0) {
groupedProperties = this.propertyDescriptorsService.load(groupNames)
.map(groups => config.reorganiseByConfig(groups))
.map(groups => this.propertyGroupTranslatorService.translateToCardViewGroups(groups, node.properties));
} else {
groupedProperties = Observable.of([]);
if (groupNames.length > 0) {
groupedProperties = this.propertyDescriptorsService.load(groupNames)
.map(groups => config.reorganiseByConfig(groups))
.map(groups => this.propertyGroupTranslatorService.translateToCardViewGroups(groups, node.properties));
}
}
return groupedProperties;