[ADF-2186] Update calculated properties on node change in content metadata compo… (#2862)

* Update calculated properties on node change in content metadata component

* Add module to public api
This commit is contained in:
Popovics András
2018-01-22 19:56:31 +00:00
committed by Eugenio Romano
parent b481bde483
commit eb6db1d449
3 changed files with 27 additions and 3 deletions

View File

@@ -237,5 +237,22 @@ describe('ContentMetadataComponent', () => {
expect(basicPropertiesComponent.displayEmpty).toBe(false); expect(basicPropertiesComponent.displayEmpty).toBe(false);
}); });
})); }));
it('should be performed again if property updating occured, since the originally passed node has changed, so the previously calculated properties', () => {
const property = <CardViewBaseItemModel> { key: 'property-key', value: 'original-value' },
updateService = fixture.debugElement.injector.get(CardViewUpdateService),
nodesApiService = TestBed.get(NodesApiService);
spyOn(nodesApiService, 'updateNode').and.callFake(() => Observable.of(node));
spyOn(contentMetadataService, 'getBasicProperties');
component.ngOnChanges({ node: new SimpleChange(null, node, true) });
updateService.update(property, 'updated-value');
component.ngOnChanges({ expanded: new SimpleChange(false, true, false) });
component.ngOnChanges({ expanded: new SimpleChange(true, false, false) });
component.ngOnChanges({ expanded: new SimpleChange(false, true, false) });
expect(contentMetadataService.getBasicProperties).toHaveBeenCalledTimes(2);
});
}); });
}); });

View File

@@ -47,6 +47,7 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
@Input() @Input()
preset: string; preset: string;
nodeHasBeenUpdated: boolean = false;
basicProperties$: Observable<CardViewItem[]>; basicProperties$: Observable<CardViewItem[]>;
aspects$: Observable<CardViewAspect[]>; aspects$: Observable<CardViewAspect[]>;
@@ -59,15 +60,20 @@ export class ContentMetadataComponent implements OnChanges, OnInit {
this.cardViewUpdateService.itemUpdated$ this.cardViewUpdateService.itemUpdated$
.switchMap(this.saveNode.bind(this)) .switchMap(this.saveNode.bind(this))
.subscribe( .subscribe(
node => this.node = node, (node) => {
this.nodeHasBeenUpdated = true;
this.node = node;
},
error => this.logService.error(error) error => this.logService.error(error)
); );
} }
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
const nodeChange: SimpleChange = changes['node']; const nodeChange: SimpleChange = changes['node'];
if (nodeChange) { if (nodeChange || this.nodeHasBeenUpdated) {
const node = nodeChange.currentValue; const node = nodeChange && nodeChange.currentValue || this.node;
this.nodeHasBeenUpdated = false;
this.basicProperties$ = this.contentMetadataService.getBasicProperties(node); this.basicProperties$ = this.contentMetadataService.getBasicProperties(node);
this.aspects$ = this.contentMetadataService.getAspectProperties(node, this.preset); this.aspects$ = this.contentMetadataService.getAspectProperties(node, this.preset);
} }

View File

@@ -16,3 +16,4 @@
*/ */
export * from './components/content-metadata-card/content-metadata-card.component'; export * from './components/content-metadata-card/content-metadata-card.component';
export { ContentMetadataModule } from './content-metadata.module';