[ADF-5390] [ADF-5391] Add multivalue cardview for Date, Datetime, Integers and Decimal properties. (#6980)

* [ADF-5390] Addd multivalue cardview for Date, Datetime, Integers and Decimal properties

* Fix unit test

* Fix linting

* Fix e2e tests

* fix e2e

Co-authored-by: Eugenio Romano <eugenio.romano@alfresco.com>
This commit is contained in:
davidcanonieto
2021-05-09 04:05:26 +01:00
committed by GitHub
parent 71cad4c287
commit bd805cb34b
23 changed files with 280 additions and 54 deletions

View File

@@ -29,6 +29,7 @@ export abstract class CardViewBaseItemModel {
validators?: CardViewItemValidator[];
data?: any;
type?: string;
multivalued?: boolean;
constructor(cardViewItemProperties: CardViewItemProperties) {
this.label = cardViewItemProperties.label || '';
@@ -40,6 +41,7 @@ export abstract class CardViewBaseItemModel {
this.icon = cardViewItemProperties.icon || '';
this.validators = cardViewItemProperties.validators || [];
this.data = cardViewItemProperties.data || null;
this.multivalued = !!cardViewItemProperties.multivalued;
if (cardViewItemProperties?.constraints?.length ?? 0) {
for (const constraint of cardViewItemProperties.constraints) {
@@ -51,7 +53,7 @@ export abstract class CardViewBaseItemModel {
}
isEmpty(): boolean {
return this.value === undefined || this.value === null || this.value === '';
return this.value === undefined || this.value === null || this.value.length === 0;
}
isValid(newValue: any): boolean {

View File

@@ -42,11 +42,19 @@ export class CardViewDateItemModel extends CardViewBaseItemModel implements Card
}
get displayValue() {
if (!this.value) {
return this.default;
if (this.multivalued) {
if (this.value) {
return this.value.map((date) => this.transformDate(date));
} else {
return this.default ? [this.default] : [];
}
} else {
this.localizedDatePipe = new LocalizedDatePipe();
return this.localizedDatePipe.transform(this.value, this.format, this.locale);
return this.value ? this.transformDate(this.value) : this.default;
}
}
transformDate(value: any) {
this.localizedDatePipe = new LocalizedDatePipe();
return this.localizedDatePipe.transform(value, this.format, this.locale);
}
}

View File

@@ -29,8 +29,12 @@ export class CardViewFloatItemModel extends CardViewTextItemModel implements Car
super(cardViewTextItemProperties);
this.validators.push(new CardViewItemFloatValidator());
if (cardViewTextItemProperties.value) {
if (cardViewTextItemProperties.value && !cardViewTextItemProperties.multivalued) {
this.value = parseFloat(cardViewTextItemProperties.value);
}
}
get displayValue(): string {
return this.applyPipes(this.value);
}
}

View File

@@ -29,8 +29,12 @@ export class CardViewIntItemModel extends CardViewTextItemModel implements CardV
super(cardViewTextItemProperties);
this.validators.push(new CardViewItemIntValidator());
if (cardViewTextItemProperties.value) {
if (cardViewTextItemProperties.value && !cardViewTextItemProperties.multivalued) {
this.value = parseInt(cardViewTextItemProperties.value, 10);
}
}
get displayValue(): string {
return this.applyPipes(this.value);
}
}

View File

@@ -24,14 +24,12 @@ export class CardViewTextItemModel extends CardViewBaseItemModel implements Card
type: string = 'text';
inputType: string = 'text';
multiline?: boolean;
multivalued?: boolean;
pipes?: CardViewTextItemPipeProperty[];
clickCallBack?: any;
constructor(cardViewTextItemProperties: CardViewTextItemProperties) {
super(cardViewTextItemProperties);
this.multiline = !!cardViewTextItemProperties.multiline;
this.multivalued = !!cardViewTextItemProperties.multivalued;
this.pipes = cardViewTextItemProperties.pipes || [];
this.clickCallBack = cardViewTextItemProperties.clickCallBack ? cardViewTextItemProperties.clickCallBack : null;
@@ -44,7 +42,7 @@ export class CardViewTextItemModel extends CardViewBaseItemModel implements Card
return this.applyPipes(this.value);
}
private applyPipes(displayValue) {
applyPipes(displayValue) {
if (this.pipes.length) {
displayValue = this.pipes.reduce((accumulator, { pipe, params = [] }) => {
return pipe.transform(accumulator, ...params);