Professional Documents
Culture Documents
Condition Editor
Condition Editor
Condition Editor
PREREQUISITES ............................................................................................................................... 2
DELIVERABLE .................................................................................................................................. 2
REQUIREMENT ................................................................................................................................ 2
FILTERCRITERIA ................................................................................................................................... 8
ATTRIBUTES ..................................................................................................................................... 12
Prerequisites
Ver good knowledge within Angular and Typescript are required. Please read the
requirements carefully.
Deliverable
The described functionality needs to be provided in components covering the requested
functionality. The coding needs to be delivered as ZIP file in the end. The developed
components need to be fully tested and automated test scripts are highly appreciated.
Requirement
The Angular components need to be provide an easy-to-use condition editor.
An example for a simple condition would be NAME = ‘JOHN’, but the creation of complex
conditions needs to be available too e.g. ( NAME = ‘JOHN’ OR NAME = ‘MATT’) AND (AGE >
20 OR MARRIED = FALSE).
User Interface
The User Interface needs to be build using the PrimeNg framework and needs to cover the
following functionality:
- PanelMenu
https://www.primefaces.org/primeng/panelmenu
- OverlayPanel
https://www.primefaces.org/primeng/overlaypanel
- CascadedSelect
https://www.primefaces.org/primeng/cascadeselect
- Chip
https://www.primefaces.org/primeng/chip
Component Interface
The component interface needs to contain the following attributes:
Condition definition
A condition always consists of an attribute name, an operator and the value which should be
compared.
Conditions can be linked to each other with OR and AND. Furthermore brackets are available
to logically define the connection between the conditions.
Class definition:
export class FilterCriteria {
field: string;
operation: string;
value: any;
valueTo: any;
and: FilterCriteria[];
or: FilterCriteria[];
The class already has a toString method which is transforming the condition into something
readable. Please note that the FilterCriteria is always processed as an array!
The next couple of examples will demonstrate the usage of the FilterCriteria class:
Example Condition Filter Criteria
#1 name EQ ‘John’
#6 age BT 20 – 30 AND
employed = true
Values
Some attributes may have fixed values. These values should be displayed to the user and
should be selectable for simple access.
Variables
Some attributes may have variables based on their data type. The available variables are
passed as part of the attributes.
last_login GE ‘%LAST_WEEK%’
Besides the simple variables there are parameter variables as well. The parameter
hasParameter defines that a number parameter needs to be entered by the user. The
parameter part of the value is always based on a number and simply added at the end of the
variable e.g.
last_login GE ‘%MINUS_WEEKS%{2}’
Provided Classes
FilterCriteria
export class FilterCriteria {
field: string;
operation: string;
value: any;
valueTo: any;
and: FilterCriteria[];
or: FilterCriteria[];
criterion.field = field;
criterion.operation = operation;
criterion.value = value;
criterion.valueTo = valueTo;
return criterion;
/**
* Check if operator is equal.
*/
public isOperatorEqual(): boolean {
return (this.operation == FilterCriteria.cOperatorEqual);
}
/**
* Check whether value is in selection.
* @param value
*/
public checkValueInSelection(value: any) :boolean {
try {
switch (this.operation) {
case FilterCriteria.cOperatorEqual:
if (value == this.value) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorNotEqual:
if (value != this.value) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorContainsPattern:
if (value.includes(this.value)) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorLowerEqual:
if (value <= this.value) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorGreaterEqual:
if (value >= this.value) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorGreaterThan:
if (value > this.value) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorBetween:
if (value <= this.value && value >= this.valueTo) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorStartsWith:
if (value.startsWith(this.value)) {
return true;
} else {
return false;
}
break;
case FilterCriteria.cOperatorEndsWith:
if (value.endsWith(this.value)) {
return true;
} else {
return false;
}
break;
}
return false;
} catch (e) {
return false;
}
}
if (this.or) {
return true;
}
return false;
}
if (this.and) {
text = text + ' (';
for (const filterCriterion of this.and) {
text = text + filterCriterion.toString() + ' AND ';
}
}
if (this.or) {
text = text + ' (';
for (const filterCriterion of this.or) {
text = text + filterCriterion.toString() + ' OR ';
}
}
return text;
}
/**
* Copy Criteria.
* @param target
* @param source
*/
public static copyCriteria(target: FilterCriteria[], source:
FilterCriteria[]) {
}
}
Attributes
export enum FilterAttributeDateTypeEnum {
string,
date,
dateTime,
boolean,
number_integer,
number_decimal
}
name: string;
label: string;
filterAttributes: FilterAttribute[];
/**
* Create filter attribute group.
* @param name
* @param label
* @param filterAttributes
*/
public static create(name: string, label: string, filterAttributes:
FilterAttribute[]) :FilterAttributeGroup {
const filterAttributeGroup = new FilterAttributeGroup();
filterAttributeGroup.name = name;
filterAttributeGroup.label = label;
filterAttributeGroup.filterAttributes = filterAttributes;
return filterAttributeGroup;
}
}
export class FilterAttributeValues {
constructor(public value: any, public label: string) {
}
}
}
}
attribute: string;
dataType: FilterAttributeDateTypeEnum;
label: string;
values: FilterAttributeValues[];
variables: FilterAttributeVariable[];
/**
* Create filter attribute without variables.
* @param attribute
* @param label
* @param dataType
*/
public static create(attribute: string, label: string, dataType:
FilterAttributeDateTypeEnum, values: FilterAttributeValues[]) :
FilterAttribute {
const filterAttribute = new FilterAttribute();
filterAttribute.attribute = attribute;
filterAttribute.dataType = dataType;
filterAttribute.label = label;
filterAttribute.values = values;
filterAttribute.variables = [];
return filterAttribute;
}
/**
* Create filter attribute with variables.
* @param attribute
* @param label
* @param dataType
*/
public static createWithVariables(attribute: string, label: string,
dataType: FilterAttributeDateTypeEnum, values: FilterAttributeValues[],
variables: FilterAttributeVariable[]) : FilterAttribute {
const filterAttribute = FilterAttribute.create(attribute, label,
dataType, values);
filterAttribute.variables = variables;
return filterAttribute;
}