From e82a3e1727403450f250b57ad145d9b2ec3bae22 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Tue, 23 Aug 2016 10:23:26 -0400 Subject: [PATCH] created current scope in event_schedule model and conference info link name and path changed --- INSTALL.md | 8 ++++++++ app.json | 12 ------------ app/assets/javascripts/refresh_current_events.js | 2 +- app/controllers/admin/conferences_controller.rb | 9 ++++----- app/models/event.rb | 15 --------------- app/models/event_schedule.rb | 1 + .../admin/conference/_current_events.html.haml | 8 ++++---- ...screen.html.haml => conference_info.html.haml} | 4 ++-- ...ide_screen.js.haml => conference_info.js.haml} | 0 app/views/layouts/_admin_sidebar.html.haml | 6 +++--- ...screen.html.haml => conference_info.html.haml} | 0 config/routes.rb | 2 +- spec/factories/event_schedule.rb | 15 +++++++++++++++ spec/factories/events.rb | 13 ------------- spec/models/event_schedule_spec.rb | 14 ++++++++++++++ spec/models/event_spec.rb | 8 -------- spec/models/schedule_spec.rb | 1 - 17 files changed, 53 insertions(+), 65 deletions(-) rename app/views/admin/conference/{conference_wide_screen.html.haml => conference_info.html.haml} (77%) rename app/views/admin/conference/{conference_wide_screen.js.haml => conference_info.js.haml} (100%) rename app/views/layouts/{conference_wide_screen.html.haml => conference_info.html.haml} (100%) diff --git a/INSTALL.md b/INSTALL.md index 95c1cb04..6caec0f7 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -75,6 +75,14 @@ $ bundle exec rake logo:reprocess ### openID In order to use [openID](http://openid.net/) logins for your OSEM installation you need to register your application with the providers ([Google](https://code.google.com/apis/console#:access), [GitHub](https://github.com/settings/applications/new) or [Facebook](https://developers.facebook.com/)) and enter their API keys in `config/secrets.yml` file, changing the existing sample values. +### Twitter + In order to embed conference tweets in the application you need to register your application here [twitter](https://apps.twitter.com/) and get twitter consumer and access keys. + Add your Twitter API keys in `.env` file into these variables: + OSEM_TWITTER_CONSUMER_KEY="" + OSEM_TWITTER_CONSUMER_SECRET="" + OSEM_TWITTER_ACCESS_TOKEN="" + OSEM_TWITTER_ACCESS_TOKEN_SECRET="" + ## Recurring Jobs ======= Open a separate terminal and go into the directory where the rails app is present, and type the following to start the delayed_jobs worker for sending email notifications. diff --git a/app.json b/app.json index 856766d1..f77f6c9c 100644 --- a/app.json +++ b/app.json @@ -59,18 +59,6 @@ }, "RAILS_ENV": { "required": false - }, - "OSEM_TWITTER_CONSUMER_KEY": { - "required": true - }, - "OSEM_TWITTER_CONSUMER_SECRET": { - "required": true - }, - "OSEM_TWITTER_ACCESS_TOKEN": { - "required": true - }, - "OSEM_TWITTER_ACCESS_TOKEN_SECRET": { - "required": true } }, "scripts": { diff --git a/app/assets/javascripts/refresh_current_events.js b/app/assets/javascripts/refresh_current_events.js index a6d050f7..24a509b1 100644 --- a/app/assets/javascripts/refresh_current_events.js +++ b/app/assets/javascripts/refresh_current_events.js @@ -15,7 +15,7 @@ $(document).ready(function() { // Makes an ajax call for fresh data function refreshCurrentEvents(){ $.ajax({ - url: "conference_wide_screen.js" + url: "conference_info.js" }); }; diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 2ad2369a..95b56d53 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -173,16 +173,15 @@ module Admin end end - def conference_wide_screen + def conference_info # To display sponsors in the conference wide information page @sponsors = @conference.sponsors - @program = @conference.program - @current_events = @conference.program.events.current + @current_event_schedules = @program.selected_schedule.event_schedules.current @tweets = twitter_client.search_tweets(15, @conference.contact.social_tag) respond_to do |format| - format.html{render layout: 'conference_wide_screen'} - format.js {render action: 'conference_wide_screen.js.haml'} + format.html{render layout: 'conference_info'} + format.js {render action: 'conference_info.js.haml'} end end diff --git a/app/models/event.rb b/app/models/event.rb index 652597d0..d2446847 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -41,7 +41,6 @@ class Event < ActiveRecord::Base scope :canceled, -> { where(state: 'canceled') } scope :withdrawn, -> { where(state: 'withdrawn') } scope :highlighted, -> { where(is_highlight: true) } - scope :current, -> { joins(:event_type).where('start_time <= ? AND state = ?', Time.current, 'confirmed').map { |e| e if e.end_time > Time.current }.compact } state_machine initial: :new do state :new @@ -248,13 +247,6 @@ class Event < ActiveRecord::Base event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time) end - ## - # Returns end of the event - # - def end_time - self.start_time + self.event_type.length.minutes - end - private ## @@ -302,11 +294,4 @@ class Event < ActiveRecord::Base def conference_id program.conference_id end - - ## - # Compares event start_time, end_with with current time to predict current events - # - def current? - Time.current >= self.start_time && Time.current <= self.end_time - end end diff --git a/app/models/event_schedule.rb b/app/models/event_schedule.rb index 4f5e4940..bf4a0de1 100644 --- a/app/models/event_schedule.rb +++ b/app/models/event_schedule.rb @@ -12,6 +12,7 @@ class EventSchedule < ActiveRecord::Base scope :confirmed, -> { joins(:event).where('state = ?', 'confirmed') } scope :canceled, -> { joins(:event).where('state = ?', 'canceled') } scope :withdrawn, -> { joins(:event).where('state = ?', 'withdrawn') } + scope :current, -> { where('start_time <= ?', Time.current).select{ |es| es.end_time >= Time.current }} delegate :guid, to: :room, prefix: true diff --git a/app/views/admin/conference/_current_events.html.haml b/app/views/admin/conference/_current_events.html.haml index 92aaba74..65ad7c8f 100644 --- a/app/views/admin/conference/_current_events.html.haml +++ b/app/views/admin/conference/_current_events.html.haml @@ -2,12 +2,12 @@ .row .col-md-12.text-center %h2 Current Events - - @current_events.each do |event| + - @current_event_schedules.each do |es| %div %h3 - = event.title + = es.event.title %h4 presented by - = event.speaker_names + = es.event.speaker_names in - = event.room.name + = es.event.room.name diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_info.html.haml similarity index 77% rename from app/views/admin/conference/conference_wide_screen.html.haml rename to app/views/admin/conference/conference_info.html.haml index 5f2e7c71..603a1dce 100644 --- a/app/views/admin/conference/conference_wide_screen.html.haml +++ b/app/views/admin/conference/conference_info.html.haml @@ -6,10 +6,10 @@ - if @conference.description.present? %h3 = @conference.description - - if @current_events.present? + - if @current_event_schedules.present? .row#current-events = render 'current_events' - - if @conference.contact.social_tag.present? && @tweets.present? + - if @conference.contact.social_tag.present? && @tweets.any? .row#conference-tweets = render 'conference_tweets' - if @sponsors.any? diff --git a/app/views/admin/conference/conference_wide_screen.js.haml b/app/views/admin/conference/conference_info.js.haml similarity index 100% rename from app/views/admin/conference/conference_wide_screen.js.haml rename to app/views/admin/conference/conference_info.js.haml diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index f1b6cd10..795b55db 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -138,7 +138,7 @@ Roles - if can? :show, @conference - %li{:class=> active_nav_li(conference_wide_screen_admin_conference_path(@conference.short_title))} - = link_to(conference_wide_screen_admin_conference_path(@conference.short_title)) do + %li{:class=> active_nav_li(conference_info_admin_conference_path(@conference.short_title))} + = link_to(conference_info_admin_conference_path(@conference.short_title)) do %span.fa.fa-expand - Conference Wide Information + Conference Info diff --git a/app/views/layouts/conference_wide_screen.html.haml b/app/views/layouts/conference_info.html.haml similarity index 100% rename from app/views/layouts/conference_wide_screen.html.haml rename to app/views/layouts/conference_info.html.haml diff --git a/config/routes.rb b/config/routes.rb index ac424004..11ade398 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,7 +27,7 @@ Osem::Application.routes.draw do resources :comments, only: [:index] resources :conferences do member do - get :conference_wide_screen + get :conference_info end resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] diff --git a/spec/factories/event_schedule.rb b/spec/factories/event_schedule.rb index 80abe677..598034b7 100644 --- a/spec/factories/event_schedule.rb +++ b/spec/factories/event_schedule.rb @@ -20,5 +20,20 @@ FactoryGirl.define do event_schedule.schedule = program.selected_schedule end end + factory :current_event_schedule do + after(:build) do |event_schedule| + event_schedule.start_time = DateTime.current + end + end + factory :past_event_schedule do + after(:build) do |event_schedule| + event_schedule.start_time = (DateTime.current - 2.days).to_s + end + end + factory :future_event_schedule do + after(:build) do |event_schedule| + event_schedule.start_time = (DateTime.current + 2.days).to_s + end + end end end diff --git a/spec/factories/events.rb b/spec/factories/events.rb index 916e840a..c306cdf9 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -33,19 +33,6 @@ FactoryGirl.define do event.event_schedules << build(:event_schedule, event: event) end end - - factory :past_event do - after(:build) do |event| - event.start_time = (DateTime.current - 2.days).to_s - event.state = 'confirmed' - end - end - factory :future_event do - after(:build) do |event| - event.start_time = (DateTime.current + 2.days).to_s - event.state = 'confirmed' - end - end end end end diff --git a/spec/models/event_schedule_spec.rb b/spec/models/event_schedule_spec.rb index 28b04ddf..78a18aaa 100644 --- a/spec/models/event_schedule_spec.rb +++ b/spec/models/event_schedule_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe EventSchedule do + subject { create(:event_schedule) } + let(:schedule) { create(:schedule) } + let(:program) { create(:program, selected_schedule: schedule) } + let!(:current_event_schedule) { create(:current_event_schedule, schedule: program.selected_schedule) } + let!(:past_event_schedule) { create(:past_event_schedule) } + let!(:future_event_schedule) { create(:future_event_schedule) } describe 'association' do it { should belong_to(:schedule) } @@ -18,4 +24,12 @@ describe EventSchedule do it { is_expected.to validate_presence_of(:room) } it { is_expected.to validate_presence_of(:start_time) } end + + describe 'scope' do + context 'current' do + it 'returns only current events' do + expect(program.selected_schedule.event_schedules.current).to match_array([current_event_schedule]) + end + end + end end diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 65b73103..f9c46559 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -114,14 +114,6 @@ describe Event do expect(conference.program.events.highlighted).to eq [my_event] end end - context 'current' do - it 'returns only current events' do - current_event = create(:event, start_time: Time.current.to_s, state: 'confirmed', program: conference.program) - create(:past_event, program: conference.program) - create(:future_event, program: conference.program) - expect(conference.program.events.current).to match_array([current_event]) - end - end end describe '#scheduled?' do diff --git a/spec/models/schedule_spec.rb b/spec/models/schedule_spec.rb index 6d1f7346..b9cc3a82 100644 --- a/spec/models/schedule_spec.rb +++ b/spec/models/schedule_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Schedule do - describe 'association' do it { should belong_to(:program) } it { should have_many(:event_schedules).dependent(:destroy) }