-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Datatables gem, yarn package and CSS file - Add code in packs.admin.js - Add Datatables partial and inheritable logic (mountain_view seems unhappy with ajax in webpacker) - Update controller logic and do some optimisation - Migrate Users, Neighbourhoods and Partners indexes to Datatables - Update Neighbourhood edit page to reflect new logic - Update webpack-dev-server, yarn versions, and CI build target - Update README Bonus: Fixes #806, #868, #861, #821 Co-authored-by: Dr Kim Foale <kim@gfsc.studio>
- Loading branch information
1 parent
6bfda4b
commit 0bb508c
Showing
35 changed files
with
1,376 additions
and
947 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
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
Empty file.
Empty file.
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
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,13 @@ | ||
class Datatable < AjaxDatatablesRails::ActiveRecord | ||
extend Forwardable | ||
|
||
def_delegator :@view, :link_to | ||
def_delegator :@view, :edit_admin_neighbourhood_path | ||
def_delegator :@view, :edit_admin_user_path | ||
def_delegator :@view, :edit_admin_partner_path | ||
|
||
def initialize(params, opts = {}) | ||
@view = opts[:view_context] | ||
super | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class NeighbourhoodDatatable < Datatable | ||
def view_columns | ||
# Declare strings in this format: ModelName.column_name | ||
# or in aliased_join_table.column_name format | ||
@view_columns ||= { | ||
id: { source: 'Neighbourhood.id', cond: :eq }, | ||
name: { source: 'Neighbourhood.name' }, | ||
unit_name: { source: 'Neighbourhood.unit_name' }, | ||
unit_code_key: { source: 'Neighbourhood.unit_code_key' }, | ||
unit_code_value: { source: 'Neighbourhood.unit_code_value' }, | ||
} | ||
end | ||
|
||
def data | ||
records.map do |record| | ||
{ | ||
id: link_to(record.id, edit_admin_neighbourhood_path(record)), | ||
name: record.name, | ||
unit_name: record.unit_name, | ||
unit_code_key: record.unit_code_key, | ||
unit_code_value: record.unit_code_value, | ||
# county: record.county, | ||
# district: record.district, | ||
# region: record.region, | ||
# country: record.country | ||
} | ||
end | ||
end | ||
|
||
def get_raw_records | ||
# insert query here | ||
# Neighbourhood.all | ||
options[:neighbourhoods] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class PartnerDatatable < Datatable | ||
def view_columns | ||
# Declare strings in this format: ModelName.column_name | ||
# or in aliased_join_table.column_name format | ||
@view_columns ||= { | ||
id: { source: 'Partner.id', cond: :eq }, | ||
name: { source: 'Partner.name' }, | ||
slug: { source: 'Partner.slug' }, | ||
address: { source: 'Partner.address'} | ||
} | ||
end | ||
|
||
def data | ||
records.map do |record| | ||
{ | ||
id: link_to(record.id, edit_admin_partner_path(record)), | ||
name: link_to(record.name, edit_admin_partner_path(record)), | ||
slug: link_to(record.slug, edit_admin_partner_path(record)), | ||
address: record.address | ||
} | ||
end | ||
end | ||
|
||
def get_raw_records | ||
# insert query here | ||
# Partner.all | ||
options[:partners] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class UserDatatable < Datatable | ||
def view_columns | ||
# Declare strings in this format: ModelName.column_name | ||
# or in aliased_join_table.column_name format | ||
@view_columns ||= { | ||
id: { source: 'User.id', cond: :eq }, | ||
first_name: { source: 'User.first_name' }, | ||
last_name: { source: 'User.last_name' }, | ||
admin_roles: { source: 'User.admin_roles' }, | ||
email: { source: 'User.email' }, | ||
} | ||
end | ||
|
||
def data | ||
records.map do |record| | ||
{ | ||
id: link_to(record.id, edit_admin_user_path(record)), | ||
first_name: link_to(record.first_name, edit_admin_user_path(record)), | ||
last_name: link_to(record.last_name, edit_admin_user_path(record)), | ||
admin_roles: record.admin_roles, | ||
email: record.email, | ||
} | ||
end | ||
end | ||
|
||
def get_raw_records | ||
# insert query here | ||
# User.all | ||
options[:users] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
require("cocoon") | ||
require("select2") | ||
require("datatables.net-bs4") | ||
|
||
import 'bootstrap' | ||
import 'vue' | ||
import 'vue-turbolinks' | ||
|
||
import '../src/behaviors/all_behaviors.js' | ||
import '../src/calendar-form.js' | ||
import '../src/datatable.js' | ||
import '../src/opening-times.js' | ||
import '../src/ward-picker.js' | ||
|
||
$(document).on('turbolinks:load', function() { | ||
|
||
$(document).on('turbolinks:load', function () { | ||
|
||
$('body').init_behaviors() | ||
|
||
$('[data-toggle="tooltip"]').tooltip() | ||
}) | ||
}); |
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,24 @@ | ||
// This makes sure Turbolinks doesn't double load the datatable code | ||
// if you press the browser back button | ||
let dataTable = "" | ||
|
||
document.addEventListener("turbolinks:before-cache", function () { | ||
if (dataTable !== null) { | ||
dataTable.destroy(); | ||
dataTable = null; | ||
} | ||
}); | ||
|
||
document.addEventListener('turbolinks:load', function () { | ||
dataTable = $('#datatable').DataTable({ | ||
"processing": true, | ||
"serverSide": true, | ||
"pageLength": 15, | ||
"ajax": { | ||
"url": $('#datatable').data('source') | ||
}, | ||
"pagingType": "full_numbers", | ||
// Column spec is loaded from a script tag in the view | ||
"columns": columns | ||
}) | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.