Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

997 fix zoning hyperlinks c3 #1028

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -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
9 changes: 1 addition & 8 deletions app/models/map-features/lot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)',
Expand Down
50 changes: 30 additions & 20 deletions app/models/map-features/zoning-district.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,32 @@ 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) => {
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 code;
};

const { attr } = DS;

// this model fragment structures the "properties"
Expand All @@ -91,12 +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 = zonedist.match(/\w\d*/)[0].toLowerCase();
return primary;

return handleCommercialZoningExceptions(zonedist);
}

@computed('zonedist')
Expand All @@ -117,20 +143,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{#unless (eq this.model.zonedist "BPC")}}
<p>
<a
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.primaryzoneURL}}.page"
href="https://www1.nyc.gov/site/planning/zoning/districts-tools/{{this.model.dcpWebsiteFileName}}.page"
target="_blank"
>
{{fa-icon "external-link-alt"}}
Expand Down