mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[MNT-23194] add long validators, correct filename typos (#9799)
* MNT-23194 add long validators, correct filename typos * MNT-23194 improve unit tests, fix naming typos * MNT-23194 change method name to more precise * MNT-23194 remove redundant type definitions, change any type, add different notation integers parsing
This commit is contained in:
committed by
GitHub
parent
4d2c489508
commit
6b8c064536
@@ -28,8 +28,8 @@ import {
|
|||||||
CardViewBoolItemModel,
|
CardViewBoolItemModel,
|
||||||
CardViewDatetimeItemModel,
|
CardViewDatetimeItemModel,
|
||||||
CardViewSelectItemModel,
|
CardViewSelectItemModel,
|
||||||
CardViewSelectItemProperties,
|
LogService,
|
||||||
LogService
|
CardViewLongItemModel
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { Constraint, Definition, Property as PropertyBase } from '@alfresco/js-api';
|
import { Constraint, Definition, Property as PropertyBase } from '@alfresco/js-api';
|
||||||
@@ -171,7 +171,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
||||||
|
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAKE:NAME': 'API Fake response' };
|
propertyValues = { 'FAKE:NAME': 'API Fake response' };
|
||||||
|
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.editable).toBe(false);
|
expect(cardViewProperty.editable).toBe(false);
|
||||||
});
|
});
|
||||||
@@ -224,10 +224,10 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe('The Chariot Line');
|
expect(cardViewProperty.value).toBe('The Chariot Line');
|
||||||
expect(cardViewProperty.multiline).toBeFalsy();
|
expect((cardViewProperty as CardViewTextItemModel).multiline).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate properly the multiline and value attributes for d:mltext', () => {
|
it('should translate properly the multiline and value attributes for d:mltext', () => {
|
||||||
@@ -236,10 +236,10 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
propertyValues = { 'FAS:PLAGUE': 'The Chariot Line' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewTextItemModel = cardViewGroup[0].properties[0] as CardViewTextItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewTextItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe('The Chariot Line');
|
expect(cardViewProperty.value).toBe('The Chariot Line');
|
||||||
expect(cardViewProperty.multiline).toBeTruthy();
|
expect((cardViewProperty as CardViewTextItemModel).multiline).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should translate properly the value attribute for d:date', () => {
|
it('should translate properly the value attribute for d:date', () => {
|
||||||
@@ -249,7 +249,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': expectedValue };
|
propertyValues = { 'FAS:PLAGUE': expectedValue };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewDateItemModel = cardViewGroup[0].properties[0] as CardViewDateItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewDateItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewDateItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(expectedValue);
|
expect(cardViewProperty.value).toBe(expectedValue);
|
||||||
});
|
});
|
||||||
@@ -261,7 +261,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': expectedValue };
|
propertyValues = { 'FAS:PLAGUE': expectedValue };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewDatetimeItemModel = cardViewGroup[0].properties[0] as CardViewDatetimeItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewDatetimeItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewDatetimeItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(expectedValue);
|
expect(cardViewProperty.value).toBe(expectedValue);
|
||||||
});
|
});
|
||||||
@@ -272,7 +272,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': '1024' };
|
propertyValues = { 'FAS:PLAGUE': '1024' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(1024);
|
expect(cardViewProperty.value).toBe(1024);
|
||||||
});
|
});
|
||||||
@@ -283,7 +283,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 0 };
|
propertyValues = { 'FAS:PLAGUE': 0 };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(0);
|
expect(cardViewProperty.value).toBe(0);
|
||||||
});
|
});
|
||||||
@@ -294,8 +294,8 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': '1024' };
|
propertyValues = { 'FAS:PLAGUE': '1024' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewIntItemModel = cardViewGroup[0].properties[0] as CardViewIntItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewIntItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(1024);
|
expect(cardViewProperty.value).toBe(1024);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -305,7 +305,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': '1024.24' };
|
propertyValues = { 'FAS:PLAGUE': '1024.24' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(1024.24);
|
expect(cardViewProperty.value).toBe(1024.24);
|
||||||
});
|
});
|
||||||
@@ -316,7 +316,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 0 };
|
propertyValues = { 'FAS:PLAGUE': 0 };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(0);
|
expect(cardViewProperty.value).toBe(0);
|
||||||
});
|
});
|
||||||
@@ -327,8 +327,8 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': '1024.24' };
|
propertyValues = { 'FAS:PLAGUE': '1024.24' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewFloatItemModel = cardViewGroup[0].properties[0] as CardViewFloatItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewFloatItemModel).toBeTrue();
|
||||||
expect(cardViewProperty.value).toBe(1024.24);
|
expect(cardViewProperty.value).toBe(1024.24);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': true };
|
propertyValues = { 'FAS:PLAGUE': true };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
const cardViewProperty: CardViewBoolItemModel = cardViewGroup[0].properties[0] as CardViewBoolItemModel;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewBoolItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewBoolItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe(true);
|
expect(cardViewProperty.value).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -363,7 +363,7 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
propertyValues = { 'FAS:PLAGUE': 'two' };
|
propertyValues = { 'FAS:PLAGUE': 'two' };
|
||||||
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, definition);
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, definition);
|
||||||
|
|
||||||
const cardViewProperty = cardViewGroup[0].properties[0] as CardViewSelectItemModel<CardViewSelectItemProperties<string>>;
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
expect(cardViewProperty instanceof CardViewSelectItemModel).toBeTruthy();
|
expect(cardViewProperty instanceof CardViewSelectItemModel).toBeTruthy();
|
||||||
expect(cardViewProperty.value).toBe('two');
|
expect(cardViewProperty.value).toBe('two');
|
||||||
});
|
});
|
||||||
@@ -428,5 +428,27 @@ describe('PropertyGroupTranslatorService', () => {
|
|||||||
expect(cardViewProperty.key).toBe('properties.fk:emperor');
|
expect(cardViewProperty.key).toBe('properties.fk:emperor');
|
||||||
expect(cardViewProperty.editable).toBe(false);
|
expect(cardViewProperty.editable).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should translate properly the value attribute for d:long', () => {
|
||||||
|
property.dataType = 'd:long';
|
||||||
|
|
||||||
|
propertyValues = { 'FAS:PLAGUE': '1024' };
|
||||||
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
|
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
|
||||||
|
expect(cardViewProperty.value).toBe(1024);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should translate properly the value attribute for d:long and value is 0', () => {
|
||||||
|
property.dataType = 'd:long';
|
||||||
|
|
||||||
|
propertyValues = { 'FAS:PLAGUE': 0 };
|
||||||
|
const cardViewGroup = service.translateToCardViewGroups(propertyGroups, propertyValues, null);
|
||||||
|
|
||||||
|
const cardViewProperty = cardViewGroup[0].properties[0];
|
||||||
|
expect(cardViewProperty instanceof CardViewLongItemModel).toBeTruthy();
|
||||||
|
expect(cardViewProperty.value).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -25,6 +25,7 @@ import {
|
|||||||
CardViewSelectItemModel,
|
CardViewSelectItemModel,
|
||||||
CardViewDatetimeItemModel,
|
CardViewDatetimeItemModel,
|
||||||
CardViewIntItemModel,
|
CardViewIntItemModel,
|
||||||
|
CardViewLongItemModel,
|
||||||
CardViewFloatItemModel,
|
CardViewFloatItemModel,
|
||||||
MultiValuePipe,
|
MultiValuePipe,
|
||||||
AppConfigService,
|
AppConfigService,
|
||||||
@@ -53,10 +54,12 @@ export const RECOGNISED_ECM_TYPES = [D_TEXT, D_MLTEXT, D_DATE, D_DATETIME, D_INT
|
|||||||
export class PropertyGroupTranslatorService {
|
export class PropertyGroupTranslatorService {
|
||||||
valueSeparator: string;
|
valueSeparator: string;
|
||||||
|
|
||||||
constructor(private multiValuePipe: MultiValuePipe,
|
constructor(
|
||||||
|
private multiValuePipe: MultiValuePipe,
|
||||||
private decimalNumberPipe: DecimalNumberPipe,
|
private decimalNumberPipe: DecimalNumberPipe,
|
||||||
private appConfig: AppConfigService,
|
private appConfig: AppConfigService,
|
||||||
private logService: LogService) {
|
private logService: LogService
|
||||||
|
) {
|
||||||
this.valueSeparator = this.appConfig.get<string>('content-metadata.multi-value-pipe-separator');
|
this.valueSeparator = this.appConfig.get<string>('content-metadata.multi-value-pipe-separator');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,42 +126,57 @@ export class PropertyGroupTranslatorService {
|
|||||||
} else {
|
} else {
|
||||||
switch (dataType) {
|
switch (dataType) {
|
||||||
case D_MLTEXT:
|
case D_MLTEXT:
|
||||||
cardViewItemProperty = new CardViewTextItemModel(Object.assign(propertyDefinition, {
|
cardViewItemProperty = new CardViewTextItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
multiline: true
|
multiline: true
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_INT:
|
case D_INT:
|
||||||
case D_LONG:
|
cardViewItemProperty = new CardViewIntItemModel(
|
||||||
cardViewItemProperty = new CardViewIntItemModel(Object.assign(propertyDefinition, {
|
Object.assign(propertyDefinition, {
|
||||||
multivalued: isMultiValued,
|
multivalued: isMultiValued,
|
||||||
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case D_LONG:
|
||||||
|
cardViewItemProperty = new CardViewLongItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
|
multivalued: isMultiValued,
|
||||||
|
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
|
})
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_FLOAT:
|
case D_FLOAT:
|
||||||
case D_DOUBLE:
|
case D_DOUBLE:
|
||||||
cardViewItemProperty = new CardViewFloatItemModel(Object.assign(propertyDefinition, {
|
cardViewItemProperty = new CardViewFloatItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
multivalued: isMultiValued,
|
multivalued: isMultiValued,
|
||||||
pipes: [
|
pipes: [{ pipe: this.decimalNumberPipe }, { pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
{ pipe: this.decimalNumberPipe },
|
})
|
||||||
{ pipe: this.multiValuePipe, params: [this.valueSeparator] }
|
);
|
||||||
]
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_DATE:
|
case D_DATE:
|
||||||
cardViewItemProperty = new CardViewDateItemModel(Object.assign(propertyDefinition, {
|
cardViewItemProperty = new CardViewDateItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
multivalued: isMultiValued,
|
multivalued: isMultiValued,
|
||||||
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_DATETIME:
|
case D_DATETIME:
|
||||||
cardViewItemProperty = new CardViewDatetimeItemModel(Object.assign(propertyDefinition, {
|
cardViewItemProperty = new CardViewDatetimeItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
multivalued: isMultiValued,
|
multivalued: isMultiValued,
|
||||||
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case D_BOOLEAN:
|
case D_BOOLEAN:
|
||||||
@@ -167,11 +185,13 @@ export class PropertyGroupTranslatorService {
|
|||||||
|
|
||||||
case D_TEXT:
|
case D_TEXT:
|
||||||
default:
|
default:
|
||||||
cardViewItemProperty = new CardViewTextItemModel(Object.assign(propertyDefinition, {
|
cardViewItemProperty = new CardViewTextItemModel(
|
||||||
|
Object.assign(propertyDefinition, {
|
||||||
multivalued: isMultiValued,
|
multivalued: isMultiValued,
|
||||||
multiline: isMultiValued,
|
multiline: isMultiValued,
|
||||||
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
pipes: [{ pipe: this.multiValuePipe, params: [this.valueSeparator] }]
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -135,8 +135,12 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepareValueForUpload(property: CardViewTextItemModel, value: string | string[]): string | string[] {
|
prepareValueForUpload(property: CardViewTextItemModel, value: string | string[]): string | string[] {
|
||||||
if (property.multivalued && typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
|
if (property.multivalued) {
|
||||||
return value.split(this.multiValueSeparator.trim()).map((item) => item.trim());
|
return value.split(this.multiValueSeparator.trim()).map((item) => item.trim());
|
||||||
|
} else if (property.type === 'int' || property.type === 'long') {
|
||||||
|
return this.prepareIntLongValue(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -151,11 +155,14 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
|||||||
|
|
||||||
addValueToList(newListItem: MatChipInputEvent) {
|
addValueToList(newListItem: MatChipInputEvent) {
|
||||||
const chipInput = newListItem.chipInput.inputElement;
|
const chipInput = newListItem.chipInput.inputElement;
|
||||||
const chipValue = newListItem.value.trim() || '';
|
let chipValue = newListItem.value.trim() || '';
|
||||||
|
|
||||||
if (typeof this.editedValue !== 'string') {
|
if (typeof this.editedValue !== 'string') {
|
||||||
if (this.property.isValid(chipValue)) {
|
if (this.property.isValid(chipValue)) {
|
||||||
if (chipValue) {
|
if (chipValue) {
|
||||||
|
if (this.property.type === 'int' || this.property.type === 'long') {
|
||||||
|
chipValue = this.prepareIntLongValue(chipValue);
|
||||||
|
}
|
||||||
this.editedValue.push(chipValue);
|
this.editedValue.push(chipValue);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
@@ -223,4 +230,8 @@ export class CardViewTextItemComponent extends BaseCardView<CardViewTextItemMode
|
|||||||
get showLabelForChips(): boolean {
|
get showLabelForChips(): boolean {
|
||||||
return this.displayLabelForChips;
|
return this.displayLabelForChips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private prepareIntLongValue(value: string): string {
|
||||||
|
return String(Math.trunc(Number(value)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,8 +21,8 @@ import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
|||||||
import { CardViewBoolItemProperties } from '../interfaces/card-view.interfaces';
|
import { CardViewBoolItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
export class CardViewBoolItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewBoolItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'bool';
|
type = 'bool';
|
||||||
value: boolean = false;
|
value = false;
|
||||||
default: boolean;
|
default: boolean;
|
||||||
|
|
||||||
constructor(cardViewBoolItemProperties: CardViewBoolItemProperties) {
|
constructor(cardViewBoolItemProperties: CardViewBoolItemProperties) {
|
||||||
|
@@ -25,7 +25,7 @@ import { DateFnsUtils } from '../../common/utils/date-fns-utils';
|
|||||||
type DateItemType = Date | Date[] | null;
|
type DateItemType = Date | Date[] | null;
|
||||||
|
|
||||||
export class CardViewDateItemModel extends CardViewBaseItemModel<DateItemType> implements CardViewItem, DynamicComponentModel {
|
export class CardViewDateItemModel extends CardViewBaseItemModel<DateItemType> implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'date';
|
type = 'date';
|
||||||
format: string;
|
format: string;
|
||||||
locale: string;
|
locale: string;
|
||||||
|
|
||||||
@@ -51,9 +51,7 @@ export class CardViewDateItemModel extends CardViewBaseItemModel<DateItemType> i
|
|||||||
return this.default ? [this.default] : [];
|
return this.default ? [this.default] : [];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return this.value && !Array.isArray(this.value)
|
return this.value && !Array.isArray(this.value) ? this.transformDate(this.prepareDate(this.value)) : this.default;
|
||||||
? this.transformDate(this.prepareDate(this.value))
|
|
||||||
: this.default;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,8 +21,8 @@ import { CardViewDateItemModel } from './card-view-dateitem.model';
|
|||||||
import { CardViewDateItemProperties } from '../interfaces/card-view.interfaces';
|
import { CardViewDateItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
export class CardViewDatetimeItemModel extends CardViewDateItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewDatetimeItemModel extends CardViewDateItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'datetime';
|
type = 'datetime';
|
||||||
format: string = 'MMM d, y, H:mm';
|
format = 'MMM d, y, H:mm';
|
||||||
|
|
||||||
constructor(cardViewDateItemProperties: CardViewDateItemProperties) {
|
constructor(cardViewDateItemProperties: CardViewDateItemProperties) {
|
||||||
super(cardViewDateItemProperties);
|
super(cardViewDateItemProperties);
|
||||||
|
@@ -22,8 +22,8 @@ import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
|||||||
import { CardViewItemFloatValidator } from '../validators/card-view.validators';
|
import { CardViewItemFloatValidator } from '../validators/card-view.validators';
|
||||||
|
|
||||||
export class CardViewFloatItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewFloatItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'float';
|
type = 'float';
|
||||||
inputType: string = 'number';
|
inputType = 'number';
|
||||||
|
|
||||||
constructor(cardViewTextItemProperties: CardViewTextItemProperties) {
|
constructor(cardViewTextItemProperties: CardViewTextItemProperties) {
|
||||||
super(cardViewTextItemProperties);
|
super(cardViewTextItemProperties);
|
||||||
|
@@ -22,8 +22,8 @@ import { CardViewIntItemProperties } from '../interfaces/card-view.interfaces';
|
|||||||
import { CardViewItemIntValidator, CardViewItemPositiveIntValidator } from '../validators/card-view.validators';
|
import { CardViewItemIntValidator, CardViewItemPositiveIntValidator } from '../validators/card-view.validators';
|
||||||
|
|
||||||
export class CardViewIntItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewIntItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'int';
|
type = 'int';
|
||||||
inputType: string = 'number';
|
inputType = 'number';
|
||||||
|
|
||||||
constructor(cardViewIntItemProperties: CardViewIntItemProperties) {
|
constructor(cardViewIntItemProperties: CardViewIntItemProperties) {
|
||||||
super(cardViewIntItemProperties);
|
super(cardViewIntItemProperties);
|
||||||
|
@@ -21,7 +21,7 @@ import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
|||||||
import { CardViewKeyValuePairsItemProperties } from '../interfaces/card-view.interfaces';
|
import { CardViewKeyValuePairsItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
export class CardViewKeyValuePairsItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewKeyValuePairsItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'keyvaluepairs';
|
type = 'keyvaluepairs';
|
||||||
|
|
||||||
constructor(cardViewKeyValuePairsItemProperties: CardViewKeyValuePairsItemProperties) {
|
constructor(cardViewKeyValuePairsItemProperties: CardViewKeyValuePairsItemProperties) {
|
||||||
super(cardViewKeyValuePairsItemProperties);
|
super(cardViewKeyValuePairsItemProperties);
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CardViewLongItemModel } from './card-view-longitem.model';
|
||||||
|
import { CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
|
describe('CardViewLongItemModel', () => {
|
||||||
|
let properties: CardViewTextItemProperties;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
properties = {
|
||||||
|
label: 'Long Number',
|
||||||
|
value: '21',
|
||||||
|
key: 'long'
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('value should be parsed as a long integer', () => {
|
||||||
|
const itemModel = new CardViewLongItemModel(properties);
|
||||||
|
|
||||||
|
expect(itemModel.value).toBe(21);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('value should be parsed as a long integer only if there is a value', () => {
|
||||||
|
properties.value = undefined;
|
||||||
|
const itemModel = new CardViewLongItemModel(properties);
|
||||||
|
|
||||||
|
expect(itemModel.value).toBe(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isValid should return the validators value', () => {
|
||||||
|
const itemModel = new CardViewLongItemModel(properties);
|
||||||
|
|
||||||
|
expect(itemModel.isValid(21)).toBe(true, 'For 21 it should be true');
|
||||||
|
expect(itemModel.isValid(21.0)).toBe(true, 'For 21.0 it should be true');
|
||||||
|
expect(itemModel.isValid('21')).toBe(true, 'For "21" it should be true');
|
||||||
|
expect(itemModel.isValid('21.0')).toBe(true, 'For "21.0" it should be true');
|
||||||
|
expect(itemModel.isValid('2e1')).toBe(true, 'For "2e1" it should be true');
|
||||||
|
expect(itemModel.isValid('2g1')).toBe(false, 'For "2g1" it should be false');
|
||||||
|
expect(itemModel.isValid(21.3)).toBe(false, 'For 21.3 it should be false');
|
||||||
|
expect(itemModel.isValid('21.3')).toBe(false, 'For "21.3" it should be false');
|
||||||
|
expect(itemModel.isValid('text')).toBe(false, 'For "text" it should be false');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate based on defined constraints', () => {
|
||||||
|
const constrainedProperties = {
|
||||||
|
label: 'Some Number',
|
||||||
|
value: '21',
|
||||||
|
key: 'number',
|
||||||
|
dataType: 'd:float',
|
||||||
|
constraints: [
|
||||||
|
{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'MINMAX',
|
||||||
|
parameters: { minValue: 10, maxValue: 15 }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CardViewLongItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(false, '21 is bigger than maximum allowed');
|
||||||
|
|
||||||
|
itemModel.value = '5';
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(false, '5 is less than minimum allowed');
|
||||||
|
|
||||||
|
itemModel.value = '13';
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(true, '13 is within the allowed range');
|
||||||
|
});
|
||||||
|
});
|
@@ -0,0 +1,45 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CardViewItem } from '../interfaces/card-view-item.interface';
|
||||||
|
import { DynamicComponentModel } from '../../common/services/dynamic-component-mapper.service';
|
||||||
|
import { CardViewTextItemModel } from './card-view-textitem.model';
|
||||||
|
import { CardViewIntItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
import { CardViewItemLongValidator, CardViewItemPositiveLongValidator } from '../validators/card-view.validators';
|
||||||
|
|
||||||
|
export class CardViewLongItemModel extends CardViewTextItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
|
type = 'long';
|
||||||
|
inputType = 'number';
|
||||||
|
|
||||||
|
constructor(cardViewIntItemProperties: CardViewIntItemProperties) {
|
||||||
|
super(cardViewIntItemProperties);
|
||||||
|
|
||||||
|
this.validators.push(new CardViewItemLongValidator());
|
||||||
|
|
||||||
|
if (cardViewIntItemProperties.allowOnlyPositiveNumbers) {
|
||||||
|
this.validators.push(new CardViewItemPositiveLongValidator());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cardViewIntItemProperties.value && !cardViewIntItemProperties.multivalued) {
|
||||||
|
this.value = Number(cardViewIntItemProperties.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get displayValue(): string {
|
||||||
|
return this.applyPipes(this.value);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,7 +20,7 @@ import { DynamicComponentModel } from '../../common/services/dynamic-component-m
|
|||||||
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
||||||
|
|
||||||
export class CardViewMapItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewMapItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'map';
|
type = 'map';
|
||||||
value: Map<string, string>;
|
value: Map<string, string>;
|
||||||
|
|
||||||
get displayValue() {
|
get displayValue() {
|
||||||
|
@@ -23,7 +23,7 @@ import { Observable, of } from 'rxjs';
|
|||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
export class CardViewSelectItemModel<T> extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewSelectItemModel<T> extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'select';
|
type = 'select';
|
||||||
options$: Observable<CardViewSelectItemOption<T>[]>;
|
options$: Observable<CardViewSelectItemOption<T>[]>;
|
||||||
displayNoneOption: boolean;
|
displayNoneOption: boolean;
|
||||||
|
|
||||||
@@ -40,7 +40,8 @@ export class CardViewSelectItemModel<T> extends CardViewBaseItemModel implements
|
|||||||
switchMap((options) => {
|
switchMap((options) => {
|
||||||
const option = options.find((o) => o.key === this.value?.toString());
|
const option = options.find((o) => o.key === this.value?.toString());
|
||||||
return of(option ? option.label : '');
|
return of(option ? option.label : '');
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get displayValue() {
|
get displayValue() {
|
||||||
|
@@ -21,8 +21,8 @@ import { CardViewBaseItemModel } from './card-view-baseitem.model';
|
|||||||
import { CardViewTextItemPipeProperty, CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
import { CardViewTextItemPipeProperty, CardViewTextItemProperties } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
export class CardViewTextItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
export class CardViewTextItemModel extends CardViewBaseItemModel implements CardViewItem, DynamicComponentModel {
|
||||||
type: string = 'text';
|
type = 'text';
|
||||||
inputType: string = 'text';
|
inputType = 'text';
|
||||||
multiline?: boolean;
|
multiline?: boolean;
|
||||||
pipes?: CardViewTextItemPipeProperty[];
|
pipes?: CardViewTextItemPipeProperty[];
|
||||||
clickCallBack?: any;
|
clickCallBack?: any;
|
||||||
|
@@ -21,6 +21,7 @@ export * from './card-view-dateitem.model';
|
|||||||
export * from './card-view-datetimeitem.model';
|
export * from './card-view-datetimeitem.model';
|
||||||
export * from './card-view-floatitem.model';
|
export * from './card-view-floatitem.model';
|
||||||
export * from './card-view-intitem.model';
|
export * from './card-view-intitem.model';
|
||||||
|
export * from './card-view-longitem.model';
|
||||||
export * from './card-view-mapitem.model';
|
export * from './card-view-mapitem.model';
|
||||||
export * from './card-view-textitem.model';
|
export * from './card-view-textitem.model';
|
||||||
export * from './card-view-keyvaluepairs.model';
|
export * from './card-view-keyvaluepairs.model';
|
||||||
|
@@ -22,14 +22,17 @@ import { CardViewTextItemComponent } from '../components/card-view-textitem/card
|
|||||||
import { CardViewSelectItemComponent } from '../components/card-view-selectitem/card-view-selectitem.component';
|
import { CardViewSelectItemComponent } from '../components/card-view-selectitem/card-view-selectitem.component';
|
||||||
import { CardViewBoolItemComponent } from '../components/card-view-boolitem/card-view-boolitem.component';
|
import { CardViewBoolItemComponent } from '../components/card-view-boolitem/card-view-boolitem.component';
|
||||||
import { CardViewKeyValuePairsItemComponent } from '../components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component';
|
import { CardViewKeyValuePairsItemComponent } from '../components/card-view-keyvaluepairsitem/card-view-keyvaluepairsitem.component';
|
||||||
import { DynamicComponentMapper, DynamicComponentResolveFunction, DynamicComponentResolver } from '../../common/services/dynamic-component-mapper.service';
|
import {
|
||||||
|
DynamicComponentMapper,
|
||||||
|
DynamicComponentResolveFunction,
|
||||||
|
DynamicComponentResolver
|
||||||
|
} from '../../common/services/dynamic-component-mapper.service';
|
||||||
import { CardViewArrayItemComponent } from '../components/card-view-arrayitem/card-view-arrayitem.component';
|
import { CardViewArrayItemComponent } from '../components/card-view-arrayitem/card-view-arrayitem.component';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class CardItemTypeService extends DynamicComponentMapper {
|
export class CardItemTypeService extends DynamicComponentMapper {
|
||||||
|
|
||||||
protected defaultValue: Type<any> = CardViewTextItemComponent;
|
protected defaultValue: Type<any> = CardViewTextItemComponent;
|
||||||
|
|
||||||
protected types: { [key: string]: DynamicComponentResolveFunction } = {
|
protected types: { [key: string]: DynamicComponentResolveFunction } = {
|
||||||
@@ -37,6 +40,7 @@ export class CardItemTypeService extends DynamicComponentMapper {
|
|||||||
select: DynamicComponentResolver.fromType(CardViewSelectItemComponent),
|
select: DynamicComponentResolver.fromType(CardViewSelectItemComponent),
|
||||||
int: DynamicComponentResolver.fromType(CardViewTextItemComponent),
|
int: DynamicComponentResolver.fromType(CardViewTextItemComponent),
|
||||||
float: DynamicComponentResolver.fromType(CardViewTextItemComponent),
|
float: DynamicComponentResolver.fromType(CardViewTextItemComponent),
|
||||||
|
long: DynamicComponentResolver.fromType(CardViewTextItemComponent),
|
||||||
date: DynamicComponentResolver.fromType(CardViewDateItemComponent),
|
date: DynamicComponentResolver.fromType(CardViewDateItemComponent),
|
||||||
datetime: DynamicComponentResolver.fromType(CardViewDateItemComponent),
|
datetime: DynamicComponentResolver.fromType(CardViewDateItemComponent),
|
||||||
bool: DynamicComponentResolver.fromType(CardViewBoolItemComponent),
|
bool: DynamicComponentResolver.fromType(CardViewBoolItemComponent),
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CardViewItemLengthValidator } from './card-view-item-length.valiator';
|
import { CardViewItemLengthValidator } from './card-view-item-length.validator';
|
||||||
|
|
||||||
describe('CardViewItemPositiveIntValidator', () => {
|
describe('CardViewItemLengthValidator', () => {
|
||||||
const validator = new CardViewItemLengthValidator(2, 3);
|
const validator = new CardViewItemLengthValidator(2, 3);
|
||||||
|
|
||||||
it('should validate empty value', () => {
|
it('should validate empty value', () => {
|
||||||
|
@@ -0,0 +1,39 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CardViewItemValidator } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
|
export class CardViewItemLongValidator implements CardViewItemValidator {
|
||||||
|
message = 'CORE.CARDVIEW.VALIDATORS.LONG_VALIDATION_ERROR';
|
||||||
|
|
||||||
|
isValid(value: number | number[] | ''): boolean {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.every(this.isLongNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value === '' || (!isNaN(value) && this.isLongNumber(value) && this.isNotSpaceOnly(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private isLongNumber(value: number): boolean {
|
||||||
|
const longNumber = Number(value);
|
||||||
|
return Math.trunc(longNumber) === longNumber && longNumber >= Number.MIN_SAFE_INTEGER && longNumber <= Number.MAX_SAFE_INTEGER;
|
||||||
|
}
|
||||||
|
|
||||||
|
private isNotSpaceOnly(value: number): boolean {
|
||||||
|
return String(value).trim() !== '';
|
||||||
|
}
|
||||||
|
}
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CardViewItemMatchValidator } from './card-view-item-match.valiator';
|
import { CardViewItemMatchValidator } from './card-view-item-match.validator';
|
||||||
|
|
||||||
describe('CardViewItemMatchValidator', () => {
|
describe('CardViewItemMatchValidator', () => {
|
||||||
const validator = new CardViewItemMatchValidator('^[a-zA-Z]+$', undefined, true);
|
const validator = new CardViewItemMatchValidator('^[a-zA-Z]+$', undefined, true);
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CardViewItemMinMaxValidator } from './card-view-item-minmax.valiator';
|
import { CardViewItemMinMaxValidator } from './card-view-item-minmax.validator';
|
||||||
|
|
||||||
describe('CardViewItemMinMaxValidator', () => {
|
describe('CardViewItemMinMaxValidator', () => {
|
||||||
const validator = new CardViewItemMinMaxValidator(1, 3);
|
const validator = new CardViewItemMinMaxValidator(1, 3);
|
||||||
|
@@ -0,0 +1,34 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CardViewItemValidator } from '../interfaces/card-view.interfaces';
|
||||||
|
|
||||||
|
export class CardViewItemPositiveLongValidator implements CardViewItemValidator {
|
||||||
|
message = 'CORE.CARDVIEW.VALIDATORS.ONLY_POSITIVE_NUMBER';
|
||||||
|
|
||||||
|
isValid(value: number | number[] | ''): boolean {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.every(this.isPositiveNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value === '' || (!isNaN(value) && this.isPositiveNumber(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private isPositiveNumber(value: number): boolean {
|
||||||
|
return Number(value) >= 0;
|
||||||
|
}
|
||||||
|
}
|
@@ -18,7 +18,9 @@
|
|||||||
export * from './card-view-item-int.validator';
|
export * from './card-view-item-int.validator';
|
||||||
export * from './card-view-item-only-positive-int.validator';
|
export * from './card-view-item-only-positive-int.validator';
|
||||||
export * from './card-view-item-float.validator';
|
export * from './card-view-item-float.validator';
|
||||||
export * from './card-view-item-match.valiator';
|
export * from './card-view-item-long.validator';
|
||||||
export * from './card-view-item-minmax.valiator';
|
export * from './card-view-item-only-positive-long.validator';
|
||||||
export * from './card-view-item-length.valiator';
|
export * from './card-view-item-match.validator';
|
||||||
|
export * from './card-view-item-minmax.validator';
|
||||||
|
export * from './card-view-item-length.validator';
|
||||||
export * from './validators.map';
|
export * from './validators.map';
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CardViewItemMatchValidator, MatchValidatorParams } from './card-view-item-match.valiator';
|
import { CardViewItemMatchValidator, MatchValidatorParams } from './card-view-item-match.validator';
|
||||||
import { CardViewItemMinMaxValidator, MinMaxValidatorParams } from './card-view-item-minmax.valiator';
|
import { CardViewItemMinMaxValidator, MinMaxValidatorParams } from './card-view-item-minmax.validator';
|
||||||
import { CardViewItemLengthValidator, LengthValidatorParams } from './card-view-item-length.valiator';
|
import { CardViewItemLengthValidator, LengthValidatorParams } from './card-view-item-length.validator';
|
||||||
|
|
||||||
const validators = {
|
const validators = {
|
||||||
minmax: (parameters: MinMaxValidatorParams) => new CardViewItemMinMaxValidator(parameters.minValue, parameters.maxValue),
|
minmax: (parameters: MinMaxValidatorParams) => new CardViewItemMinMaxValidator(parameters.minValue, parameters.maxValue),
|
||||||
|
@@ -196,6 +196,7 @@
|
|||||||
"VALIDATORS": {
|
"VALIDATORS": {
|
||||||
"FLOAT_VALIDATION_ERROR": "Use a number format",
|
"FLOAT_VALIDATION_ERROR": "Use a number format",
|
||||||
"INT_VALIDATION_ERROR": "Use an integer format",
|
"INT_VALIDATION_ERROR": "Use an integer format",
|
||||||
|
"LONG_VALIDATION_ERROR": "Use a long format",
|
||||||
"LENGTH_VALIDATION_ERROR": "Value should be between {{ minLength }} and {{ maxLength }} in length",
|
"LENGTH_VALIDATION_ERROR": "Value should be between {{ minLength }} and {{ maxLength }} in length",
|
||||||
"MATCH_VALIDATION_ERROR": "Value doesn't match pattern: {{ expression }}",
|
"MATCH_VALIDATION_ERROR": "Value doesn't match pattern: {{ expression }}",
|
||||||
"MINMAX_VALIDATION_ERROR": "Value should be between {{ minValue }} and {{ maxValue }}",
|
"MINMAX_VALIDATION_ERROR": "Value should be between {{ minValue }} and {{ maxValue }}",
|
||||||
|
Reference in New Issue
Block a user