use Chronic gem to parse uploaded date data
This commit is contained in:
parent
484959298c
commit
860ba6f393
1
Gemfile
1
Gemfile
@ -30,6 +30,7 @@ gem 'rack-utf8_sanitizer'
|
||||
gem 'newrelic_rpm'
|
||||
gem 'actionpack-xml_parser'
|
||||
gem 'activeadmin', github: 'gregbell/active_admin'
|
||||
gem 'chronic'
|
||||
|
||||
# to use debugger
|
||||
# gem 'ruby-debug'
|
||||
|
@ -90,6 +90,7 @@ GEM
|
||||
net-sftp (>= 2.0.0)
|
||||
net-ssh (>= 2.0.14)
|
||||
net-ssh-gateway (>= 1.1.0)
|
||||
chronic (0.10.2)
|
||||
coffee-rails (4.0.1)
|
||||
coffee-script (>= 2.2.0)
|
||||
railties (>= 4.0.0, < 5.0)
|
||||
@ -345,6 +346,7 @@ DEPENDENCIES
|
||||
autotest
|
||||
autotest-rails
|
||||
capistrano (~> 2.15.4)
|
||||
chronic
|
||||
coffee-rails (~> 4.0)
|
||||
daemons
|
||||
dalli
|
||||
|
@ -372,6 +372,7 @@ class ChannelsController < ApplicationController
|
||||
|
||||
# set time zone
|
||||
Time.zone = params[:feed][:time_zone]
|
||||
Chronic.time_class = Time.zone
|
||||
|
||||
# read data from uploaded file
|
||||
csv_array = CSV.parse(params[:upload][:csv].read)
|
||||
@ -409,8 +410,8 @@ class ChannelsController < ApplicationController
|
||||
|
||||
# if 2 or more rows
|
||||
if !csv_array[1].blank?
|
||||
date1 = parse_date ? Time.parse(csv_array[0][0]) : Time.at(csv_array[0][0])
|
||||
date2 = parse_date ? Time.parse(csv_array[1][0]) : Time.at(csv_array[1][0])
|
||||
date1 = Chronic.parse(csv_array[0][0]) if parse_date
|
||||
date2 = Chronic.parse(csv_array[1][0]) if parse_date
|
||||
|
||||
# reverse the array if 1st date is larger than 2nd date
|
||||
csv_array = csv_array.reverse if date1 > date2
|
||||
@ -440,7 +441,7 @@ class ChannelsController < ApplicationController
|
||||
|
||||
# set feed data
|
||||
feed.channel_id = channel.id
|
||||
feed.created_at = parse_date ? Time.zone.parse(row[0]) : Time.zone.at(row[0].to_f)
|
||||
feed.created_at = Chronic.parse(row[0]) if parse_date
|
||||
feed.field1 = row[1]
|
||||
feed.field2 = row[2]
|
||||
feed.field3 = row[3]
|
||||
|
@ -4,7 +4,7 @@ class WindowsController < ApplicationController
|
||||
def hide
|
||||
window = Window.find(params[:id])
|
||||
window.show_flag = false
|
||||
if window.save
|
||||
if window.save
|
||||
render :text => window.id.to_s
|
||||
else
|
||||
render :text => '-1'
|
||||
@ -19,7 +19,7 @@ class WindowsController < ApplicationController
|
||||
def display
|
||||
@visibility = params[:visibility_flag]
|
||||
|
||||
window = Window.find(params[:id])
|
||||
window = Window.find(params[:id])
|
||||
window = Window.new if window.nil?
|
||||
window.show_flag = true
|
||||
#Just save this change, then modify the object before rendering the JSON
|
||||
@ -103,7 +103,7 @@ class WindowsController < ApplicationController
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.html
|
||||
format.json { render :json => @windows.as_json( :include => [:window_detail] ) }
|
||||
end
|
||||
end
|
||||
@ -150,7 +150,7 @@ class WindowsController < ApplicationController
|
||||
channel.update_chart_portlets if (channel.windows.select { |w| w.wtype == :chart } )
|
||||
|
||||
windows = channel.private_windows(true).order(:position) unless params[:channel_id].nil?
|
||||
|
||||
|
||||
if channel.recent_statuses.nil? || channel.recent_statuses.size <= 0
|
||||
@windows = windows.delete_if { |w| w.wtype == "status" }
|
||||
else
|
||||
@ -173,7 +173,7 @@ class WindowsController < ApplicationController
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.html
|
||||
format.json { render :json => @windows.as_json( :include => [:window_detail] ) }
|
||||
end
|
||||
end
|
||||
@ -185,14 +185,14 @@ class WindowsController < ApplicationController
|
||||
# page"=>"{\"col\":0,\"positions\":[1,2,3]}"
|
||||
#So.. the position values are Windows.id They should get updated with the ordinal value based
|
||||
# on their array position and the column should get updated according to col value.
|
||||
# Since the windows are order by position, when a window record changes from
|
||||
# col1,position0 -> col0,position0 the entire new column is reordered.
|
||||
# The old column is missing a position, but the remaining are just left to their order
|
||||
# Since the windows are order by position, when a window record changes from
|
||||
# col1,position0 -> col0,position0 the entire new column is reordered.
|
||||
# The old column is missing a position, but the remaining are just left to their order
|
||||
# (ie., 0,1,2 become 1,2) Unless they are also changed
|
||||
|
||||
# First parse the JSON in params["page"] ...
|
||||
values = JSON(params[:page])
|
||||
|
||||
|
||||
# .. then find each window and update with new ordinal position and col.
|
||||
logger.info "Channel id = " + params[:channel_id].to_s
|
||||
@channel = current_user.channels.find(params[:channel_id])
|
||||
@ -217,3 +217,4 @@ class WindowsController < ApplicationController
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user