dtable-utils
Version:
dtable common utils
59 lines (56 loc) • 1.68 kB
JavaScript
import { getGeolocationDisplayString } from '../../cell-value-get/geolocation.js';
import { FILTER_PREDICATE_TYPE } from '../../constants/filter/filter-predicate.js';
/**
* Filter geolocation
* @param {object} location e.g. { province, ... }
* @param {string} filter_predicate
* @param {string} filter_term
* @param {object} column e.g. { type, data: { geo_format, ... }, ... }
* @returns bool
*/
var geolocationFilter = function geolocationFilter(location, _ref) {
var filter_predicate = _ref.filter_predicate,
filter_term = _ref.filter_term,
column = _ref.column;
var geolocation = getGeolocationDisplayString(location, column.data);
switch (filter_predicate) {
case FILTER_PREDICATE_TYPE.CONTAINS:
{
if (!filter_term) {
return true;
}
if (!geolocation) {
return false;
}
return geolocation.toString().toLowerCase().indexOf(filter_term.toLowerCase()) > -1;
}
case FILTER_PREDICATE_TYPE.NOT_CONTAIN:
{
if (!filter_term || !geolocation) {
return true;
}
return geolocation.toString().toLowerCase().indexOf(filter_term.toLowerCase()) < 0;
}
case FILTER_PREDICATE_TYPE.IS:
{
return !filter_term || geolocation === filter_term;
}
case FILTER_PREDICATE_TYPE.IS_NOT:
{
return !filter_term || geolocation !== filter_term;
}
case FILTER_PREDICATE_TYPE.EMPTY:
{
return !geolocation;
}
case FILTER_PREDICATE_TYPE.NOT_EMPTY:
{
return !!geolocation;
}
default:
{
return false;
}
}
};
export { geolocationFilter };