Skip to content

Commit

Permalink
Merge pull request #135 from dxw/misc-2
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
jdudley1123 authored Nov 26, 2024
2 parents a27bd7c + 53462c5 commit 1dfa815
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 114 deletions.
12 changes: 12 additions & 0 deletions app/assets/stylesheets/daqi-levels.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,15 @@
.daqi-level-10 {
@apply text-white bg-stone-700;
}

.stroke-white {
svg {
stroke: white;
}
}

.stroke-black {
svg {
stroke: black;
}
}
6 changes: 3 additions & 3 deletions app/controllers/forecasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def forecast_for_day(day, forecasts)
end

def zone
return Zone.default unless params[:zone]

Zone.find_by(name: params[:zone])
Zone.find_by!(name: params[:zone])
rescue ActiveRecord::RecordNotFound
Zone.default
end

def date
Expand Down
4 changes: 0 additions & 4 deletions app/controllers/visitors_controller.rb

This file was deleted.

35 changes: 19 additions & 16 deletions app/javascript/controllers/map_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,30 +209,21 @@ export default class MapController extends Controller {
addZonesLayer() {
const { zoneBoundaryLayers, zoneLabelMarkers } = this.zones();
zoneBoundaryLayers.forEach((layer) => layer.addTo(this.map));
this.updateZoneBoundaryLayerStyles(zoneBoundaryLayers);

this.map.on("zoomend", () => {
this.updateZoneBoundaryLayerStyles(zoneBoundaryLayers);
});

this.addZoneLabelMarkers(zoneLabelMarkers);
}

zones() {
const zoneBoundaryLayers = [];
const zoneLabelMarkers = [];
const zoneBoundaryLayerLevelStyles = {
1: { weight: 3 }, // stroke width
2: { weight: 1 },
};

for (const [, zone] of Object.entries(zones)) {
const layer = L.geoJSON(zone, {
style: function (feature) {
return {
color: "black", // stroke color
weight:
zoneBoundaryLayerLevelStyles[feature.properties.level].weight,
fill: false,
};
},
pane: "zones",
});

const layer = L.geoJSON(zone, { pane: "zones" });
zoneBoundaryLayers.push(layer);

const bounds = layer.getBounds();
Expand All @@ -255,6 +246,18 @@ export default class MapController extends Controller {
return { zoneBoundaryLayers, zoneLabelMarkers };
}

updateZoneBoundaryLayerStyles(zoneBoundaryLayers) {
const zoom = this.map.getZoom();

zoneBoundaryLayers.forEach((layer) => {
layer.setStyle({
weight: 0.1 * 20 ** (zoom / 14), // Scale the stroke width with zoom
color: "black", // stroke color
fill: false,
});
});
}

addZoneLabelMarkers(zoneLabelMarkers) {
// Only show the zone labels when the map is zoomed in enough
zoneLabelMarkers.forEach(({ marker, londonBorough }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"name": "City of Westminster",
"name": "Westminster",
"level": 2,
"londonBorough": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Feature",
"properties": {
"name": "City of Westminster",
"name": "Westminster",
"level": 2,
"londonBorough": true
},
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/zone_boundaries/zone-boundaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export { default as brent } from "./london/boroughs/brent-simplified.geojson";
export { default as bromley } from "./london/boroughs/bromley-simplified.geojson";
export { default as camden } from "./london/boroughs/camden-simplified.geojson";
export { default as cityOfLondon } from "./london/boroughs/city-of-london-simplified.geojson";
export { default as cityOfWestminster } from "./london/boroughs/city-of-westminster-simplified.geojson";
export { default as croydon } from "./london/boroughs/croydon-simplified.geojson";
export { default as ealing } from "./london/boroughs/ealing-simplified.geojson";
export { default as enfield } from "./london/boroughs/enfield-simplified.geojson";
Expand All @@ -35,6 +34,7 @@ export { default as sutton } from "./london/boroughs/sutton-simplified.geojson";
export { default as towerHamlets } from "./london/boroughs/tower-hamlets-simplified.geojson";
export { default as walthamForest } from "./london/boroughs/waltham-forest-simplified.geojson";
export { default as wandsworth } from "./london/boroughs/wandsworth-simplified.geojson";
export { default as westminster } from "./london/boroughs/westminster-simplified.geojson";

export { default as centralLondon } from "./london/regions/central-london-simplified.geojson";
export { default as eastLondon } from "./london/regions/east-london-simplified.geojson";
Expand Down
8 changes: 4 additions & 4 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<header class="site-header">
<div class="site-title">
<span class="site-name">airTEXT</span>
<%= link_to "airTEXT", root_path, class: "site-name" %>
<span class="site-strapline">Air quality service</span>
</div>
<nav data-controller="navigation">
<button data-action="navigation#toggleMenu">
</button>
<ul class="hidden" data-navigation-target="menuList">
<li><a href="forecast">Air quality forecast</a></li>
<li><%= link_to "Air quality forecast", forecast_path %></li>
<li>Alerts</li>
<li><a href="health_advice" class="">Health advice</a></li>
<li><a href="about" class="">About</a></li>
<li><%= link_to "Health advice", health_advice_path %></li>
<li><%= link_to "About", about_path %></li>
<li>Contact</li>
</ul>
</nav>
Expand Down
24 changes: 0 additions & 24 deletions app/views/visitors/index.html.erb

This file was deleted.

42 changes: 0 additions & 42 deletions config/list-of-zones.json

This file was deleted.

2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Rails.application.routes.draw do
get "health_check" => "application#health_check"

root to: "visitors#index"
root to: "forecasts#show"

get "map", to: "map#show"

Expand Down
5 changes: 3 additions & 2 deletions spec/controllers/forecasts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
let(:barnet) { double("Barnet") }

before do
allow(Zone).to receive(:find_by).and_return(barnet)
allow(Zone).to receive(:default).and_return(central_london)
allow(CercForecastService).to receive(:latest_forecasts_for).and_return(forecasts)
end
Expand All @@ -23,7 +22,9 @@

context "when zone IS given" do
it "obtains forecasts for the given zone from the CercForecastService" do
get :show, params: {zone: double}
allow(Zone).to receive(:find_by).and_return(barnet)

get :show, params: {zone: "Barnet"}

expect(CercForecastService).to have_received(:latest_forecasts_for).with(barnet)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/features/visitors/share_forecasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Then I see the share icons for multiple platforms

it "shows share icons for multiple platforms" do
view_forecasts
visit forecast_path

click_on "Share with others"

Expand All @@ -44,7 +44,7 @@
let(:share_message) { CGI.escape_uri_component(today_forecast.share_message) }

before do
view_forecasts
visit forecast_path

click_on "Share with others"
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/visitors/view_air_quality_alerts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

describe "View air quality alert for today" do
it "shows an air quality alert of high for today" do
view_forecasts
visit forecast_path

within(".today[data-date='#{Date.today}']") do
expect_to_see_alert_level(:high)
Expand All @@ -36,7 +36,7 @@

describe "View air quality alert for tomorrow", js: true do
it "shows an air quality alert of moderate for tomorrow" do
view_forecasts
visit forecast_path
switch_to_tab_for(:tomorrow)

within(".tomorrow[data-date='#{Date.tomorrow}']") do
Expand All @@ -52,7 +52,7 @@

describe "View air quality alert for the day after tomorrow", js: true do
it "shows an air quality alert of very high for the day after tomorrow" do
view_forecasts
visit forecast_path
switch_to_tab_for(:day_after_tomorrow)

within(".day_after_tomorrow[data-date='#{Date.tomorrow + 1.day}']") do
Expand Down
10 changes: 5 additions & 5 deletions spec/features/visitors/view_forecasts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# and I see predicted temperature level
##

view_forecasts
visit forecast_path

# See the forecasts page
expect(page).to have_content("Air quality forecast")
Expand Down Expand Up @@ -85,7 +85,7 @@
# And I see predicted temperature level for tomorrow
##

view_forecasts
visit forecast_path
switch_to_tab_for(:tomorrow)

# See that the tomorrow tab is active
Expand Down Expand Up @@ -118,7 +118,7 @@
# And I see predicted temperature level for the day after tomorrow
##

view_forecasts
visit forecast_path
switch_to_tab_for(:day_after_tomorrow)

# See that the day after tomorrow tab is active
Expand Down Expand Up @@ -153,7 +153,7 @@
end

it "shows the pollen prediction" do
view_forecasts
visit forecast_path

expect(page).to have_css(".pollen")
end
Expand All @@ -170,7 +170,7 @@
end

it "does not show the pollen prediction" do
view_forecasts
visit forecast_path

expect(page).not_to have_css(".pollen")
end
Expand Down
5 changes: 0 additions & 5 deletions spec/support/features/forecast_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ def stub_cerc_api_with(forecasts)
HttpStubs.stub_forecasts_with(forecast_response)
end

def view_forecasts
visit root_path
click_link("View forecasts")
end

def switch_to_tab_for(day)
case day
when :tomorrow
Expand Down

0 comments on commit 1dfa815

Please sign in to comment.