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