Displaying differences for changeset
 
display as  

services.py

@@ -13,6 +13,7 @@
 import er2.common.state as er2_state
 from er2.apps.er2_map.services import MapState
 from er2.apps.er2_map.savefile import jsondump
+from er2.apps.er2_watershedpriority import datalayer as dl
 
 
 def get_cwd():
@@ -491,3 +492,21 @@
         return True
     except ValueError:
         return False
+
+
+class DataLayer(er2_api.ApiResource):
+    cache_dir = '/tmp/wplayers'
+
+    def __init__(self, request=None, version=get_version(), meta={}):
+        super(DataLayer, self).__init__(request, version, meta)
+        self.kind = "DataLayer"
+        self.result = {}
+
+    def get_cwcb_water_rights(self):
+        try:
+            extent = er2_api.load_json(self._request.body)['extent']
+            response = dl.CWCB_WaterRights().get_list(extent)
+            return er2_api.respond(response)
+        except Exception as e:
+            logging.getLogger('er2').error(e)
+            return er2_api.respond({'error': "Error in ISF reaches."})

static/er2_watershedpriority/js/actions/index.js

@@ -11,3 +11,4 @@
 export { onSetRegion, onGetSubRegions } from './aoi'
 export { clearErrorMessage, setErrorMessage } from './error'
 export { onChangeIndicatorCheckbox, onChangeIndicatorMinMax, onChangeIndicatorWeight, onChangeMCDAType, onRunModel } from './mcda'
+export { onGetCWCBRaterRights, onDisplayISFDetails } from './data_layer'

static/er2_watershedpriority/js/components/utils/constants.js

@@ -13,3 +13,17 @@
     huc10: 'HUC 10-digit Watersheds',
     huc12: 'HUC 12-digit Watersheds',
 }
+
+export const renderRow = (name, value) => (
+    <Grid item>
+        <Grid container direction={'row'} spacing={8}>
+            <Grid item>{name}</Grid>
+            <Grid item>{value}</Grid>
+        </Grid>
+    </Grid>
+)
+
+export const isValidString = (value) => {
+    if (value !== undefined && value !== null && value.toString().length > 0) return true
+    return false
+}
\ No newline at end of file

static/er2_watershedpriority/js/constants/action_types.js

@@ -27,4 +27,10 @@
 export const SET_MODEL_RUN_STATUS = 'SET_MODEL_RUN_STATUS'
 export const SET_MODEL_RUN_RESULTS = 'SET_MODEL_RUN_RESULTS'
 
+export const SET_DATA_LAYER = 'SET_DATA_LAYER'
+
+export const SET_CWCB_WR = 'SET_CWCB_WR'
+export const SET_FETCHING_CWCB_WR = 'SET_FETCHING_CWCB_WR'
+export const SET_CWCB_CURRENT = 'SET_CWCB_CURRENT'
+
 export const RESET_AOI = 'RESET_AOI'

static/er2_watershedpriority/js/constants/ids.js

@@ -9,3 +9,4 @@
 export const INSTRUCTIONS_INTRODUCTION = 'documentationIntroduction'
 export const SUBHEADER_DOCS = 'subheaderDocs'
 export const CONTEXT_BAR_MCDA = 'contextBarMcda'
+export const DATALAYER = 'dataLayer'

static/er2_watershedpriority/js/constants/routes.js

@@ -4,3 +4,4 @@
 export const INSTRUCTIONS_INTRODUCTION = '/docs/introduction'
 export const SPECIFY_INPUTS = '/aoi/'
 export const MCDA = '/mcda/'
+export const DATALAYER = '/dataLayer/'

static/er2_watershedpriority/js/containers/app.js

@@ -19,7 +19,7 @@
 import exportData from 'highcharts/modules/export-data'
 import { Breadcrumbs, ContextBar, Header, TokenNavLink } from 'catena/er2_ui'
 import { parseLocation } from 'er2_web_utils'
-import AttributeTable from 'catena/er2_map_userlayers/js/components/attribute_table/attribute_table'
+import AttributeTable from 'catena/er2_map_userlayers/js/components/attribute_table/attribute_table_stable'
 import TabbedPanel from 'catena/er2_map_userlayers/js/components/tabbed_panel'
 import UserLayersContainer from 'catena/er2_map_userlayers/js/containers/userlayers'
 import WindowState, { windowStates } from 'catena/er2_map_userlayers/js/components/window_state'
@@ -58,6 +58,9 @@
 import Impairments from '../components/watershed/Impairments'
 import type { ErrorType } from '../reducers/error'
 import MCDALegend from '../components/watershed/MCDALegend'
+import DataLayer from '../components/data_layer'
+import type { DataLayerType } from '../reducers/data_layer'
+import ISFStreamDetails from '../components/datalayer/ISFStreamDetails'
 
 addMore(ReactHighcharts.Highcharts)
 exporting(ReactHighcharts.Highcharts)
@@ -72,6 +75,7 @@
         onChangeMCDAType: Function,
         onChangeSelectedArea: Function,
         onChangeSelectedAreaName: Function,
+        onDisplayISFDetails: Function,
         onGetSubRegions: Function,
         onPostMakeDataSourcesSelection: Function,
         onRunModel: Function,
@@ -81,6 +85,7 @@
     aoi: AOIType,
     attributeTables: AttributeTablesType,
     contextBar: ContextBarType,
+    dataLayer: DataLayerType,
     error: ErrorType,
     geoBar: GeoBarType,
     history: HistoryType,
@@ -149,11 +154,9 @@
     const parsedLoc = parseLocation(location)
     const activeMapToolbarPanel = theprops.mapToolbar.items.find(item => item.active)
 
-    const isSpecifyInputsVisible = parsedLoc.path === routes.SPECIFY_INPUTS // && theprops.selectAreaBar.visible
-    const mapMoveLeft = !isSpecifyInputsVisible && parsedLoc.path !== routes.MCDA
-
     const showCatenaPanel = true
-    const tocVisible = (location.pathname === routes.SPECIFY_INPUTS) || (location.pathname === routes.MCDA)
+    const tocVisible = (location.pathname === routes.SPECIFY_INPUTS) || (location.pathname === routes.MCDA) || (location.pathname === routes.DATALAYER)
+    const mapMoveLeft = !tocVisible
 
     useEffect(() => {
         // Fetch the application state once, on initial load
@@ -268,6 +271,18 @@
                         theme={classes}
                     />)}
             />
+            <Route
+                path={routes.DATALAYER}
+                render={() => (
+                    <Breadcrumbs
+                        theme={classes}
+                        header={{
+                            id: ids.DATALAYER,
+                            name: 'Data Layers and Mapping',
+                        }}
+                        items={[]}
+                    />)}
+            />
         </React.Fragment>)
     }
 
@@ -436,7 +451,7 @@
 
     const renderCatenaMap = () => {
         const sub = s => s.substr(1, s.length - 2)
-        const mapPath = `/(${sub(routes.SPECIFY_INPUTS)}|${sub(routes.MCDA)})`
+        const mapPath = `/(${sub(routes.SPECIFY_INPUTS)}|${sub(routes.MCDA)}|${sub(routes.DATALAYER)})`
         return (
             <Route
                 path={mapPath}
@@ -543,6 +558,67 @@
         />
     )
 
+    const renderDataLayersCB = () => (
+        <Route
+            path={routes.DATALAYER}
+            render={() => (
+                <DataLayer
+                    dataLayer={theprops.dataLayer}
+                    actions={theprops.actions}
+                    aoi={theprops.aoi}
+                    map={theprops.map}
+                    catenaMap={catenaMap.current.mapApp}
+                    indicators={theprops.indicators}
+                    mcda={theprops.mcda}
+                    theme={classes}
+                />
+            )}
+        />
+    )
+
+    const renderDataLayerTP = () => {
+        const contents = []
+        if (this.props.dataLayer.whichLayer === 2) {
+            const streamGages = this.props.dataLayer.streamGages
+            if (streamGages.currentStation && streamGages.currentStation.uniqueId) {
+                contents.push(<StreamGageStation
+                    key="Stream Gage"
+                    theme={rootCss}
+                    dataLayer={this.props.dataLayer}
+                    {...this.props.actions}
+                />)
+            }
+        } else if (this.props.dataLayer.whichLayer === 3) {
+            if (this.props.dataLayer.waterRights.currentStructure !== undefined && this.props.dataLayer.waterRights.currentStructure !== null) {
+                contents.push(<HydroBaseStructure
+                    key="Water Rights"
+                    theme={rootCss}
+                    {...this.props.actions}
+                    dataLayer={this.props.dataLayer}
+                />)
+            }
+        } else if (this.props.dataLayer.whichLayer === 4) {
+            if (this.props.dataLayer.cwcbLayer.current !== undefined && this.props.dataLayer.cwcbLayer.current !== null) {
+                contents.push(<ISFStreamDetails
+                    key="ISF"
+                    theme={rootCss}
+                    {...this.props.actions}
+                    dataLayer={this.props.dataLayer}
+                />)
+            }
+        }
+        return contents
+    }
+
+    const isMapReady = () => {
+        if (catenaMap !== undefined && catenaMap !== null) {
+            if (catenaMap['mapApp'] !== undefined && catenaMap.mapApp !== null) {
+                return true
+            }
+        }
+        return false
+    }
+
     if (!theprops.token.value) {
         // Render loading page until the server state is available
         return (<div className={classes.root}>
@@ -558,6 +634,11 @@
     const analysisPanelContents = getAnalysisPanelContents()
     const theMuiTheme = muiTheme(colors, null, overrides, palette)
     const hasMap = parsedLoc.path !== routes.INSTRUCTIONS && parsedLoc.path !== routes.HOME
+
+    // TP stands for Tabbed Panel and CB stands for Context Bar
+    const dataLayerVisible = location.pathname === routes.DATALAYER && theprops.dataLayer.visible && isMapReady()
+    if (dataLayerVisible) analysisPanelContents = renderDataLayerTP()
+
     return (
         <MuiThemeProvider theme={theMuiTheme}>
             <div className={classes.root}>
@@ -574,6 +655,7 @@
                 )}
                 {catenaMap.current && renderAoiCB()}
                 {catenaMap.current && theprops.aoi.subRegion.features !== undefined && renderMcdaCB()}
+                {catenaMap.current && renderDataLayersCB()}
                 {renderPopupDisclaimer()}
             </div>
         </MuiThemeProvider>
@@ -590,6 +672,7 @@
     aoi: state.aoi,
     attributeTables: state.attributeTables,
     contextBar: state.contextBar,
+    dataLayer: state.dataLayer,
     error: state.error,
     geoBar: state.geoBar,
     logger: state.logger,

static/er2_watershedpriority/js/reducers/context_bar.js

@@ -55,6 +55,12 @@
         isEnabled: false,
         name: 'MCDA',
         link: routes.MCDA,
+    }, {
+        icon: { default: 'fas fa-layer-group' },
+        id: ids.DATALAYER,
+        isActive,
+        name: 'Data Layers and Mapping',
+        link: routes.DATALAYER,
     }],
 }
 

static/er2_watershedpriority/js/reducers/index.js

@@ -6,6 +6,7 @@
 import services from 'catena/er2_map_services/js/reducers/services'
 import aoi from './aoi'
 import contextBar from './context_bar'
+import dataLayer from './data_layer'
 import error from './error'
 import indicators from './indicators'
 import mapToolbar from './map_toolbar'
@@ -21,6 +22,7 @@
     aoi,
     attributeTables,
     contextBar,
+    dataLayer,
     error,
     geoBar,
     identify,

static/er2_watershedpriority/js/reducers/table_of_contents.js

@@ -4,7 +4,7 @@
 const initialState = {
     items: [{
         id: 'instrIntroduction',
-        link: routes.INSTR_INTRODUCTION,
+        link: routes.INSTRUCTIONS_INTRODUCTION,
         name: 'Introduction',
     }],
 }

static/er2_watershedpriority/js/styles/wptCommon.js

@@ -14,6 +14,11 @@
 export const commonFontStyle = {
 }
 
+export const inputFontStyle = {
+    ...commonFontStyle,
+    fontSize: '14px',
+}
+
 export const resultsTabContainerStyle = {
     ...commonFontStyle,
     margin: '20px',

urls.py

@@ -14,4 +14,6 @@
     django.conf.urls.url(r'api/v1/state/$', views.state),
     django.conf.urls.url(r'api/v1/subRegion/$', views.sub_regions),
     django.conf.urls.url(r'api/v1/run/$', views.run_model),
+
+    django.conf.urls.url(r'api/v1/dl/cwcbdatalayer/$', views.dl_cwcb_water_rights),
 ]

views.py

@@ -24,4 +24,8 @@
 @csrf_exempt
 def run_model(request):
     """Returns the state of an application."""
-    return svcs.RunModel(request=request).process()
\ No newline at end of file
+    return svcs.RunModel(request=request).process()
+
+@csrf_exempt
+def dl_cwcb_water_rights(request):
+    return svcs.DataLayer(request=request).get_cwcb_water_rights()
\ No newline at end of file