simple_calendar-timeslot 0.1.0 → 0.5.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 +4 -4
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +3 -1
- data/README.md +51 -2
- data/app/assets/stylesheets/simple_calendar-timeslot.css +99 -0
- data/app/views/simple_calendar/timeslot/_timeslot_calendar.html.erb +24 -24
- data/lib/simple_calendar/timeslot/timeslot_calendar.rb +48 -45
- data/lib/simple_calendar/timeslot/version.rb +1 -1
- data/lib/simple_calendar/timeslot.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 500f5c006fc960a430d0a699af5dc48ddc9eafab0e3b4a9516b57c2cca11b1ba
|
4
|
+
data.tar.gz: '031169d10721e7fedbf94c1e797c1ef9f820c6b72eeadb343b049c56c0a56a4c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e590a993ec1a34e0cd9dc1e7984a63f9da1f440862e96c3fad2b0733f9c69287f594e3a41b059f78d39dec94d6c5a056b766a7f394d31f816e8ae7f9aa9fb038
|
7
|
+
data.tar.gz: 3f29f75df0d8117c8a14a48768fc8eb2af75375e438b7c709ca816ca70a7bcf93dbfb1eef4a62f1a04b7d928a59df330bd52b2658d8357f573a48ab00340453d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.5.0] - 2021-11-14
|
4
|
+
- Removed images for the README from the gem, sry :(
|
5
|
+
|
6
|
+
## [0.4.0] - 2021-11-14
|
7
|
+
### Added
|
8
|
+
- Added compatibilty with the attribute and end_attribute options in the view helper
|
9
|
+
- Added documentation to README
|
10
|
+
|
11
|
+
## [0.3.0] - 2021-11-14
|
12
|
+
### Fixed
|
13
|
+
- Fix issue with css styles when including style of this gem and simple_calendar
|
14
|
+
|
15
|
+
## [0.2.0] - 2021-11-14
|
16
|
+
### Fixed
|
17
|
+
- Fix css styles to be tailwind agnostic
|
18
|
+
|
3
19
|
## [0.1.0] - 2021-11-12
|
4
20
|
|
5
21
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_calendar-timeslot (0.
|
4
|
+
simple_calendar-timeslot (0.5.0)
|
5
5
|
simple_calendar (~> 2.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -90,6 +90,8 @@ GEM
|
|
90
90
|
nokogiri (1.12.5)
|
91
91
|
mini_portile2 (~> 2.6.1)
|
92
92
|
racc (~> 1.4)
|
93
|
+
nokogiri (1.12.5-x86_64-darwin)
|
94
|
+
racc (~> 1.4)
|
93
95
|
parallel (1.21.0)
|
94
96
|
parser (3.0.2.0)
|
95
97
|
ast (~> 2.4.1)
|
data/README.md
CHANGED
@@ -2,10 +2,18 @@
|
|
2
2
|
|
3
3
|
This is an extension of the rubygem `simple_calendar` by Chris Oliver aka excid3. It allows
|
4
4
|
for simple calendar creation in a Ruby on Rails app with an timeslot representation of events
|
5
|
-
in a 24h day.
|
5
|
+
in a 24h day.
|
6
|
+
|
7
|
+
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.
|
8
|
+
|
6
9
|
Horizontal and vertical layout is selectable via options, just like many other ones.
|
7
10
|
|
8
|
-
|
11
|
+
Horizontal example
|
12
|
+

|
13
|
+
|
14
|
+
Vertical example
|
15
|
+

|
16
|
+
|
9
17
|
|
10
18
|
## Installation
|
11
19
|
|
@@ -23,10 +31,51 @@ Or install it yourself as:
|
|
23
31
|
|
24
32
|
$ gem install simple_calendar-timeslot
|
25
33
|
|
34
|
+
|
35
|
+
**Important** Then include the stylesheet in your rails app.
|
36
|
+
|
37
|
+
If you have an `application.css` file, include the following:
|
38
|
+
```ruby
|
39
|
+
*= require simple_calendar-timeslot
|
40
|
+
```
|
41
|
+
If you use an SCSS file (`application.scss`), add the following line instead:
|
42
|
+
```ruby
|
43
|
+
@import 'simple_calendar-timeslot';
|
44
|
+
```
|
45
|
+
|
26
46
|
## Usage
|
27
47
|
|
28
48
|
TODO: Write usage instructions here
|
29
49
|
|
50
|
+
```erb
|
51
|
+
<%= timeslot_calendar(events: @events,
|
52
|
+
number_of_days: 2,
|
53
|
+
px_per_minute: 1.5,
|
54
|
+
orientation: :horizontal,
|
55
|
+
horizontal_height_px: 250,
|
56
|
+
# display_grid: false,
|
57
|
+
# display_bucket_title: :event_type,
|
58
|
+
# bucket_title_size: 30,
|
59
|
+
# grid_width: "20px",
|
60
|
+
# split_by_type: :event_type
|
61
|
+
) do |event| %>
|
62
|
+
<div class="timeslot-event">
|
63
|
+
<%= event.title %>
|
64
|
+
</div>
|
65
|
+
<% end %>
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
Shortversion in the meantime:
|
70
|
+
- orientation (:vertical, :horizontal, default: :vertical)
|
71
|
+
- horizontal_height_px default: 300
|
72
|
+
- split_by_type (model function to call in case of bucketung f.ex.`:event_type`, default: false)
|
73
|
+
- px_per_minute default: 0.65
|
74
|
+
- display_bucket_title (model function to call in case of bucketung f.ex.`:event_type_name`, default: false)
|
75
|
+
- bucket_title_size default: 20
|
76
|
+
- grid_width default: 20px
|
77
|
+
- display_grid default: true
|
78
|
+
|
30
79
|
## Development
|
31
80
|
|
32
81
|
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.
|
@@ -0,0 +1,99 @@
|
|
1
|
+
.timeslot-calendar div {
|
2
|
+
box-sizing: border-box;
|
3
|
+
}
|
4
|
+
.timeslot-calendar .days-wrapper-vertical {
|
5
|
+
display: flex;
|
6
|
+
flex-direction: row;
|
7
|
+
}
|
8
|
+
.timeslot-calendar .days-wrapper-horizontal {
|
9
|
+
display: flex;
|
10
|
+
flex-direction: column;
|
11
|
+
}
|
12
|
+
.timeslot-calendar .day-wrapper {
|
13
|
+
flex: 1 1 0;
|
14
|
+
}
|
15
|
+
.timeslot-calendar .day-content-vertical {
|
16
|
+
display: flex;
|
17
|
+
flex-direction: column;
|
18
|
+
position: relative;
|
19
|
+
}
|
20
|
+
.timeslot-calendar .day-content-horizontal {
|
21
|
+
display: flex;
|
22
|
+
flex-direction: column;
|
23
|
+
position: relative;
|
24
|
+
overflow-x: auto;
|
25
|
+
overflow-y: hidden;
|
26
|
+
}
|
27
|
+
.timeslot-calendar .day-content-horizontal-inner {
|
28
|
+
position: relative;
|
29
|
+
}
|
30
|
+
|
31
|
+
.timeslot-calendar .hour-indicator-col-vertical {
|
32
|
+
display: flex;
|
33
|
+
flex: 1 1 0;
|
34
|
+
flex-direction: column;
|
35
|
+
z-index: 0;
|
36
|
+
}
|
37
|
+
.timeslot-calendar .hour-indicator-col-horizontal {
|
38
|
+
display: flex;
|
39
|
+
flex: 1 1 0;
|
40
|
+
flex-direction: row;
|
41
|
+
height: 100%;
|
42
|
+
z-index: 0;
|
43
|
+
}
|
44
|
+
.timeslot-calendar .hour-indicator-vertical {
|
45
|
+
border-style: solid;
|
46
|
+
flex: 1 1 0;
|
47
|
+
border-width: 2px 0 0;
|
48
|
+
border-color: rgba(229, 231, 235, 0.5);
|
49
|
+
box-sizing: border-box;
|
50
|
+
}
|
51
|
+
.timeslot-calendar .hour-indicator-horizontal {
|
52
|
+
border-style: solid;
|
53
|
+
flex: 1 1 0;
|
54
|
+
border-width: 0 0 0 2px;
|
55
|
+
border-color: rgba(229, 231, 235, 0.5);
|
56
|
+
box-sizing: border-box;
|
57
|
+
}
|
58
|
+
.timeslot-calendar .buckets-wrapper {
|
59
|
+
position: absolute;
|
60
|
+
|
61
|
+
}
|
62
|
+
.timeslot-calendar .buckets-vertical {
|
63
|
+
display: flex;
|
64
|
+
flex-direction: row;
|
65
|
+
}
|
66
|
+
.timeslot-calendar .buckets-horizontal {
|
67
|
+
position: absolute;
|
68
|
+
display: flex;
|
69
|
+
flex-direction: column;
|
70
|
+
}
|
71
|
+
.timeslot-calendar .bucket-wrapper {
|
72
|
+
flex: 1 1 0;
|
73
|
+
}
|
74
|
+
.timeslot-calendar .bucket-horizontal {
|
75
|
+
flex: 1 1 0;
|
76
|
+
display: flex;
|
77
|
+
flex-direction: row;
|
78
|
+
}
|
79
|
+
.timeslot-calendar .bucket-inner-horizontal {
|
80
|
+
position: relative;
|
81
|
+
}
|
82
|
+
.timeslot-calendar .events-wrapper {
|
83
|
+
position: relative;
|
84
|
+
}
|
85
|
+
.timeslot-calendar .event-wrapper {
|
86
|
+
position: absolute;
|
87
|
+
z-index: 1;
|
88
|
+
box-sizing: border-box;
|
89
|
+
}
|
90
|
+
/*--- Event example style ----*/
|
91
|
+
.timeslot-event {
|
92
|
+
width: 100%;
|
93
|
+
height: 100%;
|
94
|
+
border-width: 2px;
|
95
|
+
border-style: solid;
|
96
|
+
border-color: rgba(0, 0, 0, 0.5);
|
97
|
+
border-radius: 0.25rem;
|
98
|
+
background-color: white;
|
99
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<div class="
|
1
|
+
<div class="timeslot-calendar">
|
2
2
|
<div class="calendar-heading">
|
3
3
|
<%= link_to t('simple_calendar.previous', default: 'Previous'), calendar.url_for_previous_view %>
|
4
4
|
<span class="calendar-title"><%= t('date.month_names')[start_date.month] %> <%= start_date.year %></span>
|
@@ -6,9 +6,9 @@
|
|
6
6
|
</div>
|
7
7
|
|
8
8
|
<% if calendar.orientation == :vertical %>
|
9
|
-
<div class="
|
9
|
+
<div class="days-wrapper-vertical">
|
10
10
|
<% date_range.slice(0, 7).each do |day| %>
|
11
|
-
<div class="
|
11
|
+
<div class="day-wrapper">
|
12
12
|
<div class="day-title-row">
|
13
13
|
<span class="day-weekday">
|
14
14
|
<%= t('date.abbr_day_names')[day.wday] %>
|
@@ -18,14 +18,14 @@
|
|
18
18
|
</span>
|
19
19
|
</div>
|
20
20
|
<%= content_tag :div, class: calendar.td_classes_for(day) do %>
|
21
|
-
<div class="
|
21
|
+
<div class="day-content-vertical" style="height:<%=calendar.height%>px;">
|
22
22
|
<% if calendar.display_grid %>
|
23
|
-
<div class="
|
23
|
+
<div class="hour-indicator-col-vertical">
|
24
24
|
<% if calendar.display_bucket_title %>
|
25
25
|
<div class="bucket-title" style="height:<%=calendar.bucket_title_size%>px"></div>
|
26
26
|
<% end %>
|
27
27
|
<% (0..23).each do |hour| %>
|
28
|
-
<div class="
|
28
|
+
<div class="hour-indicator-vertical" id="hour-<%=hour %>">
|
29
29
|
<%=hour%>
|
30
30
|
</div>
|
31
31
|
<% end %>
|
@@ -33,20 +33,20 @@
|
|
33
33
|
<% end %>
|
34
34
|
<% events = sorted_events.fetch(day, []) %>
|
35
35
|
<% buckets = calendar.split_into_buckets(events) %>
|
36
|
-
<div class="
|
37
|
-
<div class="buckets
|
36
|
+
<div class="buckets-wrapper" style="left:<%=calendar.grid_width%>;right:0">
|
37
|
+
<div class="buckets-vertical">
|
38
38
|
<% buckets.each do |bucket| %>
|
39
|
-
<div class="
|
40
|
-
<div class="bucket">
|
39
|
+
<div class="bucket-wrapper">
|
40
|
+
<div class="bucket-vertical">
|
41
41
|
<% if calendar.display_bucket_title %>
|
42
42
|
<div class="bucket-title" style="height:<%=calendar.bucket_title_size%>px">
|
43
43
|
<%= bucket&.first&.send calendar.display_bucket_title %>
|
44
44
|
</div>
|
45
45
|
<% end %>
|
46
|
-
<div class="
|
46
|
+
<div class="events-wrapper">
|
47
47
|
<% events_size = calendar.slot_events(bucket, day) %>
|
48
48
|
<% bucket.each do |event| %>
|
49
|
-
<div class="
|
49
|
+
<div class="event-wrapper" 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
50
|
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
|
51
51
|
<% capture_haml(event, &passed_block) %>
|
52
52
|
<% else %>
|
@@ -66,9 +66,9 @@
|
|
66
66
|
<% end %>
|
67
67
|
</div>
|
68
68
|
<% elsif calendar.orientation == :horizontal %>
|
69
|
-
<div class="
|
69
|
+
<div class="days-wrapper-horizontal">
|
70
70
|
<% date_range.slice(0, 7).each do |day| %>
|
71
|
-
<div class="
|
71
|
+
<div class="day-wrapper">
|
72
72
|
<div class="day-title-row">
|
73
73
|
<span class="day-weekday">
|
74
74
|
<%= t('date.abbr_day_names')[day.wday] %>
|
@@ -78,15 +78,15 @@
|
|
78
78
|
</span>
|
79
79
|
</div>
|
80
80
|
<%= content_tag :div, class: calendar.td_classes_for(day) do %>
|
81
|
-
<div class="
|
82
|
-
<div class="
|
81
|
+
<div class="day-content-horizontal">
|
82
|
+
<div class="day-content-horizontal-inner" style="width:<%=calendar.height%>px;height:<%=calendar.horizontal_height_px%>px">
|
83
83
|
<% if calendar.display_grid %>
|
84
|
-
<div class="
|
84
|
+
<div class="hour-indicator-col-horizontal" style="z-index:-10;">
|
85
85
|
<% if calendar.display_bucket_title %>
|
86
86
|
<div class="bucket-title" style="width:<%=calendar.bucket_title_size%>px;"></div>
|
87
87
|
<% end %>
|
88
88
|
<% (0..23).each do |hour| %>
|
89
|
-
<div class="
|
89
|
+
<div class="hour-indicator-horizontal" id="hour-<%=hour %>">
|
90
90
|
<div style="height:20px">
|
91
91
|
<%=hour%>
|
92
92
|
</div>
|
@@ -96,10 +96,10 @@
|
|
96
96
|
<% end %>
|
97
97
|
<% events = sorted_events.fetch(day, []) %>
|
98
98
|
<% buckets = calendar.split_into_buckets(events) %>
|
99
|
-
<div class="
|
100
|
-
<div class="buckets
|
99
|
+
<div class="buckets-wrapper" style="top:<%=calendar.grid_width%>;bottom:0">
|
100
|
+
<div class="buckets" >
|
101
101
|
<% buckets.each do |bucket| %>
|
102
|
-
<div class="
|
102
|
+
<div class="bucket-horizontal">
|
103
103
|
<% if calendar.display_bucket_title %>
|
104
104
|
<div class="bucket-title-size-wrap" style="width:<%=calendar.bucket_title_size%>px;">
|
105
105
|
<div class="bucket-title-text-wrapper">
|
@@ -109,11 +109,11 @@
|
|
109
109
|
</div>
|
110
110
|
</div>
|
111
111
|
<% end %>
|
112
|
-
<div class="
|
113
|
-
<div class="
|
112
|
+
<div class="events-wrapper" style="height:<%=(calendar.horizontal_height_px-(calendar.display_grid ? 20 : 0)) / buckets.size%>px;">
|
113
|
+
<div class="events-inner-horizontal">
|
114
114
|
<% events_size = calendar.slot_events(bucket, day) %>
|
115
115
|
<% bucket.each do |event| %>
|
116
|
-
<div class="
|
116
|
+
<div class="event-wrapper" style="height:<%=events_size[event][0]%>%;left:<%=events_size[event][3]%>px;top:<%=events_size[event][1]%>%;width:<%=events_size[event][2]%>px">
|
117
117
|
<% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(passed_block) %>
|
118
118
|
<% capture_haml(event, &passed_block) %>
|
119
119
|
<% else %>
|
@@ -1,53 +1,31 @@
|
|
1
1
|
require "simple_calendar"
|
2
2
|
|
3
3
|
module SimpleCalendar
|
4
|
-
module Timeslot
|
4
|
+
module Timeslot
|
5
5
|
class TimeslotCalendar < SimpleCalendar::Calendar
|
6
6
|
MINUTE_HEIGHT_PX = 0.65
|
7
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
|
-
|
8
|
+
|
31
9
|
def orientation
|
32
10
|
@options.fetch(:orientation, :vertical)
|
33
11
|
end
|
34
|
-
|
12
|
+
|
35
13
|
def horizontal_height_px
|
36
14
|
@options.fetch(:horizontal_height_px, 300)
|
37
15
|
end
|
38
|
-
|
16
|
+
|
39
17
|
def split_by_type
|
40
18
|
@options.fetch(:split_by_type, false)
|
41
19
|
end
|
42
|
-
|
20
|
+
|
43
21
|
def px_per_minute
|
44
22
|
@options.fetch(:px_per_minute, TimeslotCalendar::MINUTE_HEIGHT_PX)
|
45
23
|
end
|
46
|
-
|
24
|
+
|
47
25
|
def display_bucket_title
|
48
26
|
@options.fetch(:display_bucket_title, false)
|
49
27
|
end
|
50
|
-
|
28
|
+
|
51
29
|
def bucket_title_size
|
52
30
|
if display_bucket_title
|
53
31
|
@options.fetch(:bucket_title_size, 20)
|
@@ -55,11 +33,11 @@ module SimpleCalendar
|
|
55
33
|
0
|
56
34
|
end
|
57
35
|
end
|
58
|
-
|
36
|
+
|
59
37
|
def grid_top_offset(hour)
|
60
38
|
4.16666667 * hour
|
61
39
|
end
|
62
|
-
|
40
|
+
|
63
41
|
def grid_width
|
64
42
|
if display_grid
|
65
43
|
@options.fetch(:grid_width, "20px")
|
@@ -67,11 +45,35 @@ module SimpleCalendar
|
|
67
45
|
0
|
68
46
|
end
|
69
47
|
end
|
70
|
-
|
48
|
+
|
71
49
|
def display_grid
|
72
50
|
@options.fetch(:display_grid, true)
|
73
51
|
end
|
74
|
-
|
52
|
+
|
53
|
+
def height
|
54
|
+
#h = (24 - TimeslotCalendar::FIRST_HOUR_SLOT) * 60 * px_per_minute
|
55
|
+
h = 24 * 60 * px_per_minute
|
56
|
+
h = h+bucket_title_size if display_bucket_title
|
57
|
+
h
|
58
|
+
end
|
59
|
+
|
60
|
+
def event_height(event, day)
|
61
|
+
minutes = if event.send(attribute).to_date != day
|
62
|
+
(event.send(end_attribute) - event.send(end_attribute).midnight)/60
|
63
|
+
elsif event.send(attribute).to_date < event.send(end_attribute).to_date
|
64
|
+
(event.send(end_attribute).midnight - 60 - event.send(attribute))/60
|
65
|
+
else
|
66
|
+
event.duration
|
67
|
+
end
|
68
|
+
minutes * px_per_minute
|
69
|
+
end
|
70
|
+
|
71
|
+
def event_top_distance(event, day)
|
72
|
+
return 0 if event.send(attribute).to_date != day
|
73
|
+
#(event.send(attribute).hour - TimeslotCalendar::FIRST_HOUR_SLOT) * 60 * px_per_minute + event.send(attribute).min * px_per_minute
|
74
|
+
event.send(attribute).hour * 60 * px_per_minute + event.send(attribute).min * px_per_minute
|
75
|
+
end
|
76
|
+
|
75
77
|
def split_into_buckets(events)
|
76
78
|
if split_by_type
|
77
79
|
events.group_by{|e| e.send split_by_type}.values
|
@@ -79,33 +81,34 @@ module SimpleCalendar
|
|
79
81
|
[events]
|
80
82
|
end
|
81
83
|
end
|
82
|
-
|
84
|
+
|
83
85
|
def slot_events(events, day)
|
84
86
|
r = {}
|
85
87
|
events.each do |event|
|
86
88
|
r[event] = [0, 0, event_height(event, day), event_top_distance(event, day)]
|
87
89
|
end
|
88
|
-
#
|
90
|
+
# Credit: https://stackoverflow.com/questions/11311410/visualization-of-calendar-events-algorithm-to-layout-events-with-maximum-width
|
91
|
+
# Author: Markus Jarderot (https://stackoverflow.com/users/22364/markus-jarderot)
|
89
92
|
columns = [[]]
|
90
93
|
last_event_ending = nil
|
91
94
|
events.each do |event|
|
92
|
-
if
|
95
|
+
if !last_event_ending.nil? && event.send(attribute) > last_event_ending
|
93
96
|
pack_events(r, columns)
|
94
|
-
|
97
|
+
columns = [[]]
|
95
98
|
last_event_ending = nil
|
96
99
|
end
|
97
100
|
placed = false
|
98
101
|
columns.each do |col|
|
99
|
-
|
102
|
+
unless events_collide(r, col.last, event)
|
100
103
|
col << event
|
101
104
|
placed = true
|
102
105
|
break
|
103
106
|
end
|
104
107
|
end
|
105
|
-
|
108
|
+
unless placed
|
106
109
|
columns << [event]
|
107
110
|
end
|
108
|
-
event_end_time = event.
|
111
|
+
event_end_time = event.send(end_attribute)
|
109
112
|
if last_event_ending.nil? || event_end_time > last_event_ending
|
110
113
|
last_event_ending = event_end_time
|
111
114
|
end
|
@@ -115,7 +118,9 @@ module SimpleCalendar
|
|
115
118
|
end
|
116
119
|
r
|
117
120
|
end
|
118
|
-
|
121
|
+
|
122
|
+
private
|
123
|
+
|
119
124
|
def pack_events(r, columns)
|
120
125
|
num_columns = columns.size.to_f
|
121
126
|
columns.each_with_index do |col, iter_col|
|
@@ -126,14 +131,14 @@ module SimpleCalendar
|
|
126
131
|
end
|
127
132
|
end
|
128
133
|
end
|
129
|
-
|
134
|
+
|
130
135
|
def events_collide(r, event1, event2)
|
131
136
|
return false if event1.nil? || event2.nil?
|
132
137
|
event1_bottom = r[event1][3] + r[event1][2]
|
133
138
|
event2_bottom = r[event2][3] + r[event2][2]
|
134
139
|
event1_bottom > r[event2][3] && r[event1][3] < event2_bottom
|
135
140
|
end
|
136
|
-
|
141
|
+
|
137
142
|
def expand_event(r, event, iter_col, columns)
|
138
143
|
col_span = 1
|
139
144
|
columns.each_with_index do |column, index|
|
@@ -146,8 +151,6 @@ module SimpleCalendar
|
|
146
151
|
end
|
147
152
|
col_span
|
148
153
|
end
|
149
|
-
|
150
|
-
private
|
151
154
|
end
|
152
155
|
end
|
153
156
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_calendar-timeslot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kim Laplume
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_calendar
|