Skip to content

Commit

Permalink
Merge pull request #31 from Vizzuality/release/v1.0.1
Browse files Browse the repository at this point in the history
Release/v1.0.1
  • Loading branch information
simaob committed Aug 23, 2016
2 parents ef3d967 + f263aec commit 007dfa0
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 42 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/editor/MapOverlays/MapElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
'<p>Plain text, comma separated values</p>' +
'<a onclick="downloadGeoCAT(\'csv\');changeApplicationTo()" class="export">Download CSV</a>' +
'</div>' +
'<div class="block last">' +
'<div class="block">' +
'<p>Structured XML file for geographic data</p>' +
'<a onclick="downloadGeoCAT(\'kml\');changeApplicationTo()" class="export">Download KML</a>' +
'</div>' +
'<div class="block last">' +
'<p>IUCN Red List CSV file</p>' +
'<a onclick="downloadGeoCAT(\'sis\');changeApplicationTo()" class="export">Download SIS</a>' +
'</div>' +
'</div>' +
'</div>' +

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@
coordinateUncertaintyInMeters: '',
identifiedBy: '',
occurrenceRemarks: '',
occurrenceDetails: ''
occurrenceDetails: '',
data_sens: '',
sens_comm: '',
compiler: '',
yrcompiled: ''

}

});
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor/Modals/species_selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,4 @@
this.$el.remove();
}

});
});
13 changes: 9 additions & 4 deletions app/assets/javascripts/editor/Models/GeoCATOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
/*========================================================================================================================*/
GeoCAT.prototype.download = function(format) {
// VIEWPORT
if (report_name === undefined || report_name === "") {
report_name = "Untitled Analysis";
}
var report = {
reportName: unescape(report_name = (report_name === 'Untitled report') ? 'Analysis ' + $($('.group_combo .select2-chosen')[0]).text() : report_name),
reportName: unescape(report_name),
viewPort: {
zoom: this.zoom,
center: {
Expand Down Expand Up @@ -118,23 +121,25 @@
var sources = [];

_.each(markers, function(m) {

var group = groups.get(m.data.dcid);
var occ_data = _.clone(m.data);
occ_data.group_name = group.get('name');

_.each(non_valid, function(v) {
delete occ_data[v];
});

var s = _.find(sources, function(s) {
return s.group === group.get('name');
return s.scid === m.data.scid;
});

if (!s) {
var source = group.getSources().get(m.data.scid);
var d = source.toJSON();
d.scid = m.data.scid;
d.points = [ occ_data ];
d.group = group.get('name');
sources.push(d)
sources.push(d);
} else {
s.points.push( occ_data );
}
Expand Down
57 changes: 39 additions & 18 deletions app/assets/javascripts/editor/views/metadata_infowindow.jst.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@

<div class="row">
<div class="field field-1">
<label>SEASONAL</label>
<select id="metadata_seasonal">
<option <% if (unescape(seasonal) === 'Resident') { %>selected<% } %>>Resident</option>
<option <% if (unescape(seasonal) === 'Breeding Season') { %>selected<% } %>>Breeding Season</option>
<option <% if (unescape(seasonal) === 'Non-Breeding season') { %>selected<% } %>>Non-Breeding season</option>
<option <% if (unescape(seasonal) === 'Passage') { %>selected<% } %>>Passage</option>
<option <% if (unescape(seasonal) === 'Seasonal Occurrence Uncertain') { %>selected<% } %>>Seasonal Occurrence Uncertain</option>
<option <% if (unescape(seasonal) === 'N/A') { %>selected<% } %>>N/A</option>
<label>PRESENCE</label>
<select id="metadata_presence">
<option <% if (unescape(presence) === 'Extant') { %>selected<% } %>>Extant</option>
<option <% if (unescape(presence) === 'Possibly Extant') { %>selected<% } %>>Possibly Extant</option>
<option <% if (unescape(presence) === 'Possibly Extinct') { %>selected<% } %>>Possibly Extinct</option>
<option <% if (unescape(presence) === 'Extinct') { %>selected<% } %>>Extinct</option>
<option <% if (unescape(presence) === 'Presence Uncertain') { %>selected<% } %>>Presence Uncertain</option>
<option <% if (unescape(presence) === 'N/A') { %>selected<% } %>>N/A</option>
</select>
</div>
<div class="field field-1">
Expand All @@ -123,22 +123,43 @@
<option <% if (unescape(origin) === 'Introduced') { %>selected<% } %>>Introduced</option>
<option <% if (unescape(origin) === 'Vagrant') { %>selected<% } %>>Vagrant</option>
<option <% if (unescape(origin) === 'Origin Uncertain') { %>selected<% } %>>Origin Uncertain</option>
<option <% if (unescape(origin) === 'Assisted Colonisation') { %>selected<% } %>>Assisted Colonisation</option>
<option <% if (unescape(origin) === 'N/A') { %>selected<% } %>>N/A</option>
</select>
</div>
<div class="field field-1">
<label>PRESENCE</label>
<select id="metadata_presence">
<option <% if (unescape(presence) === 'Extant') { %>selected<% } %>>Extant</option>
<option <% if (unescape(presence) === 'Possibly Extant') { %>selected<% } %>>Possibly Extant</option>
<option <% if (unescape(presence) === 'Possibly Extinct') { %>selected<% } %>>Possibly Extinct</option>
<option <% if (unescape(presence) === 'Extinct') { %>selected<% } %>>Extinct</option>
<option <% if (unescape(presence) === 'Presence Uncertain') { %>selected<% } %>>Presence Uncertain</option>
<option <% if (unescape(presence) === 'N/A') { %>selected<% } %>>N/A</option>
<label>SEASONAL</label>
<select id="metadata_seasonal">
<option <% if (unescape(seasonal) === 'Resident') { %>selected<% } %>>Resident</option>
<option <% if (unescape(seasonal) === 'Breeding Season') { %>selected<% } %>>Breeding Season</option>
<option <% if (unescape(seasonal) === 'Non-Breeding season') { %>selected<% } %>>Non-Breeding season</option>
<option <% if (unescape(seasonal) === 'Passage') { %>selected<% } %>>Passage</option>
<option <% if (unescape(seasonal) === 'Seasonal Occurrence Uncertain') { %>selected<% } %>>Seasonal Occurrence Uncertain</option>
<option <% if (unescape(seasonal) === 'N/A') { %>selected<% } %>>N/A</option>
</select>
</div>
</div>

<div class="row">
<div class="field field-0">
<label>SENSITIVE</label>
<select id="metadata_data_sens">
<option <% if (unescape(data_sens) === 'Yes') { %>selected<% } %>>Yes</option>
<option <% if (unescape(data_sens) === 'No' || unescape(data_sens) == "") { %>selected<% } %>>No</option>
</select>
</div>
<div class="field field-0">
<label>SENSE NOTES</label>
<input type="text" class="text" id="metadata_sens_comm" value='<%= unescape(sens_comm) %>' />
</div>
<div class="field field-0">
<label>COMPILER</label>
<input type="text" class="text" id="metadata_compiler" value='<%= unescape(compiler) %>' />
</div>
<div class="field field-0">
<label class="year_compiled">YEAR COMPILED</label>
<input type="text" class="text" id="metadata_yrcompiled" value='<%= unescape(yrcompiled) %>' />
</div>
</div>
<div class="row">
<div class="field field-3">
<label>NOTES</label>
Expand Down Expand Up @@ -173,4 +194,4 @@

<span class="error"><p></p></span>
</form>
</div>
</div>
4 changes: 2 additions & 2 deletions app/assets/stylesheets/editor/layout.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ div#map_container div.footer div.right a.export:hover {background-position:0 -32


/*EXPORT WINDOW*/
div#export_window {position:absolute!important; display:none; width:320px; height:159px; padding:31px; top:50%!important; left:50%; margin:-110px 0 0 -191px!important; background: rgba(0,0,0, 0.8); z-index:20;
div#export_window {position:absolute!important; display:none; width:470px; height:159px; padding:31px; top:50%!important; left:50%; margin:-110px 0 0 -271px!important; background: rgba(0,0,0, 0.8); z-index:20;
border-radius:10px; -webkit-border-radius: 10px; -moz-border-radius: 10px;}
div#export_window a.close {position:absolute; right:14px; top:14px; padding:5px; font:bold 13px Arial; color:#CCCCCC; text-decoration:none;}
div#export_window h3 {font:bold 21px Arial; color:white; letter-spacing:-1px;}
div#export_window div.blocks {float:left; width:276px; height:73px; margin:25px 0 0 0; padding:15px 20px; background: rgba(0,0,0, 0.5); z-index:10;
div#export_window div.blocks {float:left; width:430px; height:73px; margin:25px 0 0 0; padding:15px 20px; background: rgba(0,0,0, 0.5); z-index:10;
border-radius:10px; -webkit-border-radius: 10px; -moz-border-radius: 10px;}
div#export_window div.block {float:left; width:125px; margin:0 25px 0 0;}
div#export_window div.block.last {margin:0;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
line-height:11px;
}

label.year_compiled {
font-size: 9px;
}

input.text {
position:relative;
padding:0 5px;
Expand Down Expand Up @@ -177,6 +181,12 @@

&:last-child { margin-right:0 }
}
.field-0 {
width: 81px;
margin: 4px 0px 0 0;
input.text { width: 68px; }
.select2-container { width:81px }
}

.field-1 {
width:102px;
Expand Down Expand Up @@ -241,4 +251,4 @@
color:#333333;
}
}
}
}
15 changes: 11 additions & 4 deletions app/controllers/file_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ def download
@localities = all_sources.map{|l| [l['latitude'], l['longitude']]}.uniq.length

render :action => :print
when 'csv'
when 'csv', 'sis'
file_name = filename_escape(@geocat['reportName'])
@geocat = GeocatData.new(@geocat)

send_data @geocat.to_csv,
:type => 'text/csv; charset=iso-8859-1; header=present',
:disposition => "attachment; filename=#{file_name}.csv"
if format.downcase == 'sis'
sending_info = @geocat.to_sis
else
sending_info = @geocat.to_csv
end

send_data sending_info,
:type => 'text/csv; charset=utf-8; header=present',
:filename => "#{file_name}.csv",
:disposition => "attachment"
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gbif_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def search

for i in 0..2
offset = 300 * (i * 1)
response = Typhoeus.get("http://api.gbif.org/v1/occurrence/search?hasCoordinate=true&format=darwin&limit=300&hasGeospatialIssue=false&scientificName=#{q}&offset=#{offset}", headers: { "Accept" => "application/json" })
response = Typhoeus.get("http://api.gbif.org/v1/occurrence/search?hasCoordinate=true&limit=300&hasGeospatialIssue=false&scientificName=#{q}&offset=#{offset}", headers: { "Accept" => "application/json" })
populate(response, q)
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/inaturalist_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def search
"http://www.inaturalist.org/observations.json?q=#{q}" +
"&per_page=500&page=1&has[]=geo&quality_grade=research"
)

open(inaturalist_url) {|f| @list = f.read }
@list = JSON.parse(@list)

Expand All @@ -28,6 +29,7 @@ def search
'locality' => occ['place_guess'],
'catalogNumber' => occ['id'],
'basisOfRecord' => 'HumanObservation',
'eventDate' => occ['observed_on'],
'geocat_active' => true,
'geocat_removed' => false,
'geocat_alias' => CGI.unescape(q),
Expand Down
83 changes: 79 additions & 4 deletions app/models/rlat_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def to_csv
sources.each do |source|
data += source['points'].collect do |point|
{
'recordSource' => point['recordSource'],
'scientificname' => scientificname,
'latitude' => point['latitude'],
'longitude' => point['longitude'],
Expand Down Expand Up @@ -90,6 +89,85 @@ def to_csv
output
end

def to_sis
return '' unless self.valid?
require 'date'
data = []
sources.each do |source|
data += source['points'].collect do |point|
# case point['presence']
# when 'Extant'
# point['presence'] = 1
# when 'Probably Extant'
# point['presence'] = 2
# when 'Possibly Extant'
# point['presence'] = 3
# when 'Possibly Extinct'
# point['presence'] = 4
# when 'Extinct'
# point['presence'] = 5
# when 'Presence Uncertain'
# point['presence'] = 6
# end

# case point['origin']
# when 'Native'
# point['origin'] = 1
# when 'Reintroduced'
# point['origin'] = 2
# when 'Introduced'
# point['origin'] = 3
# when 'Vagrant'
# point['origin'] = 4
# when 'Origin Uncertain'
# point['origin'] = 5
# end

# case point['seasonal']
# when 'Resident'
# point['seasonal'] = 1
# when 'Breeding Season'
# point['seasonal'] = 2
# when 'Non-breeding Season'
# point['seasonal'] = 3
# when 'Passage'
# point['seasonal'] = 4
# when 'Seasonal Occurrence Uncertain'
# point['seasonal'] = 5
# end

{
'CatalogNo' => point['catalogNumber'],
'Dist_comm' => point['occurrenceRemarks'],
'Data_sens' => point['data_sens'],
'Sens_comm' => point['sens_comm'],
'ScientificName' => source['query'],
'Presence' => point['presence'],
'Origin' => point['origin'],
'Seasonal' => point['seasonal'],
'Compiler' => point['compiler'],
'YrCompiled' => point['YrCompiled'] ? point['YrCompiled'] : Date.today.year,
'Dec_Lat' => point['latitude'],
'Dec_Long' => point['longitude'],
'SpatialRef' => 'WGS 84',
'Event_Year' => point['eventDate'],
'Citation' => point['institutionCode'],
'BasisOfRec' => point['basisOfRecord'],
'CollectID' => point['catalogue_id'],
'recordedBy' => point['collector']
}
end
end
columns = data.first.keys.sort

output = FasterCSV.generate do |csv|
csv << columns
data.each do |row|
csv << columns.collect { |column| row[column] }
end
end
output
end
private
def process_as_hash(data)
hash = if data.is_a? Hash
Expand Down Expand Up @@ -135,7 +213,6 @@ def process_as_csv(file)
}]
csv.each do |row|
self.sources.first['points'].push({
'recordSource' => row.respond_to?(:recordsource) ? row.recordsource : 'Added by user',
'latitude' => row.respond_to?(:latitude) ? row.latitude : nil,
'longitude' => row.respond_to?(:longitude) ? row.longitude : nil,
'collector' => row.respond_to?(:collector) ? row.collectioncode : nil,
Expand Down Expand Up @@ -172,7 +249,6 @@ def sources_must_be_valid
sources_warnings = []
if self.sources.present?
self.sources.each do |source|
sources_errors << 'you must provide a source name' if source['points'].select{|p| p['recordSource'].blank?}.present?
source['points'].each do |point|
if point['latitude'].blank? || point['longitude'].blank?
invalid_points.push(point)
Expand All @@ -198,5 +274,4 @@ def sources_must_be_valid
warnings[:sources] = sources_warnings if sources_warnings.present?
errors.add(:sources, sources_errors) if sources_errors.present?
end

end
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ development:
encoding: unicode
database: geocat
pool: 5
username: adrianperez
username: postgres
password:

Loading

0 comments on commit 007dfa0

Please sign in to comment.