mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -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 {
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user