volt-daterange 0.1.0

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +15 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +1 -0
  9. data/app/daterange/assets/css/daterangepicker.css +341 -0
  10. data/app/daterange/assets/js/01_moment.js +3112 -0
  11. data/app/daterange/assets/js/daterangepicker.js +1458 -0
  12. data/app/daterange/config/dependencies.rb +1 -0
  13. data/app/daterange/config/initializers/boot.rb +10 -0
  14. data/app/daterange/config/routes.rb +1 -0
  15. data/app/daterange/controllers/main_controller.rb +106 -0
  16. data/app/daterange/views/main/index.html +4 -0
  17. data/lib/volt/daterange.rb +18 -0
  18. data/lib/volt/daterange/version.rb +5 -0
  19. data/spec/dummy/.gitignore +9 -0
  20. data/spec/dummy/README.md +4 -0
  21. data/spec/dummy/app/main/assets/css/app.css.scss +1 -0
  22. data/spec/dummy/app/main/config/dependencies.rb +11 -0
  23. data/spec/dummy/app/main/config/initializers/boot.rb +10 -0
  24. data/spec/dummy/app/main/config/routes.rb +14 -0
  25. data/spec/dummy/app/main/controllers/main_controller.rb +27 -0
  26. data/spec/dummy/app/main/models/user.rb +12 -0
  27. data/spec/dummy/app/main/views/main/about.html +7 -0
  28. data/spec/dummy/app/main/views/main/index.html +6 -0
  29. data/spec/dummy/app/main/views/main/main.html +29 -0
  30. data/spec/dummy/config.ru +4 -0
  31. data/spec/dummy/config/app.rb +137 -0
  32. data/spec/dummy/config/base/index.html +15 -0
  33. data/spec/dummy/config/initializers/boot.rb +4 -0
  34. data/spec/integration/sample_integration_spec.rb +11 -0
  35. data/spec/sample_spec.rb +7 -0
  36. data/spec/spec_helper.rb +18 -0
  37. data/volt-daterange.gemspec +38 -0
  38. metadata +280 -0
@@ -0,0 +1 @@
1
+ # Component dependencies
@@ -0,0 +1,10 @@
1
+ # Place any code you want to run when the component is included on the client
2
+ # or server.
3
+
4
+ # To include code only on the client use:
5
+ # if RUBY_PLATFORM == 'opal'
6
+ #
7
+ # To include code only on the server, use:
8
+ # unless RUBY_PLATFORM == 'opal'
9
+ # ^^ this will not send compile in code in the conditional to the client.
10
+ # ^^ this include code required in the conditional.
@@ -0,0 +1 @@
1
+ # Component routes
@@ -0,0 +1,106 @@
1
+ module Daterange
2
+ class MainController < Volt::ModelController
3
+
4
+ def format_str
5
+ attrs.format_str || 'MM-DD-YYYY'
6
+ end
7
+
8
+ def index_ready
9
+ callback = proc { |start_date, end_date| set_date(start_date, end_date) }
10
+ `
11
+ var opts = {
12
+ ranges: {
13
+ 'Today': [moment(), moment()],
14
+ 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
15
+ 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
16
+ 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
17
+ 'This Month': [moment().startOf('month'), moment().endOf('month')],
18
+ 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
19
+ }
20
+ };
21
+ `
22
+ # You can specify an integer to limit the number of days you can select
23
+ # at once.
24
+ if attrs.limit_days
25
+ `opts.dateLimit = {
26
+ days: #{attrs.limit_days.to_i}
27
+ };`
28
+ end
29
+
30
+ @picker = `$(#{first_element}).daterangepicker(opts, #{callback})`
31
+
32
+ puts "a"
33
+ if attrs.start_date
34
+ start_date = `moment(#{attrs.start_date}, #{format_str})`
35
+ else
36
+ start_date = `moment().subtract(29, 'days')`
37
+ end
38
+
39
+ puts "b"
40
+
41
+ if attrs.end_date
42
+ end_date = `moment(#{attrs.end_date}, #{format_str})`
43
+ else
44
+ end_date = `moment()`
45
+ end
46
+
47
+ puts "c"
48
+
49
+ set_date(start_date, end_date)
50
+
51
+ puts "d"
52
+
53
+ @start_comp = proc do
54
+ val = attrs.start_date
55
+ picker = @picker
56
+ if val
57
+ `
58
+ if (picker.setStartDate) {
59
+ var date = moment(val);
60
+ if (date.isValid()) {
61
+ console.log('set start');
62
+ picker.setStartDate(date);
63
+ }
64
+ }
65
+ `
66
+ end
67
+ end.watch!
68
+
69
+ @end_comp = proc do
70
+ val = attrs.end_date
71
+ picker = @picker
72
+ if val
73
+ puts "Try Update"
74
+ `
75
+ if (picker.setEndDate) {
76
+ var date = moment(val);
77
+ if (date.isValid()) {
78
+ console.log('set end');
79
+ picker.setEndDate(date);
80
+ }
81
+ }
82
+ `
83
+ end
84
+ end.watch!
85
+
86
+
87
+ end
88
+
89
+ def picker
90
+ # Get the picker obj so we can set on it
91
+ return `$(#{first_element}).data('daterangepicker')`
92
+ end
93
+
94
+ def before_index_remove
95
+ @start_comp.stop
96
+ @end_comp.stop
97
+ end
98
+
99
+ def set_date(start_date, end_date)
100
+ `$(#{first_element}).find('span').html(start_date.format(#{format_str}) + ' - ' + end_date.format(#{format_str})); `
101
+
102
+ attrs.start_date = `start_date.format(#{format_str})`
103
+ attrs.end_date = `end_date.format(#{format_str})`
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,4 @@
1
+ <div class="daterange" class="pull-right" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; width: 100%">
2
+ <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
3
+ <span></span> <b class="caret"></b>
4
+ </div>
@@ -0,0 +1,18 @@
1
+ # If you need to require in code in the gem's app folder, keep in mind that
2
+ # the app is not on the load path when the gem is required. Use
3
+ # app/{gemname}/config/initializers/boot.rb to require in client or server
4
+ # code.
5
+ #
6
+ # Also, in volt apps, you typically use the lib folder in the
7
+ # app/{componentname} folder instead of this lib folder. This lib folder is
8
+ # for setting up gem code when Bundler.require is called. (or the gem is
9
+ # required.)
10
+ #
11
+ # If you need to configure volt in some way, you can add a Volt.configure block
12
+ # in this file.
13
+
14
+ module Volt
15
+ module Daterange
16
+ # Your code goes here...
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Volt
2
+ module Daterange
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ .bundle
2
+ .config
3
+ .yardoc
4
+ tmp
5
+ .idea
6
+ .yardoc
7
+ .sass-cache
8
+ .DS_Store
9
+ compiled
@@ -0,0 +1,4 @@
1
+ # Place your app's docs here.
2
+
3
+ ## New to Volt?
4
+ Be sure to read the volt docs at http://docs.voltframework.com
@@ -0,0 +1 @@
1
+ // Place your apps css here
@@ -0,0 +1,11 @@
1
+ # Specify which components you wish to include when
2
+ # the "home" component loads.
3
+
4
+ # bootstrap css framework
5
+ component 'bootstrap'
6
+
7
+ # a default theme for the bootstrap framework
8
+ component 'bootstrap_jumbotron_theme'
9
+
10
+ # provides templates for login, signup, and logout
11
+ component 'user_templates'
@@ -0,0 +1,10 @@
1
+ # Place any code you want to run when the component is included on the client
2
+ # or server.
3
+
4
+ # To include code only on the client use:
5
+ # if RUBY_PLATFORM == 'opal'
6
+ #
7
+ # To include code only on the server, use:
8
+ # unless RUBY_PLATFORM == 'opal'
9
+ # ^^ this will not send compile in code in the conditional to the client.
10
+ # ^^ this include code required in the conditional.
@@ -0,0 +1,14 @@
1
+ # See https://github.com/voltrb/volt#routes for more info on routes
2
+
3
+ client '/about', action: 'about'
4
+
5
+ # Routes for login and signup, provided by user_templates component gem
6
+ client '/signup', component: 'user_templates', controller: 'signup'
7
+ client '/login', component: 'user_templates', controller: 'login', action: 'index'
8
+ client '/password_reset', component: 'user_templates', controller: 'password_reset', action: 'index'
9
+ client '/forgot', component: 'user_templates', controller: 'login', action: 'forgot'
10
+ client '/account', component: 'user_templates', controller: 'account', action: 'index'
11
+
12
+ # The main route, this should be last. It will match any params not
13
+ # previously matched.
14
+ client '/', {}
@@ -0,0 +1,27 @@
1
+ # By default Volt generates this controller for your Main component
2
+ module Main
3
+ class MainController < Volt::ModelController
4
+ def index
5
+ # Add code for when the index view is loaded
6
+ end
7
+
8
+ def about
9
+ # Add code for when the about view is loaded
10
+ end
11
+
12
+ private
13
+
14
+ # The main template contains a #template binding that shows another
15
+ # template. This is the path to that template. It may change based
16
+ # on the params._component, params._controller, and params._action values.
17
+ def main_path
18
+ "#{params._component || 'main'}/#{params._controller || 'main'}/#{params._action || 'index'}"
19
+ end
20
+
21
+ # Determine if the current nav component is the active one by looking
22
+ # at the first part of the url against the href attribute.
23
+ def active_tab?
24
+ url.path.split('/')[1] == attrs.href.split('/')[1]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ # By default Volt generates this User model which inherits from Volt::User,
2
+ # you can rename this if you want.
3
+ class User < Volt::User
4
+ # login_field is set to :email by default and can be changed to :username
5
+ # in config/app.rb
6
+ field login_field
7
+ field :name
8
+
9
+ validate login_field, unique: true, length: 8
10
+ validate :email, email: true
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ <:Title>
2
+ About
3
+
4
+ <:Body>
5
+ <h1>About</h1>
6
+
7
+ <p>About page...</p>
@@ -0,0 +1,6 @@
1
+ <:Title>
2
+ Home
3
+
4
+ <:Body>
5
+ <h1>Home</h1>
6
+
@@ -0,0 +1,29 @@
1
+ <:Title>
2
+ {{ view main_path, "title", {controller_group: 'main'} }}
3
+
4
+ <:Body>
5
+ <div class="container">
6
+ <div class="header">
7
+ <ul class="nav nav-pills pull-right">
8
+ <:nav href="/">Home</:nav>
9
+ <:nav href="/about">About</:nav>
10
+ <:user_templates:menu />
11
+ </ul>
12
+ <h3 class="text-muted">dummy</h3>
13
+ </div>
14
+
15
+ <:volt:notices />
16
+
17
+ {{ view main_path, 'body', {controller_group: 'main'} }}
18
+
19
+ <div class="footer">
20
+ <p>&copy; Company {{ Time.now.year }}</p>
21
+ </div>
22
+
23
+ </div>
24
+
25
+ <:Nav>
26
+ <li class="{{ if active_tab? }}active{{ end }}">
27
+ <a href="{{ attrs.href }}">{{ yield }}</a>
28
+ </li>
29
+
@@ -0,0 +1,4 @@
1
+ # Run via rack server
2
+ require 'bundler/setup'
3
+ require 'volt/server'
4
+ run Volt::Server.new.app
@@ -0,0 +1,137 @@
1
+ # app.rb is used to configure your app. This code is only run on the server,
2
+ # then any config options in config.public are passed to the client as well.
3
+
4
+ Volt.configure do |config|
5
+ # Setup your global app config here.
6
+
7
+ #######################################
8
+ # Basic App Info (stuff you should set)
9
+ #######################################
10
+ config.domain = 'dummy.com'
11
+ config.app_name = 'Dummy'
12
+ config.mailer.from = 'Dummy <no-reply@dummy.com>'
13
+
14
+ ############
15
+ # App Secret
16
+ ############
17
+ # Your app secret is used for signing things like the user cookie so it can't
18
+ # be tampered with. A random value is generated on new projects that will work
19
+ # without the need to customize. Make sure this value doesn't leave your server.
20
+ #
21
+ # For added security we recommend moving the app secret into an environment. You can
22
+ # setup that like so:
23
+ #
24
+ # config.app_secret = ENV['APP_SECRET']
25
+ #
26
+ config.app_secret = 'FNiXFFRj9z-vRL6GQaSFdFwJdXAQnmBDF_BMTlQcyPzhFA2XjAPKS6wAwx2SBQ6a0tg'
27
+
28
+ ###############
29
+ # Log Filtering
30
+ ###############
31
+ # Data updates from the client come in via Tasks. The task dispatcher logs all calls to tasks.
32
+ # By default hashes in the arguments can be filtered based on keys. So any hash with a key of
33
+ # password will be filtered. You can add more fields to filter below:
34
+ config.filter_keys = [:password]
35
+
36
+ ##########
37
+ # Database
38
+ ##########
39
+ # Database config all start with db_ and can be set either in the config
40
+ # file or with an environment variable (DB_NAME for example).
41
+
42
+ # config.db_driver = 'mongo'
43
+ # config.db_name = (config.app_name + '_' + Volt.env.to_s)
44
+ # config.db_host = 'localhost'
45
+ # config.db_port = 27017
46
+
47
+ #####################
48
+ # Compression options
49
+ #####################
50
+ # If you are not running behind something like nginx in production, you can
51
+ # have rack deflate all files.
52
+ # config.deflate = true
53
+
54
+ #######################
55
+ # Public configurations
56
+ #######################
57
+ # Anything under config.public will be sent to the client as well as the server,
58
+ # so be sure no private data ends up under public
59
+
60
+ # Use username instead of email as the login
61
+ # config.public.auth.use_username = true
62
+
63
+ #####################
64
+ # Compression Options
65
+ #####################
66
+ # Disable or enable css/js/image compression. Default is to only run in production.
67
+ # if Volt.env.production?
68
+ # config.compress_javascript = true
69
+ # config.compress_css = true
70
+ # config.compress_images = true
71
+ # end
72
+
73
+ ################
74
+ # Mailer options
75
+ ################
76
+ # The volt-mailer gem uses pony (https://github.com/benprew/pony) to deliver e-mail. Any
77
+ # options you would pass to pony can be setup below.
78
+ # NOTE: The from address is setup at the top
79
+
80
+ # Normally pony uses /usr/sbin/sendmail if one is installed. You can specify smtp below:
81
+ # config.mailer.via = :smtp
82
+ # config.mailer.via_options = {
83
+ # :address => 'smtp.yourserver.com',
84
+ # :port => '25',
85
+ # :user_name => 'user',
86
+ # :password => 'password',
87
+ # :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
88
+ # :domain => "localhost.localdomain" # the HELO domain provided by the client to the server
89
+ # }
90
+
91
+ #############
92
+ # Message Bus
93
+ #############
94
+ # Volt provides a "Message Bus" out of the box. The message bus provides
95
+ # a pub/sub service between any volt instance (server, client, runner, etc..)
96
+ # that share the same database. The message bus can be used by app code. It
97
+ # is also used internally to push data to any listening clients.
98
+ #
99
+ # The default message bus (called "peer_to_peer") uses the database to sync
100
+ # socket ip's/ports.
101
+ # config.message_bus.bus_name = 'peer_to_peer'
102
+ #
103
+ # Encrypt message bus - messages on the message bus are encrypted by default
104
+ # using rbnacl.
105
+
106
+ #
107
+ # For dummy apps, we disable_encryption, to simplify the gem requirements.
108
+ config.message_bus.disable_encryption = true
109
+
110
+ #
111
+ # ## MessageBus Server -- the message bus binds to a port and ip which the
112
+ # other volt instances need to be able to connect to. You can customize
113
+ # the server below:
114
+ #
115
+ # Port range - you can specify a range of ports that an instance can bind the
116
+ # message bus on. You can specify a range, an array of Integers, or an array
117
+ # of ranges.
118
+ # config.message_bus.bind_port_ranges = (58000..61000)
119
+ #
120
+ # Bind Ip - specifies the ip address the message bus server should bind on.
121
+ # config.message_bus.bind_ip = '127.0.0.1'
122
+
123
+ #############
124
+ # Concurrency
125
+ #############
126
+ # Volt provides a thread worker pool for incoming task requests (and all
127
+ # database requests, since those use tasks to do their work.) The following
128
+ # lets you control the size of the worker pool. Threads are only created as
129
+ # needed, and are removed after a certain amount of inactivity.
130
+ # config.min_worker_threads = 1
131
+ # config.max_worker_threads = 10
132
+ #
133
+ # You can also specify the amount of time a Task should run for before it
134
+ # timeout's. Setting this to short can cause unexpected results, currently
135
+ # we recomend it be at least 10 seconds.
136
+ # config.worker_timeout = 60
137
+ end