From 3281a3f856c0ccd2c424d54d4db23b38f5cc062f Mon Sep 17 00:00:00 2001 From: Matt Gardner Date: Tue, 26 Oct 2021 13:46:50 -0500 Subject: [PATCH 1/3] Centralize zoning district primaryzone lookup code; rename --- app/models/map-features/zoning-district.js | 34 +++++++++---------- .../layer-record-views/zoning-district.hbs | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/models/map-features/zoning-district.js b/app/models/map-features/zoning-district.js index b351020dd..7f2b74085 100644 --- a/app/models/map-features/zoning-district.js +++ b/app/models/map-features/zoning-district.js @@ -83,6 +83,20 @@ const zoningAbbr = { BPC: 'bpc', }; +export const handleCommercialZoningExceptions = (primaryzone) => { + let url = ''; + + if ((primaryzone === 'c1') || (primaryzone === 'c2')) { + url = 'c1-c2'; + } else if (primaryzone === 'c3') { + url = 'c3-c3a'; + } else { + url = primaryzone; + } + + return url; +}; + const { attr } = DS; // this model fragment structures the "properties" @@ -94,8 +108,10 @@ export default class ZoningDistrictFragment extends MF.Fragment { @computed('zonedist') get primaryzone() { const zonedist = this.get('zonedist'); + // convert R6A to r6 - const primary = zonedist.match(/\w\d*/)[0].toLowerCase(); + const primary = handleCommercialZoningExceptions(zonedist.match(/\w\d*/)[0].toLowerCase()); + return primary; } @@ -117,20 +133,4 @@ export default class ZoningDistrictFragment extends MF.Fragment { return zoningDescriptions[zoneabbr]; } - - @computed('primaryzone') - get primaryzoneURL() { - const primaryzone = this.get('primaryzone'); - let url = ''; - - if ((primaryzone === 'c1') || (primaryzone === 'c2')) { - url = 'c1-c2'; - } else if (primaryzone === 'c3') { - url = 'c3-c3a'; - } else { - url = primaryzone; - } - - return url; - } } diff --git a/app/templates/components/layer-record-views/zoning-district.hbs b/app/templates/components/layer-record-views/zoning-district.hbs index 5719e165f..d1ea1adb3 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"}} From 14ae980ff2477a93cd81bee4490a24f2a395301d Mon Sep 17 00:00:00 2001 From: Matt Gardner Date: Tue, 26 Oct 2021 13:49:19 -0500 Subject: [PATCH 2/3] Add tip to pre-commit hook --- .husky/pre-commit | 1 + 1 file changed, 1 insertion(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index a54ec8f25..ca19898d3 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1,6 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" +echo "Running pre-commit hooks. In a hurry? Add --no-verify flag to your command." yarn run test yarn run lint-staged From c6609e6542f3c05aef1dd0f025cdd9816a227f50 Mon Sep 17 00:00:00 2001 From: Matt Gardner Date: Tue, 26 Oct 2021 15:36:36 -0500 Subject: [PATCH 3/3] 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 bf46de77b..3607fe71f 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 7f2b74085..7702da61c 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 d1ea1adb3..7cc795980 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"}}