diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 74a54e4..a13a854 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base # include these helper methods for views helper_method :current_user_session, :current_user, :logged_in?, :get_header_value, :to_bytes protect_from_forgery - before_filter :allow_cross_domain_access, :set_variables + before_filter :allow_cross_domain_access, :set_variables, :set_time_zone before_filter :configure_permitted_parameters, if: :devise_controller? after_filter :remove_headers before_filter :authenticate_user_from_token! @@ -37,9 +37,6 @@ class ApplicationController < ActionController::Base @locale ||= get_locale I18n.locale = @locale - # sets timezone for current user, all DateTime outputs will be automatically formatted - Time.zone = current_user.present? ? current_user.time_zone : 'UTC' - # allows use of daily params params[:timescale] = '1440' if params[:timescale] == 'daily' params[:average] = '1440' if params[:average] == 'daily' @@ -304,16 +301,13 @@ class ApplicationController < ActionController::Base return date_range end - def set_time_zone(params) - # set timezone correctly - if params[:offset] - # check for 0 offset first since it's the most common - if params[:offset] == '0' - Time.zone = 'UTC' - else - Time.zone = set_timezone_from_offset(params[:offset]) - end - elsif current_user + # set timezone correctly + def set_time_zone + if params[:timezone].present? + Time.zone = ActiveSupport::TimeZone::MAPPING.key(params[:timezone]) + elsif params[:offset].present? + Time.zone = set_timezone_from_offset(params[:offset]) + elsif current_user.present? Time.zone = current_user.time_zone else Time.zone = 'UTC' @@ -329,11 +323,12 @@ class ApplicationController < ActionController::Base # loop through each timezone ActiveSupport::TimeZone.zones_map.each do |z| current_zone = z[0] - # get time string in time zone without daylight savings time - timestring = Time.parse('2000-01-01').in_time_zone(current_zone).to_s + + # get time string in time zone + timestring = Time.now.in_time_zone(current_zone).to_s # if time zone matches the offset, leave current_zone alone - break if (timestring.slice(-5..-3).to_i == offset && timestring.slice(-2..-1).to_i == 0) + break if (current_zone != 'UTC' && timestring.slice(-5..-3).to_i == offset && timestring.slice(-2..-1).to_i == 0) end # if no time zone found, set to utc diff --git a/app/controllers/channels_controller.rb b/app/controllers/channels_controller.rb index 282b203..83a6d7f 100644 --- a/app/controllers/channels_controller.rb +++ b/app/controllers/channels_controller.rb @@ -169,14 +169,12 @@ class ChannelsController < ApplicationController def update - @channel = current_user.channels.find(params[:id]) - puts params[:channel].inspect - # make sure channel isn't social - #render :text => '' and return if @channel.social + if params["channel"]["video_type"].blank? && !params["channel"]["video_id"].blank? @channel.errors.add(:base, t(:channel_video_type_blank)) end + if @channel.errors.count <= 0 @channel.save_tags(params[:tags][:name]) @channel.assign_attributes(channel_params) @@ -458,9 +456,6 @@ class ChannelsController < ApplicationController end end - # set the user's time zone back - set_time_zone(params) - # redirect flash[:notice] = t(:upload_successful) redirect_to channel_path(channel.id, :anchor => "dataimport") diff --git a/app/controllers/docs_controller.rb b/app/controllers/docs_controller.rb index ea7da51..e8a67b7 100644 --- a/app/controllers/docs_controller.rb +++ b/app/controllers/docs_controller.rb @@ -1,7 +1,26 @@ class DocsController < ApplicationController before_filter :set_support_menu - def index; ; end + def index + @timezones = {} + + # for each timezone + ActiveSupport::TimeZone::MAPPING.each do |timezone| + # if the hash already exists, just add to the description + if @timezones[timezone[1]].present? + @timezones[timezone[1]][:description] = @timezones[timezone[1]][:description] + ", #{timezone[0]}" + # else add the timezone data + else + @timezones[timezone[1]] = { + :description => timezone[0], + :offset => Time.now.in_time_zone(timezone[0]).formatted_offset + } + end + end + + @timezones = @timezones.sort_by{ |identifier, hash| hash[:offset].to_i }.to_h + end + def errors; ; end def tweetcontrol; ; end def plugins; ; end diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb index f85a3b3..87d17d4 100644 --- a/app/controllers/feed_controller.rb +++ b/app/controllers/feed_controller.rb @@ -15,9 +15,6 @@ class FeedController < ApplicationController # set csv headers if necessary @csv_headers = feed_factory.feed_select_options if params[:format] == 'csv' - # set timezone correctly - set_time_zone(params) - # check for access if @success @@ -93,7 +90,6 @@ class FeedController < ApplicationController def last_group_call(arg) @channel = Channel.find(params[:channel_id]) @api_key = ApiKey.find_by_api_key(get_apikey) - set_time_zone(params) # limit for the number of results to get limit = 30 @@ -153,14 +149,10 @@ class FeedController < ApplicationController end def show - @channel = Channel.find(params[:channel_id]) @api_key = ApiKey.find_by_api_key(get_apikey) output = '-1' - # set timezone correctly - set_time_zone(params) - # make sure field parameter is set correctly, changes "field1" to "1" params[:field_id] = params[:field_id].sub('field', '') if params[:field_id].present? diff --git a/app/controllers/plugins_controller.rb b/app/controllers/plugins_controller.rb index d7b72fa..9e3d737 100644 --- a/app/controllers/plugins_controller.rb +++ b/app/controllers/plugins_controller.rb @@ -5,7 +5,7 @@ class PluginsController < ApplicationController def check_permission @plugin = Plugin.find(params[:id]) - if @plugin.user_id != current_user.id + if current_user.present? && @plugin.user_id != current_user.id render :text=> "#{t(:permission)} #{t(:plugin)}", :layout => true and return return true end diff --git a/app/controllers/stream_controller.rb b/app/controllers/stream_controller.rb index d3ad411..f5ddbf5 100644 --- a/app/controllers/stream_controller.rb +++ b/app/controllers/stream_controller.rb @@ -6,9 +6,6 @@ class StreamController < ApplicationController channel = Channel.find(params[:id]) api_key = ApiKey.find_by_api_key(get_apikey) - # set timezone correctly - set_time_zone(params) - # output proper http response if error render :text => '-1', :status => 400 and return if !channel_permission?(channel, api_key) diff --git a/app/views/docs/_sidebar.html.erb b/app/views/docs/_sidebar.html.erb index 19c0c6d..e82f268 100644 --- a/app/views/docs/_sidebar.html.erb +++ b/app/views/docs/_sidebar.html.erb @@ -1,6 +1,14 @@