Skip to content

Commit

Permalink
Merge pull request #3 from posm/feature/filter-apps-by-access
Browse files Browse the repository at this point in the history
Feature/filter apps by access
  • Loading branch information
tnagorra authored Jul 22, 2020
2 parents 36634b3 + b91b94b commit 5439d16
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 188 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
# POSM Admin UI

This is the [POSM](http://posm.io) admin user interface. It's intended for use with [posm-admin](https://github.com/posm/posm-admin).
This is the [POSM](http://posm.io) admin user interface.
It's intended for use with [posm-admin](https://github.com/posm/posm-admin) and [posm-auth](https://github.com/posm/posm-auth).

This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).

## Development
## Getting Started

### Setting up configuration

```bash
# Create an environment file
touch .env
```

The environment file should define these variables:

```sh
REACT_APP_POSM_AUTH_END_POINT=http://localhost:8050
```

### Running locally

```bash
yarn
yarn install
yarn start
```
```

You will also need to run [posm-auth](https://github.com/posm/posm-auth).

# Building

```bash
yarn build
```
32 changes: 26 additions & 6 deletions public/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,41 @@
"refreshInterval": 10000,
"apps": [
{
"key": "omk",
"name": "OpenMapKit",
"icon": "mobile-phone",
"url": "//posm.io/omk/"
"url": "//posm.io/omk/",
"visibleInHomePanel": true
},
{
"key": "fp",
"name": "Field Papers",
"icon": "clipboard",
"url": "//posm.io/fp/"
"url": "//posm.io/fp/",
"visibleInHomePanel": true
},
{
"key": "odkc",
"name": "ODK Central",
"icon": "mobile-phone",
"url": "//odk-central.posm.io/",
"visibleInHomePanel": true
},
{
"key": "replay",
"name": "Replay Tool",
"icon": "automatic-updates",
"url": "//replay-tool.posm.io/"
},
{
"key": "osm",
"name": "OpenStreetMap",
"icon": "send-to-map",
"url": "//osm.posm.io/"
"url": "//osm.posm.io/",
"visibleInHomePanel": true
},
{
"key": "odmgcp",
"name": "ODM GCPs",
"icon": "layout-skew-grid",
"url": "//posm.io/posm-gcpi/",
Expand All @@ -33,10 +53,10 @@
"url": "//posm.io/guide/"
},
{
"name": "About OMK",
"name": "POSM Docs",
"icon": "book",
"url": "//posm.io/openmapkit-website/",
"description": "About OpenMapKit"
"url": "//docs.posm.io",
"description": "POSM Documentation"
},
{
"name": "OSM Features",
Expand Down
11 changes: 8 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { connect } from "react-redux";
import { Route } from "react-router-dom";
import { Socket } from "react-socket-io";

import { initializeState, loadPOSMState } from "./actions";
import { initializeState, loadPOSMState, loadUserDetails } from "./actions";
import AdminPanel from "./components/AdminPanel";
import AOIPanel from "./components/AOIPanel";
import DeploymentPanel from "./components/DeploymentPanel";
Expand All @@ -29,9 +29,10 @@ const SOCKET_OPTIONS = {

class App extends Component {
componentWillMount() {
const { initializeState } = this.props;
const { initializeState, loadUserDetails } = this.props;

initializeState();
loadUserDetails();
}

componentWillUpdate(nextProps, nextState) {
Expand Down Expand Up @@ -89,5 +90,9 @@ const mapStateToProps = state => ({

export default connect(
mapStateToProps,
{ initializeState, loadPOSMState }
{
initializeState,
loadPOSMState,
loadUserDetails
}
)(App);
21 changes: 20 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@ import {
getPOSMEndpoint
} from "../selectors";

export const posmAdminEndpoint =
process.env.REACT_APP_POSM_AUTH_END_POINT || "http://localhost:8050";

const types = {
FETCHING_ODM_PROJECTS: "FETCHING_ODM_PROJECTS",
RECEIVE_CONFIG: "RECEIVE_CONFIG",
RECEIVE_IMAGERY_STATUS: "RECEIVE_IMAGERY_STATUS",
RECEIVE_ODM_PROJECTS: "RECEIVE_ODM_PROJECTS",
RECEIVE_ODM_STATUS: "RECEIVE_ODM_STATUS",
RECEIVE_POSM_STATE: "RECEIVE_POSM_STATE"
RECEIVE_POSM_STATE: "RECEIVE_POSM_STATE",
RECEIVE_USER_DETAILS: "RECEIVE_USER_DETAILS"
};

export default types;

export const loadUserDetails = () => async (dispatch, getState) => {
try {
const rsp = await fetch(`${posmAdminEndpoint}/users/me/`, {
credentials: "include"
});

dispatch({
type: types.RECEIVE_USER_DETAILS,
remoteState: await rsp.json()
});
} catch (err) {
console.warn(err);
}
};

export const loadPOSMState = () => async (dispatch, getState) => {
try {
const rsp = await fetch(
Expand Down
16 changes: 0 additions & 16 deletions src/components/Card.js

This file was deleted.

133 changes: 81 additions & 52 deletions src/components/HomePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,106 @@ import React from "react";
import { Col, Grid, Image, PageHeader, Row } from "react-bootstrap";
import { connect } from "react-redux";

import Card from "./Card";
import FilesPanel from "./FilesPanel";
import { getPOSMEndpoint, getApps } from "../selectors";
import { getPOSMEndpoint, getApps, getAllowedApps } from "../selectors";

import omkLogo from "../images/omk.png";
import odkLogo from "../images/odk.png";
import fpLogo from "../images/fp.png";
import osmLogo from "../images/osm.png";
import posmLogo from "../images/[email protected]";

const styles = {
card: {},
row: {
display: "flex",
justifyContent: "space-between"
},
imageContainer: {
display: "flex",
flexGrow: 1,
alignItems: "center"
},
heading: {
flexShrink: 0
},
link: {
display: "flex",
flexDirection: "column",
alignItems: "center",
padding: "8px",
flexGrow: 1
},
image: {
margin: "auto"
margin: "auto",
maxWidth: "160px"
},
cardContainer: {
display: "flex",
flexDirection: "column",
width: "auto",
margin: "8px",
padding: "0 32px"
}
};

const HomePanel = ({ apps, osm, posm }) => (
<div>
<div className="posm-panel apps">
<PageHeader>Apps</PageHeader>
<Grid fluid>
<Row>
{apps.map(x => x.name).includes("OpenMapKit") && (
<Col md={4}>
<a
href={`${posm}/omk/`}
target="_blank"
rel="noopener noreferrer"
>
<Card style={styles.card}>
<H3>OpenMapKitServer</H3>
<Image src={omkLogo} style={styles.image} responsive />
</Card>
</a>
</Col>
)}
{apps.map(x => x.name).includes("Field Papers") && (
<Col md={4}>
<a href={`${posm}/fp/`} target="_blank" rel="noopener noreferrer">
<Card style={styles.card}>
<H3>Field Papers</H3>
<Image src={fpLogo} style={styles.image} responsive />
</Card>
</a>
</Col>
)}
{apps.map(x => x.name).includes("OpenStreetMap") && (
<Col md={4}>
<a
href={`http://${osm.fqdn}/`}
target="_blank"
rel="noopener noreferrer"
const logos = {
omk: omkLogo,
fp: fpLogo,
odkc: odkLogo,
osm: osmLogo,

replay: posmLogo,
odmgcp: posmLogo
};

const HomePanel = ({ apps, osm, posm, allowedApps }) => {
const filteredApps = apps.filter(
app => allowedApps.includes(app.key) && app.visibleInHomePanel
);

return (
<div>
<div className="posm-panel apps">
<PageHeader>Apps</PageHeader>
<Grid fluid>
<Row style={styles.row}>
{filteredApps.map(app => (
<Col
className="bp3-cart bp3-elevation-2"
md={4}
style={styles.cardContainer}
>
<Card style={styles.card}>
<H3>OpenStreetMap</H3>
<Image src={osmLogo} style={styles.image} responsive />
</Card>
</a>
</Col>
)}
</Row>
</Grid>
<a
style={styles.link}
href={app.url}
target="_blank"
rel="noopener noreferrer"
>
<H3 style={styles.heading}>{app.name}</H3>
<div style={styles.imageContainer}>
<Image
src={logos[app.key]}
style={styles.image}
responsive
/>
</div>
</a>
</Col>
))}
</Row>
</Grid>
</div>
<FilesPanel />
</div>
<FilesPanel />
</div>
);
);
};

HomePanel.propTypes = {};

const mapStateToProps = state => ({
apps: getApps(state),
osm: state.osm,
allowedApps: getAllowedApps(state),
posm: getPOSMEndpoint(state)
});

Expand Down
Loading

0 comments on commit 5439d16

Please sign in to comment.