Skip to content

Commit

Permalink
feat(dao): Include comparators and values (JS-11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus von Rüden committed Aug 3, 2017
1 parent 740cdf1 commit 9ad41d2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/api/SearchProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ export class SearchProperty {

/** the property type */
public type: SearchPropertyType;

/** the values if any */
public values: any;
}
42 changes: 36 additions & 6 deletions src/api/SearchPropertyType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {OnmsEnum, forId, forLabel} from '../internal/OnmsEnum';
import {Comparator, Comparators} from './Comparator';

/**
* Represents a search property type.
Expand All @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/dao/AbstractDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 9ad41d2

Please sign in to comment.