diff --git a/app/src/frontend/building/data-components/planning-data-entry.tsx b/app/src/frontend/building/data-components/planning-data-entry.tsx index 73982936..75963cb7 100644 --- a/app/src/frontend/building/data-components/planning-data-entry.tsx +++ b/app/src/frontend/building/data-components/planning-data-entry.tsx @@ -4,7 +4,7 @@ import InfoBox from '../../components/info-box'; import CheckboxDataEntry from '../data-components/checkbox-data-entry'; interface PlanningDataOfficialDataEntryProps { - value: { + shownData: { uprn: string; building_id: number; description?: string; @@ -15,6 +15,7 @@ interface PlanningDataOfficialDataEntryProps { data_source: string; data_source_link?: string; }[]; + allEntryCount: number, } const {useState} = React; @@ -60,8 +61,9 @@ const LinkIfAvailable = (link) => { } const PlanningDataOfficialDataEntry: React.FC = (props) => { - const data = props.value || []; + const data = props.shownData || []; if(data.length == 0) { + if (props.allEntryCount == 0) { return ( No live planning data available currently for this building polygon via the Planning London DataHub. @@ -69,8 +71,17 @@ const PlanningDataOfficialDataEntry: React.FC ); + } else { + return ( + + No live planning data for this date range, but this building has associated planning data now shown here. +
+ +
+
); } - return <>{data.map((item) => ( + } + return <>{data.map((item) => ( diff --git a/app/src/frontend/building/data-containers/planning.tsx b/app/src/frontend/building/data-containers/planning.tsx index 064a30b4..a55f3b64 100644 --- a/app/src/frontend/building/data-containers/planning.tsx +++ b/app/src/frontend/building/data-containers/planning.tsx @@ -20,6 +20,32 @@ import { CategoryViewProps } from './category-view-props'; import { Category } from '../../config/categories-config'; const currentYear = new Date().getFullYear(); +const currentTimestamp = new Date().valueOf(); +const milisecondsInYear = 1000 * 60 * 60 * 24 * 365; + +// TODO: there is already "parseDate" in helpers +function parseDate(isoUtcDate: string): Date { + const [year, month, day] = isoUtcDate.match(/^(\d{4})-(\d\d)-(\d\d)$/) + .splice(1) + .map(x => parseInt(x, 10)); + return new Date(Date.UTC(year, month-1, day)); +} + +function isArchived(item) { + const decisionDate = item.decision_date; + console.warn(decisionDate) + if(decisionDate != null) { + if ((currentTimestamp - parseDate(decisionDate).valueOf()) > milisecondsInYear) { + return true; + } + } + if(item.registered_with_local_authority_date != null) { + if ((currentTimestamp - parseDate(item.registered_with_local_authority_date).valueOf()) > milisecondsInYear) { + return true; + } + } + return false; +} const PlanningView: React.FunctionComponent = (props) => { const communityLinkUrl = `/${props.mode}/${Category.Community}/${props.building.building_id}`; @@ -29,8 +55,15 @@ const PlanningView: React.FunctionComponent = (props) => { This section is under development as part of the project CLPV Tool. For more details and progress read here. - isArchived(item) == false) : []} + allEntryCount={props.building.planning_data ? props.building.planning_data.length : 0} + /> + + + isArchived(item)) : []} + allEntryCount={props.building.planning_data ? props.building.planning_data.length : 0} /> diff --git a/app/src/tiles/dataDefinition.ts b/app/src/tiles/dataDefinition.ts index 6f848f1c..a1077833 100644 --- a/app/src/tiles/dataDefinition.ts +++ b/app/src/tiles/dataDefinition.ts @@ -137,7 +137,7 @@ const LAYER_QUERIES = { community_public_ownership IS NOT NULL `, planning_applications_status: `SELECT - buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn + buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn, planning_data.decision_date, planning_data.registered_with_local_authority_date FROM building_properties INNER JOIN planning_data ON building_properties.uprn = planning_data.uprn INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,