diff --git a/Gemfile b/Gemfile index 255f5d9e..9220976a 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,8 @@ source 'https://rubygems.org' # The central piece of this application: the month calendar view gem 'simple_calendar' +# The recurrence management library +gem 'ice_cube' gem 'rails' gem 'has_scope' diff --git a/Gemfile.lock b/Gemfile.lock index 1687e8c4..f11b75f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -210,6 +210,7 @@ GEM http_accept_language (2.0.5) http_parser.rb (0.6.0) i18n (0.7.0) + ice_cube (0.14.0) inherited_resources (1.6.0) actionpack (>= 3.2, < 5) has_scope (~> 0.6.0.rc) @@ -447,6 +448,7 @@ DEPENDENCIES has_scope http_accept_language i18n-active_record! + ice_cube jbuilder jquery-rails (< 4.1) jquery-sparkline-rails! diff --git a/app/models/event.rb b/app/models/event.rb index 62548799..e7621bf9 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,6 +1,7 @@ # This is the central ADL class, where are managed all events class Event < ActiveRecord::Base extend SimpleCalendar + acts_as_schedulable :schedule strip_attributes has_paper_trail ignore: [:last_updated, :secret, :submitter, :decision_time, :lock_version, :latitude, :longitude] diff --git a/app/models/schedule.rb b/app/models/schedule.rb new file mode 100644 index 00000000..e931bf1a --- /dev/null +++ b/app/models/schedule.rb @@ -0,0 +1,3 @@ +# The data associated to recurrent events +class Schedule < Schedulable::Model::Schedule +end diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index e4d85edf..3c6a7974 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -12,13 +12,17 @@ .field.title = f.label :title - = f.text_field :title, required: true, placeholder: "#{t '.title_helper'}" + = f.text_field :title, required: true, placeholder: t('.title_helper') .field.start_time = f.label :start_time = f.datetime_local_field :start_time, required: true .field.end_time = f.label :end_time = f.datetime_local_field :end_time, required: true + .field + = f.label :schedule + = f.schedule_select :schedule, interval: true, until: true + .field.description .helper :markdown @@ -46,7 +50,8 @@ %option= city .field.region = f.label :region - = f.collection_select :region_id, Region.all, :id, :name, { include_blank: true } + = f.collection_select :region_id, Region.all, :id, :name, + include_blank: true .field.locality = f.label :locality %span.radios diff --git a/db/migrate/20160616190823_create_schedules.rb b/db/migrate/20160616190823_create_schedules.rb new file mode 100644 index 00000000..424686b0 --- /dev/null +++ b/db/migrate/20160616190823_create_schedules.rb @@ -0,0 +1,18 @@ +# Manage a schedule for events, that will let adl create recurring events +class CreateSchedules < ActiveRecord::Migration + def change + create_table :schedules do |t| + t.string :rule + t.string :interval + + t.text :day + t.text :day_of_week + + t.datetime :until + t.integer :count + + t.timestamps + end + add_reference :events, :schedule, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 4c0e4aba..52d88582 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160409131029) do +ActiveRecord::Schema.define(version: 20160616190823) do create_table "active_admin_comments", force: :cascade do |t| t.string "namespace", limit: 255 @@ -81,8 +81,10 @@ ActiveRecord::Schema.define(version: 20160409131029) do t.float "longitude", limit: 24 t.integer "lock_version", limit: 4, default: 0, null: false t.string "place_name", limit: 255 + t.integer "schedule_id" end + add_index "events", ["schedule_id"], name: "index_events_on_schedule_id" add_index "events", ["start_time", "end_time"], name: "events_date" create_table "kinds", force: :cascade do |t| @@ -134,6 +136,17 @@ ActiveRecord::Schema.define(version: 20160409131029) do t.string "name", limit: 255, default: "", null: false end + create_table "schedules", force: :cascade do |t| + t.string "rule" + t.string "interval" + t.text "day" + t.text "day_of_week" + t.datetime "until" + t.integer "count" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "taggings", force: :cascade do |t| t.integer "tag_id" t.integer "taggable_id"