simple_calendar-timeslot 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6707f6b5e80e3b24e0329d17e629cfef2d39179c3e725baad3a60d526503963a
4
- data.tar.gz: c05379b32ca660ac1cee7d0c44ee09c2666c0bbbbf60759c169127e057c90d1d
3
+ metadata.gz: 7522e42ad4d981ea9307e4ec7af21b95bbf1c330d321e73fd8e265d73955346e
4
+ data.tar.gz: d6562afe5db9a28979553bc1a089fa2ad0454af8dae55f120bcefd8b3d617f36
5
5
  SHA512:
6
- metadata.gz: 74c59bce0c06b79e65b9838b39c4222b5e481546f43a577acaf56cda80781bf553a86d29bfd21366aeb0b0daa226fe5b7e630b482f5e435bd3280dd438316e6a
7
- data.tar.gz: 7c7583c4197f06951d76bc784a7444ec3c2c17bfcad0e466d7d3c3449407ec1de3f93b314f83c1e40c83322106554edabe6f5f6f8239916b8529308cf0d65e90
6
+ metadata.gz: 6557f1572ef373f53325412e0e8f47eb9acaa01f639cfce83b128a1a1e31a4657eb9ff841a01e3dec96d7fd69970675c33237e3fa5e6e8b60303a53a1e15e62d
7
+ data.tar.gz: ddafaefd0434bf85d5f29b01d31c9bb279028123ffd957a8332710d25bcf125d51d475f70f4133c652869ce21c40d6aff24ec29938dca2ae51e639bacf0f99f6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_calendar-timeslot (0.3.0)
4
+ simple_calendar-timeslot (0.4.0)
5
5
  simple_calendar (~> 2.0)
6
6
 
7
7
  GEM
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. 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.
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
- TODO: show examples
11
+ Horizontal example
12
+ ![Horizontal Calendar](img/simple_calendar-timeslot_horizontal.png)
13
+
14
+ Vertical example
15
+ ![Vertical Calendar](img/simple_calendar-timeslot_vertical.png)
16
+
9
17
 
10
18
  ## Installation
11
19
 
@@ -23,12 +31,51 @@ Or install it yourself as:
23
31
 
24
32
  $ gem install simple_calendar-timeslot
25
33
 
26
- TODO: include stylesheet, show sprockets and scss usecases
34
+
35
+ **Important** Then include the stylesheet in your rails app.
36
+
37
+ If you 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
+ ```
27
45
 
28
46
  ## Usage
29
47
 
30
48
  TODO: Write usage instructions here
31
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
+
32
79
  ## Development
33
80
 
34
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.
@@ -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(!last_event_ending.nil? && event.start_time > last_event_ending)
95
+ if !last_event_ending.nil? && event.send(attribute) > last_event_ending
93
96
  pack_events(r, columns)
94
- colums = [[]]
97
+ columns = [[]]
95
98
  last_event_ending = nil
96
99
  end
97
100
  placed = false
98
101
  columns.each do |col|
99
- if !events_collide(r, col.last, event)
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
- if !placed
108
+ unless placed
106
109
  columns << [event]
107
110
  end
108
- event_end_time = event.start_time + event.duration.minutes
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SimpleCalendar
4
4
  module Timeslot
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_calendar-timeslot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kim Laplume
@@ -88,6 +88,8 @@ files:
88
88
  - app/views/simple_calendar/timeslot/_timeslot_calendar.html.erb
89
89
  - bin/console
90
90
  - bin/setup
91
+ - img/simple_calendar-timeslot_horizontal.png
92
+ - img/simple_calendar-timeslot_vertical.png
91
93
  - lib/simple_calendar/timeslot.rb
92
94
  - lib/simple_calendar/timeslot/railtie.rb
93
95
  - lib/simple_calendar/timeslot/timeslot_calendar.rb