tb_events 1.0.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +6 -14
  2. data/README.md +17 -5
  3. data/Rakefile +2 -2
  4. data/app/assets/javascripts/admin/events/application.js +16 -0
  5. data/app/assets/javascripts/{calendar_events.js → admin/events/calendar_events.js} +0 -0
  6. data/app/assets/javascripts/{spud/admin → admin/events}/calendars.js +0 -0
  7. data/app/assets/stylesheets/admin/events/application.css +4 -0
  8. data/app/assets/{javascripts/spud/events.js → stylesheets/admin/events/calendar_events.css} +0 -0
  9. data/app/assets/stylesheets/{spud → admin/events}/calendars.css +23 -28
  10. data/app/controllers/admin/calendar_events_controller.rb +67 -0
  11. data/app/controllers/{spud/admin → admin}/calendars_controller.rb +17 -14
  12. data/app/controllers/calendar_events_controller.rb +12 -6
  13. data/app/controllers/calendars_controller.rb +18 -18
  14. data/app/helpers/admin/calendar_events_helper.rb +2 -0
  15. data/app/helpers/admin/calendars_helper.rb +13 -0
  16. data/app/helpers/calendars_helper.rb +66 -35
  17. data/app/models/spud_calendar.rb +28 -3
  18. data/app/models/spud_calendar_event.rb +1 -20
  19. data/app/models/spud_events/calendar_event_model.rb +31 -0
  20. data/app/views/admin/calendar_events/_calendar.html.erb +19 -0
  21. data/app/views/admin/calendar_events/_form.html.erb +21 -0
  22. data/app/views/admin/calendar_events/edit.html.erb +1 -0
  23. data/app/views/admin/calendar_events/index.html.erb +28 -0
  24. data/app/views/admin/calendar_events/new.html.erb +1 -0
  25. data/app/views/admin/calendars/_calendar_legend.html.erb +8 -0
  26. data/app/views/admin/calendars/_form.html.erb +5 -0
  27. data/app/views/{spud/admin → admin}/calendars/edit.html.erb +0 -0
  28. data/app/views/{spud/admin → admin}/calendars/new.html.erb +0 -0
  29. data/app/views/calendar_events/index.html.erb +22 -0
  30. data/app/views/calendar_events/show.html.erb +7 -5
  31. data/app/views/calendars/show.html.erb +19 -4
  32. data/config/locales/en.yml +9 -0
  33. data/config/routes.rb +9 -15
  34. data/db/migrate/20120216191833_create_spud_calendars.rb +2 -2
  35. data/db/migrate/20140723203144_add_identifier_to_spud_calendars.rb +6 -0
  36. data/db/migrate/20140730182213_remove_color_from_spud_calendars.rb +9 -0
  37. data/lib/spud_events/calendar_builder.rb +53 -0
  38. data/lib/spud_events/configuration.rb +6 -0
  39. data/lib/spud_events/engine.rb +23 -0
  40. data/lib/spud_events/version.rb +3 -0
  41. data/lib/tb_events.rb +4 -4
  42. metadata +83 -131
  43. data/app/assets/javascripts/calendars.js +0 -2
  44. data/app/assets/javascripts/spud/admin/calendar_events.js +0 -2
  45. data/app/assets/javascripts/spud/admin/events.js +0 -51
  46. data/app/assets/lib/colorpicker/colorpicker.css +0 -164
  47. data/app/assets/lib/colorpicker/colorpicker.js +0 -484
  48. data/app/assets/lib/colorpicker/images/blank.gif +0 -0
  49. data/app/assets/lib/colorpicker/images/colorpicker_background.png +0 -0
  50. data/app/assets/lib/colorpicker/images/colorpicker_hex.png +0 -0
  51. data/app/assets/lib/colorpicker/images/colorpicker_hsb_b.png +0 -0
  52. data/app/assets/lib/colorpicker/images/colorpicker_hsb_h.png +0 -0
  53. data/app/assets/lib/colorpicker/images/colorpicker_hsb_s.png +0 -0
  54. data/app/assets/lib/colorpicker/images/colorpicker_indic.gif +0 -0
  55. data/app/assets/lib/colorpicker/images/colorpicker_overlay.png +0 -0
  56. data/app/assets/lib/colorpicker/images/colorpicker_rgb_b.png +0 -0
  57. data/app/assets/lib/colorpicker/images/colorpicker_rgb_g.png +0 -0
  58. data/app/assets/lib/colorpicker/images/colorpicker_rgb_r.png +0 -0
  59. data/app/assets/lib/colorpicker/images/colorpicker_select.gif +0 -0
  60. data/app/assets/lib/colorpicker/images/colorpicker_submit.png +0 -0
  61. data/app/assets/lib/colorpicker/images/custom_background.png +0 -0
  62. data/app/assets/lib/colorpicker/images/custom_hex.png +0 -0
  63. data/app/assets/lib/colorpicker/images/custom_hsb_b.png +0 -0
  64. data/app/assets/lib/colorpicker/images/custom_hsb_h.png +0 -0
  65. data/app/assets/lib/colorpicker/images/custom_hsb_s.png +0 -0
  66. data/app/assets/lib/colorpicker/images/custom_indic.gif +0 -0
  67. data/app/assets/lib/colorpicker/images/custom_rgb_b.png +0 -0
  68. data/app/assets/lib/colorpicker/images/custom_rgb_g.png +0 -0
  69. data/app/assets/lib/colorpicker/images/custom_rgb_r.png +0 -0
  70. data/app/assets/lib/colorpicker/images/custom_submit.png +0 -0
  71. data/app/assets/lib/colorpicker/images/select.png +0 -0
  72. data/app/assets/lib/colorpicker/images/select2.png +0 -0
  73. data/app/assets/lib/colorpicker/images/slider.png +0 -0
  74. data/app/assets/stylesheets/spud/admin/events.css +0 -16
  75. data/app/assets/stylesheets/spud/calendar_events.css +0 -18
  76. data/app/assets/stylesheets/spud/events.css +0 -4
  77. data/app/controllers/spud/admin/calendar_events_controller.rb +0 -64
  78. data/app/helpers/spud/admin/calendar_events_helper.rb +0 -2
  79. data/app/helpers/spud/admin/calendars_helper.rb +0 -15
  80. data/app/views/calendars/_calendar.html.erb +0 -26
  81. data/app/views/calendars/_calendar_options.html.erb +0 -4
  82. data/app/views/spud/admin/calendar_events/_calendar.html.erb +0 -14
  83. data/app/views/spud/admin/calendar_events/_form.html.erb +0 -98
  84. data/app/views/spud/admin/calendar_events/edit.html.erb +0 -1
  85. data/app/views/spud/admin/calendar_events/index.html.erb +0 -20
  86. data/app/views/spud/admin/calendar_events/new.html.erb +0 -1
  87. data/app/views/spud/admin/calendars/_calendar_legend.html.erb +0 -7
  88. data/app/views/spud/admin/calendars/_form.html.erb +0 -20
  89. data/config/application.rb +0 -50
  90. data/config/boot.rb +0 -6
  91. data/lib/spud/events/calendar.rb +0 -85
  92. data/lib/spud/events/calendar_builder.rb +0 -58
  93. data/lib/spud/events/configuration.rb +0 -10
  94. data/lib/spud/events/engine.rb +0 -26
  95. data/lib/spud/events/table_builder.rb +0 -88
  96. data/lib/spud/events/version.rb +0 -5
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZmMyNDc4N2IzN2I4NWVlYTlkNTM5ODM3NTQ0YTVkY2ZiZjFhYWE3NA==
5
- data.tar.gz: !binary |-
6
- NDgzMTViOGY5MjNkMGI1Zjg3ZDBjZDU4Y2M4ZjZiZWQwZTU5YzFkOA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDAzOWU5ZDIwNDY1NDVkNWQ0ZDg2MzliYjA0Yjg0NzgxNWIxN2RiNDhlMzI5
10
- Y2M2ODk2ODA4Yjg2ODg1OTk3OTc0ZTVjMjIyNTNkNWQ4MzQ1ZTY0YzhhZDNl
11
- NmIxNzc4MTdmMTJjOTRlZjYyNzI3YmQ2N2Y3Njk1MzhjOGJjMWE=
12
- data.tar.gz: !binary |-
13
- MzdhZWI5Yzk2NWY3ZmUyOGU5ZjNjMjliMDk3NjlhZGM0ZTU0Njk2YzBlYTA2
14
- NGU5ZWYzOTM2ODEzZGM5MGQwYWUxZjZkNjQ0ZTU3NWU3NzVkN2IzNTgwM2Q4
15
- NTg1NGM1NTExNDlkY2ZkODUzYTk5OTE0ZGI5Njg0ZDA1ZDg2ZDE=
2
+ SHA256:
3
+ metadata.gz: d8495699ef036385ff906c76c7d34b616b024c3c167f4e543d929d8cc15c95bf
4
+ data.tar.gz: c384b0864d671436b70da6aedd9877657f95d588227958fcb73569771ac3fa21
5
+ SHA512:
6
+ metadata.gz: 9473623e16c4e10a2184574bf4c5fc9b5e6bc5bf2c18f725dce12dc6696b97a85761b223446ad2b341be0095cc1f04fb99e005da86bddb1a7b1781fb2cb23a7b
7
+ data.tar.gz: 441459722f410fc0aff5508b49345c359953ad722a3dabdc75f34799b8afaa7cecc6064dacc6335284dda39c4f4d5312084e4c8c7e5718a25b64ff75f02e6888
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
- Spud Events
1
+ TB Events
2
2
  ===========
3
3
 
4
- Spud Events is an event and calendaring engine for the Spud Engine
4
+ TB Events is an event and calendaring engine for Twice Baked.
5
5
 
6
6
  Installation/Usage
7
7
  ------------------
8
8
 
9
9
  1. Add the following to your Gemfile
10
10
 
11
- gem 'spud_core'
12
- gem 'spud_events', :git => "git://github.com/davydotcom/spud_events.git"
11
+ gem 'tb_core'
12
+ gem 'tb_events'
13
13
 
14
14
  2. Run ```bundle install```
15
15
  3. Copy the database migrations in to your rails project
@@ -24,7 +24,7 @@ Configruations
24
24
 
25
25
  * Set the layout for the calendar pages (Defualt is layouts/spud/calendar)
26
26
 
27
- Spud::Events.configure do |config|
27
+ SpudEvents.configure do |config|
28
28
  config.calendar_layout = 'application'
29
29
  end
30
30
 
@@ -36,6 +36,18 @@ Configruations
36
36
  *= require spud/events
37
37
  */
38
38
 
39
+ ## View Helpers
40
+
41
+ TB Events comes with a handful of view helpers for generating calendars. See the Rdoc documentation for detailed information.
42
+
43
+ Return a calendar as an html table for the given date:
44
+
45
+ spud_calendar_for_date(date)
46
+
47
+ Return a calendar for the given date, populated with event data:
48
+
49
+ spud_calendar_for_events(events, date, opts)
50
+
39
51
  Testing
40
52
  -----------------
41
53
 
data/Rakefile CHANGED
@@ -20,9 +20,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
23
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
26
  Bundler::GemHelper.install_tasks
27
27
 
28
- require 'rake'
28
+ require 'rake'
@@ -0,0 +1,16 @@
1
+ //= require_self
2
+ //= require_directory
3
+
4
+ (function(){
5
+
6
+ spud.admin.events = {
7
+ init: function(){
8
+ $(document).on('ajax:success','.js-spud-calendar-delete-action', deletedCalendar);
9
+ }
10
+ };
11
+
12
+ var deletedCalendar = function(){
13
+ $(this).closest('.spud_events_admin_calendar_legend_item').fadeOut(500, function(){ $(this).remove(); });
14
+ };
15
+
16
+ })();
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require_self
3
+ *= require_directory
4
+ */
@@ -49,10 +49,8 @@
49
49
 
50
50
  #spud_events_admin_calendar,
51
51
  #spud_events_calendar {
52
- width: 700px;
53
- padding-bottom: 50px;
52
+ margin: 0 0 20px;
54
53
  position: relative;
55
- float: left;
56
54
  }
57
55
  #spud_events_calendar {
58
56
  width: auto;
@@ -66,7 +64,7 @@
66
64
  margin: 15px 0 0;
67
65
  }
68
66
  #spud_events_admin_calendar th,
69
- #spud_events_calendar th {
67
+ #spud_events_calendar th {
70
68
  text-align: center;
71
69
  }
72
70
  #spud_events_admin_calendar td,
@@ -78,21 +76,33 @@
78
76
  vertical-align: top;
79
77
  width: 98px;
80
78
  }
81
- .spud_events_admin_calendar_date_container,
82
- .spud_events_calendar_date_container {
83
- display: block;
84
- padding: 18px 5px 0;
85
- position: relative;
86
- }
87
- span.spud_events_admin_calendar_date,
88
- span.spud_events_calendar_date {
79
+ .calendar-day{
89
80
  position: absolute;
90
81
  top: 3px;
91
- right: 3px;
82
+ left: 3px;
92
83
  font-size: 11px;
93
84
  line-height: 11px;
94
85
  }
95
86
 
87
+ .not-month .calendar-day {
88
+ display: none;
89
+ }
90
+ .not-month .calendar-events {
91
+ display: none;
92
+ }
93
+
94
+ .calendar-events-list{
95
+ list-style: none;
96
+ margin: 10px 0 0;
97
+ padding: 0;
98
+ }
99
+ .calendar-events-list li{
100
+ margin: 4px;
101
+ }
102
+ .calendar-events-list a{
103
+ text-decoration: none;
104
+ }
105
+
96
106
  /* Calendar Legend
97
107
  ----------------------- */
98
108
  #spud_events_admin_calendar_legend,
@@ -100,7 +110,6 @@ span.spud_events_calendar_date {
100
110
  list-style: none;
101
111
  border: 1px solid #d9d9d9;
102
112
  padding: 0;
103
- margin: 45px 0 0 725px;
104
113
  }
105
114
  #spud_events_admin_calendar_legend li,
106
115
  #spud_events_calendar_legend li {
@@ -120,17 +129,3 @@ span.spud_events_calendar_date {
120
129
  #spud_events_calendar_legend li:last-child {
121
130
  border: none;
122
131
  }
123
- .spud_events_admin_calendar_actions,
124
- .spud_events_calendar_actions {
125
- text-align: right;
126
- }
127
-
128
- #spud_events_admin_calendar_legend span,
129
- #spud_events_calendar_legend span {
130
- display: inline-block;
131
- -moz-border-radius: 3px;
132
- -webkit-border-radius: 3px;
133
- border-radius: 3px;
134
- padding: 2px 8px;
135
- margin: 8px 0 0 8px;
136
- }
@@ -0,0 +1,67 @@
1
+ class Admin::CalendarEventsController < Admin::ApplicationController
2
+ add_breadcrumb 'Events', :admin_list_spud_calendar_events_path
3
+ belongs_to_app :events
4
+
5
+ respond_to :html, :xml, :json
6
+ respond_to :js, only: [:index]
7
+
8
+ def index
9
+ if params[:month]
10
+ year = params[:year] ? params[:year].to_i : Date.today.year
11
+ begin
12
+ @calendar_date = Date.new(year, params[:month].to_i)
13
+ rescue
14
+ @calendar_date = Date.today
15
+ end
16
+ else
17
+ @calendar_date = Date.today
18
+ end
19
+
20
+ if params[:spud_calendar] && calendar = SpudCalendar.find_by_title(params[:spud_calendar].titleize)
21
+ @calendar_events = calendar.events
22
+ else
23
+ @calendar_events = SpudCalendarEvent
24
+ end
25
+ @calendar_events = @calendar_events.in_month_of(@calendar_date).order('spud_calendar_events.start_at ASC').to_a
26
+
27
+ @calendars = SpudCalendar.all
28
+ @current_calendar = params[:spud_calendar] ? params[:spud_calendar] : 0
29
+
30
+ respond_with(@calendars, include: :events)
31
+ end
32
+
33
+ def new
34
+ @calendar_event = SpudCalendarEvent.new
35
+ if params[:spud_calendar]
36
+ @calendar_event.spud_calendar_id = SpudCalendar.find_by_title(params[:spud_calendar].titleize).id
37
+ end
38
+ end
39
+
40
+ def edit
41
+ @calendar_event = SpudCalendarEvent.find(params[:id])
42
+ end
43
+
44
+ def create
45
+ @calendar_event = SpudCalendarEvent.new(calendar_event_params)
46
+ flash[:notice] = 'Calendar event was successfully created.' if @calendar_event.save
47
+ respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
48
+ end
49
+
50
+ def update
51
+ @calendar_event = SpudCalendarEvent.find(params[:id])
52
+ flash[:notice] = 'Calendar event was successfully updated.' if @calendar_event.update_attributes(calendar_event_params)
53
+ respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
54
+ end
55
+
56
+ def destroy
57
+ @calendar_event = SpudCalendarEvent.find(params[:id])
58
+ flash[:notice] = 'Calendar event deleted successfully' if @calendar_event.destroy
59
+ respond_with(@calendar_event, location: admin_list_spud_calendar_events_path)
60
+ end
61
+
62
+ private
63
+
64
+ def calendar_event_params
65
+ params.require(:spud_calendar_event).permit(:title, :description, :start_at, :end_at, :all_day, :spud_calendar_id, :spud_calendar, :location, :address, :address_2, :city, :state, :zip)
66
+ end
67
+ end
@@ -1,40 +1,38 @@
1
- class Spud::Admin::CalendarsController < Spud::Admin::ApplicationController
1
+ class Admin::CalendarsController < Admin::ApplicationController
2
+ add_breadcrumb 'Events', :admin_list_spud_calendar_events_path
2
3
 
3
- layout 'spud/admin/detail'
4
- add_breadcrumb "Events", :spud_admin_list_spud_calendar_events_path
5
-
6
- belongs_to_spud_app :events
4
+ belongs_to_app :events
7
5
 
8
6
  respond_to :html, :xml, :json, :js
9
7
 
10
8
  def new
11
- @page_name = "New Calendar"
9
+ @page_name = 'New Calendar'
12
10
  @calendar = SpudCalendar.new
13
11
  respond_with(@calendar)
14
12
  end
15
13
 
16
14
  def create
17
- @calendar = SpudCalendar.new(params[:spud_calendar])
15
+ @calendar = SpudCalendar.new(calendar_params)
18
16
  if @calendar.save
19
- redirect_to spud_admin_list_spud_calendar_events_path
17
+ redirect_to admin_list_spud_calendar_events_path
20
18
  else
21
- render :action => "new"
19
+ render action: 'new'
22
20
  end
23
21
  end
24
22
 
25
23
  def edit
26
- @page_name = "Edit Calendar"
24
+ @page_name = 'Edit Calendar'
27
25
  @calendar = SpudCalendar.find(params[:id])
28
26
  respond_with(@calendar)
29
27
  end
30
28
 
31
29
  def update
32
30
  @calendar = SpudCalendar.find(params[:id])
33
- if @calendar.update_attributes(params[:spud_calendar])
31
+ if @calendar.update_attributes(calendar_params)
34
32
  flash[:notice] = 'Calendar was successfully updated.'
35
- redirect_to spud_admin_list_spud_calendar_events_path
33
+ redirect_to admin_list_spud_calendar_events_path
36
34
  else
37
- render :action => "edit"
35
+ render action: 'edit'
38
36
  end
39
37
  end
40
38
 
@@ -45,8 +43,13 @@ class Spud::Admin::CalendarsController < Spud::Admin::ApplicationController
45
43
  end
46
44
  @calendar.destroy
47
45
  respond_with(@calendar) do |format|
48
- format.js { render(:nothing => true) }
46
+ format.js { render(nothing: true) }
49
47
  end
50
48
  end
51
49
 
50
+ private
51
+
52
+ def calendar_params
53
+ params.require(:spud_calendar).permit(:title)
54
+ end
52
55
  end
@@ -1,8 +1,14 @@
1
1
  class CalendarEventsController < ApplicationController
2
-
3
- layout Spud::Events.config.calendar_layout || 'spud/calendar'
4
-
5
- def show
6
- @event = SpudCalendarEvent.find(params[:id])
7
- end
2
+ respond_to :html, :json
3
+ layout SpudEvents.config.calendar_layout
4
+
5
+ def index
6
+ @events = SpudCalendarEvent.ordered.paginate(per_page: 10, page: params[:page])
7
+ respond_with @events
8
+ end
9
+
10
+ def show
11
+ @event = SpudCalendarEvent.find(params[:id])
12
+ respond_with @event
13
+ end
8
14
  end
@@ -1,30 +1,30 @@
1
1
  class CalendarsController < ApplicationController
2
-
3
- layout Spud::Events.config.calendar_layout || 'spud/calendar'
2
+ respond_to :html, :json
3
+ layout SpudEvents.config.calendar_layout
4
+ before_action :calendar_date
4
5
 
5
6
  def show
6
- if params[:month]
7
- year = params[:year] ? params[:year] : Time.new.year
8
- begin
9
- @calendar_date = Time.local(year, params[:month])
10
- rescue
11
- @calendar_date = default_date
12
- end
13
- else
14
- @calendar_date = default_date
15
- end
16
7
  if params[:calendar] && calendar = SpudCalendar.find_by_title(params[:calendar].titleize)
17
- @events = calendar.spud_calendar_events.where(["start_at >= ?",@calendar_date]).order(:start_at).all
8
+ @events = calendar.spud_calendar_events.in_month_of(@calendar_date).order(:start_at).to_a
18
9
  else
19
- @events = SpudCalendarEvent.where(["start_at >= ?",@calendar_date]).order(:start_at).all
10
+ @events = SpudCalendarEvent.in_month_of(@calendar_date).order(:start_at).to_a
20
11
  end
21
12
  @current_calendar = params[:calendar] ? params[:calendar] : 0
22
- @page_title = @calendar_date.strftime("Calendar - %B %Y")
13
+ respond_with @events
23
14
  end
24
15
 
25
- def default_date
26
- tempDate = Time.new
27
- return Time.local(tempDate.year,tempDate.month)
16
+ private
28
17
 
18
+ def calendar_date
19
+ if params[:month]
20
+ year = params[:year] ? params[:year].to_i : Date.today.year
21
+ begin
22
+ @calendar_date = Date.new(year, params[:month].to_i)
23
+ rescue
24
+ @calendar_date = Date.today
25
+ end
26
+ else
27
+ @calendar_date = Date.today
28
+ end
29
29
  end
30
30
  end
@@ -0,0 +1,2 @@
1
+ module Admin::CalendarEventsHelper
2
+ end
@@ -0,0 +1,13 @@
1
+ module Admin::CalendarsHelper
2
+ def link_to_previous_admin_calendar_month(date, _url_for_options = {})
3
+ date = date.advance(months: -1)
4
+ calendar = params[:calendar] ? params[:calendar] : nil
5
+ link_to('&laquo; Previous Month'.html_safe, admin_list_spud_calendar_events_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link previous_calendar btn btn-sm btn-default').html_safe
6
+ end
7
+
8
+ def link_to_next_admin_calendar_month(date, _url_for_options = {})
9
+ date = date.advance(months: 1)
10
+ calendar = params[:calendar] ? params[:calendar] : nil
11
+ link_to('Next Month &raquo;'.html_safe, admin_list_spud_calendar_events_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link next_calendar btn btn-sm btn-default pull-right').html_safe
12
+ end
13
+ end
@@ -1,48 +1,79 @@
1
1
  module CalendarsHelper
2
-
3
- def link_to_previous_calendar_month(date, url_for_options)
4
- date = date.advance(:months => -1)
5
- calendar = params[:calendar] ? params[:calendar] : nil
6
- link_to('&laquo; Previous Month'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link previous_calendar btn').html_safe
2
+ # Builds a calendar for the given date
3
+ #
4
+ # * date: Determines the month to be displayed. Given date will have the "today" css class
5
+ # * opts:
6
+ # - headers: Array of weekday headers (optional)
7
+ #
8
+ def spud_calendar_for_date(date, opts = {}, &block)
9
+ events = SpudCalendarEvent.in_month_of(date)
10
+ spud_calendar_for_events(events, date, opts, &block)
7
11
  end
8
12
 
9
- def link_to_next_calendar_month(date, url_for_options)
10
- date = date.advance(:months => 1)
11
- calendar = params[:calendar] ? params[:calendar] : nil
12
- link_to('Next Month &raquo;'.html_safe, calendar_path(:month => date.month, :year => date.year, :calendar => calendar), :class => 'spud_events_calendar_link next_calendar btn').html_safe
13
- end
14
-
15
- def build_calendar_for(objects, *args, &block)
16
- raise ArgumentError, "Missing block" unless block_given?
17
- options = args.last.is_a?(Hash) ? args.pop : {}
18
- html_options = options[:html]
19
- builder = options[:builder] || Spud::Events::CalendarBuilder
20
- content = with_output_buffer{block.call(builder.new(objects||[], self, options))}
21
- self.content_tag(:table, content, html_options, false)
22
- end
23
-
24
- def get_calendar_options(text_for_all)
25
- options_for_select(SpudCalendar.all.collect { |f| [f.title, f.title.gsub(/([^A-Z0-9]+)/i, "-").downcase] }.insert(0, text_for_all), @current_calendar)
13
+ # Builds a calendar for the given date and identifier
14
+ #
15
+ # * identifier: Symbol for the SpudCalendar you wish to display
16
+ # * date: Determines the month to be displayed. Given date will have the "today" css class
17
+ # * opts:
18
+ # - headers: Array of weekday headers (optional)
19
+ #
20
+ def spud_calendar_for_identifier(identifier, date, opts = {}, &block)
21
+ calendar = SpudCalendar.with_identifier(identifier)
22
+ if calendar.present?
23
+ events = calendar.spud_calendar_events.in_month_of(date)
24
+ else
25
+ logger.warn "Failed to load calendar by identifer '#{identifier}'. Does it exist?"
26
+ events = []
27
+ end
28
+ spud_calendar_for_events(events, date, opts, &block)
26
29
  end
27
30
 
28
- def calendar_fore_color(backcolor)
29
- fore_color = "ffffff"
30
- if backcolor.length != 6
31
- return fore_color
31
+ # Builds a calendar for the given date, with events
32
+ #
33
+ # * events: An array or relation of SpudCalendarEvent records
34
+ # * date: Determines the month to be displayed. Given date will have the "today" css class
35
+ # * opts:
36
+ # - headers: Array of weekday headers (optional)
37
+ #
38
+ def spud_calendar_for_events(events, date, opts = {}, &block)
39
+ events_array = events.to_a
40
+ cache(['spud-calendar', date.to_s, events]) do
41
+ concat(
42
+ SpudEvents::CalendarBuilder.new(self, date, opts).table do |day|
43
+ events = extract_events_for_date(events_array, day)
44
+ if block
45
+ block.call(day, events)
46
+ else
47
+ concat content_tag(:span, day.day.to_s, class: 'calendar-day')
48
+ if events.length > 0
49
+ list_items = events.collect do |event|
50
+ '<li>' + link_to(event.title, calendar_event_path(event)) + '</li>'
51
+ end.join('')
52
+ concat content_tag(:ul, raw(list_items), class: 'events-list')
53
+ end
54
+ end
55
+ end
56
+ )
32
57
  end
58
+ end
33
59
 
34
- red = backcolor[0,2].hex
35
- green = backcolor[2,2].hex
36
- blue = backcolor[4,2].hex
60
+ def link_to_previous_calendar_month(date)
61
+ date = date.advance(months: -1)
62
+ calendar = params[:calendar] ? params[:calendar] : nil
63
+ link_to('&laquo; Previous Month'.html_safe, calendar_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link previous_calendar btn').html_safe
64
+ end
37
65
 
38
- perceived_brightness = Math.sqrt(red*red*0.241 + green*green*0.691 + blue*blue*0.068)
66
+ def link_to_next_calendar_month(date)
67
+ date = date.advance(months: 1)
68
+ calendar = params[:calendar] ? params[:calendar] : nil
69
+ link_to('Next Month &raquo;'.html_safe, calendar_path(month: date.month, year: date.year, calendar: calendar), class: 'spud_events_calendar_link next_calendar btn').html_safe
70
+ end
39
71
 
72
+ private
40
73
 
41
- # average = (red+green+blue) / 3
42
- if(perceived_brightness >= 130)
43
- return "000000"
44
- else
45
- return fore_color
74
+ def extract_events_for_date(events, date)
75
+ events.select do |event|
76
+ date >= event.start_date && date <= event.end_date
46
77
  end
47
78
  end
48
79
  end