date_book 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/vcs.xml +6 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +23 -0
  5. data/.rubocop_todo.yml +7 -0
  6. data/.ruby-gemset +1 -0
  7. data/.ruby-version +1 -0
  8. data/.travis.yml +3 -0
  9. data/Gemfile +94 -0
  10. data/Gemfile.lock +385 -0
  11. data/LICENSE.txt +20 -0
  12. data/README.md +64 -0
  13. data/Rakefile +30 -0
  14. data/VERSION +1 -0
  15. data/app/assets/images/date_book/.keep +0 -0
  16. data/app/assets/javascripts/date_book.js +21 -0
  17. data/app/assets/javascripts/date_book/calendar_events.js +57 -0
  18. data/app/assets/javascripts/date_book/event_form.js +31 -0
  19. data/app/assets/javascripts/date_book/popovers.js +3 -0
  20. data/app/assets/javascripts/date_book/wysiwyg.js +8 -0
  21. data/app/assets/stylesheets/date_book.css.scss +46 -0
  22. data/app/controllers/date_book/calendars_controller.rb +60 -0
  23. data/app/controllers/date_book/date_book_controller.rb +24 -0
  24. data/app/controllers/date_book/events_controller.rb +105 -0
  25. data/app/controllers/date_book/graphql_controller.rb +35 -0
  26. data/app/graphql/date_book_schema.rb +18 -0
  27. data/app/graphql/types/calendar_type.rb +14 -0
  28. data/app/graphql/types/date_time_type.rb +7 -0
  29. data/app/graphql/types/event_occurrence_type.rb +11 -0
  30. data/app/graphql/types/event_type.rb +19 -0
  31. data/app/graphql/types/mutation_type.rb +5 -0
  32. data/app/graphql/types/profile_type.rb +7 -0
  33. data/app/graphql/types/query_type.rb +57 -0
  34. data/app/helpers/date_book/application_helper.rb +35 -0
  35. data/app/helpers/date_book/calendar_helper.rb +4 -0
  36. data/app/helpers/date_book/events_helper.rb +42 -0
  37. data/app/jobs/date_book/application_job.rb +6 -0
  38. data/app/mailers/date_book/application_mailer.rb +9 -0
  39. data/app/views/date_book/application/_all_day_checkbox.html.haml +1 -0
  40. data/app/views/date_book/application/_date_range.html.haml +8 -0
  41. data/app/views/date_book/application/_wysiwyg.html.haml +65 -0
  42. data/app/views/date_book/calendars/_form.html.haml +6 -0
  43. data/app/views/date_book/calendars/edit.html.haml +5 -0
  44. data/app/views/date_book/calendars/index.html.haml +28 -0
  45. data/app/views/date_book/calendars/new.html.haml +5 -0
  46. data/app/views/date_book/calendars/show.html.haml +28 -0
  47. data/app/views/date_book/events/_event.json.jbuilder +12 -0
  48. data/app/views/date_book/events/_form.html.haml +16 -0
  49. data/app/views/date_book/events/_occurrence_dates.html.haml +11 -0
  50. data/app/views/date_book/events/edit.html.haml +5 -0
  51. data/app/views/date_book/events/fields/_date.html.haml +1 -0
  52. data/app/views/date_book/events/fields/_day.html.haml +1 -0
  53. data/app/views/date_book/events/fields/_day_of_week.html.haml +19 -0
  54. data/app/views/date_book/events/fields/_duration.html.haml +6 -0
  55. data/app/views/date_book/events/fields/_interval.html.haml +1 -0
  56. data/app/views/date_book/events/fields/_time.html.haml +1 -0
  57. data/app/views/date_book/events/index.html.haml +16 -0
  58. data/app/views/date_book/events/new.html.haml +5 -0
  59. data/app/views/date_book/events/popover.html.haml +7 -0
  60. data/app/views/date_book/events/rules/_daily.html.haml +4 -0
  61. data/app/views/date_book/events/rules/_monthly.html.haml +5 -0
  62. data/app/views/date_book/events/rules/_singular.html.haml +4 -0
  63. data/app/views/date_book/events/rules/_weekly.html.haml +5 -0
  64. data/app/views/date_book/events/show.html.haml +16 -0
  65. data/app/views/layouts/_date_book_scripts.html.haml +4 -0
  66. data/app/views/layouts/blank.html.haml +1 -0
  67. data/bin/rails +15 -0
  68. data/config/locales/en.yml +44 -0
  69. data/config/routes.rb +12 -0
  70. data/date_book.gemspec +337 -0
  71. data/db/migrate/20170807133845_create_calendars.rb +11 -0
  72. data/db/migrate/20170807133846_create_events.rb +20 -0
  73. data/db/migrate/20170807133847_create_schedules.rb +25 -0
  74. data/db/migrate/20170807133848_add_fields_to_schedule.rb +6 -0
  75. data/db/migrate/20170807133849_create_event_occurrences.rb +16 -0
  76. data/db/migrate/20170807133850_add_fields_to_event_occurrences.rb +5 -0
  77. data/lib/date_book.rb +40 -0
  78. data/lib/date_book/concerns/ability.rb +27 -0
  79. data/lib/date_book/concerns/acts_as_calendar.rb +29 -0
  80. data/lib/date_book/concerns/acts_as_event.rb +66 -0
  81. data/lib/date_book/concerns/acts_as_event_occurrence.rb +67 -0
  82. data/lib/date_book/concerns/acts_as_ownable.rb +29 -0
  83. data/lib/date_book/concerns/acts_as_owner.rb +18 -0
  84. data/lib/date_book/concerns/acts_as_schedule.rb +44 -0
  85. data/lib/date_book/configuration.rb +43 -0
  86. data/lib/date_book/engine.rb +40 -0
  87. data/lib/date_book/localization.rb +32 -0
  88. data/lib/date_book/version.rb +8 -0
  89. data/lib/generators/date_book/install/install_generator.rb +110 -0
  90. data/lib/generators/date_book/install/templates/app/models/ability.rb +16 -0
  91. data/lib/generators/date_book/install/templates/app/models/calendar.rb +3 -0
  92. data/lib/generators/date_book/install/templates/app/models/event.rb +3 -0
  93. data/lib/generators/date_book/install/templates/app/models/event_occurrence.rb +3 -0
  94. data/lib/generators/date_book/install/templates/app/models/schedule.rb +3 -0
  95. data/lib/generators/date_book/install/templates/config/initializers/date_book.rb +5 -0
  96. data/lib/generators/date_book/utils.rb +25 -0
  97. data/lib/tasks/date_book_tasks.rake +5 -0
  98. data/spec/abilities/calendar_spec.rb +39 -0
  99. data/spec/abilities/event_spec.rb +44 -0
  100. data/spec/controllers/date_book/calendars_controller_spec.rb +259 -0
  101. data/spec/controllers/date_book/events_controller_spec.rb +283 -0
  102. data/spec/dummy/Rakefile +9 -0
  103. data/spec/dummy/app/assets/config/manifest.js +5 -0
  104. data/spec/dummy/app/assets/images/.keep +0 -0
  105. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  106. data/spec/dummy/app/assets/stylesheets/application.css.scss +4 -0
  107. data/spec/dummy/app/assets/stylesheets/bootstrap-everything.scss +54 -0
  108. data/spec/dummy/app/controllers/application_controller.rb +21 -0
  109. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  110. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  111. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  112. data/spec/dummy/app/models/ability.rb +16 -0
  113. data/spec/dummy/app/models/application_record.rb +5 -0
  114. data/spec/dummy/app/models/calendar.rb +3 -0
  115. data/spec/dummy/app/models/concerns/.keep +0 -0
  116. data/spec/dummy/app/models/event.rb +3 -0
  117. data/spec/dummy/app/models/event_occurrence.rb +3 -0
  118. data/spec/dummy/app/models/role.rb +13 -0
  119. data/spec/dummy/app/models/schedule.rb +3 -0
  120. data/spec/dummy/app/models/user.rb +9 -0
  121. data/spec/dummy/app/views/application/403.html.haml +9 -0
  122. data/spec/dummy/app/views/application/404.html.haml +9 -0
  123. data/spec/dummy/app/views/layouts/application.html.haml +43 -0
  124. data/spec/dummy/app/views/pages/index.html.haml +1 -0
  125. data/spec/dummy/bin/bundle +5 -0
  126. data/spec/dummy/bin/rails +6 -0
  127. data/spec/dummy/bin/rake +6 -0
  128. data/spec/dummy/bin/setup +36 -0
  129. data/spec/dummy/bin/update +31 -0
  130. data/spec/dummy/config.ru +7 -0
  131. data/spec/dummy/config/application.rb +38 -0
  132. data/spec/dummy/config/boot.rb +7 -0
  133. data/spec/dummy/config/cable.yml +9 -0
  134. data/spec/dummy/config/database.yml +25 -0
  135. data/spec/dummy/config/environment.rb +7 -0
  136. data/spec/dummy/config/environments/development.rb +60 -0
  137. data/spec/dummy/config/environments/test.rb +45 -0
  138. data/spec/dummy/config/initializers/application_controller_renderer.rb +7 -0
  139. data/spec/dummy/config/initializers/assets.rb +14 -0
  140. data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
  141. data/spec/dummy/config/initializers/bootstrap_leather.rb +9 -0
  142. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  143. data/spec/dummy/config/initializers/date_book.rb +5 -0
  144. data/spec/dummy/config/initializers/devise.rb +277 -0
  145. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  146. data/spec/dummy/config/initializers/high_voltage.rb +3 -0
  147. data/spec/dummy/config/initializers/inflections.rb +17 -0
  148. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  149. data/spec/dummy/config/initializers/new_framework_defaults.rb +29 -0
  150. data/spec/dummy/config/initializers/rolify.rb +7 -0
  151. data/spec/dummy/config/initializers/session_store.rb +5 -0
  152. data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
  153. data/spec/dummy/config/locales/devise.en.yml +64 -0
  154. data/spec/dummy/config/locales/en.yml +23 -0
  155. data/spec/dummy/config/puma.rb +49 -0
  156. data/spec/dummy/config/routes.rb +15 -0
  157. data/spec/dummy/config/secrets.yml +22 -0
  158. data/spec/dummy/config/spring.rb +8 -0
  159. data/spec/dummy/db/migrate/20170728171103_create_users_table.rb +7 -0
  160. data/spec/dummy/db/migrate/20170807134122_add_devise_to_users.rb +49 -0
  161. data/spec/dummy/db/migrate/20170807134128_rolify_create_roles.rb +19 -0
  162. data/spec/dummy/db/migrate/20170807134137_create_calendars.date_book.rb +12 -0
  163. data/spec/dummy/db/migrate/20170807134138_create_events.date_book.rb +21 -0
  164. data/spec/dummy/db/migrate/20170807134139_create_schedules.date_book.rb +26 -0
  165. data/spec/dummy/db/migrate/20170807134140_add_fields_to_schedule.date_book.rb +7 -0
  166. data/spec/dummy/db/migrate/20170807134141_create_event_occurrences.date_book.rb +17 -0
  167. data/spec/dummy/db/migrate/20170807134142_add_fields_to_event_occurrences.date_book.rb +6 -0
  168. data/spec/dummy/db/schema.rb +101 -0
  169. data/spec/dummy/db/seeds.rb +0 -0
  170. data/spec/dummy/db/seeds/calendars.seeds.rb +22 -0
  171. data/spec/dummy/db/seeds/events.seeds.rb +89 -0
  172. data/spec/dummy/db/seeds/users.seeds.rb +16 -0
  173. data/spec/dummy/lib/assets/.keep +0 -0
  174. data/spec/dummy/lib/basic_benchmark.rb +9 -0
  175. data/spec/dummy/log/.keep +0 -0
  176. data/spec/factories/calendars.rb +11 -0
  177. data/spec/factories/events.rb +12 -0
  178. data/spec/factories/roles.rb +5 -0
  179. data/spec/factories/users.rb +9 -0
  180. data/spec/features/calendars_spec.rb +185 -0
  181. data/spec/features/events_spec.rb +201 -0
  182. data/spec/helpers/date_book/calendar_helper_spec.rb +17 -0
  183. data/spec/helpers/date_book/events_helper_spec.rb +17 -0
  184. data/spec/models/calendar_spec.rb +26 -0
  185. data/spec/models/event_spec.rb +67 -0
  186. data/spec/models/role_spec.rb +5 -0
  187. data/spec/rails_helper.rb +116 -0
  188. data/spec/requests/date_book/events_spec.rb +56 -0
  189. data/spec/routing/date_book/calendars_routing_spec.rb +49 -0
  190. data/spec/routing/date_book/events_routing_spec.rb +54 -0
  191. data/spec/spec_helper.rb +102 -0
  192. data/spec/support/controller_behaviors.rb +101 -0
  193. data/spec/support/controller_macros.rb +25 -0
  194. data/spec/support/factory_girl.rb +3 -0
  195. data/spec/support/feature_behaviors.rb +150 -0
  196. data/spec/support/loaded_site.rb +5 -0
  197. data/spec/support/loaded_site/calendars.rb +5 -0
  198. data/spec/support/loaded_site/events.rb +6 -0
  199. data/spec/support/loaded_site/users.rb +5 -0
  200. data/spec/support/request_behaviors.rb +89 -0
  201. data/spec/support/shared_connection.rb +14 -0
  202. data/spec/support/utilities.rb +53 -0
  203. metadata +817 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 GemVein
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ # DateBook
2
+ Date Book, still in alpha develpment, is a Rails 5 Engine for managing and publishing a calendar of events.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'date_book'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Now, restart the rails server.
17
+
18
+ Create a User model if you don't have one:
19
+ ```bash
20
+ $ rails g model User name:string
21
+ $ rake db:migrate
22
+ ```
23
+
24
+ Then run the generator:
25
+ ```bash
26
+ $ rails g date_book:install
27
+ ```
28
+
29
+ And migrate your database again:
30
+ ```bash
31
+ $ rake db:migrate
32
+ ```
33
+
34
+ Add to the end of application.html:
35
+ ```html
36
+ <%= render_footer_javascript %>
37
+ ```
38
+
39
+ ## Build Occurences
40
+
41
+ ```bash
42
+ $ rake schedulable:build_occurrences
43
+ ```
44
+
45
+ ## Automating Build of Occurences
46
+ See [Schedulable: Automate Build of Occurences](https://github.com/benignware/schedulable#automate-build-of-occurrences) for information on setting up a crontab to automate the build of occurences
47
+
48
+ ## Contributing to Paid Up
49
+
50
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
51
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
52
+ * Fork the project.
53
+ * Start a feature/bugfix branch.
54
+ * Commit and push until you are happy with your contribution.
55
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
56
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
57
+
58
+ ## Contributors
59
+ * [Karen Lundgren](https://github.com/nerakdon)
60
+ * [Chad Lundgren](https://github.com/chadlundgren)
61
+
62
+ ## Copyright
63
+
64
+ Copyright (c) 2017 [Gem Vein](https://www.gemvein.com). See LICENSE.txt for further details.
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
10
+ load 'rails/tasks/engine.rake'
11
+
12
+ load 'rails/tasks/statistics.rake'
13
+
14
+ require 'bundler/gem_tasks'
15
+
16
+ require 'juwelier'
17
+ Juwelier::Tasks.new do |gem|
18
+ # gem is a Gem::Specification...
19
+ # see http://guides.rubygems.org/specification-reference/ for more options
20
+ gem.name = 'date_book'
21
+ gem.homepage = 'http://www.gemvein.com/museum/cases/date_book'
22
+ gem.license = 'MIT'
23
+ gem.summary = 'Rails 4 & 5 Engine that does stuff.'
24
+ gem.email = 'karen.e.lundgren@gmail.com'
25
+ gem.authors = ['Karen Lundgren']
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Juwelier::RubygemsDotOrgTasks.new
29
+
30
+ task default: :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
File without changes
@@ -0,0 +1,21 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require moment
14
+ //= require fullcalendar
15
+ //= require bootstrap-wysihtml5
16
+ //= require jquery_nested_form
17
+ //= require bootstrap-datetimepicker
18
+ //= require date_book/calendar_events
19
+ //= require date_book/event_form
20
+ //= require date_book/popovers
21
+ //= require date_book/wysiwyg
@@ -0,0 +1,57 @@
1
+ function calendarBySlugQuery(slug) {
2
+ // GraphQL requires double-quoted strings in the query:
3
+ return(' { calendar(slug: "' + slug + '") { event_occurrences { url, popover_url, start, end, event {id, name, description, css_class, all_day} } } } ');
4
+ }
5
+
6
+ function calendarEventsQuery(slug) {
7
+ // GraphQL requires double-quoted strings in the query:
8
+ return(' { event_occurrences { url, popover_url, start, end, event {id, name, description, css_class, all_day} } } ');
9
+ }
10
+
11
+ function formatEventOccurrence(occurrence) {
12
+ event = occurrence.event;
13
+ if(event.css_class == null) {
14
+ className = '';
15
+ } else {
16
+ className = event.css_class;
17
+ }
18
+ if(event.all_day == true) {
19
+ className = className + ' all-day';
20
+ } else {
21
+ className = className + ' part-day';
22
+ }
23
+ return({
24
+ id: event.id,
25
+ title: event.name,
26
+ description: event.description,
27
+ className: className,
28
+ allDay: event.all_day,
29
+ url: occurrence.url,
30
+ popover_url: occurrence.popover_url,
31
+ start: occurrence.start,
32
+ end: occurrence.end
33
+ });
34
+ }
35
+
36
+ function calendarEventRender(event, element) {
37
+ element.on('click', function (e){
38
+ e.preventDefault();
39
+ $.get(event.popover_url, function(ajax_data) {
40
+ element.popover({
41
+ html: true,
42
+ placement: 'auto',
43
+ viewport: '#calendar-display',
44
+ container: 'body',
45
+ title: '<a href="' + event.url + '">' + event.title + '</a><span onclick="hideParentPopover(this);" class="float-right glyphicon glyphicon-remove"></span>',
46
+ content: ajax_data
47
+ }).popover('show');
48
+ });
49
+ });
50
+
51
+ }
52
+
53
+ var calendarEventHeader = {
54
+ left: 'today',
55
+ center: 'prevYear,prev title next,nextYear',
56
+ right: 'month,agendaWeek,agendaDay'
57
+ }
@@ -0,0 +1,31 @@
1
+ function showRelevantSection (){
2
+ active_rule = $('input.event-schedule-rule:checked').first();
3
+ value = active_rule.val();
4
+ $('.event-schedule-rule-section').html(sections[value]);
5
+ }
6
+
7
+
8
+ $(function (){
9
+ var rules = $('.event-schedule-rule');
10
+ rules.on('change', function (e){
11
+ showRelevantSection();
12
+ }).trigger('change');
13
+
14
+ $('.input-group .all-day').on('change', function(){
15
+ associated_time = $(this).parents('.input-group').find('.time-picker');
16
+ if ($(this).is(':checked') == true) {
17
+ associated_time.prop('disabled', true);
18
+ associated_time.val('');
19
+ } else {
20
+ associated_time.prop('disabled', false);
21
+ }
22
+ });
23
+
24
+ $('.date-picker').datetimepicker({
25
+ format: 'YYYY-MM-DD'
26
+ });
27
+
28
+ $('.time-picker').datetimepicker({
29
+ format: 'LT'
30
+ });
31
+ });
@@ -0,0 +1,3 @@
1
+ function hideParentPopover(element){
2
+ $(element).parents('.popover').popover('hide');
3
+ }
@@ -0,0 +1,8 @@
1
+ $(function(){
2
+ $('.date-book--wysiwyg').wysihtml5({
3
+ toolbar: {
4
+ size: 'sm'
5
+ },
6
+ useLineBreaks: false
7
+ });
8
+ });
@@ -0,0 +1,46 @@
1
+ @import 'fullcalendar.css';
2
+ @import 'bootstrap-wysihtml5/bootstrap3-wysihtml5.css';
3
+ @import 'bootstrap-datetimepicker.css';
4
+
5
+ .all-day {
6
+
7
+ }
8
+
9
+ .part-day, .part-day:hover {
10
+ color: #000;
11
+ border: solid 1px #3A87AD;
12
+ background-color: lighten(#3A87AD, 50%);
13
+ }
14
+
15
+ .float-right {
16
+ float: right;
17
+ }
18
+
19
+ .required {
20
+ color: #c00;
21
+
22
+ &:before {
23
+ content: '* ';
24
+ color: #c00;
25
+ }
26
+ }
27
+
28
+ .date-picker, .time-picker {
29
+ width: 8em;
30
+ }
31
+
32
+ .input-group .form-control {
33
+ height: auto;
34
+ }
35
+
36
+ .input-group-addon .checkbox-inline {
37
+ padding-top: 0;
38
+ }
39
+
40
+ .event-schedule-rule-section .input-group {
41
+ max-width: 20em;
42
+ }
43
+
44
+ .margin-left {
45
+ margin-left: 1em;
46
+ }
@@ -0,0 +1,60 @@
1
+ module DateBook
2
+ class CalendarsController < DateBookController
3
+ load_and_authorize_resource find_by: :slug
4
+
5
+ # GET /calendars
6
+ def index
7
+ end
8
+
9
+ # GET /calendars/slug
10
+ def show
11
+ end
12
+
13
+ # GET /calendars/new
14
+ def new
15
+ end
16
+
17
+ # GET /calendars/slug/edit
18
+ def edit
19
+ end
20
+
21
+ # POST /calendars
22
+ def create
23
+ @calendar.owners = [current_user]
24
+ if @calendar.save
25
+ redirect_to @calendar, notice: :item_acted_on.l(item: Calendar.model_name.human, action: :created.l)
26
+ else
27
+ flash[:error] = @calendar.errors.full_messages.to_sentence
28
+ render :new
29
+ end
30
+ end
31
+
32
+ # PATCH/PUT /calendars/slug
33
+ def update
34
+ if @calendar.update(calendar_params)
35
+ redirect_to @calendar, notice: :item_acted_on.l(item: Calendar.model_name.human, action: :updated.l)
36
+ else
37
+ flash[:error] = @calendar.errors.full_messages.to_sentence
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /calendars/slug
43
+ def destroy
44
+ @calendar.destroy
45
+ redirect_to calendars_url, notice: :item_acted_on.l(item: Calendar.model_name.human, action: :destroyed.l)
46
+ end
47
+
48
+ private
49
+
50
+ # Only allow a trusted parameter "white list" through.
51
+ def calendar_params
52
+ params.require(:calendar).permit(
53
+ :id,
54
+ :name,
55
+ :description,
56
+ :css_class
57
+ )
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DateBook
4
+ # Some documentation goes here
5
+ class DateBookController < ::ApplicationController
6
+ helper :all
7
+ before_action :set_locale
8
+
9
+ # Prevent CSRF attacks using :exception in the main app
10
+ # and :null_session in the API
11
+ protect_from_forgery with: :exception, unless: :api_request?
12
+ protect_from_forgery with: :null_session, if: :api_request?
13
+
14
+ private
15
+
16
+ def api_request?
17
+ request.format.json?
18
+ end
19
+
20
+ def set_locale
21
+ I18n.locale = params[:locale] || I18n.default_locale
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,105 @@
1
+ module DateBook
2
+ class EventsController < DateBookController
3
+ load_and_authorize_resource :calendar, find_by: :slug
4
+ load_and_authorize_resource :event, find_by: :slug, through: :calendar
5
+ before_action :set_occurrence, only: [:show, :popover]
6
+
7
+ # GET /events
8
+ def index
9
+ start_date = params[:start]&.to_datetime || Time.now.beginning_of_month
10
+ end_date = params[:end]&.to_datetime || Time.now.beginning_of_month.next_month
11
+ @events = @events&.ending_after(start_date)&.starting_before(end_date)
12
+ end
13
+
14
+ # GET /events/slug
15
+ def show
16
+ end
17
+
18
+ # GET /events/slug/popover
19
+ def popover
20
+ render layout: 'blank'
21
+ end
22
+
23
+ # GET /events/new
24
+ def new
25
+ end
26
+
27
+ # GET /events/slug/edit
28
+ def edit
29
+ end
30
+
31
+ # POST /events
32
+ def create
33
+ @event.owners = [current_user]
34
+ if @event.save
35
+ redirect_to [@calendar, @event], notice: :item_acted_on.l(item: Event.model_name.human, action: :created.l)
36
+ else
37
+ flash[:error] = @event.errors.full_messages.to_sentence
38
+ render :new
39
+ end
40
+ end
41
+
42
+ # PATCH/PUT /events/slug
43
+ def update
44
+ if @event.update(event_params)
45
+ redirect_to [@calendar, @event], notice: :item_acted_on.l(item: Event.model_name.human, action: :updated.l)
46
+ else
47
+ flash[:error] = @event.errors.full_messages.to_sentence
48
+ render :edit
49
+ end
50
+ end
51
+
52
+ # DELETE /events/slug
53
+ def destroy
54
+ @event.destroy
55
+ redirect_to calendar_events_url(@calendar), notice: :item_acted_on.l(item: Event.model_name.human, action: :destroyed.l)
56
+ end
57
+
58
+ private
59
+ def set_occurrence
60
+ if params[:occurrence_id].present?
61
+ @occurrence = @event.event_occurrences.find(params[:occurrence_id])
62
+ end
63
+ end
64
+
65
+ # Only allow a trusted parameter "white list" through.
66
+ def event_params
67
+ schedule_attributes = [
68
+ :id,
69
+ :date,
70
+ :time,
71
+ :rule,
72
+ :until,
73
+ :count,
74
+ :interval,
75
+ :all_day,
76
+ {
77
+ day: [],
78
+ day_of_week: [
79
+ {
80
+ monday: [],
81
+ tuesday: [],
82
+ wednesday: [],
83
+ thursday: [],
84
+ friday: [],
85
+ saturday: [],
86
+ sunday: []
87
+ }
88
+ ],
89
+ duration_attributes: [
90
+ :count,
91
+ :unit
92
+ ]
93
+ }
94
+ ]
95
+
96
+ params.require(:event).permit(
97
+ :id,
98
+ :name,
99
+ :description,
100
+ :css_class,
101
+ schedule_attributes: schedule_attributes
102
+ )
103
+ end
104
+ end
105
+ end