Skip to content

Commit 0629ad6

Browse files
committed
Merge branch 'release-0.9.4.1'
2 parents 46cb624 + a1bf312 commit 0629ad6

34 files changed

+406
-174
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
### 0.9.4.1 (2015-03-19)
2+
**Species+ Admin**
3+
* tracking dependents_updated_by_id
4+
* copying exclusions to EU listings
5+
6+
**Trade**
7+
* automatically expand the shipment year range
8+
9+
### 0.9.4 (2015-03-11)
10+
**Species+ Admin:**
11+
* fixes to T -> S and T -> A nomenclature changes processing
12+
* fix for inherited standard reference flag
13+
**Species+:**
14+
* geo entity auto complete matches on parts of name
15+
* calculation of original start date for current EU suspensions
16+
* linking EU Opinions to SRG events
17+
**Trade Admin:**
18+
* fixes to Trade Admin interface
19+
* ability to bulk update some shipment fields with blank value
20+
* speed improvements to permit number auto complete
21+
122
### 0.9.2 (2015-01-15)
223
**Species+ Admin:**
324
* API tracking

app/controllers/cites_trade/home_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class CitesTrade::HomeController < CitesTradeController
22

33
def index
4+
@years = (1975..Trade::Shipment.maximum('year')).to_a.reverse
45
end
56

67
def download

app/models/change_observer.rb

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,42 @@
11
class ChangeObserver < ActiveRecord::Observer
22
observe :taxon_common, :distribution, :eu_decision,
33
:listing_change, :taxon_concept_reference,
4-
:taxon_instrument, :taxon_relationship, :trade_restriction
4+
:taxon_instrument, :taxon_relationship, :cites_suspension, :quota
55

66
def after_save(model)
77
clear_cache model
88
if model.taxon_concept
9-
model.taxon_concept.
10-
update_column(:dependents_updated_at, Time.now)
9+
bump_dependents_timestamp(model.taxon_concept, model.updated_by_id)
10+
end
11+
if model.taxon_concept.nil? && model.taxon_concept_id_was ||
12+
model.taxon_concept && model.taxon_concept_id_was && model.taxon_concept_id != model.taxon_concept_id_was
13+
previous_taxon_concept = TaxonConcept.find_by_id(model.taxon_concept_id_was)
14+
if previous_taxon_concept
15+
bump_dependents_timestamp(previous_taxon_concept, model.updated_by_id)
16+
end
1117
end
1218
end
1319

1420
def before_destroy(model)
1521
clear_cache model
1622
if model.taxon_concept && model.can_be_deleted?
17-
model.taxon_concept.
18-
update_column(:dependents_updated_at, Time.now)
23+
# currently no easy means to tell who deleted the dependent object
24+
bump_dependents_timestamp(model.taxon_concept, nil)
1925
end
2026
end
2127

2228
protected
2329

2430
def clear_cache model
25-
DownloadsCache.send("clear_#{model.class.to_s.tableize}")
31+
DownloadsCacheCleanupWorker.perform_async(model.class.to_s.tableize.to_sym)
32+
end
33+
34+
def bump_dependents_timestamp(taxon_concept, updated_by_id)
35+
return unless taxon_concept
36+
TaxonConcept.where(id: taxon_concept.id).update_all(
37+
dependents_updated_at: Time.now,
38+
dependents_updated_by_id: updated_by_id
39+
)
40+
DownloadsCacheCleanupWorker.perform_async(:taxon_concepts)
2641
end
2742
end

app/models/checklist/csv/index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def taxon_concepts_csv_columns
2424
:introduced_uncertain_distribution, :reintroduced_distribution,
2525
:extinct_distribution, :extinct_uncertain_distribution,
2626
:uncertain_distribution
27-
]
27+
].compact
2828
end
2929

3030
def listing_changes_csv_columns
Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,7 @@
1-
class CitesSuspensionObserver < ActiveRecord::Observer
2-
3-
def after_save(cites_suspension)
4-
if cites_suspension.taxon_concept
5-
cites_suspension.taxon_concept.touch
6-
elsif cites_suspension.taxon_concept_id_was != cites_suspension.taxon_concept_id
7-
TaxonConcept.find(cites_suspension.taxon_concept_id_was).touch
8-
else
9-
touch_taxa_with_applicable_distribution(cites_suspension)
10-
end
11-
end
1+
class CitesSuspensionObserver < TradeRestrictionObserver
122

133
def after_destroy(cites_suspension)
14-
if cites_suspension.taxon_concept
15-
cites_suspension.taxon_concept.touch
16-
else
17-
touch_taxa_with_applicable_distribution(cites_suspension)
18-
end
194
DownloadsCacheCleanupWorker.perform_async(:cites_suspensions)
205
end
216

22-
def touch_taxa_with_applicable_distribution(cites_suspension)
23-
update_stmt = TaxonConcept.send(:sanitize_sql_array, [
24-
"UPDATE taxon_concepts
25-
SET updated_at = NOW()
26-
FROM distributions
27-
WHERE distributions.taxon_concept_id = taxon_concepts.id
28-
AND distributions.geo_entity_id IN (:geo_entity_id)",
29-
:geo_entity_id => [
30-
cites_suspension.geo_entity_id, cites_suspension.geo_entity_id_was
31-
].compact.uniq
32-
])
33-
TaxonConcept.connection.execute update_stmt
34-
end
35-
367
end

app/models/quota_observer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class QuotaObserver < ActiveRecord::Observer
1+
class QuotaObserver < TradeRestrictionObserver
22

33
def after_destroy(quota)
44
DownloadsCacheCleanupWorker.perform_async(:quotas)

app/models/species/orphaned_taxon_concepts_export.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ def sql_columns
2121
columns = [
2222
:id, :legacy_id, :full_name, :author_year, :rank_name, :name_status,
2323
:taxonomy_name, :internal_notes,
24-
:created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by
24+
:created_at, :created_by, :updated_at, :updated_by,
25+
:dependents_updated_at, :dependents_updated_by
2526
]
2627
end
2728

2829
def csv_column_headers
2930
headers = [
3031
'Id', 'Legacy id', 'Scientific Name', 'Author', 'Rank', 'Name status',
3132
'Taxonomy', 'Internal notes',
32-
'Date added', 'Added by', 'Taxon Concept updated date',
33-
'Taxon Concept associations updated date', 'Updated by'
33+
'Date added', 'Added by', 'Taxon Concept updated date', 'Updated by',
34+
'Associations updated date', 'Associations updated by'
3435
]
3536
end
3637

app/models/species/synonyms_and_trade_names_export.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def sql_columns
2626
:accepted_kingdom_name, :accepted_phylum_name, :accepted_class_name,
2727
:accepted_order_name, :accepted_family_name, :accepted_genus_name,
2828
:taxonomy_name, :internal_notes,
29-
:created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by
29+
:created_at, :created_by, :updated_at, :updated_by,
30+
:dependents_updated_at, :dependents_updated_by
3031
]
3132
end
3233

@@ -39,8 +40,8 @@ def csv_column_headers
3940
'Kingdom_Accepted', 'Phylum_Accepted', 'Class_Accepted',
4041
'Order_Accepted', 'Family_Accepted', 'Genus_Accepted',
4142
'Taxonomy', 'Internal notes',
42-
'Date added', 'Added by', 'Taxon Concept updated date',
43-
'Taxon Concept associations updated date', 'Updated by'
43+
'Date added', 'Added by', 'Taxon Concept updated date', 'Updated by',
44+
'Associations updated date', 'Associations updated by'
4445
]
4546
end
4647

app/models/species/taxon_concepts_names_export.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def sql_columns
2222
:id, :legacy_id, :kingdom_name, :phylum_name, :class_name, :order_name, :family_name,
2323
:genus_name, :species_name, :full_name, :author_year, :rank_name, :name_status,
2424
:taxonomy_name, :internal_notes,
25-
:created_at, :created_by, :updated_at, :dependents_updated_at, :updated_by
25+
:created_at, :created_by, :updated_at, :updated_by,
26+
:dependents_updated_at, :dependents_updated_by
2627
]
2728
end
2829

@@ -31,8 +32,8 @@ def csv_column_headers
3132
'Id', 'Legacy id', 'Kingdom', 'Phylum', 'Class', 'Order', 'Family',
3233
'Genus', 'Species', 'Scientific Name', 'Author', 'Rank', 'Name status',
3334
'Taxonomy', 'Internal notes',
34-
'Date added', 'Added by', 'Taxon Concept updated date',
35-
'Taxon Concept associations updated date', 'Updated by'
35+
'Date added', 'Added by', 'Taxon Concept updated date', 'Updated by',
36+
'Associations updated date', 'Associations updated by'
3637
]
3738
end
3839

app/models/taxon_concept.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class TaxonConcept < ActiveRecord::Base
5050

5151
has_one :m_taxon_concept, :foreign_key => :id
5252

53+
belongs_to :dependents_updater, foreign_key: :dependents_updated_by_id, class_name: User
5354
belongs_to :parent, :class_name => 'TaxonConcept'
5455
has_many :children, class_name: 'TaxonConcept', foreign_key: :parent_id, conditions: {name_status: ['A', 'N']}
5556
belongs_to :rank

app/models/trade/shipments_gross_exports_export.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ def ct_subquery_sql(options)
105105
# the categories query returns values by which to pivot (years)
106106
categories_sql = 'SELECT * FROM UNNEST(ARRAY[?])'
107107
categories_sql = ActiveRecord::Base.send(:sanitize_sql_array, [categories_sql, years.map(&:to_i)])
108-
year_columns = years_columns.map{ |y| "#{y} numeric"}.join(', ')
108+
ct_columns = [
109+
'row_name TEXT[]',
110+
report_crosstab_columns.map.each_with_index{ |c, i| "#{sql_crosstab_columns[i]} #{crosstab_columns[c][:pg_type]}"},
111+
years_columns.map{ |y| "#{y} numeric"}
112+
].flatten.join(', ')
109113
# a set returning query requires that output columns are specified
110114
<<-SQL
111115
SELECT * FROM CROSSTAB('#{source_sql}', '#{categories_sql}')
112-
AS ct(
113-
row_name TEXT[],
114-
#{report_crosstab_columns.map.each_with_index{ |c, i| "#{sql_crosstab_columns[i]} #{crosstab_columns[c][:pg_type]}"}.join(', ')},
115-
#{year_columns}
116-
)
116+
AS ct(#{ct_columns})
117117
SQL
118118
end
119119

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class TradeRestrictionObserver < ActiveRecord::Observer
2+
3+
def after_save(trade_restriction)
4+
if trade_restriction.taxon_concept.nil?
5+
touch_taxa_with_applicable_distribution(trade_restriction)
6+
end
7+
end
8+
9+
def after_destroy(trade_restriction)
10+
if trade_restriction.taxon_concept.nil?
11+
touch_taxa_with_applicable_distribution(trade_restriction)
12+
end
13+
end
14+
15+
private
16+
17+
def touch_taxa_with_applicable_distribution(trade_restriction)
18+
update_stmt = TaxonConcept.send(:sanitize_sql_array, [
19+
"UPDATE taxon_concepts
20+
SET dependents_updated_at = NOW(), dependents_updated_by_id = :updated_by_id
21+
FROM distributions
22+
WHERE distributions.taxon_concept_id = taxon_concepts.id
23+
AND distributions.geo_entity_id IN (:geo_entity_id)",
24+
:updated_by_id => trade_restriction.updated_by_id,
25+
:geo_entity_id => [
26+
trade_restriction.geo_entity_id, trade_restriction.geo_entity_id_was
27+
].compact.uniq
28+
])
29+
TaxonConcept.connection.execute update_stmt
30+
end
31+
32+
end

app/views/admin/taxon_concepts/_basic_info.html.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
%>
99
</span>
1010
</h1>
11-
<span class="pull-right">
12-
Created by <%= @taxon_concept.creator.try(:name) || "DATA_IMPORT" %> on <%= @taxon_concept.created_at.strftime("%d/%m/%Y") %> <br />
13-
Last updated by <%= @taxon_concept.updater.try(:name) || "DATA_IMPORT" %> on <%= @taxon_concept.updated_at.strftime("%d/%m/%Y") %>
14-
</span>
11+
<dl class="pull-right well well-small dl-horizontal">
12+
<dt>Created:</dt><dd><%= @taxon_concept.created_at.strftime("%d/%m/%Y") %> (<%= @taxon_concept.creator.try(:name) || "DATA_IMPORT" %>)</dd>
13+
<dt>Updated:</dt><dd><%= @taxon_concept.updated_at.strftime("%d/%m/%Y") %> (<%= @taxon_concept.updater.try(:name) || "DATA_IMPORT" %>)</dd>
14+
<dt>Associations updated:</dt><dd><%= @taxon_concept.dependents_updated_at && @taxon_concept.dependents_updated_at.strftime("%d/%m/%Y") %> (<%= @taxon_concept.dependents_updater.try(:name) || "DATA_IMPORT" %>)</dd>
15+
</dl>
1516
<%= link_to edit_icon, edit_admin_taxon_concept_url(@taxon_concept), :remote => true %>
1617
<% if can? :destroy, @taxon_concept %>
1718
<%= link_to delete_icon, admin_taxon_concept_url(@taxon_concept),

app/views/cites_trade/home/index.html.erb

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -62,89 +62,9 @@
6262
<img src="/assets/cites_trade/information3.gif" class="qtipify" title="<%= t('year_tip') %> " />
6363
</div>
6464
<%= t('from') %>
65-
<select name="time_range_start" id="qryFrom">
66-
<option selected value="2013">2013</option>
67-
<option value="2012">2012</option>
68-
<option value="2011">2011</option>
69-
<option value="2010">2010</option>
70-
<option value="2009">2009</option>
71-
<option value="2008">2008</option>
72-
<option value="2007">2007</option>
73-
<option value="2006">2006</option>
74-
<option value="2005">2005</option>
75-
<option value="2004">2004</option>
76-
<option value="2003">2003</option>
77-
<option value="2002">2002</option>
78-
<option value="2001">2001</option>
79-
<option value="2000">2000</option>
80-
<option value="1999">1999</option>
81-
<option value="1998">1998</option>
82-
<option value="1997">1997</option>
83-
<option value="1996">1996</option>
84-
<option value="1995">1995</option>
85-
<option value="1994">1994</option>
86-
<option value="1993">1993</option>
87-
<option value="1992">1992</option>
88-
<option value="1991">1991</option>
89-
<option value="1990">1990</option>
90-
<option value="1989">1989</option>
91-
<option value="1988">1988</option>
92-
<option value="1987">1987</option>
93-
<option value="1986">1986</option>
94-
<option value="1985">1985</option>
95-
<option value="1984">1984</option>
96-
<option value="1983">1983</option>
97-
<option value="1982">1982</option>
98-
<option value="1981">1981</option>
99-
<option value="1980">1980</option>
100-
<option value="1979">1979</option>
101-
<option value="1978">1978</option>
102-
<option value="1977">1977</option>
103-
<option value="1976">1976</option>
104-
<option value="1975">1975</option>
105-
</select> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
65+
<%= select_tag 'time_range_start', options_for_select(@years, @years.first), id: "qryFrom" %> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
10666
<%= t('to') %>
107-
<select name="time_range_end" id="qryTo">
108-
<option selected value="2013">2013</option>
109-
<option value="2012">2012</option>
110-
<option value="2011">2011</option>
111-
<option value="2010">2010</option>
112-
<option value="2009">2009</option>
113-
<option value="2008">2008</option>
114-
<option value="2007">2007</option>
115-
<option value="2006">2006</option>
116-
<option value="2005">2005</option>
117-
<option value="2004">2004</option>
118-
<option value="2003">2003</option>
119-
<option value="2002">2002</option>
120-
<option value="2001">2001</option>
121-
<option value="2000">2000</option>
122-
<option value="1999">1999</option>
123-
<option value="1998">1998</option>
124-
<option value="1997">1997</option>
125-
<option value="1996">1996</option>
126-
<option value="1995">1995</option>
127-
<option value="1994">1994</option>
128-
<option value="1993">1993</option>
129-
<option value="1992">1992</option>
130-
<option value="1991">1991</option>
131-
<option value="1990">1990</option>
132-
<option value="1989">1989</option>
133-
<option value="1988">1988</option>
134-
<option value="1987">1987</option>
135-
<option value="1986">1986</option>
136-
<option value="1985">1985</option>
137-
<option value="1984">1984</option>
138-
<option value="1983">1983</option>
139-
<option value="1982">1982</option>
140-
<option value="1981">1981</option>
141-
<option value="1980">1980</option>
142-
<option value="1979">1979</option>
143-
<option value="1978">1978</option>
144-
<option value="1977">1977</option>
145-
<option value="1976">1976</option>
146-
<option value="1975">1975</option>
147-
</select>
67+
<%= select_tag 'time_range_end', options_for_select(@years, @years.first), id: "qryTo" %>
14868
<span class="information qtipify" title="<%= t('year_text') %>">&nbsp;</span>
14969
</div>
15070
<div id="tabs-exp">

app/views/layouts/cites_trade.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<meta itemprop="description" content="<%= t('cites_description') %>" />
7+
<meta name="description" content="<%= t('cites_description') %>" />
8+
<meta itemprop="name" content="<%= t('cites_title') %>">
69
<%= stylesheet_link_tag "cites_trade" %>
710
<%= javascript_include_tag "cites_trade" %>
811
<script>

app/workers/download_worker.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def perform(download_id, params)
3434

3535
@download.save!
3636
rescue => msg
37-
ExceptionNotifier.notify_exception(msg)
38-
puts "Failed: #{msg}"
39-
puts "### Backtrace ###"
40-
puts msg.backtrace
37+
ExceptionNotifier.notify_exception(msg) if defined? ExceptionNotifier
38+
logger.warn "Failed: #{msg}"
39+
logger.warn "### Backtrace ###"
40+
logger.warn msg.backtrace
4141
@download.status = "failed"
4242
@download.save!
4343
end

0 commit comments

Comments
 (0)