Skip to content

Commit d021023

Browse files
committed
Merge remote-tracking branch 'origin/release-1.10.0'
2 parents 11e941a + 2512b99 commit d021023

64 files changed

Lines changed: 1200 additions & 67 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
### 1.10.0
2+
3+
**CITES Trade DB**
4+
5+
* Add EU importer/exporter grouping
6+
* Add disclaimer text beneath the search when EU is selected
7+
8+
**Species +**
9+
10+
* Add CITES Processes(RST, Captive Breeding) to the legal section (temporarily hidden)
11+
* Expand admin interface with CRUD for Captive breeding processes
12+
* Add RST API client and scheduled task (temporarily disabled) to retrieve RST processes
13+
* Add CITES Processes export via the admin interface
14+
* Fix search with diacritics (searching for Turkiye will also return Türkiye)
15+
* Add source_ids to quota and suspension internal API (used in SAT)
16+
117
### 1.9.0
218

319
* Add parameter to taxon concept show API internal endpoint to trimmed response for the mobile app

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ gem 'sidekiq-unique-jobs', '~> 4.0.17'
3838
gem 'redis-rails', '~> 4.0.0'
3939

4040
gem 'whenever', :require => false
41+
gem 'httparty'
4142

4243
gem 'sprockets', '~> 2.12.5' # upgrading to 3 breaks handlebars/tilt
4344
gem 'ember-rails', '~> 0.14.1'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ GEM
232232
http-cookie (1.0.2)
233233
domain_name (~> 0.5)
234234
http_parser.rb (0.5.3)
235+
httparty (0.16.2)
236+
multi_xml (>= 0.5.2)
235237
i18n (0.9.5)
236238
concurrent-ruby (~> 1.0)
237239
immigrant (0.1.4)
@@ -277,6 +279,7 @@ GEM
277279
mini_portile2 (2.4.0)
278280
minitest (4.7.5)
279281
multi_json (1.15.0)
282+
multi_xml (0.6.0)
280283
nested-hstore (0.0.5)
281284
activerecord
282285
activerecord-postgres-hstore
@@ -554,6 +557,7 @@ DEPENDENCIES
554557
guard-bundler
555558
guard-livereload
556559
handlebars-source (= 1.0.12)
560+
httparty
557561
immigrant
558562
inherited_resources (~> 1.7.0)
559563
jquery-cookie-rails (~> 1.3.1.1)

app/assets/javascripts/cites_trade/application.js

Lines changed: 89 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ $(document).ready(function(){
22

33
var ajaxFail, initExpctyImpcty, initTerms, initSources, initPurposes,
44
countries = {}, units = {}, terms = {}, purposes = {}, sources = {},
5+
euId = '',
56
selected_taxa = '',
67
is_search_page = $('#form_expert').length > 0,
78
is_download_page = $('#net_gross_options').length > 0,
@@ -19,14 +20,6 @@ $(document).ready(function(){
1920
$.jGrowl(text);
2021
};
2122

22-
function growlMeSticky(text){
23-
$.jGrowl(text, {sticky: true});
24-
};
25-
26-
function notyNormal(message){
27-
noty({layout: 'topRight', text: message, timeout: 4000});
28-
};
29-
3023
function notySticky(message){
3124
noty({ layout: 'top',
3225
type: 'information',
@@ -75,17 +68,6 @@ $(document).ready(function(){
7568
$('input,select').keypress(function(event) { return event.keyCode != 13; });
7669
};
7770

78-
function fixTaxonId (arr) {
79-
return _.map(arr, function (obj) {
80-
if (obj.name === 'taxon_concepts_ids[]') {
81-
return {name: 'taxon_concepts_ids[]', value: selected_taxa};
82-
} else {
83-
return obj;
84-
}
85-
});
86-
}
87-
88-
8971
function parseInputs ($inputs) {
9072
var values = {};
9173
$inputs.each(function() {
@@ -104,6 +86,7 @@ $(document).ready(function(){
10486

10587
function getParamsFromInputs(){
10688
var values = parseInputs($('#form_expert :input'));
89+
10790
return $.param({'filters': values});
10891
}
10992

@@ -183,6 +166,7 @@ $(document).ready(function(){
183166
$('#reset_search').click(function() {
184167
resetSelects();
185168
show_values_selection();
169+
setEuDisclaimerVisibility();
186170
// Removing the table results on reset
187171
$("#query_results_table").find('thead,tbody').remove();
188172
$('#query_results').find('p.info').text('');
@@ -202,17 +186,6 @@ $(document).ready(function(){
202186
hoverColor: '#D2EF9A'
203187
});
204188

205-
206-
function getSelectionTextNew(source) {
207-
var values = [];
208-
209-
$('#ms-' + source).find('div.ms-selection ul.ms-list li').each(function() {
210-
values.push($(this).text());
211-
});
212-
213-
return values.join(',')
214-
}
215-
216189
function getSelectionText(source) {
217190
myValues = new Array();
218191
$('#' + source + ' option:selected').each(function(index, value) {
@@ -231,6 +204,10 @@ $(document).ready(function(){
231204
initCountriesObj = function (data) {
232205
_.each(data.geo_entities, function (country) {
233206
countries[country.id] = country;
207+
208+
if (country.iso_code2 == 'EU') {
209+
euId = country.id.toString()
210+
}
234211
});
235212
unLock('initCountriesObj');
236213
}
@@ -256,6 +233,35 @@ $(document).ready(function(){
256233
unLock('initSourcesObj');
257234
}
258235

236+
removeCasingAndDiacritics = function (value) {
237+
return value.toString()
238+
.normalize('NFD')
239+
.replace(/[\u0300-\u036F]/g, '')
240+
.toLowerCase()
241+
}
242+
243+
matchWithDiacritics = function (term, text) {
244+
// If there are no search terms, return all of the data
245+
if ($.trim(term) === '') {
246+
return text;
247+
}
248+
249+
// Do not display the item if there is no 'text' property
250+
if (typeof text === 'undefined') {
251+
return null;
252+
}
253+
254+
var searchTerm = removeCasingAndDiacritics(term)
255+
var optionText = removeCasingAndDiacritics(text)
256+
257+
if (optionText.indexOf(searchTerm) > -1) {
258+
return text;
259+
}
260+
261+
// Return `null` if the term should not be displayed
262+
return null;
263+
}
264+
259265
initExpctyImpcty = function (data) {
260266
var args = {
261267
data: data.geo_entities,
@@ -272,7 +278,8 @@ $(document).ready(function(){
272278
$('#expcty').select2({
273279
width: '75%',
274280
allowClear: false,
275-
closeOnSelect: false
281+
closeOnSelect: false,
282+
matcher: matchWithDiacritics
276283
}).on('change', function(e){
277284
var selection = "";
278285
if (e.val.length == 0) {
@@ -288,6 +295,7 @@ $(document).ready(function(){
288295
selection = getText(new_array);
289296
}
290297
$('#expcty_out').text(selection);
298+
setEuDisclaimerVisibility();
291299
});
292300

293301
populateSelect(_.extend(args, {
@@ -298,7 +306,8 @@ $(document).ready(function(){
298306
$('#impcty').select2({
299307
width: '75%',
300308
allowClear: false,
301-
closeOnSelect: false
309+
closeOnSelect: false,
310+
matcher: matchWithDiacritics
302311
}).on('change', function(e){
303312
selection = "";
304313
if (e.val.length == 0) {
@@ -315,6 +324,7 @@ $(document).ready(function(){
315324
selection = getText(new_array);
316325
}
317326
$('#impcty_out').text(selection);
327+
setEuDisclaimerVisibility();
318328
});
319329
};
320330

@@ -461,11 +471,6 @@ $(document).ready(function(){
461471
function show_values_selection() {
462472
var year_from = $('#qryFrom').val();
463473
var year_to = $('#qryTo').val();
464-
var exp_cty = $('#expctyms2side__dx').text();
465-
var imp_cty = $('#impctyms2side__dx').text();
466-
var sources = $('#sourcesms2side__dx').text();
467-
var purposes = $('#purposesms2side__dx').text();
468-
var terms = $('#termsms2side__dx').text();
469474

470475
$('#year_from > span').text(year_from);
471476
$('#year_to > span').text(year_to);
@@ -477,6 +482,30 @@ $(document).ready(function(){
477482
$('#genus_all_id').val();
478483
};
479484

485+
function setEuDisclaimerVisibility () {
486+
['imp', 'exp'].forEach(function (type) {
487+
const disclaimerEl = $('#eu_disclaimer_' + type)
488+
489+
if (disclaimerEl.length) {
490+
hasEuDisclaimer(type) ? disclaimerEl.show() : disclaimerEl.hide()
491+
}
492+
})
493+
}
494+
495+
function hasEuDisclaimer (type) {
496+
const selections = $('#'+ type + 'cty').val()
497+
498+
if (!selections) {
499+
return false
500+
}
501+
502+
return isEuInArray(selections)
503+
}
504+
505+
function isEuInArray (array) {
506+
return array.indexOf(euId) >= 0
507+
}
508+
480509
$('#side .ui-button, #form .ui-button').hover(function() {
481510
$(this).toggleClass('ui-state-hover');
482511
});
@@ -510,18 +539,6 @@ $(document).ready(function(){
510539
return taxonDisplayName.replace(new RegExp("(" + term + '|' + termWithHyphens+ ")", "gi"), transform);
511540
}
512541

513-
function parseTaxonData (data, term, showSpp) {
514-
var d = data.auto_complete_taxon_concepts;
515-
return _.map(d, function (element, index) {
516-
var displayName = getTaxonDisplayName(element, showSpp)
517-
return {
518-
'value': element.id,
519-
'label': displayName,
520-
'drop_label': getTaxonLabel(displayName, term)
521-
};
522-
});
523-
}
524-
525542
function parseTaxonCascadeData(data, term, showSpp) {
526543
var d = data.auto_complete_taxon_concepts;
527544
var data_by_rank = [];
@@ -611,14 +628,32 @@ $(document).ready(function(){
611628
}
612629

613630
show_values_selection();
631+
setEuDisclaimerVisibility();
632+
633+
$('#qryFrom, #qryTo').on('change', function(e) {
634+
year_range = handleYearRangeChange(e.target.id)
614635

615-
$('#qryFrom, #qryTo').on('change',function() {
616-
var y_from = $('#qryFrom').val();
617-
var y_to = $('#qryTo').val();
618-
$('#year_from > span').text(y_from);
619-
$('#year_to > span').text(y_to);
636+
$('#year_from > span').text(year_range[0])
637+
$('#year_to > span').text(year_range[1])
620638
});
621639

640+
function handleYearRangeChange (id) {
641+
var y_from = $('#qryFrom').val()
642+
var y_to = $('#qryTo').val()
643+
644+
if (y_from > y_to) {
645+
if (id === 'qryFrom') {
646+
y_to = y_from
647+
$('#qryTo').val(y_to)
648+
} else {
649+
y_from = y_to
650+
$('#qryFrom').val(y_from)
651+
}
652+
}
653+
654+
return [y_from, y_to]
655+
}
656+
622657
//Put functions to be executed here
623658
initialiseControls();
624659

app/assets/javascripts/species/controllers/taxon_concept_controller.js.coffee

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
7373
else
7474
""
7575
).property('citesSuspensions')
76+
anyHistoricCitesProcesses: ( ->
77+
if @get('citesProcesses') != undefined && @get('citesProcesses')
78+
.findProperty('status', 'Closed') != undefined
79+
"show_more"
80+
else
81+
""
82+
).property('citesProcesses')
7683
anyHistoricEuDecisions: ( ->
7784
if @get('euDecisions') != undefined && @get('euDecisions')
7885
.findProperty('is_current', false) != undefined
@@ -135,6 +142,19 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
135142
else
136143
null
137144
).property('citesSuspensions')
145+
currentCitesProcesses: (->
146+
if @get('citesProcesses') != undefined
147+
@get('citesProcesses').filter (item) ->
148+
return item.status != 'Closed'
149+
else
150+
null
151+
).property('citesProcesses')
152+
historicCitesProcesses: (->
153+
if @get('citesProcesses') != undefined
154+
@get('citesProcesses').filterProperty('status', 'Closed')
155+
else
156+
null
157+
).property('citesProcesses')
138158
currentEuListings: (->
139159
if @get('euListings') != undefined
140160
@get('euListings').filterProperty('is_current', true)
@@ -185,6 +205,12 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
185205
else
186206
return yes
187207
).property('citesSuspensions')
208+
citesProcessesIsLoading: ( ->
209+
if @get('citesProcesses') != undefined
210+
return no
211+
else
212+
return yes
213+
).property('citesProcesses')
188214

189215
contentObserver: ( ->
190216
matchedOnSelf = true
@@ -235,4 +261,4 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
235261

236262
actions:
237263
openSearchPage: (taxonFullName) ->
238-
@get("controllers.search").openSearchPage taxonFullName
264+
@get("controllers.search").openSearchPage taxonFullName

app/assets/javascripts/species/helpers/handlebars_helpers.js.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,7 @@ Ember.Handlebars.helper 'truncate', (text, options) ->
6262
if text.length > limit
6363
text = text.substr(0, limit - 3) + "..."
6464
return text
65+
66+
Ember.Handlebars.registerHelper 'ifEquals', (arg1, arg2, options) ->
67+
arg1 = Ember.Handlebars.get(this, arg1, options)
68+
if (arg1 == arg2) then options.fn(this) else options.inverse(this)

app/assets/javascripts/species/models/taxon_concept.js.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Species.TaxonConcept = DS.Model.extend
2020
citesQuotas: DS.attr("array")
2121
citesSuspensions: DS.attr("array")
2222
citesListings: DS.attr("array")
23+
citesProcesses: DS.attr("array")
2324
cmsListings: DS.attr("array")
2425
cmsInstruments: DS.attr("array")
2526
euListings: DS.attr("array")

0 commit comments

Comments
 (0)