Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
smcalilly committed Feb 25, 2022
1 parent 895dbca commit bf5193f
Show file tree
Hide file tree
Showing 6 changed files with 434 additions and 49 deletions.
74 changes: 70 additions & 4 deletions asset_dashboard/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.contrib.auth.models import User
from rest_framework import serializers
from rest_framework_gis.serializers import GeoFeatureModelSerializer, \
GeometrySerializerMethodField, GeometryField

from asset_dashboard.models import Phase, Portfolio, PortfolioPhase, Project, \
User, LocalAsset, Buildings, TrailsInfo
LocalAsset, Buildings, TrailsInfo, PoiInfo, PointsOfInterest, PicnicGroves, \
ParkingLots


class UserSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -105,6 +107,17 @@ def to_representation(self, value):
return super().to_representation(value)


class NullableCharField(serializers.CharField):
def __init__(self, *args, allow_null=False, **kwargs):
super().__init__(*args, **kwargs)
self.allow_null = allow_null

def to_representation(self, value):
if self.allow_null and value is None:
return None
return super().to_representation(value)


class BaseLocalAssetSerializer(GeoFeatureModelSerializer):
"""
A base serializer for the LocalAssets because we need
Expand All @@ -117,7 +130,7 @@ class Meta:
fields = ('id', 'geom', 'asset_id', 'asset_type', 'asset_name', 'phase')
geo_field = 'geom'

asset_id = serializers.IntegerField()
asset_id = NullableCharField(allow_null=True)
asset_type = serializers.CharField(source='asset_model')
asset_name = serializers.CharField()
phase = serializers.PrimaryKeyRelatedField(queryset=Phase.objects.all())
Expand All @@ -137,9 +150,9 @@ class LocalAssetReadSerializer(BaseLocalAssetSerializer):
class SourceAssetSerializer(GeoFeatureModelSerializer):
class Meta:
fields = ('source')

source = serializers.SerializerMethodField()

def get_source(self, obj):
return 'search'

Expand Down Expand Up @@ -173,3 +186,56 @@ def get_geom(self, obj):
in viewset -> get_queryset
'''
return obj.trails.geom.transform(4326, clone=True)

class PointsOfInterestSerializer(SourceAssetSerializer):
class Meta:
model = PoiInfo
fields = ('identifier', 'name', 'geom', 'source')
geo_field = 'geom'

identifier = serializers.IntegerField(source='fpd_uid')
name = serializers.SerializerMethodField(source='nameid')
geom = GeometrySerializerMethodField()

def get_geom(self, obj):
return PointsOfInterest.objects.get(
id=obj.pointsofinterest_id
).geom.transform(4326, clone=True)

def get_name(self, obj):
return obj.nameid.name

class PicnicGrovesSerializer(SourceAssetSerializer):
class Meta:
model = PicnicGroves
fields = ('identifier', 'name', 'geom', 'source')
geo_field = 'geom'

identifier = serializers.CharField(source='fpd_uid')
name = serializers.SerializerMethodField(source='poi_info__nameid')
geom = GeometrySerializerMethodField()

def get_geom(self, obj):
return obj.geom.transform(4326, clone=True)

def get_name(self, obj):
return obj.poi_info.nameid.name

class ParkingLotsSerializer(SourceAssetSerializer):
class Meta:
model = PoiInfo # Need to use PoiInfo.name and PoiInfo.fpd_uid to lookup ParkingLots
fields = ('identifier', 'name', 'geom', 'source')
geo_field = 'geom'

identifier = serializers.SerializerMethodField()
name = serializers.SerializerMethodField()
geom = GeometrySerializerMethodField()

def get_geom(self, obj):
return ParkingLots.objects.get(id=obj.parking_info.lot_id).geom.transform(4326, clone=True)

def get_name(self, obj):
return obj.nameid.name

def get_identifier(self, obj):
return obj.fpd_uid
1 change: 0 additions & 1 deletion asset_dashboard/static/js/PortfolioPlanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import PortfolioTable from './components/PortfolioTable'
import PortfolioTotals from './components/PortfolioTotals'
import PortfolioPicker from './components/PortfolioPicker'
import SearchInput from './components/SearchInput'
import { CSVLink } from 'react-csv'

class PortfolioPlanner extends React.Component {
constructor(props) {
Expand Down
12 changes: 10 additions & 2 deletions asset_dashboard/static/js/components/PortfolioTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactTable from './BaseTable'
import Button from 'react-bootstrap/Button'
import Form from 'react-bootstrap/Form'
import InputGroup from 'react-bootstrap/InputGroup'
import columns from './table-utils/projectColumns'
import projectColumns from './table_utils/projectColumns'

const PortfolioTable = ({ portfolio, onRemoveFromPortfolio, savePortfolioName, savePortfolio, createNewPortfolio }) => {
const [edit, setEdit] = useState(portfolio.name ? false : true)
Expand All @@ -28,6 +28,14 @@ const PortfolioTable = ({ portfolio, onRemoveFromPortfolio, savePortfolioName, s
).catch(err => console.error(err))
}

const selector = () => {
return (
<span>
<i className="fa fa-minus-square bg-"></i>
</span>
)
}

return (
<div className="mb-5 mt-5">
{!edit &&
Expand Down Expand Up @@ -98,7 +106,7 @@ const PortfolioTable = ({ portfolio, onRemoveFromPortfolio, savePortfolioName, s
</Form>
}
<ReactTable
columns={React.useMemo(() => columns, [])}
columns={React.useMemo(() => projectColumns(selector), [])}
rows={portfolio.projects}
getTrProps={onRowClick}
rowClassNames='table-info'
Expand Down
10 changes: 9 additions & 1 deletion asset_dashboard/static/js/components/ProjectsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const ProjectsTable = ({ allProjects, onAddToPortfolio, searchInput }) => {
}
}

const selector = () => {
return (
<span>
<i className="fas fa-plus-square"></i>
</span>
)
}

return (
<>
<div className="d-flex justify-content-between px-2">
Expand All @@ -20,7 +28,7 @@ const ProjectsTable = ({ allProjects, onAddToPortfolio, searchInput }) => {

<ReactTable
rows={allProjects}
columns={React.useMemo(() => projectColumns, [])}
columns={React.useMemo(() => projectColumns(selector), [])}
getTrProps={onRowClick}
/>
</>
Expand Down
17 changes: 6 additions & 11 deletions asset_dashboard/static/js/components/table_utils/projectColumns.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import React from 'react'

const selector = () => {
return (
<span>
<i className="fa fa-minus-square bg-"></i>
</span>
)
}

const projectColumns = [
const projectColumns = (selector) => {
return [
{
Header: () => null,
id: 'selector',
Expand Down Expand Up @@ -39,10 +32,12 @@ const projectColumns = [
Header: () => null,
accessor: 'key',
disableSortBy: true,
Cell: props => <a href={`/projects/${props.value}`}
Cell: props => <a href={`/projects/phases/edit/${props.value}/`}
onClick={e => e.stopPropagation()}
className='btn btn-success btn-sm'>View Project</a>
className='btn btn-outline-dark btn-sm'
target="_blank">View Phase</a>
}
]
}

export default projectColumns
Loading

0 comments on commit bf5193f

Please sign in to comment.