Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge datetime fixes #617

Open
wants to merge 61 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a3e0a7b
Draft changes (temporary save).
gsrohde Oct 13, 2015
f72f4c2
tmp save
gsrohde Oct 13, 2015
c3edd69
tmp save
gsrohde Oct 14, 2015
29e6da6
Draft of new display format for dates and times on View Trait pages.
gsrohde Oct 16, 2015
5fd6284
models/trait.rb:
gsrohde Oct 19, 2015
e30a3eb
Added to $dateloc_drop and $timeloc_drop.
gsrohde Oct 19, 2015
c15c67c
Added seasons to d_month dropdown.
gsrohde Oct 19, 2015
9bbdcd8
In New Trait form, changed default utc_offset to nil and eliminated L…
gsrohde Oct 19, 2015
10407ae
Eliminated LOC display.
gsrohde Oct 19, 2015
efac6e9
Corrected month_day time format.
gsrohde Oct 19, 2015
871964f
Lot's of changes to Trait model. Needs cleanup.
gsrohde Oct 19, 2015
bae4681
Altered Trait model d_* accessors to accomodate the case where datelo…
gsrohde Oct 21, 2015
fc0d4d0
Forgot to include timeloc value 9 in t_minute's case statement.
gsrohde Oct 21, 2015
68f460b
In Trait validation method "consistent_date_and_time_fields", use ins…
gsrohde Oct 21, 2015
a89d5cd
Forgot to handle dateloc value 95 in Trait accessor method d_day.
gsrohde Oct 21, 2015
b3e7b9c
Removed time zone offset input element and made date/time layout room…
gsrohde Oct 26, 2015
77bc18f
Added seasons to month dropdown.
gsrohde Oct 26, 2015
c05c2d7
Removed timezone_offset getter and setter.
gsrohde Oct 26, 2015
14144a0
Tweaked display of timezone on Show page.
gsrohde Oct 26, 2015
2dccffb
Added migration to add time_zone to sites.
gsrohde Oct 26, 2015
2daa72d
Merge branch 'master' into GH_356-357
gsrohde Oct 26, 2015
e258e92
Added Javascript to Trait/Edit page to make site changes adjust the t…
gsrohde Oct 28, 2015
d187ad0
Added TimesOfDay constant.
gsrohde Nov 4, 2015
9ea7a97
Re-arranged code into sections and added additional comments.
gsrohde Nov 4, 2015
e1c1718
Simplified code, especially the process_datetime_input method, which …
gsrohde Nov 4, 2015
905dabf
Updated Trait model and time_formats initializer to support time-of-d…
gsrohde Nov 5, 2015
e655188
Added constants for Months, Days, Hours, and Minutes to the Trait mod…
gsrohde Nov 5, 2015
50e0383
Better error handling, especially: For validation errors, add to the …
gsrohde Nov 5, 2015
717b93c
Updated date presentation in Advanced Search results table in accorda…
gsrohde Nov 6, 2015
029d5eb
Refactored code: Moved methods from Trait and TraitsAndYieldsView cla…
gsrohde Nov 6, 2015
cb5057b
Converting Yields pages and Advanced Pages to the use of new date/dat…
gsrohde Nov 10, 2015
9cdfa32
Use named constants instead of integer literals for dummy date/time v…
gsrohde Nov 10, 2015
b8a298c
Fixed bug in Yield#consistent_date_and_time_fields for the case where…
gsrohde Nov 10, 2015
f546975
In Yield#update, use assign_attributes instead of update_attributes s…
gsrohde Nov 10, 2015
9f90309
Changed d_day accessor methods to return nil when dateloc is 5.5.
gsrohde Nov 11, 2015
17bd764
Changed CSV output for traits and yields to use LOC-aware date/time v…
gsrohde Nov 11, 2015
5402cbc
Updated yield integration test to work with new date fields.
gsrohde Nov 11, 2015
943a1ef
Added a migration that defines the normative interpretation of trait …
gsrohde Nov 20, 2015
11da0ce
Added a PL/pgSQL function that defines the normative interpretation o…
gsrohde Nov 20, 2015
65f930d
Merge branch 'master' into GH_356-357-merged
gsrohde Jan 28, 2016
e4b7feb
Merge branch 'master' into GH_356-357
gsrohde May 10, 2016
0ae10ee
Merge branch 'GH_356-357' of https://github.com/PecanProject/bety int…
gsrohde Jul 20, 2016
1c8d134
Merge branch 'master' into GH_356-357
gsrohde Jul 20, 2016
2844dc0
Removed redundant migration and changed timestamp on another.
gsrohde Jul 20, 2016
67147a7
Merge branch 'GH_356-357' of github.com:PecanProject/bety into GH_356…
gsrohde Jul 20, 2016
2086b5f
Add more testing of the Trait model.
gsrohde Jul 21, 2016
9faed8b
Add more tests.
gsrohde Jul 21, 2016
6f5db31
Added more trait date tests.
gsrohde Jul 23, 2016
848f6b6
When computing time and date LOC, use accessors to get the year, mont…
gsrohde Jul 23, 2016
8671d1c
Tweaked one trait fixture and added one new one.
gsrohde Jul 23, 2016
7ce90b1
Started incorporating Factory Girl into RSpec tests.
gsrohde Jul 26, 2016
af02ee0
Fixed first test in trait_interface_spec.rb.
gsrohde Jul 26, 2016
21d43f0
Converted trait_interface_spec over to using Factory Girl.
gsrohde Jul 26, 2016
b333289
Fixed bugs in pretty_date and pretty_time functions.
gsrohde Aug 1, 2016
1682f36
Merge branch 'master' into GH_356-357-tweaks
gsrohde Jun 28, 2017
ea0681e
Merge branch 'master' into GH_356-357-tweaks
gsrohde Jul 17, 2017
f6225a9
Fixed pretty_date to show site timezone when timeloc is 9 and dateloc…
gsrohde Jul 19, 2017
2fd4f9a
Fixed trait model test to be consistent with the July 2016 update to …
gsrohde Jul 19, 2017
b90ef72
Merge in branch 'GH_356-357-tweaks', modifying as appropriate.
gsrohde Dec 14, 2018
eb4336c
Merge branch 'develop' into merge_datetime_fixes
gsrohde Jan 16, 2019
3d5f096
Fix typo in abbreviation for season representing March-April-May.
gsrohde Mar 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ group :test do
gem "capybara", "~> 2.8"
gem "database_cleaner"
gem "rails-controller-testing" # TO-DO: rewrite the specs that rely on this
gem "factory_girl_rails", "~> 4.0"
end

# If you have difficulty installing or don't wish to install capybara-webkit,
Expand Down
110 changes: 58 additions & 52 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (>= 2.0, < 4.0)
capybara-webkit (1.15.0)
capybara-webkit (1.15.1)
capybara (>= 2.3, < 4.0)
json
childprocess (0.9.0)
Expand All @@ -78,14 +78,19 @@ GEM
execjs
coffee-script-source (1.12.2)
comma (3.0.4)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.3)
crass (1.0.4)
database_cleaner (1.7.0)
diff-lcs (1.3)
dynamic_form (1.1.4)
erubi (1.7.1)
execjs (2.7.0)
ffi (1.9.23)
factory_girl (4.9.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.9.0)
factory_girl (~> 4.9.0)
railties (>= 3.0.0)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (0.9.5)
Expand All @@ -97,44 +102,44 @@ GEM
jquery-ui-rails (6.0.1)
railties (>= 3.2.16)
json (2.1.0)
json-schema (2.8.0)
json-schema (2.8.1)
addressable (>= 2.4)
kgio (2.11.2)
loofah (2.2.2)
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
memoist (0.16.0)
method_source (0.9.0)
mini_mime (1.0.0)
method_source (0.9.2)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
multi_json (1.13.1)
mustache (1.0.5)
mustache (1.1.0)
narray (0.6.0.4)
nio4r (2.3.0)
nokogiri (1.8.2)
nio4r (2.3.1)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
passenger (5.3.4)
passenger (6.0.0)
rack
rake (>= 0.8.1)
pg (1.0.0)
pg (1.1.3)
protected_attributes_continued (1.3.0)
activemodel (~> 5.0)
pry (0.11.3)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.6.0)
byebug (~> 10.0)
pry (~> 0.10)
pry-rails (0.3.6)
pry-rails (0.3.8)
pry (>= 0.10.4)
public_suffix (3.0.2)
rabl (0.13.1)
public_suffix (3.0.3)
rabl (0.14.0)
activesupport (>= 2.3.14)
rack (2.0.5)
rack-test (1.0.0)
rack (2.0.6)
rack-test (1.1.0)
rack (>= 1.0, < 3)
railroad (0.5.0)
rails (5.1.5)
Expand All @@ -149,10 +154,10 @@ GEM
bundler (>= 1.3.0)
railties (= 5.1.5)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.2)
actionpack (~> 5.x, >= 5.0.1)
actionview (~> 5.x, >= 5.0.1)
activesupport (~> 5.x)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
Expand All @@ -166,7 +171,7 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.19.0)
rake (12.3.1)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
Expand All @@ -176,36 +181,36 @@ GEM
rgeo-activerecord (5.1.1)
activerecord (~> 5.0)
rgeo (~> 0.3)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-rails (3.7.2)
rspec-support (~> 3.8.0)
rspec-rails (3.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rspec_api_documentation (5.1.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec_api_documentation (6.1.0)
activesupport (>= 3.0.0)
mustache (~> 1.0, >= 0.99.4)
rspec (~> 3.0)
ruby-graphviz (1.0.8)
rubyzip (1.2.1)
rubyzip (1.2.2)
safe_attributes (1.0.10)
activerecord (>= 3.0.0)
sass (3.5.6)
sass (3.7.2)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -217,35 +222,35 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
seer (0.10.0)
selenium-webdriver (3.11.0)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
rubyzip (~> 1.2, >= 1.2.2)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
thor (0.20.0)
thor (0.20.3)
thread_safe (0.3.6)
tilt (2.0.8)
trollop (2.1.2)
tilt (2.0.9)
trollop (2.9.9)
tzinfo (1.2.5)
thread_safe (~> 0.1)
uglifier (4.1.9)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
unicorn (5.4.0)
unicorn (5.4.1)
kgio (~> 2.6)
raindrops (~> 0.7)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will_paginate (3.1.6)
xpath (3.0.0)
xpath (3.2.0)
nokogiri (~> 1.8)
yajl-ruby (1.3.1)
yard (0.9.12)
yard (0.9.16)

PLATFORMS
ruby
Expand All @@ -262,6 +267,7 @@ DEPENDENCIES
comma (= 3.0.4)
database_cleaner
dynamic_form
factory_girl_rails (~> 4.0)
jquery-rails
jquery-ui-rails
json
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/base.css.erb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@
font-weight: normal;
font-size: 13px;
color: #444; }
legend span.inherit {
font-weight: inherit;
font-size: inherit;
color: inherit; }

/* #Misc
================================================== */
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ class SitesController < ApplicationController
require 'csv'

#AJAX Calls

# Returns the name of the time zone for the site whose id is passed in the
# HTTP parameter "id"; or returns 'UTC' if no site having that id is found or
# if the time_zone attribute of the site found is NULL.
def get_timezone
begin
site = Site.find(params[:id])
if site.time_zone.nil?
tz = 'UTC - site timezone unknown'
else
tz = site.time_zone
end
rescue ActiveRecord::RecordNotFound
tz = 'UTC'
end

respond_to do |format|
format.text {
render(plain: tz)
}
end
end

def linked
@citation = Citation.find(session["citation"])
@site = Site.find(params[:id])
Expand Down
45 changes: 1 addition & 44 deletions app/controllers/yields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,8 @@ def edit
# POST /yields.xml
def create

set_default_date_fields(params)

@yield = Yield.new(params[:yield])

maybe_set_from_julian_date(params)

@yield.user_id = current_user.id

logger.info "Current user: #{current_user.id}"
Expand All @@ -163,11 +159,7 @@ def create
def update
@yield = Yield.all_limited(current_user).find(params[:id])

set_default_date_fields(params)

@yield.update_attributes(params[:yield])

maybe_set_from_julian_date(params)
@yield.assign_attributes(params[:yield])

if params['assign_creator']
@yield.user_id = current_user.id
Expand Down Expand Up @@ -204,39 +196,4 @@ def destroy
end
end

private

# If any piece of the date was given in the parameters, set any other pieces
# that may have been missing to default values.
def set_default_date_fields(params)
# If at least on of the date fields is non-blank, assign defaults to the others if they are blank:
if !(params[:yield]['date(1i)'].blank? and params[:yield]['date(2i)'].blank? and params[:yield]['date(3i)'].blank?)

# Default the empty fields. In Rails 3.2, it seems we must do this explicitly.
params[:yield]['date(1i)'] = "9999" if params[:yield]['date(1i)'].blank? # year default
params[:yield]['date(2i)'] = "1"if params[:yield]['date(2i)'].blank? # month default
params[:yield]['date(3i)'] = "1"if params[:yield]['date(3i)'].blank? # day default

end
end

# If either parameter julianyear or julianday was set, update the yield date
# using these parameter values.
def maybe_set_from_julian_date(params)

# They can also enter the date in julian format, so if they do, overwrite
# the other date field:
if !(params[:julianyear].blank? and params[:julianday].blank?)
params[:julianyear] = "9999" if params[:julianyear].blank? # year default
params[:julianday] = "1" if params[:julianday].blank? # day default

begin
@yield.date = Date.ordinal(params[:julianyear].to_f, params[:julianday].to_f)
rescue
flash[:error] = "Invalid values in Julian date fields were ignored"
end
end

end

end
17 changes: 16 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,33 @@ def treatment_check(ty)
"7 season" => "7.0" ,
"7.5 " => "7.5" ,
"8 year" => "8.0" ,
"9 no data" => "9.0" }
"9 no data" => "9.0",
"95 day (year unspecified)" => "95.0",
"96 month (year unspecified)" => "96.0",
"97 season (year unspecified)" => "97.0" }
$dateloc_drop_default = "9.0"
$timeloc_drop = { "1 second" => "1.0" ,
"2 minute" => "2.0" ,
"2.5 quarter-hour" => "2.5" ,
"3 hour" => "3.0" ,
"4 time of day, e.g. morning, afternoon" => "4.0" ,
"9 no data" => "9.0" }
$timeloc_drop_default = "9.0"

$statname_list = ["","SD", "SE", "MSE", "95%CI", "LSD", "MSD"]


# Query the database to get all possible timezone offsets in current use:
offsets_query = "SELECT DISTINCT utc_offset FROM pg_timezone_names ORDER BY utc_offset"
$utc_offsets = ActiveRecord::Base.connection.execute(offsets_query).to_a.collect do |item|
offset = item['utc_offset']
if !offset.match(/\+|-/)
offset = "+#{offset}"
end
offset
end


# Simple Search
def sortable(column, title = nil)
title ||= column.titleize
Expand Down
Loading