Skip to content

Commit 18d703b

Browse files
committed
Merge branch 'main' into 912_mediaasset_in_opensearch
2 parents a494175 + c58ab39 commit 18d703b

File tree

3 files changed

+110
-66
lines changed

3 files changed

+110
-66
lines changed

frontend/src/pages/ReportsAndManagamentPages/SpeciesSection.jsx

Lines changed: 62 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,72 @@ import { FormattedMessage } from "react-intl";
44
import useGetSiteSettings from "../../models/useGetSiteSettings";
55
import { observer } from "mobx-react-lite";
66

7-
export const ReportEncounterSpeciesSection = observer(
8-
({ store }) => {
9-
const { data } = useGetSiteSettings();
10-
let speciesList =
11-
data?.siteTaxonomies?.map((item) => {
12-
return {
13-
value: item?.scientificName,
14-
label: item?.scientificName,
15-
};
16-
}) || [];
17-
speciesList = [...speciesList, { value: "unknown", label: "Unknown" }];
7+
export const ReportEncounterSpeciesSection = observer(({ store }) => {
8+
const { data } = useGetSiteSettings();
9+
let speciesList =
10+
data?.siteTaxonomies?.map((item) => {
11+
return {
12+
value: item?.scientificName,
13+
label: item?.scientificName + " (" + item?.commonName + ")",
14+
};
15+
}) || [];
16+
speciesList = [...speciesList, { value: "unknown", label: "Unknown" }];
1817

19-
return (
20-
<div>
21-
<h5>
18+
return (
19+
<div>
20+
<h5>
21+
<FormattedMessage id="SPECIES" />
22+
{store.speciesSection.required && <span>*</span>}
23+
</h5>
24+
<p className="fs-6">
25+
<FormattedMessage id="SPECIES_REQUIRED_IA_WARNING" />
26+
</p>
27+
28+
<Form.Group>
29+
<Form.Label>
2230
<FormattedMessage id="SPECIES" />
2331
{store.speciesSection.required && <span>*</span>}
24-
</h5>
25-
<p className="fs-6">
26-
<FormattedMessage id="SPECIES_REQUIRED_IA_WARNING" />
27-
</p>
28-
29-
<Form.Group>
30-
<Form.Label>
31-
<FormattedMessage id="SPECIES" />
32-
{store.speciesSection.required && <span>*</span>}
33-
</Form.Label>
34-
<div className="position-relative d-inline-block w-100">
35-
<Form.Control
36-
as="select"
37-
required="true"
38-
style={{ paddingRight: "30px" }}
39-
value={store.speciesSection.value}
40-
onChange={(e) => {
41-
store.setSpeciesSectionValue(e.target.value);
42-
}}
43-
>
44-
<option value="">
45-
<FormattedMessage id="SPECIES_INSTRUCTION" />
32+
</Form.Label>
33+
<div className="position-relative d-inline-block w-100">
34+
<Form.Control
35+
as="select"
36+
required="true"
37+
style={{ paddingRight: "30px" }}
38+
value={store.speciesSection.value}
39+
onChange={(e) => {
40+
store.setSpeciesSectionValue(e.target.value);
41+
}}
42+
>
43+
<option value="">
44+
<FormattedMessage id="SPECIES_INSTRUCTION" />
45+
</option>
46+
{speciesList.map((option, optionIndex) => (
47+
<option key={optionIndex} value={option.value}>
48+
{option.label}
4649
</option>
47-
{speciesList.map((option, optionIndex) => (
48-
<option key={optionIndex} value={option.value}>
49-
{option.label}
50-
</option>
51-
))}
52-
</Form.Control>
50+
))}
51+
</Form.Control>
5352

53+
<i
54+
className="bi bi-chevron-down position-absolute top-50 translate-middle-y text-secondary"
55+
style={{ right: "10px", pointerEvents: "none" }}
56+
></i>
57+
</div>
58+
{store.speciesSection.error && (
59+
<Alert
60+
variant="danger"
61+
style={{
62+
marginTop: "10px",
63+
}}
64+
>
5465
<i
55-
className="bi bi-chevron-down position-absolute top-50 translate-middle-y text-secondary"
56-
style={{ right: "10px", pointerEvents: "none" }}
66+
className="bi bi-info-circle-fill"
67+
style={{ marginRight: "8px", color: "#560f14" }}
5768
></i>
58-
</div>
59-
{store.speciesSection.error && (
60-
<Alert
61-
variant="danger"
62-
style={{
63-
marginTop: "10px",
64-
}}
65-
>
66-
<i
67-
className="bi bi-info-circle-fill"
68-
style={{ marginRight: "8px", color: "#560f14" }}
69-
></i>
70-
<FormattedMessage id="EMPTY_REQUIRED_WARNING" />
71-
</Alert>
72-
)}
73-
</Form.Group>
74-
</div>
75-
);
76-
},
77-
);
69+
<FormattedMessage id="EMPTY_REQUIRED_WARNING" />
70+
</Alert>
71+
)}
72+
</Form.Group>
73+
</div>
74+
);
75+
});

src/main/java/org/ecocean/Shepherd.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,44 @@ public int getNumTaxonomies() {
20022002
return (Util.count(taxis));
20032003
}
20042004

2005+
public List<List<String>> getAllTaxonomyCommonNames() {return getAllTaxonomyCommonNames(false);
2006+
}
2007+
2008+
// forceSpaces will turn `Foo bar_bar` into `Foo bar bar` - use with caution!
2009+
public List<List<String>> getAllTaxonomyCommonNames(boolean forceSpaces) {
2010+
Set<String> allSciNames = new LinkedHashSet<String>();
2011+
Set<String> allComNames = new LinkedHashSet<String>();
2012+
2013+
List<String> configNamesSci = CommonConfiguration.getIndexedPropertyValues("genusSpecies",
2014+
getContext());
2015+
List<String> configNamesCom = CommonConfiguration.getIndexedPropertyValues("commonName",
2016+
getContext());
2017+
allSciNames.addAll(configNamesSci);
2018+
allComNames.addAll(configNamesCom);
2019+
2020+
List<String> allSciNamesList = new ArrayList<String>(allSciNames);
2021+
List<String> allComNamesList = new ArrayList<String>(allComNames);
2022+
2023+
List<List<String>> result = new ArrayList<>();
2024+
2025+
if (forceSpaces) {
2026+
List<String> spaceySci = new ArrayList<String>();
2027+
for (String tx : allSciNamesList) {
2028+
spaceySci.add(tx.replaceAll("_", " "));
2029+
}
2030+
List<String> spaceyCom = new ArrayList<String>();
2031+
for (String tx : allComNamesList) {
2032+
spaceyCom.add(tx.replaceAll("_", " "));
2033+
}
2034+
result.add(spaceySci);
2035+
result.add(spaceyCom);
2036+
} else {
2037+
result.add(allSciNamesList);
2038+
result.add(allComNamesList);
2039+
}
2040+
return result;
2041+
}
2042+
20052043
// tragically this mixes Taxonomy (class, via db) with commonConfiguration-based values. SIGH
20062044
// TODO when property files go away (yay) this should become just db
20072045
public List<String> getAllTaxonomyNames() {

src/main/java/org/ecocean/api/SiteSettings.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,17 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
5858
settings.put("googleMapsKey", CommonConfiguration.getGoogleMapsKey(context));
5959

6060
JSONArray txArr = new JSONArray();
61-
for (String sciName : myShepherd.getAllTaxonomyNames()) {
61+
List<List<String>> nameArray = myShepherd.getAllTaxonomyCommonNames();
62+
int nameArrayLen = nameArray.get(0).size();
63+
for (int i = 0; i < nameArrayLen; i++) {
6264
JSONObject txj = new JSONObject();
63-
txj.put("scientificName", sciName.replaceAll("_", " "));
65+
txj.put("scientificName", nameArray.get(0).get(i));
66+
if (i < nameArray.get(1).size()) {
67+
txj.put("commonName", nameArray.get(1).get(i));
68+
}
69+
else {
70+
txj.put("commonName", "");
71+
}
6472
txArr.put(txj);
6573
}
6674
settings.put("siteTaxonomies", txArr);

0 commit comments

Comments
 (0)