[ADF-4219] Multivalue Metadata Card View (#4600)

* [ADF-4219] Multivalue Metadata  Card View

* [ADF-4219] Add documentation

* [ADF-4219] Improve code, docs and tests

* [ADF-4219] Fix e2e tests
This commit is contained in:
davidcanonieto
2019-04-17 17:04:27 +01:00
committed by Eugenio Romano
parent 21fd0299bd
commit 8395b0baa5
18 changed files with 217 additions and 24 deletions

View File

@@ -18,6 +18,7 @@
import { Component, Input, OnChanges, ViewChild } from '@angular/core';
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
import { CardViewUpdateService } from '../../services/card-view-update.service';
import { AppConfigService } from '../../../app-config/app-config.service';
@Component({
selector: 'adf-card-view-textitem',
@@ -25,6 +26,9 @@ import { CardViewUpdateService } from '../../services/card-view-update.service';
styleUrls: ['./card-view-textitem.component.scss']
})
export class CardViewTextItemComponent implements OnChanges {
static DEFAULT_SEPARATOR = ', ';
@Input()
property: CardViewTextItemModel;
@@ -40,12 +44,15 @@ export class CardViewTextItemComponent implements OnChanges {
inEdit: boolean = false;
editedValue: string;
errorMessages: string[];
valueSeparator: string;
constructor(private cardViewUpdateService: CardViewUpdateService) {
constructor(private cardViewUpdateService: CardViewUpdateService,
private appConfig: AppConfigService) {
this.valueSeparator = this.appConfig.get<string>('content-metadata.multi-value-pipe-separator') || CardViewTextItemComponent.DEFAULT_SEPARATOR;
}
ngOnChanges(): void {
this.editedValue = this.property.value;
this.editedValue = this.property.multiline ? this.property.displayValue : this.property.value;
}
showProperty(): boolean {
@@ -78,20 +85,29 @@ export class CardViewTextItemComponent implements OnChanges {
}
reset(): void {
this.editedValue = this.property.value;
this.editedValue = this.property.multiline ? this.property.displayValue : this.property.value;
this.setEditMode(false);
}
update(): void {
if (this.property.isValid(this.editedValue)) {
this.cardViewUpdateService.update(this.property, this.editedValue);
this.property.value = this.editedValue;
const updatedValue = this.prepareValueForUpload(this.property, this.editedValue);
this.cardViewUpdateService.update(this.property, updatedValue);
this.property.value = updatedValue;
this.setEditMode(false);
} else {
this.errorMessages = this.property.getValidationErrors(this.editedValue);
}
}
prepareValueForUpload(property: CardViewTextItemModel, value: string): string | string [] {
const listOfValues = value;
if (property.multivalued) {
return listOfValues.split(this.valueSeparator);
}
return listOfValues;
}
onTextAreaInputChange() {
this.errorMessages = this.property.getValidationErrors(this.editedValue);
}