Skip to content

Event color #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/controllers/fullcalendar_engine/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def get_events
start: event.starttime.iso8601,
end: event.endtime.iso8601,
allDay: event.all_day,
recurring: (event.event_series_id) ? true : false }
recurring: (event.event_series_id) ? true : false,
color: event_color(event) }
end
render json: events.to_json
end
Expand Down Expand Up @@ -107,7 +108,7 @@ def load_event
end

def event_params
params.require(:event).permit('title', 'description', 'starttime', 'endtime', 'all_day', 'period', 'frequency', 'commit_button')
params.require(:event).permit(:title, :description, :starttime, :endtime, :all_day, :period, :frequency, :commit_button, :color)
end

def determine_event_type
Expand All @@ -121,5 +122,9 @@ def determine_event_type
def make_time_from_minute_and_day_delta(event_time)
params[:minute_delta].to_i.minutes.from_now((params[:day_delta].to_i).days.from_now(event_time))
end

def event_color(event)
event.color.presence || FullcalendarEngine.config.default_color
end
end
end
5 changes: 3 additions & 2 deletions app/models/fullcalendar_engine/event_series.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module FullcalendarEngine
class EventSeries < ActiveRecord::Base

attr_accessor :title, :description, :commit_button
attr_accessor :title, :description, :commit_button, :color
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why adding color to attr_accessor list when you are proposing it to be a column of the table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I'm not sure what you mean. I would like the user to be able to set the color of an event. To do so, shouldn't the color be accessible through attr_accessor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am saying that you don't need to put it in the accessor list. It will always be accessible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey. I'm pretty new to Rails. Would you mind telling me what's the difference from the title and the description that's in the attr_accessor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title and description are added as accessors in event_series model so that they can be used to set the values for any event model using that value. See here
Since I don't see that you are setting the color of the event any where in the code, that's why I asked you to remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You simply have to take care of the events create through the event_series part.
Just add another entry for color here.
And add a color picker as the input field in the form for event. You can learn more about color picker from here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I simply add it like this?

self.events.create(
  :title => title,
  :description => description,
  :all_day => all_day,
  :starttime => new_start_time,
  :endtime => new_end_time,
  :color => color
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and add the color picker as input field in the form as I asked in one of my previous comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know where to find such a color picker? How should you choose what color to pick?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply add f.color_field :name to the event form and you are done.


validates :frequency, :period, :starttime, :endtime, :title, :description, :presence => true

Expand All @@ -21,7 +21,8 @@ def create_events_until_end_time(end_time=RECURRING_EVENTS_UPTO)
:description => description,
:all_day => all_day,
:starttime => new_start_time,
:endtime => new_end_time
:endtime => new_end_time,
:color => color
)
new_start_time = old_start_time = frequency.send(frequency_period).from_now(old_start_time)
new_end_time = old_end_time = frequency.send(frequency_period).from_now(old_end_time)
Expand Down
6 changes: 5 additions & 1 deletion app/views/fullcalendar_engine/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<%=f.label :all_day %>
<%=f.check_box :all_day %>
</p>
<p>
<%=f.label :color %>
<%=f.color_field :color %>
</p>
<p>
<%=f.label :period, "Repeats" %>
<%=f.select :period, FullcalendarEngine::Event::REPEATS.values, {}, onchange: "FullcalendarEngine.Events.showPeriodAndFrequency(this.value);" %>
Expand All @@ -34,4 +38,4 @@
<p>
<%=f.submit %> <span id = "creating_events" class="spinner" style = "display:none;">Creating, Please wait...</span>
</p>
<%end %>
<%end %>
3 changes: 2 additions & 1 deletion config/initializers/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
'slotMinutes' => 15,
'dragOpacity' => 0.5,
'selectable' => true,
'timeFormat' => "h:mm t{ - h:mm t}"
'timeFormat' => "h:mm t{ - h:mm t}",
'default_color' => '#3B91AD'
}
FullcalendarEngine::Configuration.merge!(config)
FullcalendarEngine::Configuration['events'] = "#{FullcalendarEngine::Configuration['mount_path']}/events/get_events"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddColorToFullcalendarEngineEvent < ActiveRecord::Migration
def change
add_column :fullcalendar_engine_events, :color, :string
end
end