diff --git a/.gitignore b/.gitignore index 03b6b8b..0a6875c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # Ignore bundler config. /.bundle +vendor/bundle/**/*.* # Ignore the default SQLite database. /db/*.sqlite3* diff --git a/app/helpers/suit_form_builder.rb b/app/helpers/suit_form_builder.rb index 2ef7e1e..1ea2617 100644 --- a/app/helpers/suit_form_builder.rb +++ b/app/helpers/suit_form_builder.rb @@ -10,9 +10,9 @@ def form_field(field, options = {}, &block) css_classes << 'FormField--required' if required css_classes << 'is-error' if field_errors.any? css_classes << options[:class_names] - # rubocop:disable HelperInstanceVariable - @template.content_tag :div, class: css_classes, &block - # rubocop:enable HelperInstanceVariable + # rubocop:disable Rails/HelperInstanceVariable + @template.tag.div(class: css_classes, &block) + # rubocop:enable Rails/HelperInstanceVariable end def label(method, text = nil, options = {}) @@ -41,9 +41,9 @@ def check_box(attribute, options = {}, checked_value = '1', unchecked_value = '0 end label(attribute, class: 'FormField-check FormField-check--checkbox') do super(attribute, options.reverse_merge(class: 'FormField-checkInput'), checked_value, unchecked_value) + - # rubocop:disable HelperInstanceVariable - @template.content_tag(:span, label_text, class: 'FormField-checkLabel') - # rubocop:enable HelperInstanceVariable + # rubocop:disable Rails/HelperInstanceVariable + @template.tag.span(label_text, class: 'FormField-checkLabel') + # rubocop:enable Rails/HelperInstanceVariable end end diff --git a/app/models/group_website.rb b/app/models/group_website.rb index fe7bfcd..6c9cf14 100644 --- a/app/models/group_website.rb +++ b/app/models/group_website.rb @@ -2,7 +2,7 @@ class GroupWebsite < ApplicationRecord belongs_to :group - validates :url, format: URI.regexp(%w[http https]) + validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]) include Website delegate :name, prefix: true, to: :group end diff --git a/app/models/initiative_website.rb b/app/models/initiative_website.rb index abf5472..dc1b405 100644 --- a/app/models/initiative_website.rb +++ b/app/models/initiative_website.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class InitiativeWebsite < ApplicationRecord - validates :url, format: URI.regexp(%w[http https]) + validates :url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]) include Website belongs_to :initiative diff --git a/app/models/public_initiative.rb b/app/models/public_initiative.rb index 30ab8c0..0bb89df 100644 --- a/app/models/public_initiative.rb +++ b/app/models/public_initiative.rb @@ -3,7 +3,8 @@ # The publicly available data of an initiative class PublicInitiative include ActionView::Helpers::DateHelper - delegate :name, + delegate :id, + :name, :description_what, :description_how, :description_further_information, @@ -70,7 +71,7 @@ def websites end def last_updated - time_ago_in_words(timestamp) + ' ago' + "#{time_ago_in_words(timestamp)} ago" end def href @@ -81,6 +82,7 @@ def href # rubocop:disable Metrics/AbcSize def as_json(_options = {}) { + 'id': id, 'name': name, 'description_what': description_what, 'description_how': description_how, diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index d857803..9644b9e 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,4 +1,4 @@ -<%= javascript_packs_with_chunks_tag 'explore_tabs', 'data-turbolinks-track': 'reload' %> +<%= javascript_packs_with_chunks_tag 'home', 'data-turbolinks-track': 'reload' %>

We share community-based projects that work towards a Carbon Neutral Stroud District by 2030 and connect groups organising them.

Share knowledge. Enable Change

@@ -16,13 +16,9 @@ Or -
+
-
@@ -75,7 +71,7 @@ <% @initiatives.each do |initiative| %> - + <%= link_to initiative.name, initiative_path(initiative) %> <%= initiative.location %> <%= initiative.status_name %> diff --git a/frontend/packs/explore_tabs.js b/frontend/packs/explore_tabs.js deleted file mode 100644 index 5ef216c..0000000 --- a/frontend/packs/explore_tabs.js +++ /dev/null @@ -1,23 +0,0 @@ -window.addEventListener("load", function() { - document.querySelectorAll(".Explore-tab").forEach(el => { - el.addEventListener("click", e => { - e.preventDefault(); - - focusTab(el); - }); - }); -}); -function focusTab(tab) { - const name = tab.getAttribute("data-content"); - document.querySelectorAll(".Explore-tab").forEach(el => { - el.classList.remove("Explore-tab_selected"); - }); - document.querySelectorAll(".Tab").forEach(el => { - el.classList.remove("Explore-tab_displayed"); - }); - tab.classList.add("Explore-tab_selected"); - document - .querySelector(`[data-content=${name}-tab]`) - .classList.add("Explore-tab_displayed"); - return false; -} diff --git a/frontend/packs/home.js b/frontend/packs/home.js new file mode 100644 index 0000000..250f9f6 --- /dev/null +++ b/frontend/packs/home.js @@ -0,0 +1,80 @@ +function focusTab(tab) { + const name = tab.getAttribute("data-content"); + document.querySelectorAll(".Explore-tab").forEach(el => { + el.classList.remove("Explore-tab_selected"); + }); + document.querySelectorAll(".Tab").forEach(el => { + el.classList.remove("Explore-tab_displayed"); + }); + tab.classList.add("Explore-tab_selected"); + document + .querySelector(`[data-content=${name}-tab]`) + .classList.add("Explore-tab_displayed"); + return false; +} + +window.addEventListener("load", function() { + document.querySelectorAll(".Explore-tab").forEach(el => { + el.addEventListener("click", e => { + e.preventDefault(); + + focusTab(el); + }); + }); +}); + +window.addEventListener("load", () => { + document + .querySelector("#search") + .addEventListener("submit", e => e.preventDefault()); + const initiatives = JSON.parse( + document.getElementById("map_data_json").innerText + ).initiatives; + const searchStrings = {}; + initiatives.forEach(initiative => { + const initiativeString = Object.values(initiative) + .map(value => { + if (value != null && typeof value == "object") { + Object.values(value) + .toString() + .toLowerCase(); + } else { + return value; + } + }) + .toString() + .toLowerCase(); + searchStrings[initiative.id] = initiativeString; + }); + + document + .querySelector("[type=search][name=q]") + .addEventListener("input", e => { + focusTab(document.querySelector("[data-content=initiatives]")); + const search = e.target.value.toLowerCase().split(" "); + const matches = []; + + for (const initiativeId in searchStrings) { + const initiativeData = searchStrings[initiativeId]; + + const partialMatch = []; + search.forEach(item => { + if (initiativeData.includes(item)) { + partialMatch.push(initiativeId); + } + }); + if (partialMatch.length == search.length) { + matches.push(initiativeId); + } + } + + document.querySelectorAll(".Initiative").forEach(initiativeEl => { + initiativeEl.classList.add("u-hidden"); + }); + matches.forEach(initiativeId => { + document + .querySelector(`[data-content=initiative_${initiativeId}]`) + .classList.remove("u-hidden"); + }); + }); +}); diff --git a/frontend/styles/base/base.css b/frontend/styles/base/base.css index 3bf1991..f6779bb 100644 --- a/frontend/styles/base/base.css +++ b/frontend/styles/base/base.css @@ -70,3 +70,7 @@ textarea { justify-content: center; width: 37px; } + +.u-hidden { + display: none; +}