From 613f5f475bd68b8d44370d38d6546d29f501d98c Mon Sep 17 00:00:00 2001
From: esikkala <esko.ikkala@aalto.fi>
Date: Thu, 8 Nov 2018 05:05:02 -0800
Subject: [PATCH] Parametrize place fetching, show all tabs

---
 src/client/actions/index.js         |  3 ++-
 src/client/components/Deck.js       | 10 ++++++++--
 src/client/components/LeafletMap.js |  6 +++---
 src/client/components/NavTabs.js    |  8 ++++----
 src/client/containers/MapApp.js     |  8 ++++----
 src/client/epics/index.js           |  4 ++--
 src/client/reducers/options.js      |  2 +-
 src/server/index.js                 |  3 ++-
 src/server/sparql/Datasets.js       |  2 +-
 src/server/sparql/Manuscripts.js    | 10 ++++------
 10 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/src/client/actions/index.js b/src/client/actions/index.js
index 97ef8472..0258d1b9 100644
--- a/src/client/actions/index.js
+++ b/src/client/actions/index.js
@@ -134,8 +134,9 @@ export const fetchManuscriptsFailed = (error) => ({
 });
 
 // Places
-export const fetchPlaces = () => ({
+export const fetchPlaces = variant => ({
   type: FETCH_PLACES,
+  variant
 });
 export const updatePlaces = ({ places }) => ({
   type: UPDATE_PLACES,
diff --git a/src/client/components/Deck.js b/src/client/components/Deck.js
index b5a654fe..7973f696 100644
--- a/src/client/components/Deck.js
+++ b/src/client/components/Deck.js
@@ -1,6 +1,7 @@
 import React from 'react';
 import PropTypes from 'prop-types';
 import { withStyles } from '@material-ui/core/styles';
+import { has } from 'lodash';
 import DeckGL, { ArcLayer } from 'deck.gl';
 import ReactMapGL, { NavigationControl, HTMLOverlay } from 'react-map-gl';
 import 'mapbox-gl/dist/mapbox-gl.css';
@@ -78,7 +79,7 @@ class Deck extends React.Component {
   }
 
   componentDidMount() {
-    this.props.fetchPlaces();
+    this.props.fetchPlaces('migrations');
   }
 
   parseCoordinates = (coords) => {
@@ -172,9 +173,14 @@ class Deck extends React.Component {
 
  render() {
    // console.log(this.props.data)
+   let arcData = [];
+   if (has(this.props.data[0], 'to')) {
+     arcData = this.props.data;
+   }
+
    const layer = new ArcLayer({
      id: 'arc-layer',
-     data: this.props.data,
+     data: arcData,
      pickable: true,
      //getStrokeWidth: d => this.getStrokeWidth(d.manuscriptCount),
      getStrokeWidth: 1,
diff --git a/src/client/components/LeafletMap.js b/src/client/components/LeafletMap.js
index b3d59a21..a3d36267 100644
--- a/src/client/components/LeafletMap.js
+++ b/src/client/components/LeafletMap.js
@@ -47,7 +47,7 @@ class LeafletMap extends React.Component {
 
   componentDidMount() {
     //this.props.fetchManuscripts();
-    this.props.fetchPlaces();
+    this.props.fetchPlaces('creationPlaces');
 
     // Base layers
     const OSMBaseLayer = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
@@ -117,7 +117,7 @@ class LeafletMap extends React.Component {
 
     L.Marker.setBouncingOptions({ exclusive: true });
 
-    L.control.sidebar({ container: 'sidebar' }).addTo(this.leafletMap).open('home');
+    //L.control.sidebar({ container: 'sidebar' }).addTo(this.leafletMap).open('home');
 
   }
 
@@ -302,7 +302,7 @@ class LeafletMap extends React.Component {
   render() {
     return (
       <div className="leaflet-container">
-        <LeafletSidebar />
+        {/*<LeafletSidebar />*/}
         <div id="map" style={style} />
       </div>
     );
diff --git a/src/client/components/NavTabs.js b/src/client/components/NavTabs.js
index 52bde04c..7a0f0361 100644
--- a/src/client/components/NavTabs.js
+++ b/src/client/components/NavTabs.js
@@ -10,10 +10,10 @@ const NavTabs = (props) => {
   // <Tab value="migrationMap" label="migrations" />
   return (
     <Tabs value={props.resultFormat} onChange={handleChange}>
-      { /* <Tab value="table" label="Table" />
-      <Tab value="creationPlaceMap" label="creation places" /> */}
-      <Tab value="migrationMap" label="migrations" />
-      { /* <Tab value="statistics" label="Statistics" /> */}
+      <Tab value="table" label="Table" />
+      <Tab value="creationPlaces" label="creation places" />
+      <Tab value="migrations" label="migrations" />
+      <Tab value="statistics" label="Statistics" />
     </Tabs>
   );
 };
diff --git a/src/client/containers/MapApp.js b/src/client/containers/MapApp.js
index 1abda3df..42f97d66 100644
--- a/src/client/containers/MapApp.js
+++ b/src/client/containers/MapApp.js
@@ -188,7 +188,7 @@ let MapApp = (props) => {
   }
 
   let mapElement = '';
-  if ((oneColumnView && options.resultFormat === 'creationPlaceMap') || (!oneColumnView)) {
+  if ((oneColumnView && options.resultFormat === 'creationPlaces') || (!oneColumnView)) {
     mapElement = (
       <LeafletMap
         fetchPlaces={props.fetchPlaces}
@@ -207,7 +207,7 @@ let MapApp = (props) => {
       />
     );
   }
-  if ((oneColumnView && options.resultFormat === 'migrationMap') || (!oneColumnView)) {
+  if ((oneColumnView && options.resultFormat === 'migrations') || (!oneColumnView)) {
     mapElement = <Deck
       data={creationPlaces}
       fetchPlaces={props.fetchPlaces}
@@ -232,7 +232,7 @@ let MapApp = (props) => {
         mainResultsView = table;
         break;
       }
-      case 'creationPlaceMap': {
+      case 'creationPlaces': {
         mainResultsView = (
           <div className={classes.fullMap}>
             {mapElement}
@@ -240,7 +240,7 @@ let MapApp = (props) => {
         );
         break;
       }
-      case 'migrationMap': {
+      case 'migrations': {
         mainResultsView = (
           <div className={classes.fullMap}>
             {mapElement}
diff --git a/src/client/epics/index.js b/src/client/epics/index.js
index 461d646d..49da7684 100644
--- a/src/client/epics/index.js
+++ b/src/client/epics/index.js
@@ -38,9 +38,9 @@ const getManuscripts = action$ => action$.pipe(
 
 const getPlaces = action$ => action$.pipe(
   ofType(FETCH_PLACES),
-  mergeMap(() => {
+  mergeMap(action => {
     const searchUrl = apiUrl + 'places';
-    const requestUrl = `${searchUrl}`;
+    const requestUrl = `${searchUrl}?variant=${action.variant}`;
     return ajax.getJSON(requestUrl).pipe(
       map(response => updatePlaces({ places: response }))
     );
diff --git a/src/client/reducers/options.js b/src/client/reducers/options.js
index 8cf9a4be..21908ba9 100644
--- a/src/client/reducers/options.js
+++ b/src/client/reducers/options.js
@@ -5,7 +5,7 @@ import {
 } from '../actions';
 
 const DEFAULT_LANGUAGE = 'en';
-const DEFAULT_RESULT_FORMAT = 'migrationMap';
+const DEFAULT_RESULT_FORMAT = 'creationPlaces';
 const DEFAULT_MAP_MODE = 'cluster';
 
 export const INITIAL_STATE = {
diff --git a/src/server/index.js b/src/server/index.js
index 66ecbe6c..002ee368 100644
--- a/src/server/index.js
+++ b/src/server/index.js
@@ -71,7 +71,8 @@ app.get('/places/:placeId?', (req, res) => {
         return res.sendStatus(500);
       });
   } else {
-    return getPlaces().then((data) => {
+    const variant = req.query.variant ? req.query.variant : 'creationPlaces';
+    return getPlaces(variant).then((data) => {
       // console.log(data);
       res.json(data);
     })
diff --git a/src/server/sparql/Datasets.js b/src/server/sparql/Datasets.js
index 1fcce0c2..cd5e8bb3 100644
--- a/src/server/sparql/Datasets.js
+++ b/src/server/sparql/Datasets.js
@@ -188,7 +188,7 @@ module.exports = {
       }
       GROUP BY ?id ?manuscriptRecord
       `,
-    'placesQuery': `
+    'creationPlacesQuery': `
       PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
       PREFIX wgs84: <http://www.w3.org/2003/01/geo/wgs84_pos#>
       PREFIX dc: <http://purl.org/dc/elements/1.1/>
diff --git a/src/server/sparql/Manuscripts.js b/src/server/sparql/Manuscripts.js
index 124b4946..24e38a7b 100644
--- a/src/server/sparql/Manuscripts.js
+++ b/src/server/sparql/Manuscripts.js
@@ -25,12 +25,10 @@ export const getManuscriptCount = (filterObj) => {
   return sparqlSearchEngine.doSearch(countQuery, endpoint, mapCount);
 };
 
-export const getPlaces = () => {
-  const { endpoint, migrationsQuery } = datasetConfig['mmm'];
-  //const { endpoint, placesQuery } = datasetConfig['mmm'];
-  //console.log(migrationsQuery)
-  return sparqlSearchEngine.doSearch(migrationsQuery, endpoint, makeObjectList);
-  //return sparqlSearchEngine.doSearch(placesQuery, endpoint, makeObjectList);
+export const getPlaces = variant => {
+  console.log(variant)
+  const config = datasetConfig['mmm'];
+  return sparqlSearchEngine.doSearch(config[`${variant}Query`], config.endpoint, makeObjectList);
 };
 
 export const getPlace = (id) => {
-- 
GitLab