From c6609e6542f3c05aef1dd0f025cdd9816a227f50 Mon Sep 17 00:00:00 2001 From: Matt Gardner Date: Tue, 26 Oct 2021 15:36:36 -0500 Subject: [PATCH] Use zoning district page looking function from zoning-district model; Refactor function to work with all zoning codes; --- app/models/map-features/lot.js | 9 +---- app/models/map-features/zoning-district.js | 38 ++++++++++++------- .../layer-record-views/zoning-district.hbs | 2 +- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/models/map-features/lot.js b/app/models/map-features/lot.js index bf46de77..3607fe71 100644 --- a/app/models/map-features/lot.js +++ b/app/models/map-features/lot.js @@ -4,6 +4,7 @@ import { computed } from '@ember/object'; import { alias } from '@ember/object/computed'; import carto from 'labs-zola/utils/carto'; import config from 'labs-zola/config/environment'; +import { handleCommercialZoningExceptions as getPrimaryZone } from 'labs-zola/models/map-features/zoning-district'; const { specialDistrictCrosswalk } = config; @@ -14,14 +15,6 @@ const specialPurposeDistrictsSQL = function(table, spdist1, spdist2, spdist3) { WHERE sdlbl IN ('${spdist1}', '${spdist2}', '${spdist3}')`; }; -const getPrimaryZone = (zonedist = '') => { - if (!zonedist) return ''; - let primary = zonedist.match(/\w\d*/)[0].toLowerCase(); - // special handling for c1 and c2 - if ((primary === 'c1') || (primary === 'c2')) primary = 'c1-c2'; - return primary; -}; - const bldgclassLookup = { A0: 'One Family Dwellings - Cape Cod', A1: 'One Family Dwellings - Two Stories Detached (Small or Moderate Size, With or Without Attic)', diff --git a/app/models/map-features/zoning-district.js b/app/models/map-features/zoning-district.js index 7f2b7408..7702da61 100644 --- a/app/models/map-features/zoning-district.js +++ b/app/models/map-features/zoning-district.js @@ -83,18 +83,30 @@ const zoningAbbr = { BPC: 'bpc', }; +// Performs case insensitive string equality check. +// Uses "accent" level sensitivity: +// "accent": Only strings that differ in base letters or accents and other diacritic marks compare as unequal. +// Examples: a ≠ b, a ≠ á, a = A. +// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare#parameters. +const isSimilar = (string1, string2) => string1.localeCompare(string2, undefined, { sensitivity: 'accent' }) === 0; + +// This is purely intended to conform to DCP website's zoning district URL scheme. +// Originally added to make it possible to link out to DCP website: +// https://github.com/NYCPlanning/labs-zola/commit/889cd2ddaf8b17f37a977fb5f84409e3c5535695 export const handleCommercialZoningExceptions = (primaryzone) => { - let url = ''; - - if ((primaryzone === 'c1') || (primaryzone === 'c2')) { - url = 'c1-c2'; - } else if (primaryzone === 'c3') { - url = 'c3-c3a'; - } else { - url = primaryzone; + if (!primaryzone) return ''; + + let code = primaryzone.match(/\w\d*/)[0].toLowerCase(); + + // Check case insensitive similarity because zoning codes are represented either + // capitalized or otherwise + if (isSimilar(primaryzone, 'c1') || isSimilar(primaryzone, 'c2')) { + code = 'c1-c2'; + } else if (isSimilar(primaryzone, 'c3')) { + code = 'c3-c3a'; } - return url; + return code; }; const { attr } = DS; @@ -105,14 +117,12 @@ export default class ZoningDistrictFragment extends MF.Fragment { @attr('string') zonedist; + // Used to clean up the 'zonedist' field to build a URL to the DCP website @computed('zonedist') - get primaryzone() { + get dcpWebsiteFileName() { const zonedist = this.get('zonedist'); - // convert R6A to r6 - const primary = handleCommercialZoningExceptions(zonedist.match(/\w\d*/)[0].toLowerCase()); - - return primary; + return handleCommercialZoningExceptions(zonedist); } @computed('zonedist') diff --git a/app/templates/components/layer-record-views/zoning-district.hbs b/app/templates/components/layer-record-views/zoning-district.hbs index d1ea1adb..7cc79598 100644 --- a/app/templates/components/layer-record-views/zoning-district.hbs +++ b/app/templates/components/layer-record-views/zoning-district.hbs @@ -10,7 +10,7 @@ {{#unless (eq this.model.zonedist "BPC")}}

{{fa-icon "external-link-alt"}}