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

Event color #19

wants to merge 7 commits into from

Conversation

ehannes
Copy link
Contributor

@ehannes ehannes commented Nov 24, 2014

Adds support for changing color of an event. An attribute "color" is added to the FullcalendarEngine::Event model. Fullcalendar already has this function, and this pull request enables it in this rails engine.

This pull request fixes #18

@ehannes
Copy link
Contributor Author

ehannes commented Jan 14, 2015

Will you merge this pull request?

@@ -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.

@aditya-kapoor
Copy link
Contributor

hi @ehannes where do we stand on this?

@ehannes
Copy link
Contributor Author

ehannes commented Apr 6, 2015

Hi!
Sorry that I've not been in touch. I used this plugin in a project that was ended in February. Fortunately, I will resume the work of that project in May then I will try to complete this pull request.

@asadmoosa
Copy link

That is what I've been looking for. What about adding user_id? User_id + color will be awesome. Can you please write a full project (Fullcalendar_engine + project) so that I can understand how values of color and user_id are added to MySQL. And how to retrieve calendar based on user_id + color.

@ehannes
Copy link
Contributor Author

ehannes commented May 22, 2015

This pull request will unfortunately not, if I manage to finish it, include connection to user_id. It will only include the possibility to set the color of specific events in the calendar, a feature already available in Fullcalendar. Include user_id is, in my opinion, a totally different topic.

@asadmoosa
Copy link

Hannes, I totally agree with you that user_id is a different topic. I see that the color attribute is added to the gem. When i create a new project and Gemfile has that calendar gem and add a new model for user. How can the color of a speciic user be added to the event calendar?

@ehannes
Copy link
Contributor Author

ehannes commented Feb 2, 2016

@aditya-kapoor: Took me nearly a year or so, but now I've added the color attribute to the strong parameters list and a color picker to the GUI :) Are we ready to merge now?

@ehannes
Copy link
Contributor Author

ehannes commented Mar 16, 2016

@kuldeepaggarwal would you mind checking this PR as well?

'#3B91AD' #default color
else
event.color
end
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. can we extract default color to configuration, so that anyone can change the default as per their need?
  2. a little code picking:
def set_event_color(event)
  event.color.presence || FullcalendarEngine.config.default_color
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where would I include the default value? I had a look in config/initializers/configuration.rb, but if I understand it correctly, those values are passed to FullCalendar. The default_color value should not be passed to FullCalendar, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

User should be able to create an initializer file, like devise.rb if you are aware about that. And he can set default values in that configuration file.

@kuldeepaggarwal
Copy link
Contributor

@ehannes Any updates?

@ehannes
Copy link
Contributor Author

ehannes commented Mar 22, 2016

@kuldeepaggarwal Not yet I'm afraid. I'm not sure how to implement the initializer file. Any links or tips about that?

@kuldeepaggarwal
Copy link
Contributor

@ehannes We will implement that later, but could you please extract that logic to FullcalendarEngine::Configuration class and set default_color in that file and use FullcalendarEngine::Configuration.default_color

@scout208
Copy link

We are using this gem for a project and we really want to use this feature. @ehannes do you have any idea when you might be finished? Or is there anything I can help with?

@ehannes
Copy link
Contributor Author

ehannes commented Apr 3, 2016

Hi! Sorry for the delay.

@kuldeepaggarwal I gave it a try in 4bcc011. Was that what you meant? If not, please feel free to give further instructions. Otherwise I can push the branch to your repo so you can fix it.

@scout208 If we just get the default value for event color correct I think it's ready for merge.

@@ -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}",
'defaultColor' => '#3B91AD'
Copy link
Contributor

Choose a reason for hiding this comment

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

rename it to default_color.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All other variables in this config uses camelCase. Why should it use snake_case?

Copy link
Contributor

Choose a reason for hiding this comment

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

because all other variables are getting used on frontend, but if you just noticed at Line no: 18/19 we are using snake_case, as mount_path and default_color will be ruby realted variables.

I will think for a better implementation later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that clarification! I'll rename it then :)

@kuldeepaggarwal
Copy link
Contributor

@ehannes Just fix above issues and then I think, we are good to go.

Hannes Elvemyr added 2 commits April 3, 2016 18:17
According to Ruby best practice, setter methods should not be prefixed
with 'set'.
Ruby related variables should use snake_case instead of camelCase.
@ehannes
Copy link
Contributor Author

ehannes commented Apr 3, 2016

I should probably add that I have not tested these changes. And I see that the test coverage of this engine is about 0%... I am using the engine in one of my own applications, but I haven't tested this specific branch.

@kuldeepaggarwal
Copy link
Contributor

@ehannes Can you please test this in your app? It will be a great help.

@ehannes
Copy link
Contributor Author

ehannes commented Apr 4, 2016

@kuldeepaggarwal Ok, I'll test it. Though, it would be advisable to add at least some basic tests to this engine.

@kuldeepaggarwal
Copy link
Contributor

I agree that there must be test cases for the engine. Will plan something for this. Can you please create an issue for this on the repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing color of events
5 participants