From 52358b8d9c7cb99b62e398751c6a7b5d372b998d Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Tue, 5 May 2020 11:46:39 +0100 Subject: [PATCH 001/114] Update autocomplete to only take 1 idea and remove multiple types --- .../stylesheets/components/_search.scss | 3 + .../search/_search-autocomplete.scss | 2 +- app/controllers/home_controller.rb | 8 +- app/controllers/oecm_controller.rb | 7 +- app/controllers/search_wdpa_controller.rb | 7 +- app/controllers/wdpa_controller.rb | 7 +- .../components/search/SearchAreas.vue | 12 +-- .../components/search/SearchAreasHome.vue | 20 +++-- .../search/SearchAreasInputAutocomplete.vue | 77 +++---------------- app/views/home/index.html.erb | 3 +- app/views/oecm/index.html.erb | 5 +- .../partials/search/_protected-areas.html.erb | 2 +- .../_tabs-thematic-area-database.html.erb | 2 +- app/views/search_areas/index.html.erb | 2 +- app/views/wdpa/index.html.erb | 5 +- config/locales/global/en.yml | 3 +- 16 files changed, 57 insertions(+), 108 deletions(-) diff --git a/app/assets/stylesheets/components/_search.scss b/app/assets/stylesheets/components/_search.scss index 6f403294e..0f42dd855 100644 --- a/app/assets/stylesheets/components/_search.scss +++ b/app/assets/stylesheets/components/_search.scss @@ -20,6 +20,9 @@ $search-input-size-desktop: 547px; //px &--pa { height: 0; + position: relative; //make sure the dropdown sits on top of map + z-index: 1; //make sure the dropdown sits on top of map + .search { &__container { @include flex; diff --git a/app/assets/stylesheets/components/search/_search-autocomplete.scss b/app/assets/stylesheets/components/search/_search-autocomplete.scss index 9db6a2242..132e6ec7f 100644 --- a/app/assets/stylesheets/components/search/_search-autocomplete.scss +++ b/app/assets/stylesheets/components/search/_search-autocomplete.scss @@ -62,7 +62,7 @@ $search-autocomplete-select-width: rem-calc(222); position: absolute; top: 50%; - right: calc(#{$search-autocomplete-select-width} + 16px); + right: rem-calc(26); transform: translateY(-50%) scale(.7); } diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 63e6bd58b..b88e24c9e 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -4,10 +4,10 @@ def index @pa_coverage_percentage = 9999 #TODO Total PA coverage in % - @search_area_types = [ - { id: 'wdpa', title: I18n.t('global.area-types.wdpa'), placeholder: I18n.t('global.placeholder.search-wdpa') }, - { id: 'oecm', title: I18n.t('global.area-types.oecm'), placeholder: I18n.t('global.placeholder.search-oecms') } - ].to_json + @config_search_areas = { + id: 'all', + placeholder: I18n.t('global.placeholder.search-oecm-wdpa') + }.to_json @pas_title = home_yml[:pas][:title] @pas_button = home_yml[:pas][:button] diff --git a/app/controllers/oecm_controller.rb b/app/controllers/oecm_controller.rb index 755c68279..1d5680eb9 100644 --- a/app/controllers/oecm_controller.rb +++ b/app/controllers/oecm_controller.rb @@ -2,9 +2,10 @@ class OecmController < ApplicationController def index @oecm_coverage_percentage = 10 ##TODO FERDI - percentage of the world covered by OECMs - @search_area_types = [ - { id: 'oecm', title: I18n.t('global.area-types.wdpa'), placeholder: I18n.t('global.placeholder.search-oecms') } - ].to_json + @config_search_areas = { + id: 'oecm', + placeholder: I18n.t('global.placeholder.search-oecm') + }.to_json @tabs = get_tabs(3).to_json end diff --git a/app/controllers/search_wdpa_controller.rb b/app/controllers/search_wdpa_controller.rb index c27983083..ece14a1ca 100644 --- a/app/controllers/search_wdpa_controller.rb +++ b/app/controllers/search_wdpa_controller.rb @@ -7,9 +7,10 @@ class SearchWdpaController < ApplicationController before_action :load_filters, only: [:index] def index - @search_area_types = [ - { id: 'wdpa', title: I18n.t('global.area-types.wdpa'), placeholder: I18n.t('global.placeholder.search-wdpa') } - ].to_json + @config_search_areas = { + id: 'all', + placeholder: I18n.t('global.placeholder.search-wdpa') + }.to_json @results = Search::AreasSerializer.new(@search).serialize @query = params['search_term'] diff --git a/app/controllers/wdpa_controller.rb b/app/controllers/wdpa_controller.rb index 27127b156..b4f906665 100644 --- a/app/controllers/wdpa_controller.rb +++ b/app/controllers/wdpa_controller.rb @@ -2,9 +2,10 @@ class WdpaController < ApplicationController def index @pa_coverage_percentage = 20 ##TODO FERDI - percentage of the world covered by PAs - @search_area_types = [ - { id: 'wdpa', title: I18n.t('global.area-types.wdpa'), placeholder: I18n.t('global.placeholder.search-wdpa') } - ].to_json + @config_search_areas = { + id: 'wdpa', + placeholder: I18n.t('global.placeholder.search-wdpa') + }.to_json @tabs = get_tabs(3).to_json end diff --git a/app/javascript/components/search/SearchAreas.vue b/app/javascript/components/search/SearchAreas.vue index df264a399..83a995fcf 100644 --- a/app/javascript/components/search/SearchAreas.vue +++ b/app/javascript/components/search/SearchAreas.vue @@ -8,9 +8,9 @@ /> @@ -80,9 +80,9 @@ export default { mixins: [ mixinAxiosHelpers ], props: { - autocompleteAreaTypes: { - type: Array, // [ { name: String, options: [ { id: Number, name: String } ] } ] - required: true + configAutocomplete: { + required: true, + type: Object // { id: String, placeholder: String } }, endpointAutocomplete: { type: String, @@ -136,7 +136,6 @@ export default { data () { return { activeFilterOptions: [], - areaType: '', currentPage: 0, defaultPage: 1, isFilterPaneActive: false, @@ -168,7 +167,6 @@ export default { ajaxSubmission () { let data = { params: { - area_type: this.areaType, filters: this.activeFilterOptions, items_per_page: 3, search_term: this.searchTerm @@ -226,7 +224,6 @@ export default { updateSearchTerm (searchParams) { this.resetFilters() this.$eventHub.$emit('reset-pagination') - this.areaType = searchParams.type this.searchTerm = searchParams.search_term this.ajaxSubmission() }, @@ -236,7 +233,6 @@ export default { let data = { params: { - area_type: this.areaType, filters: this.activeFilterOptions, geo_type: paginationParams.geoType, items_per_page: this.items_per_page, diff --git a/app/javascript/components/search/SearchAreasHome.vue b/app/javascript/components/search/SearchAreasHome.vue index 0bb55afe0..0305314f6 100644 --- a/app/javascript/components/search/SearchAreasHome.vue +++ b/app/javascript/components/search/SearchAreasHome.vue @@ -1,8 +1,8 @@ @@ -83,23 +56,21 @@ export default { ], props: { + config: { + required: true, + type: Object // { id: String, placeholder: String } + }, endpoint: { required: true, type: String }, - prePopulatedSearchTerm: String, - types: { - required: true, - type: Array // [ { id: String, title: String, placeholder: String } ] } ] - } + prePopulatedSearchTerm: String }, data () { return { autocomplete: [], // [ { title: String, url: String } ] - searchTerm: '', - typeDropdownActive: false, - selectedTypeIndex: 0, + searchTerm: '' } }, @@ -107,24 +78,12 @@ export default { hasAutocompleteOptions () { return this.autocomplete.length > 0 }, - hasMultipleTypes () { - return this.types.length > 1 - }, searchParams () { return { - type: this.selectedTypeId, - search_term: this.searchTerm + search_term: this.searchTerm, + type: this.config.id } }, - selectedPlaceholder () { - return this.types[this.selectedTypeIndex].placeholder - }, - selectedTypeId () { - return this.types[this.selectedTypeIndex].id - }, - selectedTypeTitle () { - return this.types[this.selectedTypeIndex].title - }, showResetIcon () { return this.searchTerm.length != 0 } @@ -132,9 +91,6 @@ export default { mounted () { if(this.prePopulatedSearchTerm) { this.searchTerm = this.prePopulatedSearchTerm } - // this.addTabFromSearchListener() - // this.addArrowKeyListeners() - // this.addTabForwardFromResetListener() }, methods: { @@ -157,21 +113,6 @@ export default { }) }, - updateType (type, index) { - this.selectedTypeIndex = index - this.type = type.id - this.placeholder = type.placeholder - this.toggleTypes() - this.resetSearchTerm() - this.resetAutocomplete() - }, - - toggleTypes () { - if(!this.hasMultipleTypes) { return false } - - this.typeDropdownActive = !this.typeDropdownActive - }, - resetSearchTerm () { this.searchTerm = '' this.resetAutocomplete() diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 7b7b4e7e3..1c32dea59 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -4,7 +4,8 @@ hero_stat_text: t('home.hero.stat-text') } %> -<%= render "partials/search/protected-areas" %> + +<%= render "partials/search/protected-areas", locals: { config: @config_search_areas } %>

<%= @pas_title %>

diff --git a/app/views/oecm/index.html.erb b/app/views/oecm/index.html.erb index d93b856a6..9d55386af 100644 --- a/app/views/oecm/index.html.erb +++ b/app/views/oecm/index.html.erb @@ -13,7 +13,10 @@ %>
- <%= render partial: "partials/tabs/tabs-thematic-area-database", locals: { tabs: @tabs } %> + <%= render partial: "partials/tabs/tabs-thematic-area-database", locals: { + config_search: @config_search_areas, + tabs: @tabs + } %>
diff --git a/app/views/partials/search/_protected-areas.html.erb b/app/views/partials/search/_protected-areas.html.erb index 03e981456..917dee65f 100644 --- a/app/views/partials/search/_protected-areas.html.erb +++ b/app/views/partials/search/_protected-areas.html.erb @@ -1,7 +1,7 @@
diff --git a/app/views/partials/tabs/_tabs-thematic-area-database.html.erb b/app/views/partials/tabs/_tabs-thematic-area-database.html.erb index 231777eaf..0368187d0 100644 --- a/app/views/partials/tabs/_tabs-thematic-area-database.html.erb +++ b/app/views/partials/tabs/_tabs-thematic-area-database.html.erb @@ -9,7 +9,7 @@
- <%= render "partials/search/protected-areas" %> + <%= render partial: "partials/search/protected-areas", locals: { config: config_search } %>
diff --git a/app/views/search_areas/index.html.erb b/app/views/search_areas/index.html.erb index 9f03bb8f6..f51397296 100644 --- a/app/views/search_areas/index.html.erb +++ b/app/views/search_areas/index.html.erb @@ -3,7 +3,7 @@
- <%= render partial: "partials/tabs/tabs-thematic-area-database", locals: { tabs: @tabs } %> + <%= render partial: "partials/tabs/tabs-thematic-area-database", locals: { + config_search: @config_search_areas, + tabs: @tabs + } %>
diff --git a/config/locales/global/en.yml b/config/locales/global/en.yml index 6b576fb69..95a467a78 100644 --- a/config/locales/global/en.yml +++ b/config/locales/global/en.yml @@ -24,7 +24,8 @@ en: email: "Email: %{email}" visit: "Visit: %{link}" placeholder: - search-oecms: Search for OECMs... + search-oecm-wdpa: Search for a protected area or OECM... + search-oecm: Search for an OECM... search-wdpa: Search for a protected area... search-site: Search... search: From 0f2fc9cfa5ecd7b2f58cce977c7ee3bbd2812d11 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Tue, 5 May 2020 12:03:26 +0100 Subject: [PATCH 002/114] Fix up missing variable --- app/controllers/search_areas_controller.rb | 5 +++++ app/controllers/search_wdpa_controller.rb | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_areas_controller.rb b/app/controllers/search_areas_controller.rb index c3a15cab1..f512a3226 100644 --- a/app/controllers/search_areas_controller.rb +++ b/app/controllers/search_areas_controller.rb @@ -10,6 +10,11 @@ class SearchAreasController < ApplicationController before_action :load_filters, only: [:index, :search_results] def index + @config_search_areas = { + id: 'all', + placeholder: I18n.t('global.placeholder.search-oecm-wdpa') + }.to_json + @query = search_params[:search_term] end diff --git a/app/controllers/search_wdpa_controller.rb b/app/controllers/search_wdpa_controller.rb index ece14a1ca..98ceef6ae 100644 --- a/app/controllers/search_wdpa_controller.rb +++ b/app/controllers/search_wdpa_controller.rb @@ -9,7 +9,7 @@ class SearchWdpaController < ApplicationController def index @config_search_areas = { id: 'all', - placeholder: I18n.t('global.placeholder.search-wdpa') + placeholder: I18n.t('global.placeholder.search-oecm-wdpa') }.to_json @results = Search::AreasSerializer.new(@search).serialize From 53dd82f439e5bcfae8ec2bdc604490b0154c9ca4 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 7 May 2020 13:14:02 +0100 Subject: [PATCH 003/114] Refactor autocomplete to use ElasticSearch and without limit --- lib/modules/autocompletion.rb | 37 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/modules/autocompletion.rb b/lib/modules/autocompletion.rb index 40ffa3b91..aa3f5fe5b 100644 --- a/lib/modules/autocompletion.rb +++ b/lib/modules/autocompletion.rb @@ -1,34 +1,29 @@ module Autocompletion - AUTOCOMPLETION_KEY = "autocompletion" + AUTOCOMPLETION_KEY = "autocompletion".freeze + IDENTIFIER_FIELDS = { + 'protected_area' => :wdpa_id, + 'country' => :iso_3 + }.freeze - def self.lookup term - limit = {limit: [0, 5]} + def self.lookup(term, search_index=Search::PA_INDEX) + search = Search.search(term.downcase, {}, search_index) - $redis.zrangebylex(AUTOCOMPLETION_KEY, "(#{term.downcase}", "+", limit).map do |result| - result = result.split("||") + results = search.results.objects.values.compact.flatten - term = result[0] - name = result[1] - type = result[2] - identifier = result[3] + results.map do |result| + name = result.name + type = result.class.name.underscore + identifier = result.send(identifier_field(type)) - url = type == 'protected_area' ? "/#{identifier}" : "/country/#{identifier}" + url = type == 'country' ? "/country/#{identifier}" : "/#{identifier}" { title: name, url: url } end end - def self.populate - ProtectedArea.pluck(:name, :wdpa_id).each do |name, wdpa_id| - $redis.zadd(AUTOCOMPLETION_KEY, 0, "#{name.downcase}||#{name}||protected_area||#{wdpa_id}") - end - - Country.pluck(:name, :iso).each do |name, iso| - $redis.zadd(AUTOCOMPLETION_KEY, 0, "#{name.downcase}||#{name}||country||#{iso}") - end - end + private - def self.drop - $redis.del(AUTOCOMPLETION_KEY) + def self.identifier_field(type) + IDENTIFIER_FIELDS[type] || :id end end From e5862750f14e3f8471eb66785527c11f1e4bcf6f Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Fri, 22 May 2020 11:09:07 +0100 Subject: [PATCH 004/114] Start to refactor the search so that it works with 1 set of results rather than an Array of results grouped by geo type --- app/controllers/concerns/filterable.rb | 24 ++++++++-------- app/controllers/search_areas_controller.rb | 8 ++++++ .../components/search/SearchAreas.vue | 21 ++++++++++---- .../components/search/SearchAreasResults.vue | 28 +++++++++---------- ...eoType.vue => SearchAreasResultsItems.vue} | 20 ++++++------- app/javascript/components/tabs/TabsFake.vue | 2 +- app/serializers/search/areas_serializer.rb | 4 +-- app/views/search/index.html.erb | 4 +-- app/views/search_areas/index.html.erb | 9 +++--- config/deploy/staging.rb | 2 +- config/locales/en.yml | 8 +----- config/locales/global/en.yml | 26 ----------------- config/locales/search/en.yml | 27 ++++++++++++++++++ 13 files changed, 98 insertions(+), 85 deletions(-) rename app/javascript/components/search/{SearchAreasGeoType.vue => SearchAreasResultsItems.vue} (95%) create mode 100644 config/locales/search/en.yml diff --git a/app/controllers/concerns/filterable.rb b/app/controllers/concerns/filterable.rb index 6a516b86a..f7d7d2d7b 100644 --- a/app/controllers/concerns/filterable.rb +++ b/app/controllers/concerns/filterable.rb @@ -16,15 +16,15 @@ def load_filters @filter_groups = [ { - title: I18n.t('global.search.view-by'), + title: I18n.t('search.view-by'), filters: [ { id: 'geo_type', name: 'geo_type', options: [ - { id: 'all', title: I18n.t('global.search.view-group-geo-type.options')[0] }, - { id: 'regions', title: I18n.t('global.search.view-group-geo-type.options')[1] }, - { id: 'countries', title: I18n.t('global.search.view-group-geo-type.options')[2] }, + { id: 'all', title: I18n.t('search.view-group-geo-type.options')[0] }, + { id: 'regions', title: I18n.t('search.view-group-geo-type.options')[1] }, + { id: 'countries', title: I18n.t('search.view-group-geo-type.options')[2] }, { id: 'sites', title: I18n.t('global.area-types.wdpa') } ## OR I18n.t('global.area-types.oecm') ], type: 'radio' @@ -32,35 +32,35 @@ def load_filters ] }, { - title: I18n.t('global.search.filter-by'), + title: I18n.t('search.filter-by'), filters: [ { id: 'is_type', name: 'is_type', options: [ - { id: 'all', title: I18n.t('global.search.filter-group-type.options')[0] }, - { id: 'terrestrial', title: I18n.t('global.search.filter-group-type.options')[1] }, - { id: 'marine', title: I18n.t('global.search.filter-group-type.options')[2] } + { id: 'all', title: I18n.t('search.filter-group-type.options')[0] }, + { id: 'terrestrial', title: I18n.t('search.filter-group-type.options')[1] }, + { id: 'marine', title: I18n.t('search.filter-group-type.options')[2] } ], - title: I18n.t('global.search.filter-group-type.title'), + title: I18n.t('search.filter-group-type.title'), type: 'radio' }, { id: 'designation', options: objs_for(Designation), - title: I18n.t('global.search.filter-group-designation.title'), + title: I18n.t('search.filter-group-designation.title'), type: 'checkbox' }, { id: 'governance', options: objs_for(Governance), - title: I18n.t('global.search.filter-group-governance.title'), + title: I18n.t('search.filter-group-governance.title'), type: 'checkbox' }, { id: 'iucn_category', options: objs_for(IucnCategory), - title: I18n.t('global.search.filter-group-iucn-category.title'), + title: I18n.t('search.filter-group-iucn-category.title'), type: 'checkbox' } ] diff --git a/app/controllers/search_areas_controller.rb b/app/controllers/search_areas_controller.rb index f512a3226..fbcf4fe43 100644 --- a/app/controllers/search_areas_controller.rb +++ b/app/controllers/search_areas_controller.rb @@ -15,6 +15,14 @@ def index placeholder: I18n.t('global.placeholder.search-oecm-wdpa') }.to_json + @tabs = [] + + I18n.t('search.geo-types').each_with_index.map do |type, i| + @tabs << { id: i, title: type } + end + + @tabs.to_json + @query = search_params[:search_term] end diff --git a/app/javascript/components/search/SearchAreas.vue b/app/javascript/components/search/SearchAreas.vue index 560684621..91a13cf86 100644 --- a/app/javascript/components/search/SearchAreas.vue +++ b/app/javascript/components/search/SearchAreas.vue @@ -27,7 +27,7 @@
@@ -35,12 +35,17 @@ class="search__filters" :filter-close-text="filterCloseText" :filter-groups="filterGroups" - :isActive="isFilterPaneActive" + :is-active="isFilterPaneActive" :title="textFilters" v-on:update:filter-group="updateFilters" v-on:toggle:filter-pane="toggleFilterPane" />
+ + - @@ -25,13 +23,13 @@ diff --git a/app/javascript/components/form-fields/RadioButtonsSearch.vue b/app/javascript/components/form-fields/RadioButtonSearch.vue similarity index 100% rename from app/javascript/components/form-fields/RadioButtonsSearch.vue rename to app/javascript/components/form-fields/RadioButtonSearch.vue diff --git a/app/javascript/components/search/SearchAreas.vue b/app/javascript/components/search/SearchAreas.vue index eccb78022..933149913 100644 --- a/app/javascript/components/search/SearchAreas.vue +++ b/app/javascript/components/search/SearchAreas.vue @@ -196,11 +196,13 @@ export default { params: { filters: this.activeFilterOptions, items_per_page: 9, + requested_page: 1, search_term: this.searchTerm, // geo_type: this.selectedTab } } + console.log('data', data.params.filters) this.axiosSetHeaders() axios.get(this.endpointSearch, data) diff --git a/app/serializers/search/filters_serializer.rb b/app/serializers/search/filters_serializer.rb index 464ba33af..5c9b78d93 100644 --- a/app/serializers/search/filters_serializer.rb +++ b/app/serializers/search/filters_serializer.rb @@ -56,7 +56,7 @@ def serialize } ], title: I18n.t('search.filter-group-geo-type.title'), - type: 'radio-search' + type: 'checkbox-search' }, { id: 'designation', From 53b3a50088aa9a2c0522f932004c028c79fad6dc Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Wed, 17 Jun 2020 16:10:41 +0100 Subject: [PATCH 032/114] Make tabs work again --- app/controllers/search_areas_controller.rb | 7 +++---- app/javascript/components/search/SearchAreas.vue | 2 +- app/serializers/search/areas_serializer.rb | 13 ++++--------- app/serializers/search/base_serializer.rb | 6 +++--- config/locales/search/en.yml | 7 +++---- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/controllers/search_areas_controller.rb b/app/controllers/search_areas_controller.rb index 61c3aac3d..1d8e617a2 100644 --- a/app/controllers/search_areas_controller.rb +++ b/app/controllers/search_areas_controller.rb @@ -7,6 +7,7 @@ class SearchAreasController < ApplicationController before_action :load_search, only: [:search_results] before_action :load_filters, only: [:index, :search_results] + TABS = %w(region country site).freeze def index placeholder = @db_type == 'all' ? 'oecm-wdpa' : @db_type @config_search_areas = { @@ -16,11 +17,9 @@ def index @tabs = [] - I18n.t('search.geo-types').each_with_index.map do |type, i| - @tabs << { id: "geo-type-#{i}", title: type } #FERDI update the ids here to what you need + TABS.each do |tab| + @tabs << { id: tab, title: I18n.t("search.geo-types.#{tab}") } end - - @tabs.to_json end def search_results diff --git a/app/javascript/components/search/SearchAreas.vue b/app/javascript/components/search/SearchAreas.vue index eccb78022..3b43a0bbe 100644 --- a/app/javascript/components/search/SearchAreas.vue +++ b/app/javascript/components/search/SearchAreas.vue @@ -197,7 +197,7 @@ export default { filters: this.activeFilterOptions, items_per_page: 9, search_term: this.searchTerm, - // geo_type: this.selectedTab + geo_type: this.selectedTab } } diff --git a/app/serializers/search/areas_serializer.rb b/app/serializers/search/areas_serializer.rb index 13452aaba..155eff6e3 100644 --- a/app/serializers/search/areas_serializer.rb +++ b/app/serializers/search/areas_serializer.rb @@ -7,12 +7,7 @@ def initialize(search, geo_type=nil) end def serialize - if @geo_type - areas = @geo_type == 'site' ? @results.protected_areas : paginate(@aggregations[@geo_type]) - return areas_ary(@geo_type, areas).to_json - end - - sites + send(@geo_type.pluralize) end private @@ -20,13 +15,13 @@ def serialize def regions _regions = @aggregations['region'] - geo_hash('region', _regions, _regions.length) + geo_hash('region', paginate(_regions), _regions.length) end def countries _countries = @aggregations['country'] - geo_hash('country', _countries, _countries.length) + geo_hash('country', paginate(_countries), _countries.length) end def sites @@ -39,7 +34,7 @@ def sites geo_hash('site', _sites, _total_count) end - def geo_hash(geo_type, areas, total=nil) + def geo_hash(geo_type, areas, total=0) areas = areas.present? ? areas.first(9) : [] geo_type_locale = geo_type == 'site' ? 'area-types.wdpa' : "geo-types.#{geo_type.pluralize}" { diff --git a/app/serializers/search/base_serializer.rb b/app/serializers/search/base_serializer.rb index 822f6f0ba..bf4646e22 100644 --- a/app/serializers/search/base_serializer.rb +++ b/app/serializers/search/base_serializer.rb @@ -19,11 +19,11 @@ def serialize private def paginate(items) - size = @search.options[:size] - page = @search.options[:page] + size = @search.options[:size] || 1 + page = @search.options[:page] || 1 offset = size * (page - 1) last_item = size * page - 1 - items[offset..last_item].presence || [] + items && items[offset..last_item].presence || [] end end diff --git a/config/locales/search/en.yml b/config/locales/search/en.yml index 4c7883dd5..2bfc302e5 100644 --- a/config/locales/search/en.yml +++ b/config/locales/search/en.yml @@ -30,10 +30,9 @@ en: - Terrestrial - Marine geo-types: - - All - - Regions - - Countries - - Individual Areas + region: Regions + country: Countries + site: Individual Areas map: Map protected-areas: Protected Areas results: results From e740b465a7d6d359f0c91664d19d53247674a949 Mon Sep 17 00:00:00 2001 From: stacytalbot Date: Wed, 17 Jun 2020 16:13:13 +0100 Subject: [PATCH 033/114] Work on styling the checkbox search filter --- app/assets/stylesheets/base/_base.scss | 4 ++ app/assets/stylesheets/base/_buttons.scss | 34 ++++++++++++++++- app/assets/stylesheets/base/mixins/_text.scss | 1 + app/assets/stylesheets/components/_tabs.scss | 38 +++++++++++++++---- .../stylesheets/components/form/_input.scss | 9 +++++ app/javascript/components/filters/vFilter.vue | 18 ++++----- .../components/form-fields/CheckboxSearch.vue | 5 ++- .../components/search/SearchAreas.vue | 2 +- app/javascript/components/tabs/TabsFake.vue | 2 +- 9 files changed, 90 insertions(+), 23 deletions(-) diff --git a/app/assets/stylesheets/base/_base.scss b/app/assets/stylesheets/base/_base.scss index 9a69eed57..0ef756389 100644 --- a/app/assets/stylesheets/base/_base.scss +++ b/app/assets/stylesheets/base/_base.scss @@ -42,6 +42,10 @@ h3 { &.h3-big-white { @include h-big; color: $white; } } + +h4 { + @include h4; +} p,a { color: inherit; diff --git a/app/assets/stylesheets/base/_buttons.scss b/app/assets/stylesheets/base/_buttons.scss index ffaa2bc04..e1ffcc106 100644 --- a/app/assets/stylesheets/base/_buttons.scss +++ b/app/assets/stylesheets/base/_buttons.scss @@ -16,7 +16,6 @@ $padding-medium: rem-calc(27); } @mixin button-basic { - @include responsive(font-size, rem-calc(16), rem-calc(18), rem-calc(18)); background-color: transparent; border: none; color: inherit; @@ -28,6 +27,10 @@ $padding-medium: rem-calc(27); &:hover { text-decoration: none; } } +@mixin button-font { + @include responsive(font-size, rem-calc(16), rem-calc(18), rem-calc(18)); +} + @mixin button-disabled { cursor: disabled; } @mixin button-height { @@ -37,7 +40,7 @@ $padding-medium: rem-calc(27); align-items: center; } -@mixin button-padding { +@mixin button-padding($size: default) { @include responsive(padding-right, $padding-small, $padding-medium, $padding-medium); @include responsive(padding-left, $padding-small, $padding-medium, $padding-medium); } @@ -53,6 +56,7 @@ $padding-medium: rem-calc(27); @mixin button-block ($bg: $purple, $text: $white) { @include button-basic; @include button-height; + @include button-font; @include button-padding; @include button-radius; background-color: $bg; @@ -61,6 +65,7 @@ $padding-medium: rem-calc(27); @mixin button-with-icon { @include button-basic; + @include button-font; @include flex; @include flex-v-center; @@ -74,6 +79,7 @@ $padding-medium: rem-calc(27); @mixin button-outline ($colour: $black) { @include button-basic; + @include button-font; @include button-height; @include button-padding; @include button-radius; @@ -95,6 +101,7 @@ $padding-medium: rem-calc(27); @mixin button-download-trigger { @include button-basic; + @include button-font; @include button-radius; @include flex; @include flex-center; @@ -146,6 +153,7 @@ $padding-medium: rem-calc(27); @mixin button-search { @include button-basic; + @include button-font; @include button-radius; @include flex-center; background-color: $primary; @@ -157,6 +165,28 @@ $padding-medium: rem-calc(27); } } +@mixin button-tab-rounded($size: default) { + @include button-basic; + border: solid transparent 1px; + border-radius: rem-calc(20); + + @if $size == 'small' { + font-size: rem-calc(14); + padding: rem-calc(6 16); + } @else { + @include text-tabs-fake; + padding: rem-calc(5 26); + } + + &:hover, + .active { border-color: $primary; } + + &.active { + background-color: $primary; + color: $white; + } +} + //-------------------------------------------------- // classes //-------------------------------------------------- diff --git a/app/assets/stylesheets/base/mixins/_text.scss b/app/assets/stylesheets/base/mixins/_text.scss index ae411456d..8b6b4578b 100644 --- a/app/assets/stylesheets/base/mixins/_text.scss +++ b/app/assets/stylesheets/base/mixins/_text.scss @@ -61,6 +61,7 @@ @mixin h4 { @include text-2; @include responsive(font-size, rem-calc(18), rem-calc(18), rem-calc(16)); + margin: 1.5em 0 .8em 0; } @mixin h-big { diff --git a/app/assets/stylesheets/components/_tabs.scss b/app/assets/stylesheets/components/_tabs.scss index c69e73274..a8c20b45b 100644 --- a/app/assets/stylesheets/components/_tabs.scss +++ b/app/assets/stylesheets/components/_tabs.scss @@ -5,7 +5,7 @@ //-------------------------------------------------- // mixins //-------------------------------------------------- -@mixin tab-trigger { +@mixin tab-trigger-underlined { @include text-tabs-fake; border-bottom: solid transparent 2px; cursor: pointer; @@ -42,25 +42,47 @@ } &__trigger { - @include tab-trigger; + @include tab-trigger-underlined; &.active { color: $primary; } } } } - &--fake { + &--rounded { @include flex; + @include flex-h-center; @include ul-unstyled; - @include responsive(flex-wrap, nowrap, nowrap, wrap); - @include responsive(overflow-x, scroll, scroll, initial); - @include responsive(margin, rem-calc(26 0), rem-calc(26 0 32 0), rem-calc(30 0 10 0)); + margin: rem-calc(26 0); + overflow-x: scroll; + + @include breakpoint($medium) { margin: rem-calc(26 0 32 0); } + + @include breakpoint($medium) { + @include flex-wrap; + margin: rem-calc(30 0 10 0); + overflow-x: initial; + } .tab { &__trigger { + @include button-tab-rounded; @include flex-no-shrink; - @include tab-trigger; - @include responsive(margin-bottom, 0, 0, rem-calc(10)); + margin: rem-calc(0 10); + } + } + } + + &--rounded-small { + @include ul-unstyled; + margin: rem-calc(0 0 10 0); + + .tab { + &__trigger { + @include button-tab-rounded(small); + margin: rem-calc(0 4); + + display: inline-block; } } } diff --git a/app/assets/stylesheets/components/form/_input.scss b/app/assets/stylesheets/components/form/_input.scss index 1da8d0e50..1a479d01e 100644 --- a/app/assets/stylesheets/components/form/_input.scss +++ b/app/assets/stylesheets/components/form/_input.scss @@ -2,4 +2,13 @@ input { @include input-basic; @include input-text; height: rem-calc(47); +} + +//-------------------------------------------------- +// classes +//-------------------------------------------------- +.input--search { + width: 100%; + + } \ No newline at end of file diff --git a/app/javascript/components/filters/vFilter.vue b/app/javascript/components/filters/vFilter.vue index 906633a0a..8e8a0c233 100644 --- a/app/javascript/components/filters/vFilter.vue +++ b/app/javascript/components/filters/vFilter.vue @@ -14,15 +14,6 @@ v-on:update:options="updateFilter" /> - -
+ +
diff --git a/app/javascript/components/form-fields/CheckboxSearch.vue b/app/javascript/components/form-fields/CheckboxSearch.vue index 1d74cb54d..1154120d1 100644 --- a/app/javascript/components/form-fields/CheckboxSearch.vue +++ b/app/javascript/components/form-fields/CheckboxSearch.vue @@ -2,17 +2,18 @@
-
+
diff --git a/app/javascript/components/tabs/TabsFake.vue b/app/javascript/components/tabs/TabsFake.vue index 9d507e55c..34a2ddcae 100644 --- a/app/javascript/components/tabs/TabsFake.vue +++ b/app/javascript/components/tabs/TabsFake.vue @@ -1,5 +1,5 @@ diff --git a/lib/modules/asset_generator.rb b/lib/modules/asset_generator.rb index bd33014dc..de09fb874 100644 --- a/lib/modules/asset_generator.rb +++ b/lib/modules/asset_generator.rb @@ -31,7 +31,7 @@ def self.mapbox_url geojson mapbox_config = Rails.application.secrets.mapbox access_token = mapbox_config[:access_token] || mapbox_config['access_token'] uri = URI(mapbox_config[:base_url] || mapbox_config['base_url']) - size = {y: 128, x: 256} + size = {y: 138, x: 304} raise AssetGenerationFailedError unless geojson.present? From e55222592b135e09a1d0ee804a5aa845a1f0572e Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Thu, 25 Jun 2020 17:08:58 +0100 Subject: [PATCH 084/114] Fetch images from CMS fragments --- app/controllers/application_controller.rb | 7 +++++++ app/models/comfy/cms/searchable_page.rb | 8 ++++++++ app/serializers/search/full_serializer.rb | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f5c702a8e..7eb99c2e2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,8 @@ class PageNotFound < StandardError; end; before_action :set_locale before_action :load_cms_content before_action :check_for_pdf + #Temporary fix for development. To test if it is required on staging/production + before_action :set_host_for_local_storage after_action :store_location def set_cms_site @@ -117,4 +119,9 @@ def store_location session[:previous_url] = request.fullpath end end + + def set_host_for_local_storage + Rails.application.routes.default_url_options[:host] = request.base_url if Rails.application.config.active_storage.service == :local + #ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local + end end diff --git a/app/models/comfy/cms/searchable_page.rb b/app/models/comfy/cms/searchable_page.rb index c45ab7e0b..23a8efa09 100644 --- a/app/models/comfy/cms/searchable_page.rb +++ b/app/models/comfy/cms/searchable_page.rb @@ -35,4 +35,12 @@ def summary fragment.content end + + # TODO Consider lazy loading + def image + fragment = self.fragments.find_by(identifier: 'image') + return '' unless fragment + + Rails.application.routes.url_helpers.rails_blob_path(fragment.attachments_blobs.first) + end end diff --git a/app/serializers/search/full_serializer.rb b/app/serializers/search/full_serializer.rb index a9edd8d59..af1ed6e1e 100644 --- a/app/serializers/search/full_serializer.rb +++ b/app/serializers/search/full_serializer.rb @@ -64,7 +64,7 @@ def image(obj) if obj.is_a?(ProtectedArea) ApplicationController.helpers.protected_area_cover(obj, with_tag: false) elsif obj.is_a?(Comfy::Cms::SearchablePage) - 'page_image' #TODO + obj.image else 'placeholder_image' #TODO end From 0ca319af90b8811e1fecfd91694af140f948e559 Mon Sep 17 00:00:00 2001 From: Jonathan Feist Date: Thu, 25 Jun 2020 19:26:10 +0100 Subject: [PATCH 085/114] Add custom models to import/export functionality of CMS --- .env.example | 1 + .../initializers/comfortable_mexican_sofa.rb | 65 +++++++++++++++++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 542983f36..f4c5284d5 100644 --- a/.env.example +++ b/.env.example @@ -31,3 +31,4 @@ API_COUNTRY_NAME_ATTRIBUTE=XXXXXXXXXX API_JRC_COUNTRY_AREA_ATTRIBUTE=XXXXXXXXXX API_JRC_TERR_AREA_ATTRIBUTE=XXXXXXXXXX +COMFY_CMS_INCLUDED_EXPORT_MODELS="HomeCarouselSlide CallToAction" diff --git a/config/initializers/comfortable_mexican_sofa.rb b/config/initializers/comfortable_mexican_sofa.rb index 7fd55170d..c24ee4734 100644 --- a/config/initializers/comfortable_mexican_sofa.rb +++ b/config/initializers/comfortable_mexican_sofa.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'cms_tags/date_not_null' require 'cms_tags/text_custom' # encoding: utf-8 @@ -37,10 +39,10 @@ # Sofa allows you to setup entire site from files. Database is updated with each # request (if necessary). Please note that database entries are destroyed if there's # no corresponding file. Fixtures are disabled by default. - #config.enable_fixtures = false + # config.enable_fixtures = false # Path where fixtures can be located. - #config.fixtures_path = File.expand_path('cms', Rails.root) + # config.fixtures_path = File.expand_path('cms', Rails.root) # Importing fixtures into Database # To load fixtures into the database just run this rake task: @@ -96,14 +98,13 @@ # Create thumbnails of all images uploaded to the CMS # - dropdownImage dimensions were calculated at thier largest in the desktop breakpoint - #config.upload_file_options[:styles] = { dropdownImage: '853x853>'} - + # config.upload_file_options[:styles] = { dropdownImage: '853x853>'} end # Default credentials for ComfortableMexicanSofa::AccessControl::AdminAuthentication # YOU REALLY WANT TO CHANGE THIS BEFORE PUTTING YOUR SITE LIVE -ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = ENV["COMFY_ADMIN_USERNAME"] -ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = ENV["COMFY_ADMIN_PASSWORD"] +ComfortableMexicanSofa::AccessControl::AdminAuthentication.username = ENV['COMFY_ADMIN_USERNAME'] +ComfortableMexicanSofa::AccessControl::AdminAuthentication.password = ENV['COMFY_ADMIN_PASSWORD'] # Uncomment this module and `config.admin_auth` above to use custom admin authentication # module ComfyAdminAuthentication @@ -125,3 +126,55 @@ # return true # end # end + +module ComfortableMexicanSofa + module ExtraModels + COMFY_CMS_INCLUDED_EXPORT_MODELS = ENV['COMFY_CMS_INCLUDED_EXPORT_MODELS'].split(' ') + end + + module Seeds + class Importer + old_import = instance_method(:import!) + + define_method(:import!) do |*args| + ActiveRecord::Base.transaction do + old_import.bind(self).call(*args) + + ExtraModels::COMFY_CMS_INCLUDED_EXPORT_MODELS.each do |model_name| + path = ::File.join(ComfortableMexicanSofa.config.seeds_path, from, model_name.underscore + '.json') + raise Error, "File for import: '#{path}' is not found" unless ::File.exist?(path) + + model_name.constantize.destroy_all + ::File.open(path, 'r') do |file| + ::JSON.load(file).each do |record| + model_name.constantize.create!(record) + end + end + message = "[CMS SEEDS] Imported Model \t #{model_name}" + ComfortableMexicanSofa.logger.info(message) + end + end + end + end + + class Exporter + old_export = instance_method(:export!) + + define_method(:export!) do |*args| + ActiveRecord::Base.transaction do + old_export.bind(self).call(*args) + + ExtraModels::COMFY_CMS_INCLUDED_EXPORT_MODELS.each do |model_name| + path = ::File.join(ComfortableMexicanSofa.config.seeds_path, from, model_name.underscore + '.json') + ::FileUtils.rm_rf(path) + ::File.open(path, 'w') do |file| + file.write(model_name.constantize.all.to_json) + end + message = "[CMS SEEDS] Exported Model \t #{model_name}" + ComfortableMexicanSofa.logger.info(message) + end + end + end + end + end +end From acd211a9716ac006db7ec5fa20f22620316922fe Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Fri, 26 Jun 2020 11:58:38 +0100 Subject: [PATCH 086/114] First draft for making the search match the term for countries and regions --- app/controllers/concerns/searchable.rb | 14 ++++++++++++-- app/models/region.rb | 2 +- app/serializers/search/areas_serializer.rb | 18 +++++++++--------- lib/modules/search.rb | 3 ++- lib/modules/search/index.rb | 3 +++ lib/modules/search/results.rb | 5 +++++ lib/modules/search/templates/mappings.json | 19 +++++++++++++++++-- 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/app/controllers/concerns/searchable.rb b/app/controllers/concerns/searchable.rb index 307686089..53682b902 100644 --- a/app/controllers/concerns/searchable.rb +++ b/app/controllers/concerns/searchable.rb @@ -29,9 +29,18 @@ def search_options options end + INDEX_BY_TYPE = { + 'site' => Search::PA_INDEX, + 'country' => Search::COUNTRY_INDEX, + 'region' => Search::REGION_INDEX, + 'all' => Search::DEFAULT_INDEX_NAME, + 'areas' => Search::PA_INDEX + }.freeze def search_index - is_area_category = parsed_filters && parsed_filters['ancestor'] == 'areas' - (controller_name.include?('area') || is_area_category) ? Search::PA_INDEX : Search::DEFAULT_INDEX_NAME + _index = INDEX_BY_TYPE[parsed_filters['ancestor']] if parsed_filters + return _index if _index + + INDEX_BY_TYPE[search_params[:geo_type]] || Search::DEFAULT_INDEX_NAME end DB_TYPES = %w(wdpa oecm all).freeze @@ -62,6 +71,7 @@ def load_search_from_query_string # def filters return '' unless search_params[:filters].present? + return '' if %w(country region).include?(search_params[:geo_type]) _filters = sanitise_filters _filters.to_hash.symbolize_keys.slice(*Search::ALLOWED_FILTERS) end diff --git a/app/models/region.rb b/app/models/region.rb index 26854683f..47d841e4e 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -102,7 +102,7 @@ def sources_per_jurisdiction def as_indexed_json options={} self.as_json( - only: [:id, :name] + only: [:id, :name, :iso] ) end diff --git a/app/serializers/search/areas_serializer.rb b/app/serializers/search/areas_serializer.rb index 837fdc29c..42ef887ed 100644 --- a/app/serializers/search/areas_serializer.rb +++ b/app/serializers/search/areas_serializer.rb @@ -13,13 +13,13 @@ def serialize private def regions - _regions = @aggregations['region'] + _regions = @results.regions || [] geo_hash('region', paginate(_regions), _regions.length) end def countries - _countries = @aggregations['country'] + _countries = @results.countries || [] geo_hash('country', paginate(_countries), _countries.length) end @@ -52,19 +52,19 @@ def areas_ary(geo_type, areas) def region_hash(region) { - title: region[:label], - totalAreas: "#{region[:count]} #{I18n.t('search.protected-areas')}", - url: region_path(iso: region[:identifier]) + title: region.name, + totalAreas: "#{region.protected_areas.count} #{I18n.t('search.protected-areas')}", + url: region_path(iso: region.iso) } end def country_hash(country) - _slug = slug(country[:label]) + _slug = slug(country.name) { countryFlag: ActionController::Base.helpers.image_url("flags/#{_slug}.svg"), - totalAreas: "#{country[:count]} #{I18n.t('search.protected-areas')}", - title: country[:label], - url: country_path(iso: country[:identifier]) + totalAreas: "#{country.protected_areas.count} #{I18n.t('search.protected-areas')}", + title: country.name, + url: country_path(iso: country.iso_3) } end diff --git a/lib/modules/search.rb b/lib/modules/search.rb index d50faf928..b1280a745 100644 --- a/lib/modules/search.rb +++ b/lib/modules/search.rb @@ -2,9 +2,10 @@ class Search CONFIGURATION_FILE = File.read(Rails.root.join('config', 'search.yml')).freeze ALLOWED_FILTERS = [:type, :country, :iucn_category, :designation, :region, :marine, :has_irreplaceability_info, :has_parcc_info, :governance, :is_green_list, :category, :ancestor, :is_oecm].freeze COUNTRY_INDEX = "countries_#{Rails.env}".freeze + REGION_INDEX = "regions_#{Rails.env}".freeze PA_INDEX = "protectedareas_#{Rails.env}".freeze CMS_INDEX = "cms_#{Rails.env}".freeze - DEFAULT_INDEX_NAME = [PA_INDEX, COUNTRY_INDEX, CMS_INDEX].join(',').freeze + DEFAULT_INDEX_NAME = [PA_INDEX, CMS_INDEX].join(',').freeze AREAS_INDEX_NAME = [PA_INDEX, COUNTRY_INDEX].join(',').freeze attr_reader :search_term, :options diff --git a/lib/modules/search/index.rb b/lib/modules/search/index.rb index 62695913e..47d8d2db3 100644 --- a/lib/modules/search/index.rb +++ b/lib/modules/search/index.rb @@ -12,10 +12,13 @@ def self.create ]) + region_index = Search::Index.new Search::REGION_INDEX, Region.without_geometry.all + region_index.create country_index = Search::Index.new Search::COUNTRY_INDEX, Country.without_geometry.all country_index.create pa_index = Search::Index.new Search::PA_INDEX, pa_relation pa_index.create + region_index.index country_index.index pa_index.index end diff --git a/lib/modules/search/results.rb b/lib/modules/search/results.rb index 56b89cc68..4ede43ab5 100644 --- a/lib/modules/search/results.rb +++ b/lib/modules/search/results.rb @@ -2,6 +2,7 @@ class Search::Results def initialize query_results @query_results = query_results @type_index_map = { + Search::REGION_INDEX => "Region", Search::COUNTRY_INDEX => "Country", Search::PA_INDEX => "ProtectedArea", Search::CMS_INDEX => "Comfy::Cms::SearchablePage" @@ -46,6 +47,10 @@ def countries @countries ||= objects[@type_index_map[Search::COUNTRY_INDEX]] end + def regions + @regions ||= objects[@type_index_map[Search::REGION_INDEX]] + end + def cms_pages @cms_pages ||= objects[@type_index_map[Search::CMS_INDEX]] end diff --git a/lib/modules/search/templates/mappings.json b/lib/modules/search/templates/mappings.json index 28dab8c97..582c11344 100644 --- a/lib/modules/search/templates/mappings.json +++ b/lib/modules/search/templates/mappings.json @@ -115,7 +115,6 @@ "type": "text", "analyzer": "english" }, - "countries_for_index": { "type": "nested", "properties": { @@ -143,7 +142,23 @@ } } } - }, + }, + "regions_for_index": { + "type": "nested", + "properties": { + "id": { + "type": "integer" + }, + "name": { + "type": "text", + "analyzer": "english" + }, + "iso": { + "type": "keyword", + "normalizer": "lc_normalizer" + } + } + }, "iucn_category": { "type": "nested", "properties": { From c5d8d9c16d4d5d7dc33cad26eafca70a73352cd8 Mon Sep 17 00:00:00 2001 From: Jonathan Feist Date: Mon, 29 Jun 2020 16:37:34 +0100 Subject: [PATCH 087/114] Add description exception when COMFY_CMS_INCLUDED_EXPORT_MODELS is missing from .env --- config/initializers/comfortable_mexican_sofa.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config/initializers/comfortable_mexican_sofa.rb b/config/initializers/comfortable_mexican_sofa.rb index c24ee4734..0089e8ea1 100644 --- a/config/initializers/comfortable_mexican_sofa.rb +++ b/config/initializers/comfortable_mexican_sofa.rb @@ -129,7 +129,12 @@ module ComfortableMexicanSofa module ExtraModels - COMFY_CMS_INCLUDED_EXPORT_MODELS = ENV['COMFY_CMS_INCLUDED_EXPORT_MODELS'].split(' ') + begin + COMFY_CMS_INCLUDED_EXPORT_MODELS = ENV['COMFY_CMS_INCLUDED_EXPORT_MODELS'].split(' ') + rescue NoMethodError + raise $ERROR_INFO, "COMFY_CMS_INCLUDED_EXPORT_MODELS has not been set in .env - see .env.example: #{$ERROR_INFO}", + $ERROR_INFO.backtrace + end end module Seeds From 7823acaa307369164b78e6cb34e6f8468d2c474f Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Mon, 29 Jun 2020 16:40:12 +0100 Subject: [PATCH 088/114] Update CMS seeds on the db branch --- db | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db b/db index 0ed9a7a1f..39040eac8 160000 --- a/db +++ b/db @@ -1 +1 @@ -Subproject commit 0ed9a7a1fef07d61561263d50c7709779dd4b564 +Subproject commit 39040eac8869cf6833e0858b04d0f7f8e0d468d2 From 972e7d261cbaa78bf828afd0a04ea39c52fce2c5 Mon Sep 17 00:00:00 2001 From: Stacy Talbot Date: Mon, 6 Jul 2020 17:03:32 +0100 Subject: [PATCH 089/114] Add placeholder image for search results --- .../cards/cards/_cards-articles.scss | 12 +---- .../cards/_cards-search-results-areas.scss | 10 ++++- .../cards/cards/_cards-search-results.scss | 8 +++- app/assets/stylesheets/helpers/_helpers.scss | 1 + app/assets/stylesheets/helpers/_images.scss | 25 +++++++++++ .../components/card/CardSearchResult.vue | 4 ++ .../components/card/CardSearchResultArea.vue | 44 ++++++++++--------- 7 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 app/assets/stylesheets/helpers/_images.scss diff --git a/app/assets/stylesheets/components/cards/cards/_cards-articles.scss b/app/assets/stylesheets/components/cards/cards/_cards-articles.scss index 61f3d666a..a546c5915 100644 --- a/app/assets/stylesheets/components/cards/cards/_cards-articles.scss +++ b/app/assets/stylesheets/components/cards/cards/_cards-articles.scss @@ -28,15 +28,7 @@ &__summary { margin: 0 } &__image { - @include flex-center; - background-color: $grey-light; - background-position: center; - background-size: cover; - width: 100%; height: rem-calc(265); - } - - &__icon { - @include icon-placeholder-image; + @include image-placeholder(); } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/app/assets/stylesheets/components/cards/cards/_cards-search-results-areas.scss b/app/assets/stylesheets/components/cards/cards/_cards-search-results-areas.scss index 2b4831a3c..bf00e2ae6 100644 --- a/app/assets/stylesheets/components/cards/cards/_cards-search-results-areas.scss +++ b/app/assets/stylesheets/components/cards/cards/_cards-search-results-areas.scss @@ -2,6 +2,8 @@ // variables //-------------------------------------------------- $card-search-results-areas-flag-size: rem-calc(60); +$card-search-results-areas-width: 100%; +$card-search-results-areas-height: rem-calc(155); //-------------------------------------------------- // mixins @@ -44,7 +46,13 @@ $card-search-results-areas-flag-size: rem-calc(60); } &__image { - width: 100%; height: auto; + background-position: center; + background-size: cover; + width: $card-search-results-areas-width; height: $card-search-results-areas-height; + } + + &__image-placeholder { + @include image-placeholder($card-search-results-areas-width, $card-search-results-areas-height); } &__title { diff --git a/app/assets/stylesheets/components/cards/cards/_cards-search-results.scss b/app/assets/stylesheets/components/cards/cards/_cards-search-results.scss index 33d6acdd9..c488d18c9 100644 --- a/app/assets/stylesheets/components/cards/cards/_cards-search-results.scss +++ b/app/assets/stylesheets/components/cards/cards/_cards-search-results.scss @@ -2,6 +2,7 @@ // variables //-------------------------------------------------- $search-results-image-width: rem-calc(165); +$search-results-image-height: rem-calc(130); //-------------------------------------------------- // classes //-------------------------------------------------- @@ -28,14 +29,17 @@ $search-results-image-width: rem-calc(165); } &__image { - background-color: $grey-light; background-position: center; background-size: cover; - width: $search-results-image-width; height: rem-calc(130); + width: $search-results-image-width; height: $search-results-image-height; display: none; @include breakpoint($small) { display: block; } } + + &__image-placeholder { + @include image-placeholder($search-results-image-width, $search-results-image-height); + } } } \ No newline at end of file diff --git a/app/assets/stylesheets/helpers/_helpers.scss b/app/assets/stylesheets/helpers/_helpers.scss index 70d2e230a..9c6bb65c6 100644 --- a/app/assets/stylesheets/helpers/_helpers.scss +++ b/app/assets/stylesheets/helpers/_helpers.scss @@ -2,6 +2,7 @@ @import './background'; @import './border-and-shadows'; @import './form-fields'; +@import './images'; @mixin limit_lines($number, $line-height: 1.25) { overflow-y: hidden; diff --git a/app/assets/stylesheets/helpers/_images.scss b/app/assets/stylesheets/helpers/_images.scss new file mode 100644 index 000000000..923d196fd --- /dev/null +++ b/app/assets/stylesheets/helpers/_images.scss @@ -0,0 +1,25 @@ +//-------------------------------------------------- +// variables +//-------------------------------------------------- + + +//-------------------------------------------------- +// mixins +//-------------------------------------------------- +@mixin image-placeholder($width: 100%, $height: rem-calc(265)) { + @include flex-center; + background-color: $grey-light; + background-position: center; + background-size: cover; + width: $width; height: $height; + + &::after { + @include icon-placeholder-image; + width: 30%; + content: ''; + } +} + +//-------------------------------------------------- +// classes +//-------------------------------------------------- diff --git a/app/javascript/components/card/CardSearchResult.vue b/app/javascript/components/card/CardSearchResult.vue index 6bcb28fc9..aea73de59 100644 --- a/app/javascript/components/card/CardSearchResult.vue +++ b/app/javascript/components/card/CardSearchResult.vue @@ -23,6 +23,10 @@ class="card__image" :style="{ backgroundImage: `url(${image})` }" /> +
diff --git a/app/javascript/components/card/CardSearchResultArea.vue b/app/javascript/components/card/CardSearchResultArea.vue index b77f22867..453ed0a3a 100644 --- a/app/javascript/components/card/CardSearchResultArea.vue +++ b/app/javascript/components/card/CardSearchResultArea.vue @@ -1,26 +1,30 @@