Skip to content

Commit cb6ac4b

Browse files
Merge pull request #102 from geoCML/server-recommendations
Show recommendations from DRGON on geoCML Server Portal
2 parents 1c09c19 + 94fb586 commit cb6ac4b

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

build-resources/geocml-server/portal/src/App.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useDispatch } from "react-redux";
55
import { collectInfoFromWMS } from "./utils/wms.util";
66
import { HostedLayers } from "./components/HostedLayers";
77
import { reportInvalidWMS, showWebMap } from "./app-slice";
8+
import { Recommendations } from "./components/Recommendations";
89

910
export default function App() {
1011
const dispatch = useDispatch();
@@ -145,7 +146,8 @@ export default function App() {
145146
</p>
146147
</div>
147148
</div>
148-
</div>
149+
<Recommendations/>
150+
</div>
149151
);
150152
} catch (err) {
151153
console.log(err);

build-resources/geocml-server/portal/src/app-slice.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const appSlice = createSlice({
88
wmsInfoValid: true,
99
webMapVisible: false,
1010
layers: [],
11+
recommendations: []
1112
},
1213

1314
reducers: {
@@ -43,6 +44,10 @@ export const appSlice = createSlice({
4344
state.layers = action.payload;
4445
},
4546

47+
setRecommendations: (state, action) => {
48+
state.recommendations = action.payload
49+
},
50+
4651
toggleLayer: (state, action) => {
4752
for (const layer of state.layers) {
4853
if (layer.name === action.payload) layer.visible = !layer.visible;
@@ -58,6 +63,7 @@ export const {
5863
reportInvalidWMS,
5964
reportValidWMS,
6065
setLayers,
66+
setRecommendations,
6167
showWebMap,
6268
hideWebMap,
6369
toggleLayer,
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import axios from "axios";
2+
import { setRecommendations } from "../app-slice";
3+
import { useEffect } from "react";
4+
import { useDispatch, useSelector } from "react-redux";
5+
6+
export function collectRecommendations(dispatch, wmsInfo) {
7+
const tags = []
8+
for (const [_, value] of Object.entries(wmsInfo.WMS_Capabilities.Service.KeywordList)) {
9+
for (let i = 1; i < value.length; i++) {
10+
tags.push(value[i])
11+
}
12+
}
13+
14+
axios.get(`http://drgon.geocml.com:8000/recommendations`, { // TODO: https://github.com/geoCML/geocml-base-deployment/issues/76
15+
params: {
16+
"tags": tags.join(","),
17+
"limit": 10
18+
}
19+
}).then((res) => {
20+
dispatch(setRecommendations(res.data.deployments))
21+
})
22+
}
23+
24+
export function Recommendations() {
25+
const dispatch = useDispatch()
26+
const wmsInfo = useSelector((state) => state.app.wmsInfo)
27+
const recommendations = useSelector((state) => state.app.recommendations)
28+
29+
useEffect(() => {
30+
collectRecommendations(dispatch, wmsInfo)
31+
}, [])
32+
33+
return (
34+
<div>
35+
<h3 className="row justify-content-center pt-5">Explore Similar Datasets</h3>
36+
<i className="row justify-content-center pb-2">Results powered by DRGON</i>
37+
<table id="drgon-recommendations" className="table table-responsive" style={{ width: "100%" }}>
38+
<thead>
39+
<tr>
40+
<th>Title</th>
41+
<th>Description</th>
42+
<th>Owner</th>
43+
<th>URL</th>
44+
<th>Tags</th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
{recommendations.map((recommendation, i) => {
49+
return (
50+
<tr>
51+
<td>
52+
{recommendation[i].title}
53+
</td>
54+
<td>
55+
{recommendation[i].description}
56+
</td>
57+
<td>
58+
{recommendation[i].owner}
59+
</td>
60+
<td>
61+
<a href={recommendation[i].url}>{recommendation[i].url}</a>
62+
</td>
63+
<td>{recommendation[i].tags.split(",").map((tag) => {
64+
return (
65+
<span className="rounded bg-info p-2 mx-2">{tag}</span>
66+
)
67+
})}</td>
68+
</tr>
69+
)
70+
})}
71+
</tbody>
72+
</table>
73+
</div>
74+
)
75+
}
76+

0 commit comments

Comments
 (0)