Permalink
Browse files

feat(dao): Include comparators and values (JS-11)

  • Loading branch information...
mvrueden committed Aug 3, 2017
1 parent 740cdf1 commit 9ad41d2009643988613c591c2167e01dd4eb639b
Showing with 40 additions and 6 deletions.
  1. +3 −0 src/api/SearchProperty.ts
  2. +36 −6 src/api/SearchPropertyType.ts
  3. +1 −0 src/dao/AbstractDAO.ts
@@ -16,4 +16,7 @@ export class SearchProperty {
/** the property type */
public type: SearchPropertyType;
/** the values if any */
public values: any;
}
@@ -1,4 +1,5 @@
import {OnmsEnum, forId, forLabel} from '../internal/OnmsEnum';
import {Comparator, Comparators} from './Comparator';
/**
* Represents a search property type.
@@ -9,15 +10,44 @@ export class SearchPropertyType extends OnmsEnum<string> {
public static forId(id: string) {
return forId(SearchPropertyTypes, id);
}
/** supported comparators. */
private comparators: Comparator[];
constructor(id: string, label: string, someComparators: Comparator[]) {
super(id, label);
this.comparators = someComparators;
}
/**
* Returns the comparators supported by this type.
*
* @returns {Comparator[]} the supported comparators.
*/
public getComparators() {
return this.comparators;
}
}
/** @hidden */
const StringComparators = [
Comparators.EQ, Comparators.NE,
];
/** @hidden */
const NumberComparators = [
Comparators.EQ, Comparators.NE,
Comparators.GE, Comparators.GT,
Comparators.LE, Comparators.LT,
];
const SearchPropertyTypes = {
FLOAT: new SearchPropertyType('FLOAT', 'floating-point number'),
INTEGER: new SearchPropertyType('INTEGER', 'integer'),
IP_ADDRESS: new SearchPropertyType('IP_ADDRESS', 'IP address'),
LONG: new SearchPropertyType('LONG', 'long integer'),
STRING: new SearchPropertyType('STRING', 'string'),
TIMESTAMP: new SearchPropertyType('TIMESTAMP', 'date and time'),
FLOAT: new SearchPropertyType('FLOAT', 'floating-point number', NumberComparators),
INTEGER: new SearchPropertyType('INTEGER', 'integer', NumberComparators),
IP_ADDRESS: new SearchPropertyType('IP_ADDRESS', 'IP address', StringComparators),
LONG: new SearchPropertyType('LONG', 'long integer', NumberComparators),
STRING: new SearchPropertyType('STRING', 'string', StringComparators),
TIMESTAMP: new SearchPropertyType('TIMESTAMP', 'date and time', NumberComparators),
};
/** @hidden */
View
@@ -208,6 +208,7 @@ export abstract class AbstractDAO<K, T> {
prop.name = data.name;
prop.orderBy = !!data.orderBy;
prop.type = SearchPropertyType.forId(data.type);
prop.values = data.values;
return prop;
}

0 comments on commit 9ad41d2

Please sign in to comment.