-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from platanus/datetime-picker-filter
Datetime picker filter
- Loading branch information
Showing
10 changed files
with
127 additions
and
4 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
11 changes: 11 additions & 0 deletions
11
app/assets/stylesheets/activeadmin_addons/inputs/date-time-picker-filter.scss
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,11 @@ | ||
.filter_date_time_picker_filter { | ||
li { | ||
list-style: none; | ||
|
||
label { | ||
display: none; | ||
} | ||
|
||
margin-bottom: 5px; | ||
} | ||
} |
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,26 @@ | ||
class DateTimePickerFilterInput < ActiveAdminAddons::InputBase | ||
include ActiveAdminAddons::FilterInput | ||
|
||
def load_control_attributes | ||
load_attr(:picker_options, default: {}) | ||
end | ||
|
||
def render_custom_input | ||
concat(label_html) | ||
concat_date_time_picker_field(gteq_input_name) | ||
concat_date_time_picker_field(lteq_input_name) | ||
end | ||
|
||
def concat_date_time_picker_field(control_name) | ||
concat(builder.input(control_name, date_time_picker_options(control_name))) | ||
end | ||
|
||
def date_time_picker_options(input_name = gteq_input_name) | ||
is_gt = (input_name == gteq_input_name) | ||
|
||
input_html_options.merge( | ||
as: :date_time_picker, | ||
placeholder: is_gt ? "min" : "max" | ||
) | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
72 changes: 72 additions & 0 deletions
72
spec/features/inputs/date_time_picker_filter_input_spec.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,72 @@ | ||
require 'rails_helper' | ||
|
||
describe "Date Time Picker Filter Input", type: :feature do | ||
let(:now) { DateTime.new(1984, 6, 4, 9, 0, 0).in_time_zone } | ||
|
||
before do | ||
register_page(Invoice) do | ||
config.sort_order = 'created_at_asc' | ||
|
||
filter :created_at, as: :date_time_picker_filter | ||
|
||
index do | ||
column :created_at | ||
end | ||
end | ||
|
||
5.times { |i| Invoice.create(id: i + 1, created_at: now + i.hours) } | ||
visit admin_invoices_path | ||
end | ||
|
||
it "shows date time pickers", js: true do | ||
expect(page).to have_css(".date-time-picker-input", count: 2) | ||
expect(page).to have_css("#q_created_at_gteq", count: 1) | ||
expect(page).to have_css("#q_created_at_lteq", count: 1) | ||
end | ||
|
||
context "setting min and max values" do | ||
before do | ||
find("#q_created_at_gteq").set("1984-06-04 10:00") | ||
find("#q_created_at_lteq").set("1984-06-04 12:00") | ||
click_filter_btn | ||
end | ||
|
||
it "shows filtered rows", js: true do | ||
expect(page).to_not have_css("#invoice_5") | ||
expect(page).to have_css("#invoice_4", count: 1) | ||
expect(page).to have_css("#invoice_3", count: 1) | ||
expect(page).to have_css("#invoice_2", count: 1) | ||
expect(page).to_not have_css("#invoice_1") | ||
end | ||
end | ||
|
||
context "setting min value only" do | ||
before do | ||
find("#q_created_at_gteq").set("1984-06-04 12:00") | ||
click_filter_btn | ||
end | ||
|
||
it "shows filtered rows", js: true do | ||
expect(page).to have_css("#invoice_5", count: 1) | ||
expect(page).to have_css("#invoice_4", count: 1) | ||
expect(page).not_to have_css("#invoice_3") | ||
expect(page).not_to have_css("#invoice_2") | ||
expect(page).not_to have_css("#invoice_1") | ||
end | ||
end | ||
|
||
context "setting max value only" do | ||
before do | ||
find("#q_created_at_lteq").set("1984-06-04 12:00") | ||
click_filter_btn | ||
end | ||
|
||
it "shows filtered rows", js: true do | ||
expect(page).to_not have_css("#invoice_5") | ||
expect(page).to have_css("#invoice_4", count: 1) | ||
expect(page).to have_css("#invoice_3", count: 1) | ||
expect(page).to have_css("#invoice_2", count: 1) | ||
expect(page).to have_css("#invoice_1", count: 1) | ||
end | ||
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