Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: nikhgupta/event_line
base: 8a9b417e09
...
head fork: nikhgupta/event_line
compare: 78b1a7acfa
  • 2 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
View
3  Gemfile
@@ -44,7 +44,10 @@ end
# Use debugger
# gem 'debugger', group: [:development, :test]
+# helpers
gem 'acts-as-taggable-on'
+gem 'chronic'
+gem 'validates_timeliness'
group :development do
gem 'pry-rails'
View
6 Gemfile.lock
@@ -39,6 +39,7 @@ GEM
xpath (~> 2.0)
celluloid (0.15.2)
timers (~> 1.1.0)
+ chronic (0.10.2)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.0.1)
@@ -206,6 +207,7 @@ GEM
thread_safe (0.1.3)
atomic
tilt (1.4.1)
+ timeliness (0.3.7)
timers (1.1.0)
tins (0.13.1)
treetop (1.4.15)
@@ -217,6 +219,8 @@ GEM
uglifier (2.3.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
+ validates_timeliness (3.0.14)
+ timeliness (~> 0.3.6)
websocket-driver (0.3.1)
xpath (2.0.0)
nokogiri (~> 1.3)
@@ -226,6 +230,7 @@ PLATFORMS
DEPENDENCIES
acts-as-taggable-on
+ chronic
coffee-rails (~> 4.0.0)
coveralls
cucumber-rails
@@ -251,3 +256,4 @@ DEPENDENCIES
terminal-notifier-guard
turbolinks
uglifier (>= 1.3.0)
+ validates_timeliness
View
5 Guardfile
@@ -3,7 +3,7 @@
notification :terminal_notifier
-guard :rspec, cmd: "bundle exec rspec --color", all_on_start: true do
+guard :rspec, zeus: true, bundler: false, all_on_start: true do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
@@ -24,8 +24,7 @@ guard :rspec, cmd: "bundle exec rspec --color", all_on_start: true do
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
-
-guard 'cucumber', cmd: "bundle exec cucumber --color" do
+guard :cucumber, command_prefix: "zeus" do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
View
3  app/assets/javascripts/events.js.coffee
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://coffeescript.org/
View
18 app/assets/javascripts/events.js.coffee.erb
@@ -0,0 +1,18 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/
+
+$ ->
+
+ # capture the json for this timeline
+ event_json = $("#timeline-embed").data("event-json")
+
+ # prepare the timeline data
+ event_data = {
+ type: 'timeline',
+ source: event_json,
+ embed_id: "timeline-embed"
+ }
+
+ # create the timeline
+ createStoryJS event_data
View
4 app/models/channel.rb
@@ -3,6 +3,10 @@ class Channel < ActiveRecord::Base
validates :url, presence: true, url: true, allow_blank: false
before_save :sanitize_data
+ def timeline_json
+ { media: url, thumbnail: thumbnail, credit: credits, caption: caption }
+ end
+
private
def sanitize_data
View
21 app/models/event.rb
@@ -4,12 +4,27 @@ class Event < ActiveRecord::Base
before_save :sanitize_data
def cover
- slide = slides.select { |slide| slide.cover }.first
- slide ? slide : slides.first
+ slides.primary.first
+ end
+
+ def subsidiary
+ slides.subsidiary.all
end
def channels
- slides.map{|slide| slide.channel}.compact
+ slides.map(&:channel).compact
+ end
+
+ def timeline_json
+ return {timeline: {date: []}} unless slides.any?
+ _slides = subsidiary.map(&:timeline_json)
+ { timeline: cover.timeline_json.merge(type: "default", date: _slides) }.to_json
+ end
+
+ def self.timeline_for id
+ event = Event.find(id)
+ return nil unless event
+ event.timeline_json
end
private
View
18 app/models/slide.rb
@@ -5,9 +5,27 @@ class Slide < ActiveRecord::Base
before_save :sanitize_data
acts_as_taggable
+ scope :primary, lambda{ where(cover: true) }
+ scope :subsidiary, lambda{ where(cover: false) }
+
+ validates_datetime :end_date, if: :start_date, allow_nil: true, on_or_after: :start_date
+ validates_datetime :end_date, unless: :start_date, allow_nil: true, is_at: Time.at(0)
+ validates_datetime :start_date, if: :end_date, allow_nil: false, on_or_before: :end_date
+ validates_datetime :start_date, unless: :end_date, allow_nil: true, on_or_before: lambda{|m| Time.now}
+
+ # TODO: missing classname
+ def timeline_json
+ json = {headline: title, text: description, tag: tag_list.join(", ")}
+ json[:startDate] = start_date.strftime("%Y,%m,%d") if start_date
+ json[:endDate] = end_date.strftime("%Y,%m,%d") if end_date
+ json[:asset] = channel.timeline_json if channel
+ json
+ end
+
private
def sanitize_data
self.description = nil if self.description.blank?
+ self.cover = true unless self.event.cover
end
end
View
2  app/views/events/show.html.erb
@@ -12,3 +12,5 @@
<%= link_to 'Edit', edit_event_path(@event) %> |
<%= link_to 'Back', events_path %>
+
+<div id="timeline-embed" data-event-json="<%= @event.timeline_json %>"></div>
View
1  app/views/layouts/application.html.erb
@@ -5,6 +5,7 @@
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
+ <script type="text/javascript" src="http://cdn.knightlab.com/libs/timeline/latest/js/storyjs-embed.js"></script>
</head>
<body>
View
40 config/initializers/validates_timeliness.rb
@@ -0,0 +1,40 @@
+ValidatesTimeliness.setup do |config|
+ # Extend ORM/ODMs for full support (:active_record, :mongoid).
+ # config.extend_orms = [ :active_record ]
+ #
+ # Default timezone
+ # config.default_timezone = :utc
+ #
+ # Set the dummy date part for a time type values.
+ # config.dummy_date_for_time_type = [ 2000, 1, 1 ]
+ #
+ # Ignore errors when restriction options are evaluated
+ # config.ignore_restriction_errors = false
+ #
+ # Re-display invalid values in date/time selects
+ # config.enable_date_time_select_extension!
+ #
+ # Handle multiparameter date/time values strictly
+ # config.enable_multiparameter_extension!
+ #
+ # Shorthand date and time symbols for restrictions
+ # config.restriction_shorthand_symbols.update(
+ # :now => lambda { Time.current },
+ # :today => lambda { Date.current }
+ # )
+ #
+ # Use the plugin date/time parser which is stricter and extendable
+ # config.use_plugin_parser = false
+ #
+ # Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy')
+ # config.parser.add_formats()
+ #
+ # Remove one or more formats making them invalid. e.g. remove_formats(:date, 'dd/mm/yyy')
+ # config.parser.remove_formats()
+ #
+ # Change the amiguous year threshold when parsing a 2 digit year
+ # config.parser.ambiguous_year_threshold = 30
+ #
+ # Treat ambiguous dates, such as 01/02/1950, as a Non-US date.
+ # config.parser.remove_us_formats
+end
View
16 config/locales/validates_timeliness.en.yml
@@ -0,0 +1,16 @@
+en:
+ errors:
+ messages:
+ invalid_date: "is not a valid date"
+ invalid_time: "is not a valid time"
+ invalid_datetime: "is not a valid datetime"
+ is_at: "must be at %{restriction}"
+ before: "must be before %{restriction}"
+ on_or_before: "must be on or before %{restriction}"
+ after: "must be after %{restriction}"
+ on_or_after: "must be on or after %{restriction}"
+ validates_timeliness:
+ error_value_formats:
+ date: '%Y-%m-%d'
+ time: '%H:%M:%S'
+ datetime: '%Y-%m-%d %H:%M:%S'
View
4 spec/controllers/slides_controller_spec.rb
@@ -20,6 +20,10 @@
describe SlidesController do
+ before do
+ create(:event, id: 1)
+ end
+
# This should return the minimal set of attributes required to create a valid
# Slide. As you add validations to Slide, be sure to
# adjust the attributes here as well.
View
3  spec/models/channel_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe Channel do
+ subject { create(:channel) }
it { should belong_to(:slide) }
it { should validate_presence_of(:url) }
@@ -11,7 +12,7 @@
it { should allow_value('http://github.com', 'https://google.com/something?as=da').for(:url)}
it { should_not allow_value(" ", nil, 'http://', 'asdasda', "//google.com").for(:url)}
- context "when saving new channel" do
+ context "when being saved" do
it "should trim whitespace on caption, credits and thumbnail" do
channel = create(:channel, thumbnail: " ", caption: " ", credits: " ")
channel.caption.should be_nil
View
22 spec/models/event_spec.rb
@@ -1,16 +1,16 @@
require 'spec_helper'
describe Event do
- let(:event) { create(:event) }
+ subject { create(:event) }
it { should have_many(:slides) }
it { should validate_presence_of(:title) }
- it { should_not allow_value(" ", nil).for(:title) }
it { should allow_value(" ", nil).for(:description) }
+ it { should_not allow_value(" ", nil).for(:title) }
# FIXME: should have atleast one slide?
# it { should_not allow_value([]).for(:slides) }
- context "when saving new event" do
+ context "when being saved" do
it "strips whitespace from description" do
event = create(:event, description: " ")
event.description.should be_nil
@@ -19,28 +19,28 @@
context "without any associated slide" do
it "should not have a cover slide" do
- event.cover.should be_nil
+ subject.cover.should be_nil
end
it "should not have channels" do
- event.channels.should eq([])
+ subject.channels.should eq([])
end
end
context "with associated slides and channels" do
before :each do
- event.slides.create build(:slide).attributes
- event.slides.last.create_channel build(:channel).attributes
+ subject.slides.create build(:slide).attributes
+ subject.slides.last.create_channel build(:channel).attributes
end
it "should have a cover slide when" do
- event.cover.should be_a(Slide)
- event.cover.should_not be_nil
+ subject.cover.should be_a(Slide)
+ subject.cover.should_not be_nil
end
it "should return associated channels" do
- event.channels.first.should be_a(Channel)
- event.channels.count.should eq(1)
+ subject.channels.first.should be_a(Channel)
+ subject.channels.count.should eq(1)
end
end
end
View
38 spec/models/slide_spec.rb
@@ -1,29 +1,49 @@
require 'spec_helper'
+# should allow an empty channel association
# start date must be before end date
describe Slide do
+ subject { create(:slide) }
+
it { should have_one(:channel) }
it { should belong_to(:event) }
it { should have_many(:tags) }
it { should validate_presence_of(:title) }
+ it { should allow_value(nil).for(:channel) }
- it { should_not allow_value(" ", nil).for(:title) }
it { should allow_value(" ", nil).for(:description) }
- it { should allow_value(nil).for(:channel) }
+ it { should_not allow_value(" ", nil).for(:title) }
+
+ # should be valid without a start date and end date
+ it { should allow_value(nil).for(:start_date) }
+ it { should allow_value(nil).for(:end_date) }
+
+ # should not be valid when start date is in future
+ it { should_not allow_value(1.day.since).for(:start_date)}
+ # should be valid with a start date in the past
+ it { should allow_value(1.day.ago).for(:start_date)}
+
+ # should not be valid with end date without a start date
+ it { should_not allow_value(1.day.ago).for(:end_date) }
+
+ # should not be valid for invalid values on start or end dates
+ it { should_not allow_value("INVALID DATE").for(:start_date) }
+ it { should_not allow_value("INVALID DATE").for(:end_date) }
+
+ # end date is before start date
+ it { should allow_value(1.day.ago).for(:start_date); should_not allow_value(2.day.ago).for(:end_date) }
+ # end date is after start date
+ it { should allow_value(2.day.ago).for(:start_date); should allow_value(1.day.ago).for(:end_date) }
it "should be taggable" do
- slide = create(:slide)
- slide.tag_list = "tag1, tag2"
- slide.tag_list.count.should eq(2)
+ subject.tag_list = "tag1, tag2"
+ subject.tag_list.count.should eq(2)
end
- context "when saving new slide" do
+ context "when being saved" do
it "strips whitespace from description" do
slide = create(:slide, description: " ")
slide.description.should be_nil
end
end
-
- # should allow an empty channel association
- # should strip title
end

No commit comments for this range

Something went wrong with that request. Please try again.