simple_calendar-timeslot 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5cfde73c9c6d8b224e50a8f079ae7643f8b91137960d70756be3a11a75a978ac
4
+ data.tar.gz: 6e7e4a61b8d70a1a1bfa142af26d955501959a9c632261926a48fe462137846a
5
+ SHA512:
6
+ metadata.gz: 26abeb52ef9536d375ae8a601b28ea74ee7c0bc7efd4d766fc2251858a39086810eea328bb411546f68dd4cef1d60b73329481173f40e0e01b7b38aa52b5e368
7
+ data.tar.gz: 8827d6d91de47f8a21a8e7256489955957dfbc6c7363315672b8428668ee0622e4fbe3ed3f799543316f8c44b96aac073879d1b37458c2db347816c8a5842170
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.1
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-12
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in simple_calendar-timeslot.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,184 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ simple_calendar-timeslot (0.1.0)
5
+ simple_calendar (~> 2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.1.4.1)
11
+ actionpack (= 6.1.4.1)
12
+ activesupport (= 6.1.4.1)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (>= 0.6.1)
15
+ actionmailbox (6.1.4.1)
16
+ actionpack (= 6.1.4.1)
17
+ activejob (= 6.1.4.1)
18
+ activerecord (= 6.1.4.1)
19
+ activestorage (= 6.1.4.1)
20
+ activesupport (= 6.1.4.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.1.4.1)
23
+ actionpack (= 6.1.4.1)
24
+ actionview (= 6.1.4.1)
25
+ activejob (= 6.1.4.1)
26
+ activesupport (= 6.1.4.1)
27
+ mail (~> 2.5, >= 2.5.4)
28
+ rails-dom-testing (~> 2.0)
29
+ actionpack (6.1.4.1)
30
+ actionview (= 6.1.4.1)
31
+ activesupport (= 6.1.4.1)
32
+ rack (~> 2.0, >= 2.0.9)
33
+ rack-test (>= 0.6.3)
34
+ rails-dom-testing (~> 2.0)
35
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
+ actiontext (6.1.4.1)
37
+ actionpack (= 6.1.4.1)
38
+ activerecord (= 6.1.4.1)
39
+ activestorage (= 6.1.4.1)
40
+ activesupport (= 6.1.4.1)
41
+ nokogiri (>= 1.8.5)
42
+ actionview (6.1.4.1)
43
+ activesupport (= 6.1.4.1)
44
+ builder (~> 3.1)
45
+ erubi (~> 1.4)
46
+ rails-dom-testing (~> 2.0)
47
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
+ activejob (6.1.4.1)
49
+ activesupport (= 6.1.4.1)
50
+ globalid (>= 0.3.6)
51
+ activemodel (6.1.4.1)
52
+ activesupport (= 6.1.4.1)
53
+ activerecord (6.1.4.1)
54
+ activemodel (= 6.1.4.1)
55
+ activesupport (= 6.1.4.1)
56
+ activestorage (6.1.4.1)
57
+ actionpack (= 6.1.4.1)
58
+ activejob (= 6.1.4.1)
59
+ activerecord (= 6.1.4.1)
60
+ activesupport (= 6.1.4.1)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (>= 1.1.0)
63
+ activesupport (6.1.4.1)
64
+ concurrent-ruby (~> 1.0, >= 1.0.2)
65
+ i18n (>= 1.6, < 2)
66
+ minitest (>= 5.1)
67
+ tzinfo (~> 2.0)
68
+ zeitwerk (~> 2.3)
69
+ ast (2.4.2)
70
+ builder (3.2.4)
71
+ concurrent-ruby (1.1.9)
72
+ crass (1.0.6)
73
+ diff-lcs (1.4.4)
74
+ erubi (1.10.0)
75
+ globalid (0.5.2)
76
+ activesupport (>= 5.0)
77
+ i18n (1.8.11)
78
+ concurrent-ruby (~> 1.0)
79
+ loofah (2.12.0)
80
+ crass (~> 1.0.2)
81
+ nokogiri (>= 1.5.9)
82
+ mail (2.7.1)
83
+ mini_mime (>= 0.1.1)
84
+ marcel (1.0.2)
85
+ method_source (1.0.0)
86
+ mini_mime (1.1.2)
87
+ mini_portile2 (2.6.1)
88
+ minitest (5.14.4)
89
+ nio4r (2.5.8)
90
+ nokogiri (1.12.5)
91
+ mini_portile2 (~> 2.6.1)
92
+ racc (~> 1.4)
93
+ parallel (1.21.0)
94
+ parser (3.0.2.0)
95
+ ast (~> 2.4.1)
96
+ racc (1.6.0)
97
+ rack (2.2.3)
98
+ rack-test (1.1.0)
99
+ rack (>= 1.0, < 3)
100
+ rails (6.1.4.1)
101
+ actioncable (= 6.1.4.1)
102
+ actionmailbox (= 6.1.4.1)
103
+ actionmailer (= 6.1.4.1)
104
+ actionpack (= 6.1.4.1)
105
+ actiontext (= 6.1.4.1)
106
+ actionview (= 6.1.4.1)
107
+ activejob (= 6.1.4.1)
108
+ activemodel (= 6.1.4.1)
109
+ activerecord (= 6.1.4.1)
110
+ activestorage (= 6.1.4.1)
111
+ activesupport (= 6.1.4.1)
112
+ bundler (>= 1.15.0)
113
+ railties (= 6.1.4.1)
114
+ sprockets-rails (>= 2.0.0)
115
+ rails-dom-testing (2.0.3)
116
+ activesupport (>= 4.2.0)
117
+ nokogiri (>= 1.6)
118
+ rails-html-sanitizer (1.4.2)
119
+ loofah (~> 2.3)
120
+ railties (6.1.4.1)
121
+ actionpack (= 6.1.4.1)
122
+ activesupport (= 6.1.4.1)
123
+ method_source
124
+ rake (>= 0.13)
125
+ thor (~> 1.0)
126
+ rainbow (3.0.0)
127
+ rake (13.0.6)
128
+ regexp_parser (2.1.1)
129
+ rexml (3.2.5)
130
+ rspec (3.10.0)
131
+ rspec-core (~> 3.10.0)
132
+ rspec-expectations (~> 3.10.0)
133
+ rspec-mocks (~> 3.10.0)
134
+ rspec-core (3.10.1)
135
+ rspec-support (~> 3.10.0)
136
+ rspec-expectations (3.10.1)
137
+ diff-lcs (>= 1.2.0, < 2.0)
138
+ rspec-support (~> 3.10.0)
139
+ rspec-mocks (3.10.2)
140
+ diff-lcs (>= 1.2.0, < 2.0)
141
+ rspec-support (~> 3.10.0)
142
+ rspec-support (3.10.3)
143
+ rubocop (1.22.3)
144
+ parallel (~> 1.10)
145
+ parser (>= 3.0.0.0)
146
+ rainbow (>= 2.2.2, < 4.0)
147
+ regexp_parser (>= 1.8, < 3.0)
148
+ rexml
149
+ rubocop-ast (>= 1.12.0, < 2.0)
150
+ ruby-progressbar (~> 1.7)
151
+ unicode-display_width (>= 1.4.0, < 3.0)
152
+ rubocop-ast (1.13.0)
153
+ parser (>= 3.0.1.1)
154
+ ruby-progressbar (1.11.0)
155
+ simple_calendar (2.4.3)
156
+ rails (>= 3.0)
157
+ sprockets (4.0.2)
158
+ concurrent-ruby (~> 1.0)
159
+ rack (> 1, < 3)
160
+ sprockets-rails (3.3.0)
161
+ actionpack (>= 5.2)
162
+ activesupport (>= 5.2)
163
+ sprockets (>= 3.0.0)
164
+ thor (1.1.0)
165
+ tzinfo (2.0.4)
166
+ concurrent-ruby (~> 1.0)
167
+ unicode-display_width (2.1.0)
168
+ websocket-driver (0.7.5)
169
+ websocket-extensions (>= 0.1.0)
170
+ websocket-extensions (0.1.5)
171
+ zeitwerk (2.5.1)
172
+
173
+ PLATFORMS
174
+ ruby
175
+ x86_64-darwin-19
176
+
177
+ DEPENDENCIES
178
+ rake
179
+ rspec (~> 3.2)
180
+ rubocop
181
+ simple_calendar-timeslot!
182
+
183
+ BUNDLED WITH
184
+ 2.2.21
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Kim Laplume
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # SimpleCalendar::Timeslot
2
+
3
+ This is an extension of the rubygem `simple_calendar` by Chris Oliver aka excid3. It allows
4
+ for simple calendar creation in a Ruby on Rails app with an timeslot representation of events
5
+ in a 24h day. This helps to visually grasps the length of events and the time between them. In case of overlapping, the respective events are shown side-by-side. It is also possible to categorise events in buckets according to some function, then they will be shown next to one another in the 24h timeline.
6
+ Horizontal and vertical layout is selectable via options, just like many other ones.
7
+
8
+ TODO: show examples
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'simple_calendar-timeslot'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install simple_calendar-timeslot
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/1klap/simple_calendar-timeslot.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+ =begin
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
17
+ =end
18
+
19
+ require "bundler/gem_tasks"
20
+
21
+ begin
22
+ require "rspec/core/rake_task"
23
+ RSpec::Core::RakeTask.new(:spec)
24
+ task default: :spec
25
+ rescue LoadError
26
+ end
@@ -0,0 +1,139 @@
1
+ <div class="slotted-calendar">
2
+ <div class="calendar-heading">
3
+ <%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
4
+ <span class="calendar-title"><%= t('date.month_names')[start_date.month] %> <%= start_date.year %></span>
5
+ <%= link_to t('simple_calendar.next', default: 'Next'), calendar.url_for_next_view %>
6
+ </div>
7
+
8
+ <% if calendar.orientation == :vertical %>
9
+ <div class="flex flex-row">
10
+ <% date_range.slice(0, 7).each do |day| %>
11
+ <div class="flex-1 border-0 border-gray-500 border-opacity-25">
12
+ <div class="day-title-row">
13
+ <span class="day-weekday">
14
+ <%= t('date.abbr_day_names')[day.wday] %>
15
+ </span>
16
+ <span class="day-date">
17
+ <%= day %>
18
+ </span>
19
+ </div>
20
+ <%= content_tag :div, class: calendar.td_classes_for(day) do %>
21
+ <div class="flex flex-col relative" style="height:<%=calendar.height%>px;">
22
+ <% if calendar.display_grid %>
23
+ <div class="cal-hour-indicator-col flex-1 flex flex-col" style="z-index:-10;">
24
+ <% if calendar.display_bucket_title %>
25
+ <div class="bucket-title" style="height:<%=calendar.bucket_title_size%>px"></div>
26
+ <% end %>
27
+ <% (0..23).each do |hour| %>
28
+ <div class="cal-hour-indicator border-t-2 border-gray-200 border-opacity-50 flex-1" id="hour-<%=hour %>">
29
+ <%=hour%>
30
+ </div>
31
+ <% end %>
32
+ </div>
33
+ <% end %>
34
+ <% events = sorted_events.fetch(day, []) %>
35
+ <% buckets = calendar.split_into_buckets(events) %>
36
+ <div class="absolute" style="left:<%=calendar.grid_width%>;right:0">
37
+ <div class="buckets w-full flex flex-row bg-white" style="z-index:1;">
38
+ <% buckets.each do |bucket| %>
39
+ <div class="flex-1">
40
+ <div class="bucket">
41
+ <% if calendar.display_bucket_title %>
42
+ <div class="bucket-title" style="height:<%=calendar.bucket_title_size%>px">
43
+ <%= bucket&.first&.send calendar.display_bucket_title %>
44
+ </div>
45
+ <% end %>
46
+ <div class="relative">
47
+ <% events_size = calendar.slot_events(bucket, day) %>
48
+ <% bucket.each do |event| %>
49
+ <div class="absolute border-2 border-opacity-25 border-red-500 bg-white rounded box-border hover:w-full" style="z-index:20;width:<%=events_size[event][0]%>%;top:<%=events_size[event][3]%>px;left:<%=events_size[event][1]%>%;height:<%=events_size[event][2]%>px">
50
+ <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
51
+ <% capture_haml(event, &passed_block) %>
52
+ <% else %>
53
+ <% passed_block.call event %>
54
+ <% end %>
55
+ </div>
56
+ <% end %>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ <% end %>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ <% end %>
65
+ </div>
66
+ <% end %>
67
+ </div>
68
+ <% elsif calendar.orientation == :horizontal %>
69
+ <div class="flex flex-col">
70
+ <% date_range.slice(0, 7).each do |day| %>
71
+ <div class="flex-1 border-0 border-gray-500 border-opacity-25">
72
+ <div class="day-title-row">
73
+ <span class="day-weekday">
74
+ <%= t('date.abbr_day_names')[day.wday] %>
75
+ </span>
76
+ <span class="day-date">
77
+ <%= day %>
78
+ </span>
79
+ </div>
80
+ <%= content_tag :div, class: calendar.td_classes_for(day) do %>
81
+ <div class="flex flex-col overflow-x-auto">
82
+ <div class="relative" style="width:<%=calendar.height%>px;height:<%=calendar.horizontal_height_px%>px">
83
+ <% if calendar.display_grid %>
84
+ <div class="cal-hour-indicator-col flex-1 flex flex-row h-full" style="z-index:-10;">
85
+ <% if calendar.display_bucket_title %>
86
+ <div class="bucket-title" style="width:<%=calendar.bucket_title_size%>px;"></div>
87
+ <% end %>
88
+ <% (0..23).each do |hour| %>
89
+ <div class="cal-hour-indicator border-l-2 border-gray-200 border-opacity-50 flex-1" id="hour-<%=hour %>">
90
+ <div style="height:20px">
91
+ <%=hour%>
92
+ </div>
93
+ </div>
94
+ <% end %>
95
+ </div>
96
+ <% end %>
97
+ <% events = sorted_events.fetch(day, []) %>
98
+ <% buckets = calendar.split_into_buckets(events) %>
99
+ <div class="absolute" style="top:<%=calendar.grid_width%>;bottom:0">
100
+ <div class="buckets flex flex-col bg-white absolute" >
101
+ <% buckets.each do |bucket| %>
102
+ <div class="flex-1 flex flex-row">
103
+ <% if calendar.display_bucket_title %>
104
+ <div class="bucket-title-size-wrap" style="width:<%=calendar.bucket_title_size%>px;">
105
+ <div class="bucket-title-text-wrapper">
106
+ <div class="bucket-title-text">
107
+ <%= bucket&.first&.send calendar.display_bucket_title %>
108
+ </div>
109
+ </div>
110
+ </div>
111
+ <% end %>
112
+ <div class="bucket relative" style="height:<%=(calendar.horizontal_height_px-(calendar.display_grid ? 20 : 0)) / buckets.size%>px;">
113
+ <div class="w-full">
114
+ <% events_size = calendar.slot_events(bucket, day) %>
115
+ <% bucket.each do |event| %>
116
+ <div class="absolute border-2 border-opacity-25 border-red-500 bg-white rounded box-border" style="height:<%=events_size[event][0]%>%;left:<%=events_size[event][3]%>px;top:<%=events_size[event][1]%>%;width:<%=events_size[event][2]%>px">
117
+ <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
118
+ <% capture_haml(event, &passed_block) %>
119
+ <% else %>
120
+ <% passed_block.call event %>
121
+ <% end %>
122
+ </div>
123
+ <% end %>
124
+ </div>
125
+ </div>
126
+ </div>
127
+ <% end %>
128
+ </div>
129
+ </div>
130
+ </div>
131
+ </div>
132
+ <% end %>
133
+ </div>
134
+ <% end %>
135
+ </div>
136
+ <% else %>
137
+ <div>Unsupported orientation: <%= calendar.orientation %></div>
138
+ <% end %>
139
+ </div>
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "simple_calendar/timeslot"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ module SimpleCalendar
2
+ module Timeslot
3
+ class Engine < Rails::Engine
4
+ initializer "simple_calendar-timeslot.view_helpers" do
5
+ ActiveSupport.on_load(:action_view) do
6
+ include ViewHelpers
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,153 @@
1
+ require "simple_calendar"
2
+
3
+ module SimpleCalendar
4
+ module Timeslot
5
+ class TimeslotCalendar < SimpleCalendar::Calendar
6
+ MINUTE_HEIGHT_PX = 0.65
7
+ FIRST_HOUR_SLOT = 0
8
+
9
+ def height
10
+ h = (24 - TimeslotCalendar::FIRST_HOUR_SLOT) * 60 * px_per_minute
11
+ h = h+bucket_title_size if display_bucket_title
12
+ h
13
+ end
14
+
15
+ def event_height(event, day)
16
+ minutes = if event.start_time.to_date != day
17
+ (event.end_time - event.end_time.midnight)/60
18
+ elsif event.start_time.to_date < event.end_time.to_date
19
+ (event.end_time.midnight - 60 - event.start_time)/60
20
+ else
21
+ event.duration
22
+ end
23
+ minutes * px_per_minute
24
+ end
25
+
26
+ def event_top_distance(event, day)
27
+ return 0 if event.start_time.to_date != day
28
+ (event.start_time.hour - TimeslotCalendar::FIRST_HOUR_SLOT) * 60 * px_per_minute + event.start_time.min * px_per_minute
29
+ end
30
+
31
+ def orientation
32
+ @options.fetch(:orientation, :vertical)
33
+ end
34
+
35
+ def horizontal_height_px
36
+ @options.fetch(:horizontal_height_px, 300)
37
+ end
38
+
39
+ def split_by_type
40
+ @options.fetch(:split_by_type, false)
41
+ end
42
+
43
+ def px_per_minute
44
+ @options.fetch(:px_per_minute, TimeslotCalendar::MINUTE_HEIGHT_PX)
45
+ end
46
+
47
+ def display_bucket_title
48
+ @options.fetch(:display_bucket_title, false)
49
+ end
50
+
51
+ def bucket_title_size
52
+ if display_bucket_title
53
+ @options.fetch(:bucket_title_size, 20)
54
+ else
55
+ 0
56
+ end
57
+ end
58
+
59
+ def grid_top_offset(hour)
60
+ 4.16666667 * hour
61
+ end
62
+
63
+ def grid_width
64
+ if display_grid
65
+ @options.fetch(:grid_width, "20px")
66
+ else
67
+ 0
68
+ end
69
+ end
70
+
71
+ def display_grid
72
+ @options.fetch(:display_grid, true)
73
+ end
74
+
75
+ def split_into_buckets(events)
76
+ if split_by_type
77
+ events.group_by{|e| e.send split_by_type}.values
78
+ else
79
+ [events]
80
+ end
81
+ end
82
+
83
+ def slot_events(events, day)
84
+ r = {}
85
+ events.each do |event|
86
+ r[event] = [0, 0, event_height(event, day), event_top_distance(event, day)]
87
+ end
88
+ #
89
+ columns = [[]]
90
+ last_event_ending = nil
91
+ events.each do |event|
92
+ if(!last_event_ending.nil? && event.start_time > last_event_ending)
93
+ pack_events(r, columns)
94
+ colums = [[]]
95
+ last_event_ending = nil
96
+ end
97
+ placed = false
98
+ columns.each do |col|
99
+ if !events_collide(r, col.last, event)
100
+ col << event
101
+ placed = true
102
+ break
103
+ end
104
+ end
105
+ if !placed
106
+ columns << [event]
107
+ end
108
+ event_end_time = event.start_time + event.duration.minutes
109
+ if last_event_ending.nil? || event_end_time > last_event_ending
110
+ last_event_ending = event_end_time
111
+ end
112
+ end
113
+ if columns.size > 0
114
+ pack_events(r, columns)
115
+ end
116
+ r
117
+ end
118
+
119
+ def pack_events(r, columns)
120
+ num_columns = columns.size.to_f
121
+ columns.each_with_index do |col, iter_col|
122
+ col.each do |event|
123
+ col_span = expand_event(r, event, iter_col, columns)
124
+ r[event][1] = (iter_col / num_columns)*100
125
+ r[event][0] = ((iter_col + col_span)/ (num_columns ))*100 - r[event][1]
126
+ end
127
+ end
128
+ end
129
+
130
+ def events_collide(r, event1, event2)
131
+ return false if event1.nil? || event2.nil?
132
+ event1_bottom = r[event1][3] + r[event1][2]
133
+ event2_bottom = r[event2][3] + r[event2][2]
134
+ event1_bottom > r[event2][3] && r[event1][3] < event2_bottom
135
+ end
136
+
137
+ def expand_event(r, event, iter_col, columns)
138
+ col_span = 1
139
+ columns.each_with_index do |column, index|
140
+ if index > iter_col
141
+ column.each do |event_iter|
142
+ return col_span if events_collide(r, event, event_iter)
143
+ end
144
+ col_span = col_span+1
145
+ end
146
+ end
147
+ col_span
148
+ end
149
+
150
+ private
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleCalendar
4
+ module Timeslot
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module SimpleCalendar
2
+ module Timeslot
3
+ module ViewHelpers
4
+ def timeslot_calendar(options = {}, &block)
5
+ raise "calendar requires a block" unless block
6
+ TimeslotCalendar.new(self, options).render(&block)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "timeslot/version"
4
+ require_relative "timeslot/timeslot_calendar"
5
+ require_relative "timeslot/view_helpers"
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/simple_calendar/timeslot/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "simple_calendar-timeslot"
7
+ spec.version = SimpleCalendar::Timeslot::VERSION
8
+ spec.authors = ["Kim Laplume"]
9
+ spec.email = ["kl@heartforge.eu"]
10
+
11
+ spec.summary = "Calendar with Timeslots for Ruby on Rails"
12
+ spec.description = "This gem extends simple_calendar to be able to display events in a 24h grid sized according to the respective start and end times"
13
+ spec.homepage = "https://github.com/1klap/simple_calendar-timeslot"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+ spec.license = "MIT"
16
+
17
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/1klap/simple_calendar-timeslot"
21
+ spec.metadata["changelog_uri"] = "https://github.com/1klap/simple_calendar-timeslot/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ # spec.bindir = "exe"
29
+ # spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency 'simple_calendar', '~> 2.0'
34
+ #spec.add_development_dependency 'rails'
35
+ spec.add_development_dependency "rspec", "~> 3.2"
36
+ spec.add_development_dependency 'rake'
37
+ spec.add_development_dependency 'rubocop'
38
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_calendar-timeslot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kim Laplume
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple_calendar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '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: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This gem extends simple_calendar to be able to display events in a 24h
70
+ grid sized according to the respective start and end times
71
+ email:
72
+ - kl@heartforge.eu
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".github/workflows/main.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - app/assets/stylesheets/simple_calendar-timeslot.css
88
+ - app/views/simple_calendar/timeslot/_timeslot_calendar.html.erb
89
+ - bin/console
90
+ - bin/setup
91
+ - lib/simple_calendar/timeslot.rb
92
+ - lib/simple_calendar/timeslot/railtie.rb
93
+ - lib/simple_calendar/timeslot/timeslot_calendar.rb
94
+ - lib/simple_calendar/timeslot/version.rb
95
+ - lib/simple_calendar/timeslot/view_helpers.rb
96
+ - simple_calendar-timeslot.gemspec
97
+ homepage: https://github.com/1klap/simple_calendar-timeslot
98
+ licenses:
99
+ - MIT
100
+ metadata:
101
+ homepage_uri: https://github.com/1klap/simple_calendar-timeslot
102
+ source_code_uri: https://github.com/1klap/simple_calendar-timeslot
103
+ changelog_uri: https://github.com/1klap/simple_calendar-timeslot/blob/main/CHANGELOG.md
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 2.4.0
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.1.2
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Calendar with Timeslots for Ruby on Rails
123
+ test_files: []