mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
committed by
Eugenio Romano
parent
21fd0299bd
commit
8395b0baa5
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user