Giter Club home page Giter Club logo

wildaid / o-fish-web Goto Github PK

View Code? Open in Web Editor NEW
31.0 4.0 42.0 1.3 MB

Web application for the Officer's Fishery Information Sharing Hub (O-FISH). The web app allows agencies to gain insights from the aggregated information gathered during a routine vessel inspection (submitted via the web app).

License: Apache License 2.0

HTML 0.33% JavaScript 92.97% CSS 6.69% Shell 0.01%
react dataviz charts hacktoberfest hacktoberfest2020 non-profit nonprofit wildaid mongodb mongodb-database

o-fish-web's Introduction

WildAid O-FISH Web App

The WildAid Marine Program works to protect vulnerable marine environments.

O-FISH (Officer Fishery Information Sharing Hub) is a multi-platform application that enables officers to browse and record boarding report data from their mobile devices.

Developers are expected to follow the MongoDB Community Code of Conduct guidelines.

This repo implements the O-FISH web app.

The details behind the data architecture, schema, and partitioning strategy are described in Realm Data and Partitioning Strategy Behind the WildAid O-FISH Mobile Apps.

Details on installing all applications making up the solution can be found here.

Prerequisites

This is the Web app for O-FISH. To build and use the app, you must use the sandbox realm-app-id or build your own foundation.

Setting up MongoDB Charts is optional, but places where charts should be will show errors if you don't - other functionality will be unaffected.

Node.js must be installed.

Building and running the app:

  1. From the top-level directory (where this README file lives) run: npm install
  2. Copy src/config.js.tmpl to src/config.js
  3. Set your configuration data in src/config.js (leave the chartId values as they are if you haven't set up MongoDB Charts for the sample data - if you have then you can get the ids from the Charts UI):
module.exports = {
    appName: 'ofish-web',
    realmServiceName: "mongodb-atlas",
    realmAppId: 'wildaid-xxxxx',
    database: 'wildaid',
    chartsConfig: {
      baseUrl: "https://charts.mongodb.com/charts-wildaid-xxxxx",
      "boardings": {
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "boarding-compliance":{
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "patrol-hours":{
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "compliance-rate":{
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "boardings-count-chart":{
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      },
      "citations-and-warnings":{
        chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      }
    }
  }
  1. npm start (for local testing)
  2. npm run build (for deployment)

Code and architecture highlights:

This application uses React and is based on the React Services Architecture rather than Redux. If you are interested in why, read You Might Not Need Redux from Dan Abramov (co-author of Redux).

All services use as a singleton object. There is no dependency injection needed because there is no service inheritance.

Key code snippets:

Services

Found in /src/services. Here you will find all of the basic interaction with the MongoDB Realm service.

Connect MongoDB Realm - stitch.service.js:

  get client() {
    return this._localStitchClient;//For use the stitch client from another services
  }

  get database() {
    if (!this._database) {
      throw new Error("You are not logged in! Please, login first.");
    }
    return this._database;
  }

  constructor() {
    this._localStitchClient = Stitch.initializeDefaultAppClient(config.realmAppId);

    // The database object will be available only after authentication
    this._database = null;
  }

  // This method should be called from Login form with the Realm user credentials:
  authenticateStitch(login, pass) {
    return this._localStitchClient.auth
      .loginWithCredential(new UserPasswordCredential(login, pass))
      .then((user) => {
        this.reinitializeClient();
        return user;
      });
  }

  //After stitch authentication, you can connect to the database
  reinitializeClient() {
    this._database = this._localStitchClient
      .getServiceClient(RemoteMongoClient.factory, config.realmServiceName)
      .db(config.database);
  }

There are also examples of calling Realm functions:

getVesselsWithFacet(limit, offset, search, filter) {
    return this._localStitchClient.callFunction("searchFacetByVessels", [limit, offset, search, filter]);
  }

auth.service.js uses EventEmitter to fire an authorized event when authentication is complete:

this.emit("authorized", user);

Other components subscribe to that event, for example the user profile component uses it as a trigger to display user information.

Authentication

Authentication is invoked from /src/root/root.component.js through the renderRoutes method (/src/helpers/map-routing.js).

This method checks if the user is already authenticated and redirects the user to the login page if not:

const auth = authService.isStitchAuthenticated;
if (route.auth){
  if (!auth){
    return <Redirect to="/login" />;
  } else {
    if (!authService.isAuthenticated){
      return authService.reauthenticateUser().then(()=>{
        return <Redirect to={route.path} />
      });
    }
  }
}

if (route.redirectTo) return <Redirect to={route.redirectTo} />;

if (route.routes){
  return <route.component isLoggedIn={auth} {...props} routes={route.routes}/>;
} else {
  return <route.component isLoggedIn={auth} {...props} />;
}
};

MongoDB Charts

src/charts/chart-box.component.js is a React-ready component to embed MongoDB Charts:

export default function ChartBox({ options, className })

Example chart options:

const chartOptions = {
  width: "100%",
  height: "100%",
  refreshInterval: 1300, // in seconds.
  useAuthenticatedAccess: true,
  chartId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  filter: {exampleField: "someValue"}
};

Pages

The code for each page is in /src.

Common components are in /src/partials.

Testing

  • Quick examples of Jest and React-Testing-Library tests in src/test-examples/
  • Read TESTS.md for detailed how-tos, setup, and test structure

o-fish-web's People

Contributors

am-mongodb avatar antwonthegreat avatar ayushjainrksh avatar azzoo avatar brittanylau avatar cr96 avatar crowtech7 avatar deveshchatuphale7 avatar djdarkbeat avatar evayde avatar ismaeldcom avatar jessrichmond avatar jflip avatar joellord avatar joquendo avatar jsdmaria avatar k-azadzoi avatar lenmorld avatar mdegis avatar mfhan avatar mmhuseynov avatar o-fish-wildaid avatar pranshumaheshwari avatar rh9891 avatar ritikpandey1 avatar segh avatar sheeri avatar sourabhbagrecha avatar stennie avatar zsobral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

o-fish-web's Issues

User creation page design

The user creation page is great! However, there are a few design changes. See https://mongodb.invisionapp.com/share/MYXRXC2T2H3#/screens/422349126

First Name and Last Name are on the same line, everything else has its own line.
The role should be a drop down with at most 4 items as per https://mongodb.invisionapp.com/share/MYXRXC2T2H3#/screens/422349130_Global_Admin-Users-Create_New-Role-
Global Admin
Agency Admin
Group Admin
Field Officer

Only a Global Admin can make another Global Admin, so only a global admin sees all 4 choices.
An Agency Admin should see the 3 choices under Global Admin but not see Global Admin.

A group admin and a field officer cannot create users and should never see this page.

Search Results page clickable fields

On the search_results page after clicking 'See all results for 'search term' a user can only click on 'See all' for Records of Vessels or Captains & Crew or Boardings. Users should also be able to click on the vessel or person or boarding record shown on the page and go directly to that record - as if they had clicked through to the 'See all' page and then clicked that record. It will save 2 clicks and is what the users expect.

Typo in Boarding Records

On the 'boardings' screen (search results for bboarding records) - The 'Bordered by' column should be 'Boarded by'.

Web: App should create Realm user accounts

The user-creation page should create a Realm user as well as a document in the User collection (where the realmUserID attribute should be a string representing the Realm user account)

Search Results clickable

When you first search on the home page and get autocomplete results - the only thing you can click is 'See all results for 'search term''. A user should be able to click on the vessel or crew or boarding result if that's exactly the one they want; so they do not have to click on 'See all results for 'search term'' and then click 'See all' on the next page and THEN click on the same record they saw in the autocomplete.

Web: Incorrectly logging in on 1st attempt

When logging in through the web app the app makes a failed login attempt and then tries again with the correct credentials. Should log in just once with the correct credentials.

Map on Boardings page

The map on the boardings page shows points by specifying a list of _ids in the SDK for filtering. The filter should be by agency which is retrieved from the User collection (can be retrieved on login). This should be applied to all other maps and charts in the web app. Eventually users will be able to see data from more than their own agency - if they have sharing permissoins - so that filtering will be changed at that time. For now though - the map on the boardings page does not render when there are too many _id values being passed.

Web: MPA functionality

Have a hard-coded square overlaying some of the map area to represent a Marine Protected Area. Reports should be able to filter by MPA name.

Web: Use the bucket pattern rather than skipping - web

When iterating using skip to page through a collection it works but it inefficient when working through many pages. A better pattern is the bucket pattern: [https://www.mongodb.com/blog/post/paging-with-the-bucket-pattern--part-1]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.