Coder Social home page Coder Social logo

active_admin_datetimepicker's People

Contributors

adamkiczula avatar cdesch avatar fivell avatar gbirchmeier avatar gigorok avatar iarie avatar jnajera avatar senid231 avatar skumring avatar sunny avatar swrobel avatar timoschilling avatar workgena avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

active_admin_datetimepicker's Issues

"To" being set to "From" after submit.

We encountered a problem where the date time range filter would show up with both fields having the placeholder "From". After submission the the lteq field would be set to the gteq field.

Here's the filter. start is a datetime column.

  filter :start,
    as: :date_time_range,
    label: "Date range"

Showing the From/From.
Screen Shot 2020-01-22 at 13 12 39

Different values filled in.
Screen Shot 2020-01-22 at 13 12 54

After submission, To is set to From, but the original inputs were understood.
Screen Shot 2020-01-22 at 13 13 09

Upon investigation we noticed the IDs are q_field_gteq and q_field_lteq for a Date rather than q_field_gteq_datetimepicker and q_field_lteq_datetimepicker for a DateTime.

I believe this is because ActiveAdmin::Inputs::Filters::DateTimeRangeInput inherits ActiveAdmin::Inputs::Filters::DateRangeInput#input_html_options which casts the value to a Date. This was added a few years ago.

This results in DateTimeRangeInput#gt_input_name and DateTimeRangeInput#lt_input_name both using the name from their superclass DateRangeInput.

The following monkey patch fixes the issue for us.

class ActiveAdmin::Inputs::Filters::DateTimeRangeInput
  def input_html_options_for(input_name, placeholder)
    current_value = begin
                      #cast value to Time object before rendering input
                      @object.public_send(input_name).to_s.to_datetime
                    rescue
                      nil
                    end

    return input_html_options.merge(
      placeholder: placeholder,
      value: current_value&.strftime("%Y-%m-%d %H:%M:%S")
    )
  end
end

Here's our relevant Gemfile.lock.

    active_admin_datetimepicker (0.7.3)
      activeadmin (>= 1.1, < 3.a)
      coffee-rails
      xdan-datetimepicker-rails (~> 2.5.4)
    active_admin_scoped_collection_actions (0.4.0)
      activeadmin (>= 1.1, < 3.a)
    activeadmin (2.6.0)
      arbre (~> 1.2, >= 1.2.1)
      formtastic (~> 3.1)
      formtastic_i18n (~> 0.4)
      inherited_resources (~> 1.7)
      jquery-rails (~> 4.2)
      kaminari (~> 1.0, >= 1.0.1)
      railties (>= 5.2, < 6.1)
      ransack (~> 2.1, >= 2.1.1)
      sassc-rails (~> 2.1)
      sprockets (>= 3.0, < 4.1)
    activeadmin-ajax_filter (0.4.4)
      activeadmin (>= 1.0)
      coffee-rails (>= 4.1.0)
      has_scope (>= 0.6.0)
      rails (>= 4.2.11)
      selectize-rails (>= 0.12.6)

Uncaught ReferenceError: DateFormatter is not defined - Bump to 2.5.1 shekibobo/xdan-datetimepicker-rails breaks

Recent bump of shekibobo/xdan-datetimepicker-rails to 2.5.1 breaks active_admin_datetimepicker resulting in this error.

jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:628 Uncaught ReferenceError: DateFormatter is not defined

 jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:628 Uncaught ReferenceError: DateFormatter is not definedinitDateFormatter @ jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:628(anonymous function) @ jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:655(anonymous function) @ jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:17(anonymous function) @ jquery.xdan.datetimepicker.self-cee7ca77af23156f09c944bc1271816c17ae6b0ac426696a551e13b964547639.js…:19

Fixing requires specifying gem 'xdan-datetimepicker-rails', '2.4.3' in the gemfileand running bundle update active_admin_datetimepicker

I'm working on a pull request to fix.

multiple errors, unfortunately

Sass::SyntaxError - Undefined variable: "$filter-field-seperator-width".:
sass (3.4.22) lib/sass/script/tree/variable.rb:49:in `_perform'
sass (3.4.22) lib/sass/script/tree/node.rb:58:in `perform'

if i set this vars directly

$filter-field-seperator-width: 20px;
$side-by-side-filter-input-width: 20px;

then new error appears

Formtastic::UnknownInputError - Unable to find input class for date_time_picker:
formtastic (3.1.4) lib/formtastic/helpers/input_helper.rb:379:in `rescue in input_class_by_trying'

rails 4.2.6
activeadmin 1.0.0.pre2

:(

errors in readme Development section

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

Yeah, there is no bin or setup.

Please update this section.

How to set up

The usage section seems to be outdated. How do I correctly set this thing up?

Adding //= require active_admin_datetimepicker to active_admin.js yields

Sprockets::FileNotFound
couldn't find file 'active_admin_datetimepicker' with type 'application/javascript'

Adding @import "active_admin_datetimepicker"; to active_admin.scss yields

Sass::SyntaxError
File to import not found or unreadable: active_admin_datetimepicker.

ruby 2.2.6, rails 4.2.9, aa 1.1.0

Found config.register_javascript 'active_admin_datetimepicker.js' in the issues - not mentioned in the README.

Incorrect alignment on very wide pages

With very wide active admin pages, when using the date_time_range filter, the positioning of the date picker can be off.

See the attached picture. I have an even wide page where when you click on the filter, it looks like nothing happens because the date picker is off screen.

screen shot 2016-12-14 at 7 51 39 am

input_html isn't work

this input_html not work
f.input :expire_after, :as => :date_time_picker, :input_html => { :style => 'width: 100%', autocomplete: "off" }

Docs appear wrong for passing options

Thank you for this code!

These do not appear to work (allow selection of past dates):

      input :start_at, as: :date_time_picker, date_time_picker_options: {
        min_date: Time.now.to_date
      }
      input :start_at, as: :date_time_picker, datepicker_options: {
        min_date: Time.now.to_date
      }

This does appear to work: (does not allow selection of past dates):

      input :start_at, as: :date_time_picker, picker_options: {
        min_date: Time.now.to_date
      }

(FYI: I found my fix my inspecting the page HTML, and noticed that the div's attribute was data-picker-options)

inputs value converted to date on active_admin 2.0

after submit filters we see only date (without time) in inputs value

this patch fix the issue

module DateTimeRangeInputPatch
  def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeholder)
    super.tap do |options|
      options[:value] = current_value_for(input_name)
    end
  end

  def current_value_for(input_name)
    @object.public_send(input_name).to_s.to_time.strftime("%F %T")
  rescue
    ''
  end
end

ActiveAdmin::Inputs::Filters::DateTimeRangeInput.include DateTimeRangeInputPatch

Webpack direction

Hi i configured AA to work with webpacker but i'm seeing this at runtime.

2020-10-08T02:20:16.469618+00:00 app[web.1]: [bb1d92c0-719b-403e-9e75-5b55800db3ee] ActionView::Template::Error (Webpacker can't find jquery.xdan.datetimepicker.css in /app/public/packs/manifest.json. Possible causes:
2020-10-08T02:20:16.469618+00:00 app[web.1]: 1. You want to set webpacker.yml value of compile to true for your environment
2020-10-08T02:20:16.469619+00:00 app[web.1]: unless you are using the `webpack -w` or the webpack-dev-server.
2020-10-08T02:20:16.469619+00:00 app[web.1]: 2. webpack has not yet re-run to reflect updates.
2020-10-08T02:20:16.469620+00:00 app[web.1]: 3. You have misconfigured Webpacker's config/webpacker.yml file.
2020-10-08T02:20:16.469620+00:00 app[web.1]: 4. Your webpack configuration is not creating a manifest.
2020-10-08T02:20:16.469620+00:00 app[web.1]: Your manifest contains:
2020-10-08T02:20:16.469621+00:00 app[web.1]: {
2020-10-08T02:20:16.469621+00:00 app[web.1]: "active_admin.css": "/packs/css/active_admin-db07d18a.css",
2020-10-08T02:20:16.469621+00:00 app[web.1]: "active_admin.js": "/packs/js/active_admin-7fec0a7e08fd0c655301.js",
2020-10-08T02:20:16.469622+00:00 app[web.1]: "active_admin.js.map": "/packs/js/active_admin-7fec0a7e08fd0c655301.js.map",
2020-10-08T02:20:16.469622+00:00 app[web.1]: "active_admin/print.css": "/packs/css/active_admin/print-70585d69.css",
2020-10-08T02:20:16.469622+00:00 app[web.1]: "active_admin/print.js": "/packs/js/active_admin/print-698d01661c2d9661ce50.js",
2020-10-08T02:20:16.469623+00:00 app[web.1]: "active_admin/print.js.map": "/packs/js/active_admin/print-698d01661c2d9661ce50.js.map"
...

I did yarn add jquery-datetimepicker but still same.

Do you have any direction ?

Regards

when default options not present: `undefined method `map' for nil:NilClass`

(version 0.2.0, rails 4.0.14, ruby 2.1.0, activeadmin 1.0.0.pre1)

I followed the instructions in the README, but I get this error when I try to load my ActiveAdmin page:

undefined method `map' for nil:NilClass

top of framework trace:
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:48:in `_default_datetime_picker_options'
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:41:in `datetime_picker_options'
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:23:in `input_html_options'

I saw that the submitter of #18 had an initializer, so I added this to the bottom of my `config/initializers/active_admin.rb":

ActiveAdminDatetimepicker::Base.default_datetime_picker_options = {}

This made my AA object-creation form work. Should that line be necessary?

Problem for custom format

When I try to use:

This if for front-end javascript side

ActiveAdminDatetimepicker::Base.default_datetime_picker_options = {
defaultDate: proc { Time.current.strftime("%Y-%m-%d 00:00") }
}

This if for backend(Ruby)

ActiveAdminDatetimepicker::Base.format = "%Y-%m-%d %H:%M:%S"

in initializers of active admin, I get this error:

/config/initializers/util.rb:8:in `<top (required)>': uninitialized constant ActiveAdminDatetimepicker::Base (NameError)

Rails 6 support

Hey, I am trying to use the gem within a rails 6 project but the datetime picker does not load. Will there be rails 6 support with this gem any time soon?

rails v6.0.0, active_admin_datetimepicker v0.7.2, active_admin v2.3.1

not work

rails 423, activeadmin 1.0.0.pre1

my admin/entity.rb


Entity.column_names.each do |column_name|
    filter column_name unless column_name == :updated_at
end

filter :updated_at, as: :date_time_range

initializers/active_admin.rb include:


ActiveAdminDatetimepicker::Base.default_datetime_picker_options = {
    defaultDate: proc { Time.current.strftime("%Y-%m-%d 00:00") }
}
# This if for backend(Ruby)
ActiveAdminDatetimepicker::Base.format = "%Y-%m-%d %H:%M"

and

config.register_javascript 'active_admin_datetimepicker.js'

active_admin.css.scss contain:

@import "active_admin/mixins";
@import "active_admin/base";
@import "active_admin_datetimepicker";

i have empty fields in filters block. datetimepicker don't show.
(web inspector is clean, no errors any)

Very very big thanks for reply!!

Unable to set the "steps" in the timepicker

Hi,

Thanks for the plugins. It works great!

Although, I am unable to set the "steps" for the timepicker. I tried

input :start_time, as: :date_time_picker, datepicker_options: {step: 5}

It didn't work, I also tried, the below, to see if options are being processed

input :start_time, as: :date_time_picker, datepicker_options: {step: 5, timepicker: false}

And it did not hide the time picker.

Could you help me out please?

Thanks!

Deprecation warning in ActiveAdmin 2+

DEPRECATION WARNING: Active Admin: The `register_stylesheet` config is deprecated and will be removed
in v2. Import your "jquery.xdan.datetimepicker.css" stylesheet in the active_admin.scss.

Please release version 0.6 to rubygems

As we can see on https://rubygems.org/gems/active_admin_datetimepicker

The latest version on rubygems is 0.5, which can not work under the guide.

After change to 0.6 by

gem 'active_admin_datetimepicker', git: 'https://github.com/activeadmin-plugins/active_admin_datetimepicker.git'

It works.

Why don't you release version 0.6 to rubygems.org?
If there is anything I can do that can help the new version's releasing, I will try my best to help.

Drop dependency "xdan-datetimepicker-rails"

Background

Currently "active_admin_datetimepicker" has strong dependency on shekibobo/xdan-datetimepicker-rails

It provides Rails-wrapper for xdan/datetimepicker JS-library.

xdan-datetimepicker-rails is abandoned and is not updates since 2016.

The last update for xdan/datetimepicker JS-lib is dated 2020 year.

Proposition

Remove dependency on "shekibobo/xdan-datetimepicker-rails" and be dependant directly to "xdan/datetimepicker".

Or, create PR with update to xdan-datetimepicker-rails.

Related issues

Wrong value for lteq_datetime predicate

DateTimeRangeInput inherits from ActiveAdmin's DateRangeInput. So it uses lteq_datetime predicate. But definition of this predicate is correct if we use date part of the datetime/timestamp value rather than whole value
https://github.com/activeadmin/activeadmin/blob/v2.3.1/lib/ransack_ext.rb#L17

So now if end range field of the date_time_range filter is non-empty we always get incorrect request to DB.

For the whole value when lteq predicate is being converted to lt predicate then microseconds have to be increased by 1 (at least for Postgresql that stores timestamps with microsecond resolution) instead of days.

How use "date_time_range" in a custom filter?

I need a custom param but It's not an attribute of my model. I need this param to filter the table with different columns. This is an example:

models/my_model.rb

class MyModel < ActiveRecord::Base
  #attributes: create_at, update_at
end

admin/my_model.rb

ActiveAdmin.register Team do
  filter :date, as: :date_time_range

  controller do
    def scoped_collection
       #filter here
    end
  end
end

But I get an error with that implementation.

undefined method `date_gteq_datetime_picker' for Ransack::Search<class: MyModel, base: Grouping <combinator: and>>:Ransack::Search

I guess the date column is not an attribute.

Deprecation warning for `register_stylesheet`

Using activeadmin v1.4.3, we get the following warning:

DEPRECATION WARNING: Active Admin: The register_stylesheet config is deprecated and will be removed
in v2. Import your "jquery.xdan.datetimepicker.css" stylesheet in the active_admin.scss.

ActiveAdminDatetimepicker::Base mattr_accessor :format defaults to nil

(version 0.2.0, rails 4.0.14, ruby 2.1.0, activeadmin 1.0.0.pre1)

If I don't explicitly set ActiveAdminDatetimepicker::Base.format = "%Y-%m-%d %H:%M" in an initializer, I get this exception when I submit my form or load the edit-object form:

no implicit conversion of nil into String

top of framework trace:
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:31:in `strftime'
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:31:in `input_value'
  active_admin_datetimepicker (0.2.0) lib/active_admin_datetimepicker/base.rb:24:in `input_html_options'

I traced this to lib/active_admin_datetimepicker/base.rb line 31. The variable format is nil.

It appears that the mattr_accessor :format block (same file) is supposed to set a default value for format, but my experience today is that it's not doing anything.

UPDATE:

(from #19) mattr_accessor :default_datetime_picker_options has the same defect.

Intermittent datepicker issues with filters

When using the datepicker with activeadmin filter, the datepicker when clicking on the input field seems to be very buggy, sometimes showing the datepicker other times not triggering at all.

If you click on a filter field, somewhere else on the page and click back on the field a few times it replicates the issue. Sometimes the page loads and it is not shown at all.

No java-script console error messages are being shown.

ruby 2.7.5p203
Rails 6.1.4.4
activeadmin 2.13.1
active_admin_datetimepicker 1.0.0

intializer

# This if for the front-end JavaScript side
ActiveAdminDatetimepicker::Base.default_datetime_picker_options = {
  format: 'd/m/Y H:i',
  defaultTime: proc { Time.current.strftime('%H:00') },
  defaultDate: proc { Time.current.strftime("%d/%m/%Y 00:00") }
}
# This if for the Ruby backend
ActiveAdminDatetimepicker::Base.format = "%d/%m/%Y %H:%M"

activeadmin filter

filter :appointment_date, as: :date_time_range

sass variables

$filter-field-seperator-width:100;
$side-by-side-filter-input-width:100;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.