Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date and Time fields #931

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
Add date field, views, and update time picker js
  • Loading branch information
schpet authored and bronislav committed Jul 14, 2017
commit 19c2df622884cc158cd388d7be50411527f0aa54
Original file line number Diff line number Diff line change
@@ -3,4 +3,9 @@ $(function () {
debug: false,
format: "YYYY-MM-DD HH:mm:ss",
});

$(".datepicker").datetimepicker({
debug: false,
format: "YYYY-MM-DD",
});
});
24 changes: 24 additions & 0 deletions app/views/fields/date/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%#
# Date Form Partial

This partial renders an input element for a date attribute.
By default, the input is a text field that is augmented with [DatePicker].

## Local variables:

- `f`:
A Rails form generator, used to help create the appropriate input fields.
- `field`:
An instance of [Administrate::Field::Date][1].
A wrapper around the Date value pulled from the database.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
[DatePicker]: https://github.com/Eonasdan/bootstrap-datetimepicker
%>

<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.text_field field.attribute, class: "datepicker" %>
</div>
21 changes: 21 additions & 0 deletions app/views/fields/date/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%#
# Date Index Partial

This partial renders a date attribute,
to be displayed on a resource's index page.

By default, the attribute is rendered
as a localized date string.

## Local variables:

- `field`:
An instance of [Administrate::Field::Date][1].
A wrapper around the Date value pulled from the database.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
%>

<% if field.data %>
<%= l field.data.to_date %>
<% end %>
21 changes: 21 additions & 0 deletions app/views/fields/date/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%#
# Date Show Partial

This partial renders a date attribute,
to be displayed on a resource's show page.

By default, the attribute is rendered
as a localized date string.

## Local variables:

- `field`:
An instance of [Administrate::Field::Date][1].
A wrapper around the Date value pulled from the database.

[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Date
%>

<% if field.data %>
<%= l(field.data, default: field.data) %>
<% end %>
1 change: 1 addition & 0 deletions lib/administrate/base_dashboard.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "administrate/field/belongs_to"
require "administrate/field/boolean"
require "administrate/field/date_time"
require "administrate/field/date"
require "administrate/field/email"
require "administrate/field/has_many"
require "administrate/field/has_one"
8 changes: 8 additions & 0 deletions lib/administrate/field/date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require_relative "base"

module Administrate
module Field
class Date < Base
end
end
end
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module Generators
class DashboardGenerator < Rails::Generators::NamedBase
ATTRIBUTE_TYPE_MAPPING = {
boolean: "Field::Boolean",
date: "Field::DateTime",
date: "Field::Date",
datetime: "Field::DateTime",
enum: "Field::String",
float: "Field::Number",
6 changes: 6 additions & 0 deletions spec/lib/fields/date_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "spec_helper"
require "administrate/field/date"
require "support/field_matchers"

describe Administrate::Field::Date do
end