diff --git a/app/assets/stylesheets/components/cards/cards/_cards-sites.scss b/app/assets/stylesheets/components/cards/cards/_cards-sites.scss deleted file mode 100644 index 2715d8321..000000000 --- a/app/assets/stylesheets/components/cards/cards/_cards-sites.scss +++ /dev/null @@ -1,25 +0,0 @@ -//-------------------------------------------------- -// classes -//-------------------------------------------------- -&--sites { - .cards { - &__cards { - @include flex; - @include flex-h-between; - @include flex-wrap; - } - } - - .card { - @include border-grey-light; - @include box-shadow-grey-light; - @include responsive(width, 100%, 50%, calc(33% - 7.5px)); - background-color: $white; - margin-bottom: rem-calc(30); - padding: rem-calc(14 12); - - .image { - width: 100%; - } - } -} \ No newline at end of file diff --git a/app/controllers/marine_controller.rb b/app/controllers/marine_controller.rb index 774631acb..d16f6ddc9 100644 --- a/app/controllers/marine_controller.rb +++ b/app/controllers/marine_controller.rb @@ -12,11 +12,14 @@ class MarineController < ApplicationController before_action :most_protected_areas, only: [:index] before_action :national_statistics, only: [:index] before_action :designations, only: [:index, :download_designations] - before_action :green_list_areas, only: [:index] before_action :load_cms_content def index + @marineSites = ProtectedArea.marine_areas.limit(3) ## FERDI 3 marine PAs + @marineSitesTotal = number_with_delimiter(ProtectedArea.marine_areas.count()) + @marineViewAllUrl = '/' #TODO URL to filtered search results page + @regionCoverage = Region.without_global.map do |region| RegionPresenter.new(region).marine_coverage end @@ -278,8 +281,4 @@ def pledges ] }.to_json end - - def green_list_areas - @green_list_areas = ProtectedArea.marine_areas.green_list_areas - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5a528c237..40642f7b8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,7 +5,13 @@ module ApplicationHelper ProtectedArea => :protected_area_cover, Country => :country_cover, Region => :region_cover - } + }.freeze + + PLACEHOLDERS = { + ProtectedArea => "search-placeholder-country.png", + Country => "search-placeholder-country.png", + Region => "search-placeholder-region.png" + }.freeze def commaify number number_with_delimiter(number, delimeter: ',') @@ -32,31 +38,49 @@ def cover item send COVER_HELPERS[item.class], item end + def cover_placeholder klass + PLACEHOLDERS[klass] + end + + def cover_data(image_params, item_class) + placeholder = cover_placeholder(item_class) + { + 'data-src': tiles_path(image_params), + 'data-error': image_path(placeholder), + 'data-loading': image_path(placeholder), + } + end + def protected_area_cover protected_area version = Rails.application.secrets.mapbox[:version] image_params = {id: protected_area.wdpa_id, type: "protected_area", version: version} + data = cover_data(image_params, protected_area.class) image_tag( - "search-placeholder-country.png", - alt: protected_area.name, - data: {async: tiles_path(image_params)}, - class: 'image' #TODO find a way to add classes via parameters + cover_placeholder(protected_area.class), + { + alt: protected_area.name, + class: 'image' #TODO find a way to add classes via parameters + }.merge(data) ) end def country_cover country version = Rails.application.secrets.mapbox[:version] image_params = {id: country.iso, type: "country", version: version} + data = cover_data(image_params, country.class) image_tag( - "search-placeholder-country.png", - alt: country.name, - data: {async: tiles_path(image_params)}, + cover_placeholder(country.class), + {alt: country.name}.merge(data) ) end def region_cover region - image_tag("search-placeholder-region.png", alt: region.name) + image_tag( + cover_placeholder(region.class), + alt: region.name + ) end def site_title diff --git a/app/javascript/vue.js b/app/javascript/vue.js index 51457ba44..ffe36a7a8 100644 --- a/app/javascript/vue.js +++ b/app/javascript/vue.js @@ -8,6 +8,7 @@ import Vue from 'vue/dist/vue.esm' import VueAnalytics from 'vue-analytics' import Vue2TouchEvents from 'vue2-touch-events' import ScrollMagic from 'scrollmagic' +import VueLazyload from 'vue-lazyload' // import VueAgile from 'vue-agile' // store @@ -49,7 +50,7 @@ import Tooltip from './components/tooltip/Tooltip' import VSelectSearchable from './components/select/VSelectSearchable' import VTable from './components/table/VTable' -document.addEventListener('DOMContentLoaded', () => { +document.addEventListener('DOMContentLoaded', () => { if(document.getElementById('v-app')) { Vue.use(VueAnalytics, { id: 'UA-12920389-2' }) // production @@ -57,7 +58,9 @@ document.addEventListener('DOMContentLoaded', () => { Vue.prototype.$eventHub = new Vue() Vue.use(Vue2TouchEvents) - + + Vue.use(VueLazyload) + const app = new Vue({ el: '#v-app', store, @@ -100,4 +103,4 @@ document.addEventListener('DOMContentLoaded', () => { } }) } -}) \ No newline at end of file +}) diff --git a/app/views/marine/index.html.erb b/app/views/marine/index.html.erb index 66ae744fa..79934cdd0 100644 --- a/app/views/marine/index.html.erb +++ b/app/views/marine/index.html.erb @@ -60,7 +60,13 @@ <%= render partial: "marine/sections/coverage_map" %> -<%#= render partial: "partials/cards/sites", locals: { cards: @wdpa } %> +
+ <%= render partial: "partials/cards/sites", locals: { + cards: @marineSites, + title: "#{t('global.area-types.wdpa')} (#{@marineSitesTotal})", + url: @marineViewAllUrl + } %> +
<%= render "partials/carousels/themes" %> diff --git a/app/views/partials/cards/_sites.html.erb b/app/views/partials/cards/_sites.html.erb index df391b464..9974dc106 100644 --- a/app/views/partials/cards/_sites.html.erb +++ b/app/views/partials/cards/_sites.html.erb @@ -1,24 +1,22 @@ -
-

<%#= title %>

+<% if local_assigns.has_key? :url %> +
+

<%= title %>

+ <%= link_to t('global.button.all'), url, title: t('global.button.all'), class: 'button--all' %> +
+<% end %> - <%#= link_to t('global.button.all'), url, target: '_blank', title: t('global.button.all') %> +
+ <% cards.each do |card| %> + <%= link_to protected_area_path(card.wdpa_id), title: "View more about the site: #{ card.name }", class: "card__link" do %> -
- <% cards.each do |card| %> - <%= link_to protected_area_path(card.wdpa_id), title: "View more about the site: #{card.name}", class: "card" do %> - <%= cover card %> +
+ <%= protected_area_cover(card) %> +
-

<%= card.name %>

-
-

- <% card.countries_for_index.each do |country| %> - <%= country.iso_3 %> - <%= country.name %> - <% end %> -

-
- <% end %> +
+

<%= card.name %>

+
<% end %> -
-
\ No newline at end of file + <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index c3f059af2..bddfdc8fe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,8 @@ #TODO get '/:id', to: 'protected_areas#show', as: 'protected_area' + get '/assets/tiles/:id', to: 'assets#tiles', as: 'tiles' + scope "(:locale)", locale: /en|es|fr/ do root to: 'home#index' @@ -25,7 +27,6 @@ put '/admin/maintenance', as: 'maintenance' put '/admin/clear_cache', as: 'clear_cache' - get '/assets/tiles/:id', to: 'assets#tiles', as: 'tiles' namespace :api do namespace :v3 do diff --git a/package.json b/package.json index 9f9bff6fd..6b3deb89e 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "save": "^2.4.0", "scrollmagic": "^2.0.6", "vue": "^2.6.10", + "vue-lazyload": "^1.3.3", "vue-agile": "^1.0.11", "vue-analytics": "^5.17.2", "vue-loader": "^15.7.0",