From 9d1094cdd577a36cec1d732567c2997be8de4a8f Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Sat, 19 Jan 2019 18:47:08 +0000 Subject: [PATCH] Include text_multi with links in view --- app/src/frontend/building-view.js | 94 +++++++++++++++++++++++++---- app/src/frontend/fields-config.json | 2 +- 2 files changed, 83 insertions(+), 13 deletions(-) diff --git a/app/src/frontend/building-view.js b/app/src/frontend/building-view.js index 71e2143a..4bc52479 100644 --- a/app/src/frontend/building-view.js +++ b/app/src/frontend/building-view.js @@ -1,3 +1,4 @@ +import urlapi from 'url'; import React, { Fragment } from 'react'; import { Link, NavLink } from 'react-router-dom'; @@ -32,18 +33,27 @@ const BuildingView = (props) => { {...section_props}> { section_props.fields.map(field_props => { - return (field_props.slug === 'uprns')? - - : - + + switch (field_props.type) { + case "uprn_list": + return + case "text_multi": + return + default: + return + } }) } @@ -100,6 +110,66 @@ const DataEntry = (props) => ( ); +const MultiDataEntry = (props) => { + let content; + + if (props.value && props.value.length) { + content =
    { + props.value.map((item, index) => { + return
  • {item}
  • + }) + }
+ } else { + content = '\u00A0' + } + + return ( + +
+ { props.title } + { props.tooltip? : null } +
+
{ content }
+
+ ); +} + +function sanitise_url(string){ + let url_ + + // http or https + if (!(string.substring(0, 7) === 'http://' || string.substring(0, 8) === 'https://')){ + return null + } + + try { + url_ = document.createElement('a') + url_.href = string + } catch (error) { + try { + url_ = urlapi.parse(string) + } catch (error) { + return null + } + } + + // required (www.example.com) + if (!url_.hostname || url_.hostname === '' || url_.hostname === 'localhost'){ + return null + } + + // optional (/some/path) + // url_.pathname; + + // optional (?name=value) + // url_.search; + + // optional (#anchor) + // url_.hash; + + return `${url_.protocol}//${url_.hostname}${url_.pathname || ''}${url_.search || ''}${url_.hash || ''}` +} + const UPRNsDataEntry = (props) => { const uprns = props.value || []; const no_parent = uprns.filter(uprn => uprn.parent_uprn == null); diff --git a/app/src/frontend/fields-config.json b/app/src/frontend/fields-config.json index b2ca7a3a..0ff476d9 100644 --- a/app/src/frontend/fields-config.json +++ b/app/src/frontend/fields-config.json @@ -36,7 +36,7 @@ "disabled": true }, { - "title": "UPRNs", "slug": "uprns", "type": "list", + "title": "UPRNs", "slug": "uprns", "type": "uprn_list", "tooltip": "Unique Property Reference Numbers (to be filled automatically)", "disabled": true },