Commit 586a5c8c authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '49-update-core-filters'

parents 78bd1f44 e8550ccd
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
* Defined in OpenAPI as '#/definitions/DateFilter' * Defined in OpenAPI as '#/definitions/DateFilter'
*/ */
class DateFilter { class DateFilter {
public between: Date[]; public ge?: Date;
public ge: Date; public gt?: Date;
public gt: Date; public le?: Date;
public le: Date; public lt?: Date;
public lt: Date;
} }
......
...@@ -3,12 +3,11 @@ ...@@ -3,12 +3,11 @@
* Defined in Swagger as '#/definitions/NumberFilter«double»' * Defined in Swagger as '#/definitions/NumberFilter«double»'
*/ */
class NumberFilter { class NumberFilter {
public between: number[]; public eq?: number;
public eq: number; public ge?: number;
public ge: number; public gt?: number;
public gt: number; public le?: number;
public le: number; public lt?: number;
public lt: number;
} }
......
...@@ -3,6 +3,8 @@ import { Field } from 'redux-form'; ...@@ -3,6 +3,8 @@ import { Field } from 'redux-form';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import NumberFilterModel from 'model/NumberFilter';
interface INumberFilterInternal extends React.ClassAttributes<any> { interface INumberFilterInternal extends React.ClassAttributes<any> {
name: string; name: string;
input: any; input: any;
...@@ -10,56 +12,49 @@ interface INumberFilterInternal extends React.ClassAttributes<any> { ...@@ -10,56 +12,49 @@ interface INumberFilterInternal extends React.ClassAttributes<any> {
label: string; label: string;
} }
// The operations of NumberFilter supported
const opGe = 'ge';
const opLe = 'le';
class NumberFilterInternal extends React.Component<INumberFilterInternal, any> { class NumberFilterInternal extends React.Component<INumberFilterInternal, any> {
private constructor(props, context) { private constructor(props, context) {
super(props, context); super(props, context);
const { value } = props.input; const { value }: { value: NumberFilterModel } = props.input;
let textA = value[opGe] && value[opGe] || ''; let textA = value && value.ge !== null ? value.ge : '';
let textB = value[opLe] && value[opLe] || ''; let textB = value && value.le !== null ? value.le : '';
if (textA && textB) { if (textA && textB) {
const sorted = [ +textA, +textB ].sort((a, b) => b - a); const sorted = [ +textA, +textB ].sort((a, b) => b - a);
textA = sorted[0]; textA = sorted[0] === 0 ? '0' : sorted[0];
textB = sorted[1]; textB = sorted[1] === 0 ? '0' : sorted[1];
} }
// console.log('Constructor', textA, textB); // console.log('Constructor', textA, textB);
this.state = { textA, textB }; this.state = { textA, textB };
} }
public componentWillReceiveProps(nextProps) { public componentWillReceiveProps(nextProps) {
const { value } = nextProps.input; const { value }: { value: NumberFilterModel } = nextProps.input;
const textA = value[opGe] && value[opGe] || ''; const textA = value && value.ge !== null ? value.ge : '';
const textB = value[opLe] && value[opLe] || ''; const textB = value && value.le !== null ? value.le : '';
// console.log('receive props', textA, textB); // console.log('receive props', textA, textB);
this.setState({ textA, textB }); this.setState({ textA, textB });
} }
private report(valueA, valueB) { private report(filter: NumberFilterModel) {
const { input } = this.props; const { input } = this.props;
if (valueA || valueB) { if (filter) {
const r = { ge: null, le: null }; console.log('Reporting', filter);
r[opGe] = valueA && +valueA || undefined; input.onChange(filter);
r[opLe] = valueB && +valueB || undefined;
console.log('Reporting', r);
input.onChange(r);
} else { } else {
input.onChange(null); input.onChange(null);
} }
} }
private textAChange = (event) => { private textAChange = (event) => {
this.setState({ ...this.state, textA: event.target.value }); this.setState({textA: event.target.value , textB: this.state.textB});
this.report(event.target.value, this.state.textB); this.report({ge: event.target.value, le: this.state.textB});
} }
private textBChange = (event) => { private textBChange = (event) => {
this.setState({ ...this.state, textB: event.target.value }); this.setState({ textA: this.state.textA, textB: event.target.value });
this.report(this.state.textA, event.target.value); this.report({ge: this.state.textA, le: event.target.value});
} }
public render() { public render() {
...@@ -88,7 +83,7 @@ interface INumberFilter extends React.ClassAttributes<any> { ...@@ -88,7 +83,7 @@ interface INumberFilter extends React.ClassAttributes<any> {
label: string; label: string;
} }
// NumberFilter supports between [a,b], eq, ge, gt, le, lt // NumberFilter supports eq, ge, gt, le, lt
class NumberFilter extends React.Component<INumberFilter, any> { class NumberFilter extends React.Component<INumberFilter, any> {
public constructor(props: any) { public constructor(props: any) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment