rails_admin_duration 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 01fba5891039c9b6c6f1a7ae8d6fbf14423cae84
4
+ data.tar.gz: 3dc9685c02c12566f188fa9811ea075f25b859e6
5
+ SHA512:
6
+ metadata.gz: 5ea66a4efd06b1d2aee3a102d49c9cab6d928a5fed666a6094e45717520d197cca9dc261f52529cb264fa9c2301890a9e06b33bde94f458fad3dc20cddf559ac
7
+ data.tar.gz: 11270a3bfe6ade62e8124ffe034349a467b1f0a925e9d596ea9b15990956cbdbfdc118d59d1f1377f2b98fd7dd736f45216242f2c56eebca096788c87c479cea
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Michael Colavita
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RailsAdminDuration'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,20 @@
1
+ .aligned-set {
2
+ display: inline-block;
3
+ text-align: center;
4
+ }
5
+
6
+ .mid-label {
7
+ display: inline-block;
8
+ width: 10px;
9
+ }
10
+
11
+ .below-label {
12
+ font-weight: normal;
13
+ display: block;
14
+ margin-left: -5px;
15
+ }
16
+
17
+ .duration-field {
18
+ display: inline-block;
19
+ width: 50px !important;
20
+ }
@@ -0,0 +1,27 @@
1
+ = stylesheet_link_tag 'rails_admin/ra.duration'
2
+
3
+ =form.fields_for field.name, class: "form-inline" do |nested_form|
4
+ .aligned-set
5
+ %div
6
+ = nested_form.number_field :days, field.html_attributes.merge({ value: field.days, min: 0, class: "form-control duration-field" })
7
+ %span.mid-label= ","
8
+ = nested_form.label :days, :days, class: "below-label"
9
+
10
+
11
+ .aligned-set
12
+ %div
13
+ = nested_form.number_field :hours, field.html_attributes.merge({ value: field.hours, min: 0, max: 23, class: "form-control duration-field" })
14
+ %span.mid-label= ":"
15
+ = nested_form.label :hours, :hours, class: "below-label"
16
+
17
+
18
+ .aligned-set
19
+ %div
20
+ = nested_form.number_field :minutes, field.html_attributes.merge({ value: field.minutes, min: 0, max: 59, class: "form-control duration-field" })
21
+ %span.mid-label= ":"
22
+ = nested_form.label :minutes, :minutes, class: "below-label"
23
+
24
+
25
+ .aligned-set
26
+ = nested_form.number_field :seconds, field.html_attributes.merge({ value: field.seconds, min: 0, max: 59, class: "form-control duration-field" })
27
+ = nested_form.label :seconds, :seconds, class: "below-label"
@@ -0,0 +1,79 @@
1
+ require "rails_admin_duration/engine"
2
+
3
+ module RailsAdminDuration
4
+ end
5
+
6
+ require 'rails_admin/config/fields'
7
+ require 'rails_admin/config/fields/base'
8
+
9
+ module RailsAdmin
10
+ module Config
11
+ module Fields
12
+ module Types
13
+ class Duration < RailsAdmin::Config::Fields::Base
14
+ RailsAdmin::Config::Fields::Types::register(self)
15
+
16
+ register_instance_option :partial do
17
+ :form_duration
18
+ end
19
+
20
+ register_instance_option :pretty_value do
21
+ parts = []
22
+
23
+ parts << ActionController::Base.helpers.pluralize(days, "day") if days > 0
24
+ parts << ActionController::Base.helpers.pluralize(hours, "hour") if hours > 0
25
+ parts << ActionController::Base.helpers.pluralize(minutes, "minute") if minutes > 0
26
+ parts << ActionController::Base.helpers.pluralize(seconds, "second") if seconds > 0
27
+
28
+ parts.join(", ")
29
+ end
30
+
31
+ def days
32
+ return 0 if value.blank?
33
+ value / 1.day
34
+ end
35
+
36
+ def hours
37
+ return 0 if value.blank?
38
+ (value % 1.day) / 1.hour
39
+ end
40
+
41
+ def minutes
42
+ return 0 if value.blank?
43
+ (value % 1.hour) / 1.minute
44
+ end
45
+
46
+ def seconds
47
+ return 0 if value.blank?
48
+ (value % 1.minute) / 1.second
49
+ end
50
+
51
+ def parse_input(params)
52
+ n_days = params[name][:days].try(:to_i)
53
+ n_hours = params[name][:hours].try(:to_i)
54
+ n_minutes = params[name][:minutes].try(:to_i)
55
+ n_seconds = params[name][:seconds].try(:to_i)
56
+
57
+ if n_days.nil? || n_hours.nil? || n_minutes.nil? || n_seconds.nil?
58
+ params[name] = nil
59
+ else
60
+ params[name] = n_days.days + n_hours.hours + n_minutes.minutes + n_seconds.seconds
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
71
+ if properties.name == :duration
72
+ fields << RailsAdmin::Config::Fields::Types::Duration.new(parent, properties.name, properties)
73
+ true
74
+ else
75
+ false
76
+ end
77
+ end
78
+
79
+
@@ -0,0 +1,9 @@
1
+ module RailsAdminDuration
2
+ class Engine < ::Rails::Engine
3
+ initializer "RailsAdminDuration precompile" do |app|
4
+ app.config.assets.precompile += %w(
5
+ rails_admin/ra.duration.css
6
+ )
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module RailsAdminDuration
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_duration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Colavita
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails_admin
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.8
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.8
41
+ description: RailsAdminDuration adds a duration field type to RailsAdmin. It stores
42
+ durations in seconds (like Rails's Duration type) and can be used with integer columns.
43
+ email:
44
+ - colavitam@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - Rakefile
51
+ - app/assets/stylesheets/rails_admin/ra.duration.css.scss
52
+ - app/views/rails_admin/main/_form_duration.html.haml
53
+ - lib/rails_admin_duration.rb
54
+ - lib/rails_admin_duration/engine.rb
55
+ - lib/rails_admin_duration/version.rb
56
+ homepage: https://github.com/colavitam/rails_admin_duration
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.6
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: RailsAdminDuration adds a duration field type to RailsAdmin.
80
+ test_files: []