Commit e779d8ac authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Accession filters: SAMPSTAT, STORAGE

- Upgrade StringArrFilter
parent 53acbdaf
......@@ -109,6 +109,8 @@
"crops": "Crop name",
"acceNumb": "Accession number contains",
"seqNo": "Sequential number",
"sampStat": "Biological status",
"storage": "Type of germplasm storage",
"geo": {
"latitude": "Latitude",
"longitude": "Longitude",
......
......@@ -59,9 +59,46 @@ class Accession {
property: 'seqNo',
direction: 'ASC',
};
public static SORT_OPTIONS = {
seqNo: { label: 'Accession number', dir: 'ASC' },
};
public static SAMPSTAT: { [key: number]: string; } = {
100: 'accession.sampleStatus.100',
110: 'accession.sampleStatus.110',
120: 'accession.sampleStatus.120',
130: 'accession.sampleStatus.130',
200: 'accession.sampleStatus.200',
300: 'accession.sampleStatus.300',
400: 'accession.sampleStatus.400',
410: 'accession.sampleStatus.410',
411: 'accession.sampleStatus.411',
412: 'accession.sampleStatus.412',
413: 'accession.sampleStatus.413',
414: 'accession.sampleStatus.414',
415: 'accession.sampleStatus.415',
416: 'accession.sampleStatus.416',
420: 'accession.sampleStatus.420',
421: 'accession.sampleStatus.421',
422: 'accession.sampleStatus.422',
423: 'accession.sampleStatus.423',
500: 'accession.sampleStatus.500',
600: 'accession.sampleStatus.600',
999: 'accession.sampleStatus.999',
};
public static STORAGE: { [key: number]: string; } = {
10: 'accession.storage.10',
11: 'accession.storage.11',
12: 'accession.storage.12',
13: 'accession.storage.13',
20: 'accession.storage.20',
30: 'accession.storage.30',
40: 'accession.storage.40',
50: 'accession.storage.50',
99: 'accession.storage.99',
};
}
export default Accession;
......@@ -7,6 +7,7 @@ import Paper from '@material-ui/core/Paper';
import * as flattenjs from 'flattenjs';
import * as _ from 'lodash';
import { cleanFilters } from 'utilities';
import Accession from 'model/Accession';
/**
* filterObj example: {crop: ["bannana", "apple"], description: {contains: "de"}, title: {contains: "ti"}}
......@@ -102,8 +103,9 @@ function getLabelName(path, value, lookups, prefix, t) {
.join('.');
const translatedPrettyPath = t(`f.${prefix}.${prettyPath}`);
const translatedPrettyName = t(`${name}`);
return `${translatedPrettyPath}: ${name}`;
return `${translatedPrettyPath}: ${translatedPrettyName}`;
}
class PrettyFilters extends React.Component<IPrettyFiltersProps, any> {
......@@ -156,7 +158,9 @@ const mapStateToProps = (state, ownProps) => ({
lookups: {
crop: [],
category: '',
key: {
sampStat: Accession.SAMPSTAT,
storage: Accession.STORAGE,
accessions: {
true: 'Yes',
false: 'No',
},
......
import * as React from 'react';
import { Field } from 'redux-form';
import { translate } from 'react-i18next';
import FormGroup from '@material-ui/core/FormGroup';
import FormControlLabel from '@material-ui/core/FormControlLabel';
......@@ -19,6 +20,7 @@ interface IStringArrFilterInternal extends React.ClassAttributes<any> {
placeholder?: string;
label?: string;
options?: { [key: string]: any; };
t: any;
}
class InternalStringArrField extends React.Component<IStringArrFilterInternal & any, any> {
......@@ -32,9 +34,18 @@ class InternalStringArrField extends React.Component<IStringArrFilterInternal &
};
}
public componentWillMount() {
const value = typeof this.props.input.value[0] === 'number' ? this.props.input.value.map((key) => `${key}`) : this.props.input.value;
this.setState({
values: [ ...value ],
text: '',
});
}
public componentWillReceiveProps(nextProps) {
const value = typeof nextProps.input.value[0] === 'number' ? nextProps.input.value.map((key) => `${key}`) : nextProps.input.value;
this.setState({
values: [ ...nextProps.input.value ],
values: [ ...value ],
text: '',
});
}
......@@ -115,7 +126,7 @@ class InternalStringArrField extends React.Component<IStringArrFilterInternal &
}
public render() {
const { placeholder, label, options } = this.props;
const { placeholder, label, options, t } = this.props;
const { text, values } = this.state;
const withOptions: boolean = options !== undefined && typeof options === 'object';
......@@ -124,10 +135,10 @@ class InternalStringArrField extends React.Component<IStringArrFilterInternal &
<div>
{ withOptions ?
<FormControl fullWidth component="fieldset">
{ label && <FormLabel component="label">{ label }</FormLabel> }
{ label && <FormLabel component="label">{ t(`${label}`) }</FormLabel> }
<FormGroup>
{ Object.keys(options).map((key) => (
<FormControlLabel key={ `${key}` } label={ options[key] }
<FormControlLabel key={ `${key}` } label={ t(`${options[key]}`) }
control={
<Checkbox value={ key }
checked={ values.indexOf(key) >= 0 }
......@@ -138,12 +149,12 @@ class InternalStringArrField extends React.Component<IStringArrFilterInternal &
</FormControl>
:
<FormControl fullWidth className="full-width">
<InputLabel>{ label }</InputLabel>
<InputLabel>{ t(`${label}`) }</InputLabel>
<Input
className="full-width"
value={ text }
onChange={ this.handleChange }
placeholder={ placeholder || '' }
placeholder={ placeholder ? t(`${placeholder}`) : '' }
onKeyPress={ this.handleKeyPres }
onBlur={ this.handleAddCurrent }
endAdornment={
......@@ -173,6 +184,7 @@ interface IStringArrFilter extends React.ClassAttributes<any> {
placeholder?: string;
label?: string;
options?: { [key: string]: any; };
t: any;
}
class StringArrFilter extends React.Component<IStringArrFilter, any> {
......@@ -182,7 +194,7 @@ class StringArrFilter extends React.Component<IStringArrFilter, any> {
}
public render() {
const { name, label, placeholder, options } = this.props;
const { name, label, placeholder, options, t } = this.props;
return (
<div>
<Field
......@@ -191,10 +203,11 @@ class StringArrFilter extends React.Component<IStringArrFilter, any> {
label={ label }
placeholder={ placeholder }
options={ options }
t={ t }
/>
</div>
);
}
}
export default StringArrFilter;
export default translate()(StringArrFilter);
......@@ -15,7 +15,7 @@ export default function PrettyDate({
return (
<span className="prettydate">
{ diffDays < 4 ?
<TimeAgo>{ value }</TimeAgo>
<TimeAgo>{ valueTime }</TimeAgo>
:
moment(value).format('D MMMM YYYY')
}
......
......@@ -123,8 +123,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
<PropertiesItem title="Country of holding institute">{ accession.institute.country.name }</PropertiesItem>
<PropertiesItem title="Institute code">{ accession.institute.code }</PropertiesItem>
<PropertiesItem title="Acquisition date"><McpdDate value={ accession.acquisitionDate } /></PropertiesItem>
<PropertiesItem title="Biological status of accession">{ accession.sampStat }</PropertiesItem>
{ accession.sampStat && <PropertiesItem title="Biological status of accession">{ t(`accession.sampleStatus.${accession.sampStat}`) }</PropertiesItem> }
<PropertiesItem title="Availability for distribution">{ t(`accession.available.${accession.available}`) }</PropertiesItem>
{ accession.storage && accession.storage.length > 0 && <PropertiesItem title="Type of Germplasm storage">
......
......@@ -8,6 +8,7 @@ import CollapsibleComponentSearch from 'ui/common/filter/CollapsibleComponentSea
import NumberFilter from 'ui/common/filter/NumberFilter';
import StringFilter from 'ui/common/filter/StringFilter';
import StringArrFilter from 'ui/common/filter/StringArrFilter';
import Accession from 'model/Accession';
const AccessionFilters = ({handleSubmit, initialValues, initialize, ...other}) => {
// console.log('AccessionFilters', initialValues);
......@@ -29,6 +30,12 @@ const AccessionFilters = ({handleSubmit, initialValues, initialize, ...other}) =
<NumberFilter name="geo.longitude" label="Longitude" />
<NumberFilter name="geo.elevation" label="Elevation" />
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title="Biological status of accession">
<StringArrFilter name="sampStat" options={ Accession.SAMPSTAT } />
</CollapsibleComponentSearch>
<CollapsibleComponentSearch title="Type of germplasm storage">
<StringArrFilter name="storage" options={ Accession.STORAGE } />
</CollapsibleComponentSearch>
</FiltersBlock>
);
};
......
Markdown is supported
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