From 35afdcead4ce3cba726ca974f3208e1e2846b775 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Wed, 6 Jul 2016 15:30:39 -0400 Subject: [PATCH 1/7] added conference wide information page and linked to the admin sidebar --- .../admin/conferences_controller.rb | 6 +++++ .../conference_wide_screen.html.haml | 13 ++++++++++ app/views/layouts/_admin_sidebar.html.haml | 6 +++++ config/routes.rb | 5 +++- .../admin/conferences_controller_spec.rb | 25 +++++++++++++++++++ 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/conference/conference_wide_screen.html.haml diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index b7063e6e..094d1f0b 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -173,6 +173,12 @@ module Admin end end + def conference_wide_screen + #To display sponsors in the conference wide information page + @conference = Conference.find_by(short_title: params[:id]) + @sponsors = @conference.sponsors + end + private def conference_params diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_wide_screen.html.haml new file mode 100644 index 00000000..9ced72cb --- /dev/null +++ b/app/views/admin/conference/conference_wide_screen.html.haml @@ -0,0 +1,13 @@ +.container +- if @conference.present? + .row + .col-md-12.text-center + %h2 Upcoming Events + .row + .col-md-12.text-center + %h2 Tweets About Conference + .row + .col-md-12 + - if @sponsors.any? + %section#sponsors + = render 'conference/sponsors' diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 62645e0c..f1b6cd10 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -136,3 +136,9 @@ = link_to(admin_conference_roles_path(@conference.short_title)) do %span.fa.fa-group 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 + %span.fa.fa-expand + Conference Wide Information diff --git a/config/routes.rb b/config/routes.rb index 7bd331d9..ac424004 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,9 @@ Osem::Application.routes.draw do end resources :comments, only: [:index] resources :conferences do + member do + get :conference_wide_screen + end resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] resources :event_schedules, only: [:create, :update, :destroy] @@ -102,7 +105,7 @@ Osem::Application.routes.draw do get '/revision_history/:id/revert_attribute' => 'versions#revert_attribute', as: 'revision_history_revert_attribute' end - resources :conferences, only: [:index, :show] do + resources :conferences, only: [:index, :show ] do resource :program, only: [] do resources :proposals, except: :destroy do get 'commercials/render_commercial' => 'commercials#render_commercial' diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index eac4c68c..85c32c82 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -165,6 +165,18 @@ describe Admin::ConferencesController do end end + describe 'GET #conference_wide_screen' do + it 'assigns the requested conference to conference' do + get :show, id: conference.short_title + expect(assigns(:conference)).to eq conference + end + + it 'renders the conference_wide_screen page' do + get :conference_wide_screen, id: conference.short_title + expect(response).to render_template :conference_wide_screen + end + end + describe 'GET #index' do context 'with more than 0 conferences' do it 'populates an array with conferences' do @@ -280,8 +292,21 @@ describe Admin::ConferencesController do end end end + + describe 'GET #conference_wide_screen' do + it 'requires organizer privileges' do + get :conference_wide_screen, id: conference.short_title, + conference: attributes_for(:conference, + short_title: 'ExCon') + expect(response).to redirect_to(send(path)) + if message + expect(flash[:alert]).to match(/#{message}/) + end + end + end end + describe 'participant access' do before(:each) do sign_in(participant) From febd3451ad99a07fbabec347e028a461610f38e4 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Fri, 15 Jul 2016 16:28:03 -0400 Subject: [PATCH 2/7] is_current method added to check an event is current and function addded to refresh conference_wide_information --- app/assets/javascripts/application.js | 1 + .../javascripts/refresh_current_events.js | 10 ++++++++ .../admin/conferences_controller.rb | 7 ++++++ app/models/event.rb | 17 +++++++++++++ .../conference/_current_events.html.haml | 9 +++++++ .../conference_wide_screen.html.haml | 6 +++-- .../conference/conference_wide_screen.js.haml | 1 + spec/models/event_spec.rb | 25 +++++++++++++++++++ 8 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/refresh_current_events.js create mode 100644 app/views/admin/conference/_current_events.html.haml create mode 100644 app/views/admin/conference/conference_wide_screen.js.haml diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8853d6e6..d29bc4eb 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -45,6 +45,7 @@ //= require osem-commercials //= require unobtrusive_flash //= require unobtrusive_flash_bootstrap +//= require refresh_current_events $(document).ready(function() { $('a[disabled=disabled]').click(function(event){ diff --git a/app/assets/javascripts/refresh_current_events.js b/app/assets/javascripts/refresh_current_events.js new file mode 100644 index 00000000..eee62bec --- /dev/null +++ b/app/assets/javascripts/refresh_current_events.js @@ -0,0 +1,10 @@ +$(document).ready(function() { + // will call refreshCurrentEvents every 15 minutes + setInterval(refreshCurrentEvents, 900000) + }); + +function refreshCurrentEvents(){ + $.ajax({ + url: "conference_wide_screen.js" + }); +}; diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 094d1f0b..2957a780 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -177,6 +177,13 @@ module Admin #To display sponsors in the conference wide information page @conference = Conference.find_by(short_title: params[:id]) @sponsors = @conference.sponsors + @program = @conference.program + @current_events = @conference.program.events.confirmed.select{ |event| event.is_current?} + + respond_to do |format| + format.html + format.js {render :action=>"conference_wide_screen.js.haml"} + end end private diff --git a/app/models/event.rb b/app/models/event.rb index d2446847..db8338d2 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -41,6 +41,8 @@ class Event < ActiveRecord::Base scope :canceled, -> { where(state: 'canceled') } scope :withdrawn, -> { where(state: 'withdrawn') } scope :highlighted, -> { where(is_highlight: true) } + + state_machine initial: :new do state :new @@ -247,6 +249,13 @@ class Event < ActiveRecord::Base event_schedules.find_by(schedule_id: program.selected_schedule_id).try(:start_time) end + ## + #Compares event start_time, end_with with current time to predict current events + # + def is_current? + Time.current >= self.start_time && Time.current <= end_time + end + private ## @@ -294,4 +303,12 @@ 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 is_current? + Time.current >= self.start_time && Time.current <= end_time + end + end diff --git a/app/views/admin/conference/_current_events.html.haml b/app/views/admin/conference/_current_events.html.haml new file mode 100644 index 00000000..233365ba --- /dev/null +++ b/app/views/admin/conference/_current_events.html.haml @@ -0,0 +1,9 @@ +.text-center + %h2 Upcoming Events + - @current_events.each do |event| + %div + %h3 + = link_to event.title, conference_program_proposal_path(@conference.short_title, event.id) + %h4 + presented by + = event.speaker_names diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_wide_screen.html.haml index 9ced72cb..62d2b7e2 100644 --- a/app/views/admin/conference/conference_wide_screen.html.haml +++ b/app/views/admin/conference/conference_wide_screen.html.haml @@ -1,8 +1,10 @@ .container - if @conference.present? .row - .col-md-12.text-center - %h2 Upcoming Events + .col-md-12 + - if @program.present? + %section#program#current-events + = render 'current_events' .row .col-md-12.text-center %h2 Tweets About Conference diff --git a/app/views/admin/conference/conference_wide_screen.js.haml b/app/views/admin/conference/conference_wide_screen.js.haml new file mode 100644 index 00000000..998342dc --- /dev/null +++ b/app/views/admin/conference/conference_wide_screen.js.haml @@ -0,0 +1 @@ +$('#current-events').html("#{escape_javascript(render 'current_events', data: @current_events)}"); diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index f9c46559..709a3bc1 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -327,4 +327,29 @@ describe Event do expect(other_event.week).to eq 48 end end + + + describe 'is_current?' do + let(:past_event) { create(:event, program: conference.program) } + let(:future_event) { create(:event, program: conference.program) } + + before do + event.update_attributes(start_time: "#{Time.current}") + past_event.update_attributes(start_time: "#{Time.current - 2.days}") + future_event.update_attributes(start_time: "#{Time.current + 2.days}") + end + + it 'returns false for a completed event' do + expect(past_event.is_current?).to be_falsey + end + + it 'returns false for a future event' do + expect(future_event.is_current?).to be_falsey + end + + it 'returns true for a current event' do + expect(event.is_current?).to be_truthy + end + end + end From f29a15b8e4f58b3d65fcce3050c14f7ae6312eed Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Wed, 20 Jul 2016 15:11:50 -0400 Subject: [PATCH 3/7] twitter gem and a partial added to embed tweets about a conference and new layout added for conference info screen --- Gemfile | 3 +- Gemfile.lock | 25 ++++++ app/assets/stylesheets/application.css | 1 + .../osem-conference-wide-screen.css.scss | 77 +++++++++++++++++++ .../admin/conferences_controller.rb | 11 ++- app/models/twitter_wrapper.rb | 25 ++++++ .../conference/_conference_tweets.html.haml | 8 ++ .../conference/_current_events.html.haml | 22 +++--- .../admin/conference/_sponsors.html.haml | 11 +++ .../conference_wide_screen.html.haml | 36 +++++---- .../layouts/conference_wide_screen.html.haml | 25 ++++++ 11 files changed, 216 insertions(+), 28 deletions(-) create mode 100644 app/assets/stylesheets/osem-conference-wide-screen.css.scss create mode 100644 app/models/twitter_wrapper.rb create mode 100644 app/views/admin/conference/_conference_tweets.html.haml create mode 100644 app/views/admin/conference/_sponsors.html.haml create mode 100644 app/views/layouts/conference_wide_screen.html.haml diff --git a/Gemfile b/Gemfile index c4564a2b..6e43d68b 100644 --- a/Gemfile +++ b/Gemfile @@ -183,9 +183,10 @@ gem 'dotenv-rails' gem 'faker' # for seeds gem 'factory_girl_rails' - # for integrating Stripe payment gateway gem 'stripe' +#For embedding tweets +gem 'twitter' # Use guard and spring for testing in development group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 2f84aa81..740bb43e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,6 +82,7 @@ GEM bootstrap3-datetimepicker-rails (3.0.3) momentjs-rails (>= 2.8.1) browser (0.6.0) + buftok (0.2.0) builder (3.2.2) byebug (3.1.2) columnize (~> 0.8) @@ -167,6 +168,7 @@ GEM dotenv-rails (2.1.1) dotenv (= 2.1.1) railties (>= 4.0, < 5.1) + equalizer (0.0.10) erubis (2.7.0) execjs (2.6.0) factory_girl (4.5.0) @@ -214,8 +216,15 @@ GEM activesupport builder htmlentities (4.3.4) + http (1.0.4) + addressable (~> 2.3) + http-cookie (~> 1.0) + http-form_data (~> 1.0.1) + http_parser.rb (~> 0.6.0) http-cookie (1.0.2) domain_name (~> 0.5) + http-form_data (1.0.1) + http_parser.rb (0.6.0) i18n (0.7.0) i18n_data (0.7.0) inversion (0.12.3) @@ -253,6 +262,8 @@ GEM lumberjack (1.0.5) mail (2.6.3) mime-types (>= 1.16, < 3) + memoizable (0.4.2) + thread_safe (~> 0.3, >= 0.3.1) method_source (0.8.2) mime-types (2.99.1) mina (0.3.8) @@ -277,6 +288,7 @@ GEM multi_xml (0.5.5) multipart-post (2.0.0) mysql2 (0.4.2) + naught (1.1.0) netrc (0.11.0) nio4r (1.2.1) nokogiri (1.6.8) @@ -462,6 +474,7 @@ GEM sprockets-rails (~> 2.0) shoulda-matchers (2.6.1) activesupport (>= 3.0.0) + simple_oauth (0.3.1) simplecov (0.11.2) docile (~> 1.1.0) json (~> 1.8) @@ -502,6 +515,17 @@ GEM ttfunk (1.1.1) turbolinks (2.5.3) coffee-rails + twitter (5.16.0) + addressable (~> 2.3) + buftok (~> 0.2.0) + equalizer (= 0.0.10) + faraday (~> 0.9.0) + http (~> 1.0) + http_parser.rb (~> 0.6.0) + json (~> 1.8) + memoizable (~> 0.4.0) + naught (~> 1.0) + simple_oauth (~> 0.3.0) tzinfo (1.2.2) thread_safe (~> 0.1) uglifier (3.0.0) @@ -630,6 +654,7 @@ DEPENDENCIES timecop transitions turbolinks + twitter uglifier (>= 1.3.0) unobtrusive_flash (>= 3) web-console (~> 2.0) diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index ac01136f..662ab1cd 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -8,6 +8,7 @@ *= require osem-schedule-print *= require osem-dashboard *= require osem-splash + *= require osem-conference-wide-screen *= require font-awesome *= require osem-fonts *= require bootstrap-markdown diff --git a/app/assets/stylesheets/osem-conference-wide-screen.css.scss b/app/assets/stylesheets/osem-conference-wide-screen.css.scss new file mode 100644 index 00000000..51f43c08 --- /dev/null +++ b/app/assets/stylesheets/osem-conference-wide-screen.css.scss @@ -0,0 +1,77 @@ +@import "breakpoints.css.scss"; + +html { + position: relative; + min-height: 100%; +} + +body { + /* Margin bottom by 2 times the footer height */ + // margin-bottom: 60px; + /* Margin bottom by navbar height */ + padding-top: 10px; +} + +#main-display { + // Counter the general padding for #content + // margin-bottom: -60px; + section { + padding: 10px; + } + + #main-heading { + position: absolute; + top: 0; + width: 100%; + height: 120px; + background-color: #abcdef; + } + + + #event-display{ + position: absolute; + bottom:480px; + width: 100%; + top: 120px; + background-color: #00FF00; + } + #tweets-display { + position: absolute; + height: 150px; + bottom: 330px; + width: 100%; + background-color: #F63; + } + + #sponsor-display { + position: absolute; + bottom: 0; + width: 100%; + max-height: 330px; + background-color: #FF1493; + .container { + background-color: yellow; + max-height: 310px; + } + + .img-sponsor { + max-height: 50px; + margin: 2% auto; + } + .img-sponsor-1 { + max-height: 90px; + } + .img-sponsor-2 { + max-height: 70px; + } + .img-sponsor-3 { + max-height: 50px; + } + @include breakpoint(xs) { + .img-sponsor, .img-sponsor-1, .img-sponsor-3, .img-sponsor-3{ + max-height: unset; + max-width: 280px; + } + } + } +} diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 2957a780..cd1af181 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -179,14 +179,19 @@ module Admin @sponsors = @conference.sponsors @program = @conference.program @current_events = @conference.program.events.confirmed.select{ |event| event.is_current?} - + @tweets = twitter_client.search_tweets(3, @conference.contact.social_tag) + respond_to do |format| - format.html - format.js {render :action=>"conference_wide_screen.js.haml"} + format.html{render layout: "conference_wide_screen"} + format.js {render :action=> "conference_wide_screen.js.haml"} end end private + # To create a twitter client + def twitter_client + @twitter_client ||= TwitterWrapper.new + end def conference_params params.require(:conference).permit(:title, :short_title, :description, :timezone, diff --git a/app/models/twitter_wrapper.rb b/app/models/twitter_wrapper.rb new file mode 100644 index 00000000..63b47547 --- /dev/null +++ b/app/models/twitter_wrapper.rb @@ -0,0 +1,25 @@ +class TwitterWrapper + attr_accessor :client + + def initialize + @client = Twitter::REST::Client.new do |config| + config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"] + config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"] + config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"] + config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"] + end + end + + ## + #Fetches tweets from twitter api based on search_term and no_of_tweets + # + def search_tweets(no_of_tweets, search_term) + begin + @client.search(search_term, result_type: "recent").take(no_of_tweets).collect + rescue Twitter::Error::TooManyRequests => error + sleep error.rate_limit.reset_in + 1 + retry + end + end + +end diff --git a/app/views/admin/conference/_conference_tweets.html.haml b/app/views/admin/conference/_conference_tweets.html.haml new file mode 100644 index 00000000..83b5168c --- /dev/null +++ b/app/views/admin/conference/_conference_tweets.html.haml @@ -0,0 +1,8 @@ +.container + .row + .col-md-12.text-center + %h2 Conference Tweets + - @tweets.each do |tweet| + %div#tweet + = tweet.user.name + = tweet.text diff --git a/app/views/admin/conference/_current_events.html.haml b/app/views/admin/conference/_current_events.html.haml index 233365ba..92aaba74 100644 --- a/app/views/admin/conference/_current_events.html.haml +++ b/app/views/admin/conference/_current_events.html.haml @@ -1,9 +1,13 @@ -.text-center - %h2 Upcoming Events - - @current_events.each do |event| - %div - %h3 - = link_to event.title, conference_program_proposal_path(@conference.short_title, event.id) - %h4 - presented by - = event.speaker_names +.container + .row + .col-md-12.text-center + %h2 Current Events + - @current_events.each do |event| + %div + %h3 + = event.title + %h4 + presented by + = event.speaker_names + in + = event.room.name diff --git a/app/views/admin/conference/_sponsors.html.haml b/app/views/admin/conference/_sponsors.html.haml new file mode 100644 index 00000000..335eade8 --- /dev/null +++ b/app/views/admin/conference/_sponsors.html.haml @@ -0,0 +1,11 @@ +.container + .row + .col-md-12.text-center + %h2 Sponsors + - @conference.sponsorship_levels.each do |sponsorship_level| + -if sponsorship_level.sponsors.any? + - sponsorship_level.sponsors.each_slice(3) do |slice| + .row.row-centered + - slice.each do |sponsor| + .col-md-4.col-sm-4.col-centered.col-top + = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_wide_screen.html.haml index 62d2b7e2..82a58b2c 100644 --- a/app/views/admin/conference/conference_wide_screen.html.haml +++ b/app/views/admin/conference/conference_wide_screen.html.haml @@ -1,15 +1,21 @@ -.container -- if @conference.present? - .row - .col-md-12 - - if @program.present? - %section#program#current-events - = render 'current_events' - .row - .col-md-12.text-center - %h2 Tweets About Conference - .row - .col-md-12 - - if @sponsors.any? - %section#sponsors - = render 'conference/sponsors' +#main-display + - if @conference.present? + %section#main-heading + .container + .row + .col-md-12.text-center + %h1 + = @conference.title + - if @conference.description.present? + %h3 + = @conference.description + - if @program.present? + %section#event-display + = render 'current_events' + - if @conference.contact.social_tag.present? + %section#tweets-display + - if @tweets.present? + = render 'conference_tweets' + - if @sponsors.any? + %section#sponsor-display + = render 'sponsors' diff --git a/app/views/layouts/conference_wide_screen.html.haml b/app/views/layouts/conference_wide_screen.html.haml new file mode 100644 index 00000000..21b710c0 --- /dev/null +++ b/app/views/layouts/conference_wide_screen.html.haml @@ -0,0 +1,25 @@ +%html{:xmlns => "http://www.w3.org/1999/html"} + %head + %meta{:charset => "utf-8"} + %meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"} + %title= content_for?(:title) ? yield(:title) : (ENV['OSEM_NAME'] || 'OSEM') + %meta{:content => "", :name => "description"} + %meta{:content => "", :name => "author"} + = stylesheet_link_tag "application", :media => "all" + = javascript_include_tag "application" + + = csrf_meta_tags + :javascript + window.liveSettings = { + api_key: "#{ENV['OSEM_TRANSIFEX_APIKEY']}", + picker: "bottom-right", + detectlang: true, + autocollect: true + }; + = content_for(:script_head) + = javascript_include_tag "//cdn.transifex.com/live.js" + + = yield(:head) + %body + .container + = yield From 881518f1f34534b6ce06b51a427db83b7a5cd977 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Wed, 27 Jul 2016 17:02:40 -0400 Subject: [PATCH 4/7] cycle method added to auto cycle through tweets and exception handling is modified to capture all errors that raise from twitter --- INSTALL.md | 5 +++ .../javascripts/refresh_current_events.js | 13 +++++++- .../admin/conferences_controller.rb | 13 ++++---- app/models/event.rb | 14 ++++----- app/models/twitter_wrapper.rb | 20 +++++------- .../conference_wide_screen.html.haml | 31 ++++++++----------- config/secrets.yml.example | 7 +++++ dotenv.example | 6 ++++ .../admin/conferences_controller_spec.rb | 5 ++- spec/models/event_spec.rb | 15 +++++---- 10 files changed, 73 insertions(+), 56 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index cc363338..afd2ded8 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -57,6 +57,11 @@ There are a couple of environment variables you can set to configure OSEM. We use [Stripe](https://stripe.com) for accepting your ticket payments securely over the web. Our application uses iFrame for accepting your user's payment details without storing them, making the application PCI SAQ-A Compliant. Please refer to [PAYMENTS](PAYMENTS.md) documentation file for setting up your stripe account and start accepting payments from your users. +| CLOUDINARY_URL | *string* | Configure your cloudinary.com cloud name and api key/secret +| OSEM_TWITTER_CONSUMER_KEY | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_CONSUMER_SECRET | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_ACCESS_TOKEN | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_ACCESS_TOKEN_SECRET | *string* | To embed tweets about the conference in the conference wide page ## Dependencies diff --git a/app/assets/javascripts/refresh_current_events.js b/app/assets/javascripts/refresh_current_events.js index eee62bec..2d9ac5e0 100644 --- a/app/assets/javascripts/refresh_current_events.js +++ b/app/assets/javascripts/refresh_current_events.js @@ -1,6 +1,17 @@ $(document).ready(function() { // will call refreshCurrentEvents every 15 minutes - setInterval(refreshCurrentEvents, 900000) + setInterval(refreshCurrentEvents, 900000) + // To cycle through tweets + var tweets = $('div[id^="tweet"]').hide(); + var i = 0; + + (function cycle() { + tweets.eq(i).show(0) + .delay(5000) + .hide(0, cycle); + i = ++i % tweets.length; + })(); + }); function refreshCurrentEvents(){ diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index cd1af181..f3d87af1 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -174,20 +174,21 @@ module Admin end def conference_wide_screen - #To display sponsors in the conference wide information page + # To display sponsors in the conference wide information page @conference = Conference.find_by(short_title: params[:id]) @sponsors = @conference.sponsors @program = @conference.program - @current_events = @conference.program.events.confirmed.select{ |event| event.is_current?} - @tweets = twitter_client.search_tweets(3, @conference.contact.social_tag) - + @current_events = @conference.program.events.confirmed.select(&: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_wide_screen'} + format.js {render action: 'conference_wide_screen.js.haml'} end end private + # To create a twitter client def twitter_client @twitter_client ||= TwitterWrapper.new diff --git a/app/models/event.rb b/app/models/event.rb index db8338d2..da7efd0f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -41,8 +41,6 @@ class Event < ActiveRecord::Base scope :canceled, -> { where(state: 'canceled') } scope :withdrawn, -> { where(state: 'withdrawn') } scope :highlighted, -> { where(is_highlight: true) } - - state_machine initial: :new do state :new @@ -250,10 +248,10 @@ class Event < ActiveRecord::Base end ## - #Compares event start_time, end_with with current time to predict current events + # Compares event start_time, end_with with current time to predict current events # - def is_current? - Time.current >= self.start_time && Time.current <= end_time + def current? + Time.current >= self.start_time && Time.current <= self.end_time end private @@ -305,10 +303,10 @@ class Event < ActiveRecord::Base end ## - #Compares event start_time, end_with with current time to predict current events + # Compares event start_time, end_with with current time to predict current events # - def is_current? - Time.current >= self.start_time && Time.current <= end_time + def current? + Time.current >= self.start_time && Time.current <= self.end_time end end diff --git a/app/models/twitter_wrapper.rb b/app/models/twitter_wrapper.rb index 63b47547..d4887720 100644 --- a/app/models/twitter_wrapper.rb +++ b/app/models/twitter_wrapper.rb @@ -3,23 +3,19 @@ class TwitterWrapper def initialize @client = Twitter::REST::Client.new do |config| - config.consumer_key = ENV["OSEM_TWITTER_CONSUMER_KEY"] - config.consumer_secret = ENV["OSEM_TWITTER_CONSUMER_SECRET"] - config.access_token = ENV["OSEM_TWITTER_ACCESS_TOKEN"] - config.access_token_secret = ENV["OSEM_TWITTER_ACCESS_TOKEN_SECRET"] + config.consumer_key = ENV['OSEM_TWITTER_CONSUMER_KEY'] + config.consumer_secret = ENV['OSEM_TWITTER_CONSUMER_SECRET'] + config.access_token = ENV['OSEM_TWITTER_ACCESS_TOKEN'] + config.access_token_secret = ENV['OSEM_TWITTER_ACCESS_TOKEN_SECRET'] end end ## - #Fetches tweets from twitter api based on search_term and no_of_tweets + # Fetches tweets from twitter api based on search_term and no_of_tweets # def search_tweets(no_of_tweets, search_term) - begin - @client.search(search_term, result_type: "recent").take(no_of_tweets).collect - rescue Twitter::Error::TooManyRequests => error - sleep error.rate_limit.reset_in + 1 - retry - end + @client.search(search_term, result_type: 'recent').take(no_of_tweets).collect + rescue + nil end - end diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_wide_screen.html.haml index 82a58b2c..4e2991fe 100644 --- a/app/views/admin/conference/conference_wide_screen.html.haml +++ b/app/views/admin/conference/conference_wide_screen.html.haml @@ -1,21 +1,16 @@ -#main-display - - if @conference.present? - %section#main-heading - .container - .row - .col-md-12.text-center - %h1 - = @conference.title - - if @conference.description.present? - %h3 - = @conference.description +- if @conference.present? + .row + .col-md-12.text-center + %h1 + = @conference.title + - if @conference.description.present? + %h3 + = @conference.description - if @program.present? - %section#event-display + .row = render 'current_events' - - if @conference.contact.social_tag.present? - %section#tweets-display - - if @tweets.present? - = render 'conference_tweets' + - if @conference.contact.social_tag.present? && @tweets.present? + .row + = render 'conference_tweets' - if @sponsors.any? - %section#sponsor-display - = render 'sponsors' + = render 'sponsors' diff --git a/config/secrets.yml.example b/config/secrets.yml.example index a8d67504..0ee787cc 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -54,6 +54,13 @@ production: facebook_key: '' facebook_secret: '' + # Register your application with Twitter from + # https://apps.twitter.com/ + twitter_consumer_key: '' + twitter_consumer_secret: '' + twitter_access_token: '' + twitter_access_token_secret: '' + # Developers do not need to register their application for suse account to # work. You must, however, add some sample value to the variables, for the # login option to appear. For example: diff --git a/dotenv.example b/dotenv.example index ec2715ea..92c51f6d 100644 --- a/dotenv.example +++ b/dotenv.example @@ -57,3 +57,9 @@ OSEM_SMTP_DOMAIN="" # Enable the usage of the devise ichain plugin OSEM_ICHAIN_ENABLED=false + +# To embed tweets about the conference in the conference wide screen +OSEM_TWITTER_CONSUMER_KEY="" +OSEM_TWITTER_CONSUMER_SECRET="" +OSEM_TWITTER_ACCESS_TOKEN="" +OSEM_TWITTER_ACCESS_TOKEN_SECRET="" diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 85c32c82..ac377a69 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -296,8 +296,8 @@ describe Admin::ConferencesController do describe 'GET #conference_wide_screen' do it 'requires organizer privileges' do get :conference_wide_screen, id: conference.short_title, - conference: attributes_for(:conference, - short_title: 'ExCon') + conference: attributes_for(:conference, + short_title: 'ExCon') expect(response).to redirect_to(send(path)) if message expect(flash[:alert]).to match(/#{message}/) @@ -306,7 +306,6 @@ describe Admin::ConferencesController do end end - describe 'participant access' do before(:each) do sign_in(participant) diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index 709a3bc1..77aa4566 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -328,27 +328,26 @@ describe Event do end end - - describe 'is_current?' do + describe 'current?' do let(:past_event) { create(:event, program: conference.program) } let(:future_event) { create(:event, program: conference.program) } before do - event.update_attributes(start_time: "#{Time.current}") - past_event.update_attributes(start_time: "#{Time.current - 2.days}") - future_event.update_attributes(start_time: "#{Time.current + 2.days}") + event.update_attributes(start_time: Time.current.to_s) + past_event.update_attributes(start_time: (Time.current - 2.days).to_s) + future_event.update_attributes(start_time: (Time.current + 2.days).to_s) end it 'returns false for a completed event' do - expect(past_event.is_current?).to be_falsey + expect(past_event.current?).to be_falsey end it 'returns false for a future event' do - expect(future_event.is_current?).to be_falsey + expect(future_event.current?).to be_falsey end it 'returns true for a current event' do - expect(event.is_current?).to be_truthy + expect(event.current?).to be_truthy end end From e8d3177ec18c01ac418a0e9b4d73ba57be072f79 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Mon, 1 Aug 2016 15:44:01 -0400 Subject: [PATCH 5/7] method added to autocycle through sponsors based on sponsor level and code added to inherit twitter env variables --- INSTALL.md | 9 +-- app.json | 12 +++ .../javascripts/refresh_current_events.js | 33 +++++--- app/assets/stylesheets/application.css | 1 - .../osem-conference-wide-screen.css.scss | 77 ------------------- .../admin/conferences_controller.rb | 3 +- app/models/event.rb | 8 +- .../conference/_conference_tweets.html.haml | 16 ++-- .../admin/conference/_sponsors.html.haml | 15 ++-- .../conference_wide_screen.html.haml | 6 +- .../conference/conference_wide_screen.js.haml | 3 + .../admin/conferences_controller_spec.rb | 24 ------ spec/factories/events.rb | 13 ++++ spec/models/event_spec.rb | 32 ++------ 14 files changed, 89 insertions(+), 163 deletions(-) delete mode 100644 app/assets/stylesheets/osem-conference-wide-screen.css.scss diff --git a/INSTALL.md b/INSTALL.md index afd2ded8..95c1cb04 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -52,16 +52,15 @@ There are a couple of environment variables you can set to configure OSEM. | CLOUDINARY_URL | *string* | Configure your cloudinary.com cloud name and api key/secret | STRIPE_PUBLISHABLE_KEY | *string* | Publishable Key for Stripe Gateway | STRIPE_SECRET_KEY | *string* | Secret Key for Stripe Gateway +| OSEM_TWITTER_CONSUMER_KEY | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_CONSUMER_SECRET | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_ACCESS_TOKEN | *string* | To embed tweets about the conference in the conference wide page +| OSEM_TWITTER_ACCESS_TOKEN_SECRET | *string* | To embed tweets about the conference in the conference wide page ### Online Ticket Payments We use [Stripe](https://stripe.com) for accepting your ticket payments securely over the web. Our application uses iFrame for accepting your user's payment details without storing them, making the application PCI SAQ-A Compliant. Please refer to [PAYMENTS](PAYMENTS.md) documentation file for setting up your stripe account and start accepting payments from your users. -| CLOUDINARY_URL | *string* | Configure your cloudinary.com cloud name and api key/secret -| OSEM_TWITTER_CONSUMER_KEY | *string* | To embed tweets about the conference in the conference wide page -| OSEM_TWITTER_CONSUMER_SECRET | *string* | To embed tweets about the conference in the conference wide page -| OSEM_TWITTER_ACCESS_TOKEN | *string* | To embed tweets about the conference in the conference wide page -| OSEM_TWITTER_ACCESS_TOKEN_SECRET | *string* | To embed tweets about the conference in the conference wide page ## Dependencies diff --git a/app.json b/app.json index f77f6c9c..856766d1 100644 --- a/app.json +++ b/app.json @@ -59,6 +59,18 @@ }, "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 2d9ac5e0..a6d050f7 100644 --- a/app/assets/javascripts/refresh_current_events.js +++ b/app/assets/javascripts/refresh_current_events.js @@ -1,21 +1,32 @@ $(document).ready(function() { // will call refreshCurrentEvents every 15 minutes - setInterval(refreshCurrentEvents, 900000) - // To cycle through tweets - var tweets = $('div[id^="tweet"]').hide(); - var i = 0; + setInterval(refreshCurrentEvents,900000); - (function cycle() { - tweets.eq(i).show(0) - .delay(5000) - .hide(0, cycle); - i = ++i % tweets.length; - })(); + // Only show the first child of tweet and sponsor containers on page load + $('#tweet-container').children().hide(); + $('#tweet-container').children().eq(0).show(); + $('#sponsor-container').children().hide(); + $('#sponsor-container').children().eq(0).show(); - }); + setInterval(function(){ cycleVisibleElement($('#tweet-container'))}, 5000) + setInterval(function(){ cycleVisibleElement($('#sponsor-container'))}, 10000) +}); +// Makes an ajax call for fresh data function refreshCurrentEvents(){ $.ajax({ url: "conference_wide_screen.js" }); }; + +// Cycle through children in a container and toggles visibility +function cycleVisibleElement(container){ + var childrens = $(container).children(); + for(var i = 0; i < childrens.length; i++ ){ + if(childrens.eq(i).is(":visible")){ + childrens.eq(i).hide(); + childrens.eq(++i % childrens.length).show(); + return + } + } +}; diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 662ab1cd..ac01136f 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -8,7 +8,6 @@ *= require osem-schedule-print *= require osem-dashboard *= require osem-splash - *= require osem-conference-wide-screen *= require font-awesome *= require osem-fonts *= require bootstrap-markdown diff --git a/app/assets/stylesheets/osem-conference-wide-screen.css.scss b/app/assets/stylesheets/osem-conference-wide-screen.css.scss deleted file mode 100644 index 51f43c08..00000000 --- a/app/assets/stylesheets/osem-conference-wide-screen.css.scss +++ /dev/null @@ -1,77 +0,0 @@ -@import "breakpoints.css.scss"; - -html { - position: relative; - min-height: 100%; -} - -body { - /* Margin bottom by 2 times the footer height */ - // margin-bottom: 60px; - /* Margin bottom by navbar height */ - padding-top: 10px; -} - -#main-display { - // Counter the general padding for #content - // margin-bottom: -60px; - section { - padding: 10px; - } - - #main-heading { - position: absolute; - top: 0; - width: 100%; - height: 120px; - background-color: #abcdef; - } - - - #event-display{ - position: absolute; - bottom:480px; - width: 100%; - top: 120px; - background-color: #00FF00; - } - #tweets-display { - position: absolute; - height: 150px; - bottom: 330px; - width: 100%; - background-color: #F63; - } - - #sponsor-display { - position: absolute; - bottom: 0; - width: 100%; - max-height: 330px; - background-color: #FF1493; - .container { - background-color: yellow; - max-height: 310px; - } - - .img-sponsor { - max-height: 50px; - margin: 2% auto; - } - .img-sponsor-1 { - max-height: 90px; - } - .img-sponsor-2 { - max-height: 70px; - } - .img-sponsor-3 { - max-height: 50px; - } - @include breakpoint(xs) { - .img-sponsor, .img-sponsor-1, .img-sponsor-3, .img-sponsor-3{ - max-height: unset; - max-width: 280px; - } - } - } -} diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index f3d87af1..2ad2369a 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -175,10 +175,9 @@ module Admin def conference_wide_screen # To display sponsors in the conference wide information page - @conference = Conference.find_by(short_title: params[:id]) @sponsors = @conference.sponsors @program = @conference.program - @current_events = @conference.program.events.confirmed.select(&:current?) + @current_events = @conference.program.events.current @tweets = twitter_client.search_tweets(15, @conference.contact.social_tag) respond_to do |format| diff --git a/app/models/event.rb b/app/models/event.rb index da7efd0f..652597d0 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -41,6 +41,7 @@ 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,10 +249,10 @@ class Event < ActiveRecord::Base end ## - # Compares event start_time, end_with with current time to predict current events + # Returns end of the event # - def current? - Time.current >= self.start_time && Time.current <= self.end_time + def end_time + self.start_time + self.event_type.length.minutes end private @@ -308,5 +309,4 @@ class Event < ActiveRecord::Base def current? Time.current >= self.start_time && Time.current <= self.end_time end - end diff --git a/app/views/admin/conference/_conference_tweets.html.haml b/app/views/admin/conference/_conference_tweets.html.haml index 83b5168c..58ed4e9e 100644 --- a/app/views/admin/conference/_conference_tweets.html.haml +++ b/app/views/admin/conference/_conference_tweets.html.haml @@ -1,8 +1,14 @@ .container .row .col-md-12.text-center - %h2 Conference Tweets - - @tweets.each do |tweet| - %div#tweet - = tweet.user.name - = tweet.text + %h2 + = "#" + @conference.contact.social_tag + " Tweets" + %div#tweet-container + - @tweets.each do |tweet| + %div#tweet + %blockquote.twitter-tweet + %p{:lang => "en"} + = tweet.text + = link_to "— @" + tweet.user.name, "http://www.twitter.com/#{tweet.user.name}", target: "_blank" + = link_to tweet.url, tweet.url.to_s + diff --git a/app/views/admin/conference/_sponsors.html.haml b/app/views/admin/conference/_sponsors.html.haml index 335eade8..5fb6a8c7 100644 --- a/app/views/admin/conference/_sponsors.html.haml +++ b/app/views/admin/conference/_sponsors.html.haml @@ -2,10 +2,11 @@ .row .col-md-12.text-center %h2 Sponsors - - @conference.sponsorship_levels.each do |sponsorship_level| - -if sponsorship_level.sponsors.any? - - sponsorship_level.sponsors.each_slice(3) do |slice| - .row.row-centered - - slice.each do |sponsor| - .col-md-4.col-sm-4.col-centered.col-top - = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" + %div#sponsor-container + - @conference.sponsorship_levels.each do |sponsorship_level| + -if sponsorship_level.sponsors.any? + - sponsorship_level.sponsors.each_slice(3) do |slice| + .row.row-centered#sponsor + - slice.each do |sponsor| + .col-md-4.col-sm-4.col-centered.col-top + = image_tag get_logo(sponsor), class: "img-responsive img-sponsor img-sponsor-#{sponsorship_level.position}" diff --git a/app/views/admin/conference/conference_wide_screen.html.haml b/app/views/admin/conference/conference_wide_screen.html.haml index 4e2991fe..5f2e7c71 100644 --- a/app/views/admin/conference/conference_wide_screen.html.haml +++ b/app/views/admin/conference/conference_wide_screen.html.haml @@ -6,11 +6,11 @@ - if @conference.description.present? %h3 = @conference.description - - if @program.present? - .row + - if @current_events.present? + .row#current-events = render 'current_events' - if @conference.contact.social_tag.present? && @tweets.present? - .row + .row#conference-tweets = render 'conference_tweets' - if @sponsors.any? = render 'sponsors' diff --git a/app/views/admin/conference/conference_wide_screen.js.haml b/app/views/admin/conference/conference_wide_screen.js.haml index 998342dc..694d5ace 100644 --- a/app/views/admin/conference/conference_wide_screen.js.haml +++ b/app/views/admin/conference/conference_wide_screen.js.haml @@ -1 +1,4 @@ $('#current-events').html("#{escape_javascript(render 'current_events', data: @current_events)}"); +$('#conference-tweets').html("#{escape_javascript(render 'conference_tweets', data: @tweets)}"); +$('#tweet-container').children().hide(); +$('#tweet-container').children().eq(0).show(); diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index ac377a69..eac4c68c 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -165,18 +165,6 @@ describe Admin::ConferencesController do end end - describe 'GET #conference_wide_screen' do - it 'assigns the requested conference to conference' do - get :show, id: conference.short_title - expect(assigns(:conference)).to eq conference - end - - it 'renders the conference_wide_screen page' do - get :conference_wide_screen, id: conference.short_title - expect(response).to render_template :conference_wide_screen - end - end - describe 'GET #index' do context 'with more than 0 conferences' do it 'populates an array with conferences' do @@ -292,18 +280,6 @@ describe Admin::ConferencesController do end end end - - describe 'GET #conference_wide_screen' do - it 'requires organizer privileges' do - get :conference_wide_screen, id: conference.short_title, - conference: attributes_for(:conference, - short_title: 'ExCon') - expect(response).to redirect_to(send(path)) - if message - expect(flash[:alert]).to match(/#{message}/) - end - end - end end describe 'participant access' do diff --git a/spec/factories/events.rb b/spec/factories/events.rb index c306cdf9..916e840a 100644 --- a/spec/factories/events.rb +++ b/spec/factories/events.rb @@ -33,6 +33,19 @@ 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_spec.rb b/spec/models/event_spec.rb index 77aa4566..65b73103 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -114,6 +114,14 @@ 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 @@ -327,28 +335,4 @@ describe Event do expect(other_event.week).to eq 48 end end - - describe 'current?' do - let(:past_event) { create(:event, program: conference.program) } - let(:future_event) { create(:event, program: conference.program) } - - before do - event.update_attributes(start_time: Time.current.to_s) - past_event.update_attributes(start_time: (Time.current - 2.days).to_s) - future_event.update_attributes(start_time: (Time.current + 2.days).to_s) - end - - it 'returns false for a completed event' do - expect(past_event.current?).to be_falsey - end - - it 'returns false for a future event' do - expect(future_event.current?).to be_falsey - end - - it 'returns true for a current event' do - expect(event.current?).to be_truthy - end - end - end From e82a3e1727403450f250b57ad145d9b2ec3bae22 Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Tue, 23 Aug 2016 10:23:26 -0400 Subject: [PATCH 6/7] 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) } From 514a88e0bec0b36f3168d928be21c355d93c22ee Mon Sep 17 00:00:00 2001 From: AnithaPal Date: Mon, 26 Sep 2016 14:46:46 -0400 Subject: [PATCH 7/7] display current events based on track --- app/assets/stylesheets/osem.css.scss | 17 ++++++++++++++ .../admin/conferences_controller.rb | 2 +- .../conference/_current_events.html.haml | 13 ----------- .../conference/conference_info.html.haml | 16 ------------- .../_conference_tweets.html.haml | 3 +-- .../conferences/_current_events.html.haml | 14 +++++++++++ .../_sponsors.html.haml | 0 .../conferences/conference_info.html.haml | 23 +++++++++++++++++++ .../conference_info.js.haml | 0 config/secrets.yml.example | 7 ------ 10 files changed, 56 insertions(+), 39 deletions(-) delete mode 100644 app/views/admin/conference/_current_events.html.haml delete mode 100644 app/views/admin/conference/conference_info.html.haml rename app/views/admin/{conference => conferences}/_conference_tweets.html.haml (84%) create mode 100644 app/views/admin/conferences/_current_events.html.haml rename app/views/admin/{conference => conferences}/_sponsors.html.haml (100%) create mode 100644 app/views/admin/conferences/conference_info.html.haml rename app/views/admin/{conference => conferences}/conference_info.js.haml (100%) diff --git a/app/assets/stylesheets/osem.css.scss b/app/assets/stylesheets/osem.css.scss index d2a2cd10..462fa955 100644 --- a/app/assets/stylesheets/osem.css.scss +++ b/app/assets/stylesheets/osem.css.scss @@ -90,3 +90,20 @@ p.comment-body { .changeset{ display: none; } + +#conference-header{ + margin: auto; + width: 304px; + .conference-heading{ + float: left; + width: 150px; + } + .conference-logo{ + float: left; + width: 150px; + img{ + width: 100px; + height: 100px; + } + } +} diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 95b56d53..67836ec5 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -176,8 +176,8 @@ module Admin def conference_info # To display sponsors in the conference wide information page @sponsors = @conference.sponsors - @current_event_schedules = @program.selected_schedule.event_schedules.current @tweets = twitter_client.search_tweets(15, @conference.contact.social_tag) + @current_event_schedules = @program.selected_schedule.event_schedules.current.group_by{|es| es.event.track.name} respond_to do |format| format.html{render layout: 'conference_info'} diff --git a/app/views/admin/conference/_current_events.html.haml b/app/views/admin/conference/_current_events.html.haml deleted file mode 100644 index 65ad7c8f..00000000 --- a/app/views/admin/conference/_current_events.html.haml +++ /dev/null @@ -1,13 +0,0 @@ -.container - .row - .col-md-12.text-center - %h2 Current Events - - @current_event_schedules.each do |es| - %div - %h3 - = es.event.title - %h4 - presented by - = es.event.speaker_names - in - = es.event.room.name diff --git a/app/views/admin/conference/conference_info.html.haml b/app/views/admin/conference/conference_info.html.haml deleted file mode 100644 index 603a1dce..00000000 --- a/app/views/admin/conference/conference_info.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -- if @conference.present? - .row - .col-md-12.text-center - %h1 - = @conference.title - - if @conference.description.present? - %h3 - = @conference.description - - if @current_event_schedules.present? - .row#current-events - = render 'current_events' - - if @conference.contact.social_tag.present? && @tweets.any? - .row#conference-tweets - = render 'conference_tweets' - - if @sponsors.any? - = render 'sponsors' diff --git a/app/views/admin/conference/_conference_tweets.html.haml b/app/views/admin/conferences/_conference_tweets.html.haml similarity index 84% rename from app/views/admin/conference/_conference_tweets.html.haml rename to app/views/admin/conferences/_conference_tweets.html.haml index 58ed4e9e..99f1be51 100644 --- a/app/views/admin/conference/_conference_tweets.html.haml +++ b/app/views/admin/conferences/_conference_tweets.html.haml @@ -2,7 +2,7 @@ .row .col-md-12.text-center %h2 - = "#" + @conference.contact.social_tag + " Tweets" + = "##{@conference.contact.social_tag} Tweets" %div#tweet-container - @tweets.each do |tweet| %div#tweet @@ -11,4 +11,3 @@ = tweet.text = link_to "— @" + tweet.user.name, "http://www.twitter.com/#{tweet.user.name}", target: "_blank" = link_to tweet.url, tweet.url.to_s - diff --git a/app/views/admin/conferences/_current_events.html.haml b/app/views/admin/conferences/_current_events.html.haml new file mode 100644 index 00000000..109b96af --- /dev/null +++ b/app/views/admin/conferences/_current_events.html.haml @@ -0,0 +1,14 @@ +.container + .row.row-centered + - @current_event_schedules.each do |track, event_schedules| + .col-md-4.col-sm-4.col-centered + %h2.text-center + = track + - event_schedules.each do |event_schedule| + %h3.text-center + = event_schedule.event.title + %h4.text-center + presented by + = event_schedule.event.speaker_names + in + = event_schedule.event.room.name diff --git a/app/views/admin/conference/_sponsors.html.haml b/app/views/admin/conferences/_sponsors.html.haml similarity index 100% rename from app/views/admin/conference/_sponsors.html.haml rename to app/views/admin/conferences/_sponsors.html.haml diff --git a/app/views/admin/conferences/conference_info.html.haml b/app/views/admin/conferences/conference_info.html.haml new file mode 100644 index 00000000..21c7bbc3 --- /dev/null +++ b/app/views/admin/conferences/conference_info.html.haml @@ -0,0 +1,23 @@ +.container + - if @conference.present? + .row + .col-md-12.text-center + %div#conference-header + %div.conference-logo + = image_tag(@conference.picture_url, class: 'img-responsive') if @conference.picture? + %div.conference-heading + %h1 + = @conference.title + %span + = @conference.short_title + - if @conference.description.present? + %h3 + = @conference.description + - if @current_event_schedules.present? + .row#current-events + = render 'current_events' + - if @conference.contact.social_tag.present? && @tweets.any? + .row#conference-tweets + = render 'conference_tweets' + - if @sponsors.any? + = render 'sponsors' diff --git a/app/views/admin/conference/conference_info.js.haml b/app/views/admin/conferences/conference_info.js.haml similarity index 100% rename from app/views/admin/conference/conference_info.js.haml rename to app/views/admin/conferences/conference_info.js.haml diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 0ee787cc..a8d67504 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -54,13 +54,6 @@ production: facebook_key: '' facebook_secret: '' - # Register your application with Twitter from - # https://apps.twitter.com/ - twitter_consumer_key: '' - twitter_consumer_secret: '' - twitter_access_token: '' - twitter_access_token_secret: '' - # Developers do not need to register their application for suse account to # work. You must, however, add some sample value to the variables, for the # login option to appear. For example: