Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-1.10.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacug committed Dec 16, 2022
2 parents 11e941a + 2512b99 commit d021023
Show file tree
Hide file tree
Showing 64 changed files with 1,200 additions and 67 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
### 1.10.0

**CITES Trade DB**

* Add EU importer/exporter grouping
* Add disclaimer text beneath the search when EU is selected

**Species +**

* Add CITES Processes(RST, Captive Breeding) to the legal section (temporarily hidden)
* Expand admin interface with CRUD for Captive breeding processes
* Add RST API client and scheduled task (temporarily disabled) to retrieve RST processes
* Add CITES Processes export via the admin interface
* Fix search with diacritics (searching for Turkiye will also return Türkiye)
* Add source_ids to quota and suspension internal API (used in SAT)

### 1.9.0

* Add parameter to taxon concept show API internal endpoint to trimmed response for the mobile app
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ gem 'sidekiq-unique-jobs', '~> 4.0.17'
gem 'redis-rails', '~> 4.0.0'

gem 'whenever', :require => false
gem 'httparty'

gem 'sprockets', '~> 2.12.5' # upgrading to 3 breaks handlebars/tilt
gem 'ember-rails', '~> 0.14.1'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ GEM
http-cookie (1.0.2)
domain_name (~> 0.5)
http_parser.rb (0.5.3)
httparty (0.16.2)
multi_xml (>= 0.5.2)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
immigrant (0.1.4)
Expand Down Expand Up @@ -277,6 +279,7 @@ GEM
mini_portile2 (2.4.0)
minitest (4.7.5)
multi_json (1.15.0)
multi_xml (0.6.0)
nested-hstore (0.0.5)
activerecord
activerecord-postgres-hstore
Expand Down Expand Up @@ -554,6 +557,7 @@ DEPENDENCIES
guard-bundler
guard-livereload
handlebars-source (= 1.0.12)
httparty
immigrant
inherited_resources (~> 1.7.0)
jquery-cookie-rails (~> 1.3.1.1)
Expand Down
143 changes: 89 additions & 54 deletions app/assets/javascripts/cites_trade/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $(document).ready(function(){

var ajaxFail, initExpctyImpcty, initTerms, initSources, initPurposes,
countries = {}, units = {}, terms = {}, purposes = {}, sources = {},
euId = '',
selected_taxa = '',
is_search_page = $('#form_expert').length > 0,
is_download_page = $('#net_gross_options').length > 0,
Expand All @@ -19,14 +20,6 @@ $(document).ready(function(){
$.jGrowl(text);
};

function growlMeSticky(text){
$.jGrowl(text, {sticky: true});
};

function notyNormal(message){
noty({layout: 'topRight', text: message, timeout: 4000});
};

function notySticky(message){
noty({ layout: 'top',
type: 'information',
Expand Down Expand Up @@ -75,17 +68,6 @@ $(document).ready(function(){
$('input,select').keypress(function(event) { return event.keyCode != 13; });
};

function fixTaxonId (arr) {
return _.map(arr, function (obj) {
if (obj.name === 'taxon_concepts_ids[]') {
return {name: 'taxon_concepts_ids[]', value: selected_taxa};
} else {
return obj;
}
});
}


function parseInputs ($inputs) {
var values = {};
$inputs.each(function() {
Expand All @@ -104,6 +86,7 @@ $(document).ready(function(){

function getParamsFromInputs(){
var values = parseInputs($('#form_expert :input'));

return $.param({'filters': values});
}

Expand Down Expand Up @@ -183,6 +166,7 @@ $(document).ready(function(){
$('#reset_search').click(function() {
resetSelects();
show_values_selection();
setEuDisclaimerVisibility();
// Removing the table results on reset
$("#query_results_table").find('thead,tbody').remove();
$('#query_results').find('p.info').text('');
Expand All @@ -202,17 +186,6 @@ $(document).ready(function(){
hoverColor: '#D2EF9A'
});


function getSelectionTextNew(source) {
var values = [];

$('#ms-' + source).find('div.ms-selection ul.ms-list li').each(function() {
values.push($(this).text());
});

return values.join(',')
}

function getSelectionText(source) {
myValues = new Array();
$('#' + source + ' option:selected').each(function(index, value) {
Expand All @@ -231,6 +204,10 @@ $(document).ready(function(){
initCountriesObj = function (data) {
_.each(data.geo_entities, function (country) {
countries[country.id] = country;

if (country.iso_code2 == 'EU') {
euId = country.id.toString()
}
});
unLock('initCountriesObj');
}
Expand All @@ -256,6 +233,35 @@ $(document).ready(function(){
unLock('initSourcesObj');
}

removeCasingAndDiacritics = function (value) {
return value.toString()
.normalize('NFD')
.replace(/[\u0300-\u036F]/g, '')
.toLowerCase()
}

matchWithDiacritics = function (term, text) {
// If there are no search terms, return all of the data
if ($.trim(term) === '') {
return text;
}

// Do not display the item if there is no 'text' property
if (typeof text === 'undefined') {
return null;
}

var searchTerm = removeCasingAndDiacritics(term)
var optionText = removeCasingAndDiacritics(text)

if (optionText.indexOf(searchTerm) > -1) {
return text;
}

// Return `null` if the term should not be displayed
return null;
}

initExpctyImpcty = function (data) {
var args = {
data: data.geo_entities,
Expand All @@ -272,7 +278,8 @@ $(document).ready(function(){
$('#expcty').select2({
width: '75%',
allowClear: false,
closeOnSelect: false
closeOnSelect: false,
matcher: matchWithDiacritics
}).on('change', function(e){
var selection = "";
if (e.val.length == 0) {
Expand All @@ -288,6 +295,7 @@ $(document).ready(function(){
selection = getText(new_array);
}
$('#expcty_out').text(selection);
setEuDisclaimerVisibility();
});

populateSelect(_.extend(args, {
Expand All @@ -298,7 +306,8 @@ $(document).ready(function(){
$('#impcty').select2({
width: '75%',
allowClear: false,
closeOnSelect: false
closeOnSelect: false,
matcher: matchWithDiacritics
}).on('change', function(e){
selection = "";
if (e.val.length == 0) {
Expand All @@ -315,6 +324,7 @@ $(document).ready(function(){
selection = getText(new_array);
}
$('#impcty_out').text(selection);
setEuDisclaimerVisibility();
});
};

Expand Down Expand Up @@ -461,11 +471,6 @@ $(document).ready(function(){
function show_values_selection() {
var year_from = $('#qryFrom').val();
var year_to = $('#qryTo').val();
var exp_cty = $('#expctyms2side__dx').text();
var imp_cty = $('#impctyms2side__dx').text();
var sources = $('#sourcesms2side__dx').text();
var purposes = $('#purposesms2side__dx').text();
var terms = $('#termsms2side__dx').text();

$('#year_from > span').text(year_from);
$('#year_to > span').text(year_to);
Expand All @@ -477,6 +482,30 @@ $(document).ready(function(){
$('#genus_all_id').val();
};

function setEuDisclaimerVisibility () {
['imp', 'exp'].forEach(function (type) {
const disclaimerEl = $('#eu_disclaimer_' + type)

if (disclaimerEl.length) {
hasEuDisclaimer(type) ? disclaimerEl.show() : disclaimerEl.hide()
}
})
}

function hasEuDisclaimer (type) {
const selections = $('#'+ type + 'cty').val()

if (!selections) {
return false
}

return isEuInArray(selections)
}

function isEuInArray (array) {
return array.indexOf(euId) >= 0
}

$('#side .ui-button, #form .ui-button').hover(function() {
$(this).toggleClass('ui-state-hover');
});
Expand Down Expand Up @@ -510,18 +539,6 @@ $(document).ready(function(){
return taxonDisplayName.replace(new RegExp("(" + term + '|' + termWithHyphens+ ")", "gi"), transform);
}

function parseTaxonData (data, term, showSpp) {
var d = data.auto_complete_taxon_concepts;
return _.map(d, function (element, index) {
var displayName = getTaxonDisplayName(element, showSpp)
return {
'value': element.id,
'label': displayName,
'drop_label': getTaxonLabel(displayName, term)
};
});
}

function parseTaxonCascadeData(data, term, showSpp) {
var d = data.auto_complete_taxon_concepts;
var data_by_rank = [];
Expand Down Expand Up @@ -611,14 +628,32 @@ $(document).ready(function(){
}

show_values_selection();
setEuDisclaimerVisibility();

$('#qryFrom, #qryTo').on('change', function(e) {
year_range = handleYearRangeChange(e.target.id)

$('#qryFrom, #qryTo').on('change',function() {
var y_from = $('#qryFrom').val();
var y_to = $('#qryTo').val();
$('#year_from > span').text(y_from);
$('#year_to > span').text(y_to);
$('#year_from > span').text(year_range[0])
$('#year_to > span').text(year_range[1])
});

function handleYearRangeChange (id) {
var y_from = $('#qryFrom').val()
var y_to = $('#qryTo').val()

if (y_from > y_to) {
if (id === 'qryFrom') {
y_to = y_from
$('#qryTo').val(y_to)
} else {
y_from = y_to
$('#qryFrom').val(y_from)
}
}

return [y_from, y_to]
}

//Put functions to be executed here
initialiseControls();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
else
""
).property('citesSuspensions')
anyHistoricCitesProcesses: ( ->
if @get('citesProcesses') != undefined && @get('citesProcesses')
.findProperty('status', 'Closed') != undefined
"show_more"
else
""
).property('citesProcesses')
anyHistoricEuDecisions: ( ->
if @get('euDecisions') != undefined && @get('euDecisions')
.findProperty('is_current', false) != undefined
Expand Down Expand Up @@ -135,6 +142,19 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
else
null
).property('citesSuspensions')
currentCitesProcesses: (->
if @get('citesProcesses') != undefined
@get('citesProcesses').filter (item) ->
return item.status != 'Closed'
else
null
).property('citesProcesses')
historicCitesProcesses: (->
if @get('citesProcesses') != undefined
@get('citesProcesses').filterProperty('status', 'Closed')
else
null
).property('citesProcesses')
currentEuListings: (->
if @get('euListings') != undefined
@get('euListings').filterProperty('is_current', true)
Expand Down Expand Up @@ -185,6 +205,12 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon
else
return yes
).property('citesSuspensions')
citesProcessesIsLoading: ( ->
if @get('citesProcesses') != undefined
return no
else
return yes
).property('citesProcesses')

contentObserver: ( ->
matchedOnSelf = true
Expand Down Expand Up @@ -235,4 +261,4 @@ Species.TaxonConceptController = Ember.ObjectController.extend Species.SearchCon

actions:
openSearchPage: (taxonFullName) ->
@get("controllers.search").openSearchPage taxonFullName
@get("controllers.search").openSearchPage taxonFullName
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ Ember.Handlebars.helper 'truncate', (text, options) ->
if text.length > limit
text = text.substr(0, limit - 3) + "..."
return text

Ember.Handlebars.registerHelper 'ifEquals', (arg1, arg2, options) ->
arg1 = Ember.Handlebars.get(this, arg1, options)
if (arg1 == arg2) then options.fn(this) else options.inverse(this)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Species.TaxonConcept = DS.Model.extend
citesQuotas: DS.attr("array")
citesSuspensions: DS.attr("array")
citesListings: DS.attr("array")
citesProcesses: DS.attr("array")
cmsListings: DS.attr("array")
cmsInstruments: DS.attr("array")
euListings: DS.attr("array")
Expand Down
Loading

0 comments on commit d021023

Please sign in to comment.