From bf7f5ce09f4ed2fe4fa554822de99210407be74b Mon Sep 17 00:00:00 2001 From: Ana Date: Sat, 2 Jul 2016 17:23:56 +0200 Subject: [PATCH] The schedule takes you to the current day and time The schedule takes you to the current day and time in case that the current date belongs to the conference schedule. Closes https://github.com/openSUSE/osem/issues/1057 --- app/controllers/conference_controller.rb | 7 +++++ app/helpers/application_helper.rb | 10 +++++++ app/models/conference.rb | 9 +++++++ app/views/conference/_carousel.html.haml | 2 +- app/views/conference/schedule.html.haml | 34 ++++++++++++++++-------- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/app/controllers/conference_controller.rb b/app/controllers/conference_controller.rb index 7068061e..1dc1ded8 100644 --- a/app/controllers/conference_controller.rb +++ b/app/controllers/conference_controller.rb @@ -24,6 +24,13 @@ class ConferenceController < ApplicationController @conf_start = 9 conf_end = 20 @conf_period = conf_end - @conf_start + + # the schedule takes you to today if it is a date of the schedule + @current_day = @conference.current_conference_day + @day = @current_day.present? ? @current_day : @dates.first + return unless @current_day + # the schedule takes you to the current time if it is beetween the start and the end time. + @hour_column = @conference.hours_from_start_time(@conf_start, conf_end) end def events diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5004347c..ddc072af 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,4 +335,14 @@ module ApplicationHelper # speaker picture padding: 4px 2px; and we want the picture to be a circle speaker_height(rooms) - 4 end + + def carousel_item_class(number, carousel_number, num_cols, col) + item_class = 'item' + item_class += ' first' if number == 0 + item_class += ' last' if number == (carousel_number - 1) + if (col && ((col / num_cols) == number)) || (!col && number == 0) + item_class += ' active' + end + item_class + end end diff --git a/app/models/conference.rb b/app/models/conference.rb index d3fd5590..6d35946b 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -615,6 +615,15 @@ class Conference < ActiveRecord::Base day if (start_date..end_date).cover? day end + # Returns the number of hours since the conference start hour (9) to the + # current hour, in case that the current hour is beetween the start and the + # end hour (20). Otherwise, returns 0 + def hours_from_start_time(start_hour, end_hour) + current_time = Time.find_zone(timezone).now + current_hour = current_time.strftime('%H').to_i + (start_hour..(end_hour-1)).cover?(current_hour) ? current_hour - start_hour : 0 + end + private # Returns a different html colour for every i and consecutive colors are diff --git a/app/views/conference/_carousel.html.haml b/app/views/conference/_carousel.html.haml index 4a43f424..bc8b3157 100644 --- a/app/views/conference/_carousel.html.haml +++ b/app/views/conference/_carousel.html.haml @@ -9,7 +9,7 @@ .carousel-inner - start_time = DateTime.parse("#{date} #{@conf_start}:00") - (0..carousel_number-1).each do |number| - %div{ class: "item #{ number == 0 ? 'active first' : ( number == carousel_number-1 ? 'last' : '') }" } + %div{ class: "#{ carousel_item_class(number, carousel_number, number_columns, @hour_column)}" } %table.table.table-bordered.schedule-table#schedule %tr %th diff --git a/app/views/conference/schedule.html.haml b/app/views/conference/schedule.html.haml index 05476aae..ea9971c1 100644 --- a/app/views/conference/schedule.html.haml +++ b/app/views/conference/schedule.html.haml @@ -7,16 +7,16 @@ = @conference.title .dropdown.schedule-dropdown %button{ type: "button", class: "btn btn-default dropdown-toggle", 'data-toggle' => "dropdown" } - = @dates.first + = @day %span.caret %ul.dropdown-menu - @dates.each do |date| - %li.li-dropdown-schedule + %li.li-dropdown-schedule{ class: "#{ 'active' if @day == date }" } = link_to date, "#" + "#{date}", "data-toggle" => "tab", "class" => "date-tab" .tab-content - @dates.each do |date| - %div{ class: "tab-pane #{ 'active' if @dates.first == date }", id: "#{ date }" } + %div{ class: "tab-pane #{ 'active' if @day == date }", id: "#{ date }" } .visible-xs-inline = render partial: 'carousel', locals: { date: date, number_columns: 1 } @@ -28,7 +28,7 @@ = render partial: 'carousel', locals: { date: date, number_columns: 3 } :javascript - // change of active tab and the button title when a date clicked + // change of active tab and the button title when a date is clicked $(function() { $('.date-tab').on('click', function(e) { $('.li-dropdown-schedule').removeClass('active'); @@ -43,14 +43,22 @@ $(this).children('.right.carousel-control').show(); if($(this).find('.first').hasClass('active')) { $(this).children('.left.carousel-control').hide(); - } else if($(this).find('.last').hasClass('active')) { + } + if($(this).find('.last').hasClass('active')) { $(this).children('.right.carousel-control').hide(); } }); $(document).ready(function(){ // hide the left control when the page is ready - $('.carousel').children('.left.carousel-control').hide(); + $('.carousel').each(function() { + if($(this).find('.first').hasClass('active')) { + $(this).children('.left.carousel-control').hide(); + } + if($(this).find('.last').hasClass('active')) { + $(this).children('.right.carousel-control').hide(); + } + }); // carousel swipe $(".carousel-inner").swiperight(function() { @@ -60,10 +68,14 @@ $(this).parent().carousel('next'); }); - // use the date tag in the url to select a tab and the title of the button - var hash = window.location.hash; - if(hash && !(hash === '#schedule')){ - hash && $('ul a[href="' + hash + '"]').tab('show'); - $('button.dropdown-toggle').text(hash.substr(1)); + var day = "#{@current_day}"; + // we only go to the date tag in the url if the conference is not taking place now + if(day === ""){ + // use the date tag in the url to select a tab and the title of the button + var hash = window.location.hash; + if(hash && !(hash === '#schedule')){ + hash && $('ul a[href="' + hash + '"]').tab('show'); + $('button.dropdown-toggle').text(hash.substr(1)); + } } });