openaustralia/planningalerts

View on GitHub
app/views/_tailwind/authorities/show.html.erb

Summary

Maintainability
Test Coverage
<% content_for :page_title do %>
  Information on <%= @authority.full_name %>
<% end %>

<%= render Tailwind::Heading.new(tag: :h1) do %>
  Information <span class="block mt-1 text-xl font-bold font-display">on <%= @authority.full_name %></span>
<% end %>

<% if @authority.boundary && Flipper.enabled?(:show_authority_map, current_user) %>
  <%# TODO: Probably want to precompute the bounding box when the boundary data is loaded instead %>
  <div class="w-full my-8 h-80 bg-google-maps-green"
       x-init="initialiseAuthorityMap($el, <%= bb = RGeo::Cartesian::BoundingBox.create_from_geometry(@authority.boundary)
                                               { json: boundary_authority_url(format: :json), sw: { lng: bb.min_x, lat: bb.min_y }, ne: { lng: bb.max_x, lat: bb.max_y } }.to_json %>)">
  </div>
<% end %>

<% if @authority.population_2021 %>
  <p class="py-4 mt-8 text-xl border-y text-navy border-light-grey2">Population <%= number_with_delimiter @authority.population_2021 %> (2021 census)</p>
<% end %>

<% if @authority.covered? %>
  <div class="divide-y divide-light-grey2">
    <% unless @authority.applications.empty? %>
      <section class="py-12">
        <%# TODO: This title isn't right because the section has comments in it too %>
        <%= render Tailwind::Heading.new(tag: :h2) do %>
          Browse applications from <%= @authority.full_name %>
        <% end %>
        <ul class="mt-8 text-xl text-navy">
          <li>
            View all
            <%= pa_link_to "recent applications", authority_applications_path(@authority.short_name_encoded) %>
          </li>
          <li>
            View all
            <%= pa_link_to "comments on applications", authority_comments_path(@authority.short_name_encoded) %>
          </li>
        </ul>
      </section>
    <% end %>

    <section class="py-12">
      <%= render Tailwind::Heading.new(tag: :h2) do %>
        Applications collected by Planning Alerts
      <% end %>
      <% if @authority.applications.empty? %>
        <p class="mt-8 text-xl text-navy">No applications have yet been collected.</p>
      <% else %>
        <% if @authority.broken? %>
          <%# TODO: We need a proper design for this warning message %>
          <p class="mt-8 text-xl text-navy">
            It looks like something might be wrong.
            The last new application was received <%= time_ago_in_words(@authority.date_last_new_application_scraped) %> ago.
            <%= pa_link_to "Why?", faq_path(anchor: "broken_scraper") %>
          </p>
        <% end %>
        <table class="mt-8 text-xl text-navy">
          <tbody>
            <tr class="flex flex-col pb-4 sm:table-row">
              <td class="pr-8 font-bold text-7xl"><%= @authority.applications.where("first_date_scraped >= ?", 1.week.ago).count %></td>
              <th class="font-normal text-left">in the last week</th>
            </tr>
            <tr class="flex flex-col pb-4 sm:table-row">
              <td class="pr-8 font-bold text-7xl"><%= @authority.applications.where("first_date_scraped >= ?", 1.month.ago).count %></td>
              <th class="font-normal text-left">in the last month</th>
            </tr>
            <tr class="flex flex-col pb-4 sm:table-row">
              <td class="pr-8 font-bold text-7xl"><%= @authority.applications.count %></td>
              <th class="font-normal text-left">
                since <%= @authority.earliest_date.strftime("%-d %b %Y") %>
                (when this authority was first added to Planning Alerts)
              </th>
            </tr>
            <tr class="flex flex-col pb-4 sm:table-row">
              <td class="pr-8 font-bold text-7xl"><%= @authority.median_new_applications_per_week %></td>
              <th class="font-normal text-left">
                <%= pa_link_to "median", "https://en.wikipedia.org/wiki/Median" %>
                per week
                (ignoring weeks without any new applications at all)
              </th>
            </tr>
          </tbody>
        </table>
      <% end %>
    </section>

    <% unless @authority.applications.empty? %>
      <section class="py-12">
        <%= render Tailwind::Heading.new(tag: :h2, extra_classes: "pb-12") do %>
          Number of new applications scraped over time
        <% end %>
        <div class="h-40 sm:h-52">
          <div class="chart bg-fuchsia"
               x-init="barGraph(
                         $el,
                         '<%= per_week_authority_applications_url(@authority.short_name_encoded, format: :json) %>',
                         'new applications scraped')">
          </div>
        </div>
      </section>

      <section class="clear-both py-12">
        <%= render Tailwind::Heading.new(tag: :h2, extra_classes: "pb-12") do %>
          Number of comments posted over time
        <% end %>
        <div class="h-40 sm:h-52">
          <div class="chart bg-fuchsia"
               x-init="barGraph(
                         $el,
                         '<%= per_week_authority_comments_url(@authority.short_name_encoded, format: :json) %>',
                         'comments posted')">
          </div>
        </div>
      </section>

      <%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.12/d3.min.js" %>
      <%= javascript_include_tag "tailwind/bar_graph" %>
    <% end %>

    <section class="py-12">
      <%= render Tailwind::Heading.new(tag: :h2, extra_classes: "pb-12") do %>
        Under the Hood
      <% end %>
      <p class="text-xl text-navy">
        Are you a developer or keen to learn some new things and help out in the process?
        Then, <%= pa_link_to "look under the hood", authority_under_the_hood_path(@authority.short_name_encoded) %>,
        see more about how the information gets into PlanningAlerts, what problems are
        happening and what you might do to help fix them.
      </p>
      <p class="mt-6 text-xl text-navy">
        <%= pa_link_to "Look under the hood", authority_under_the_hood_path(@authority.short_name_encoded) %>
      </p>

    </section>
  </div>
<% else %>
  <%# TODO: Need a proper design for this section explaining why this authority isn't covered yet %>
  <div class="flex flex-col items-start gap-16 p-16 mt-12 md:flex-row bg-light-grey">
    <%= image_tag "tailwind/illustration/no_results", alt: "" %>
    <div>
      <p class="text-2xl font-bold text-navy">
        This authority is not yet covered by Planning&nbsp;Alerts.
      </p>
      <p class="mt-8 text-xl text-navy">
        This is because either
        a scraper has not yet been written for it,
        or the information is not available online or in a form that can be read by a scraper.
      </p>
      <p class="mt-6 text-xl text-navy">
        There is a list of the planning authorities we currently cover
        <%= pa_link_to "here", authorities_path %>.
      </p>
    </div>
  </div>
  <section class="mt-16">
    <%= render Tailwind::Heading.new(tag: :h2).with_content("You can help!") %>
    <p class="mt-8 text-xl text-navy">
      We are a free service brought to you by the charity the
      <%= pa_link_to "OpenAustralia Foundation", "https://www.oaf.org.au" %>.
      Donations and other kinds of support allow us to add more local authorities,
      including this one.
    </p>
    <p class="mt-6 text-xl text-navy">
      Check out our <%= pa_link_to "get involved", get_involved_path %> section.
    </p>
  </section>
<% end %>