This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
forked from geeksforsocialchange/PlaceCal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve SitesNeighbourhoods selector (geeksforsocialchange#887)
* Add select2 to primary neighbourhoods form * Add select2 + cocoon to secondary neighbourhoods form * Memoize parent_name field in Neighbourhoods * Give neighbourhoods more context * Add try/catch block to datatable.js to stop errors appearing on pages that do not contain datatables * Remove filtering of primary id from options_for_sites_neighbourhoods * Correct Sites behaviours file to remove primary neighbourhood from form field input * Fix CSS on Cocoon * Buttons: Red. Descriptions: Added Co-authored-by: Dr Kim Foale <[email protected]>
- Loading branch information
1 parent
6273272
commit 392fb42
Showing
16 changed files
with
147 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module SitesHelper | ||
def options_for_sites_neighbourhoods | ||
# Remove the primary neighbourhood from the list | ||
@all_neighbourhoods.filter { |e| e.name != '' } | ||
.collect { |e| { name: e.contextual_name, id: e.id } } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
jQuery.extend(Behaviors, { | ||
site: { | ||
form: { | ||
init: function() { | ||
// If the sites neighbourhood's relation_type is primary, it generates a label | ||
// with the class 'cocoon_delete-this'. This allows us to remove it from the form | ||
// so it does not submit a primary relation as being a secondary one or remove it | ||
$('.cocoon_delete-this').parents('.nested-fields').remove(); | ||
|
||
// Attach select2 to the current select2 nodes | ||
$('.select2').each(function () { $(this).select2({ multiple: false }); }); | ||
|
||
// Attach select2 to all future select2 nodes | ||
$('.sites_neighbourhoods').bind('cocoon:after-insert', function (_, element) { | ||
$('.select2', element).select2({ multiple: false }); | ||
}); | ||
} | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/views/admin/sites/_sites_neighbourhood_fields.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<fieldset class="input-group nested-fields p-0"> | ||
<%# The style width setting here is applied to dynamically created elements, we do not know why. %> | ||
<%# TODO: Fix the dynamic styling so that width does not get applied, so we can remove this smell %> | ||
<%= f.input :neighbourhood_id, collection: options_for_sites_neighbourhoods, include_blank: false, | ||
value_method: ->(obj) { obj[:id] }, | ||
label_method: ->(obj) { obj[:name] }, | ||
input_html: { class: 'form-control select2', style: "width: 599.8px;" }, | ||
label: '', label_html: { hidden: true } %> | ||
|
||
<%# This label causes behaviours.site.js to remove the association from the form %> | ||
<%= f.label :ignore, class: 'cocoon_delete-this' if f.object.relation_type == 'Primary' %> | ||
<div class="input-group-append p-0"> | ||
<%= f.hidden_field :relation_type, value: 'Secondary' %> | ||
<%= link_to_remove_association 'Remove', f, class: "pl-2 pt-1 text-danger" %> | ||
</div> | ||
</fieldset> |
7 changes: 7 additions & 0 deletions
7
db/migrate/20220125175817_add_parent_name_field_to_neighbourhoods.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddParentNameFieldToNeighbourhoods < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :neighbourhoods, :parent_name, :string | ||
|
||
Neighbourhood.find_each(&:save) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -910,6 +910,13 @@ | |
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210" | ||
integrity sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw== | ||
|
||
"@nathanvda/cocoon@^1.2.14": | ||
version "1.2.14" | ||
resolved "https://registry.yarnpkg.com/@nathanvda/cocoon/-/cocoon-1.2.14.tgz#aaea910e4b9c0d28d5bdcb7f3743617db46b09af" | ||
integrity sha512-WcEt2vVp50de2i7rkD4O+96O1iMtMIcTBNGPocrHfcmHDujKOngoLHFF8Ektgoh8PjwFAJMxx8WyGv0BtKTjxQ== | ||
dependencies: | ||
jquery "^3.3.1" | ||
|
||
"@nodelib/[email protected]": | ||
version "2.1.5" | ||
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" | ||
|
@@ -4033,7 +4040,7 @@ jest-worker@^26.5.0: | |
merge-stream "^2.0.0" | ||
supports-color "^7.0.0" | ||
|
||
jquery@>=1.7, jquery@^3.4.1: | ||
jquery@>=1.7, jquery@^3.3.1, jquery@^3.4.1: | ||
version "3.6.0" | ||
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.6.0.tgz#c72a09f15c1bdce142f49dbf1170bdf8adac2470" | ||
integrity sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw== | ||
|