Skip to content

Commit af0d3ba

Browse files
authored
Merge pull request #139 from caseyhofford/master
Various Fixes and Changes
2 parents 5be7cc7 + 2097fb4 commit af0d3ba

File tree

18 files changed

+112
-1395
lines changed

18 files changed

+112
-1395
lines changed

app/assets/javascripts/calculator.js

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -35,106 +35,6 @@ var options = {
3535
var experiment = new Experiment("untitled", [], options);
3636
var included_ecosystems = experiment.ecosystems;
3737

38-
var ecosystems,
39-
user_ecosystems;
40-
41-
$.ajax({
42-
type: "GET",
43-
url: "data/default_ecosystems.json",
44-
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
45-
success: function(response) {
46-
user_ecosystems = response;
47-
ecosystems = response;
48-
}
49-
});
50-
51-
var variable_db;
52-
53-
$.ajax({
54-
type: "GET",
55-
url: "data/variable_db.json",
56-
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
57-
success: function(response) {
58-
variable_db = response;
59-
}
60-
});
61-
62-
var descriptions;
63-
64-
$.ajax({
65-
type: "GET",
66-
url: "/data/descriptions.json",
67-
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
68-
success: function(response) {
69-
descriptions = response;
70-
}
71-
});
72-
73-
var sources;
74-
75-
$.ajax({
76-
type: "GET",
77-
url: "/data/sources.json",
78-
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
79-
success: function(response) {
80-
sources = response;
81-
}
82-
});
83-
84-
85-
var addhtml, addjs, edithtml, editjs;
86-
87-
var CONTENT;
88-
89-
//$.ajax({
90-
// type: "GET",
91-
// url: "loadContent.php",
92-
// contentType: "application/x-www-form-urlencoded; charset=UTF-8",
93-
// success: function(response) {
94-
// CONTENT = response;
95-
// }
96-
//});
97-
98-
/*$.ajax({
99-
type: "GET",
100-
url: "content/add_ecosystem/add_ecosystem.html",
101-
success: function(response) {
102-
addhtml = response;
103-
}
104-
});
105-
106-
$.ajax({
107-
type: "GET",
108-
url: "content/add_ecosystem/add_ecosystem.js",
109-
success: function(response) {
110-
addjs = response;
111-
}
112-
});
113-
114-
$.ajax({
115-
type: "GET",
116-
url: "content/edit_ecosystem/edit_ecosystem.html",
117-
success: function(response) {
118-
edithtml = response;
119-
}
120-
});
121-
122-
$.ajax({
123-
type: "GET",
124-
url: "content/edit_ecosystem/edit_ecosystem.js",
125-
success: function(response) {
126-
editjs = response;
127-
}
128-
});*/
129-
130-
//ddsmoothmenu.init({
131-
// mainmenuid: "mainmenu",
132-
// orientation: 'h',
133-
// classname: "ddsmoothmenu",
134-
// customtheme: ["#007700", "#003300"],
135-
// contentsource: "markup"
136-
//})
137-
13838
function showPopup(contentName) {
13939
var popup = $("#popup_div");
14040
var disable = $("#disable_div");
@@ -147,17 +47,6 @@ function showPopup(contentName) {
14747
eval(CONTENT[contentName].js);
14848
centerPopup();
14949
popup.show();
150-
151-
/*$.ajax({
152-
type: "GET",
153-
url: contentURL,
154-
success: function(content) {
155-
popup.html(content);
156-
popup.append('<script type="text/javascript" src="' + scriptURL + '"></script>');
157-
popup.append('<script type="text/javascript">centerPopup();</script>');
158-
popup.show();
159-
}
160-
});*/
16150
}
16251

16352
function centerPopup() {

app/assets/javascripts/workflows.js

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,31 @@ function remove_google_maps_pin( biome_site_id ) {
1616
//
1717
// TODO: Replace this with an actual JS library that handles quotes, commas,
1818
// etc. Shouldn't need to hand-roll this
19+
20+
1921
function convert_to_csv(json_data) {
20-
columns = Object.keys(json_data['site_1_data']['Grass']);
2122
json2csvParser = json2csv.Parser;
22-
parser = new json2csvParser(columns, flatten=true);
2323
flat_data = [];
2424
for (site in json_data) {
2525
for (ecosystem in json_data[site]) {
26-
flat_data.push(json_data[site][ecosystem]);
26+
cleaned = json_data[site][ecosystem]
27+
for(field in cleaned){
28+
cleaned[field] = json_data[site][ecosystem][field].join(", ")
29+
}
30+
flat_data.push(cleaned);
2731
}
2832
}
33+
columns= flat_data.reduce(function (x, y) {
34+
keys = Object.keys(y)
35+
for(columns in keys){
36+
if(x.indexOf(keys[columns]) === -1){
37+
x.push(keys[columns])
38+
}
39+
}
40+
return x
41+
},[])
42+
43+
parser = new json2csvParser(columns, flatten=true);
2944
str = parser.parse(flat_data)
3045
var element = document.createElement('a');
3146
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(str));
@@ -137,36 +152,33 @@ function populate_html_from_latlng( lat, lng ) {
137152

138153
// Tag the site w the given lat and lng
139154
$('div.well:not(.inactive_site)').find('.site_latlng').text("( "+ lat.toFixed(2) + ", " + lng.toFixed(2) + " )");
140-
141-
if ( data.native_eco != null ) {
142-
$.each( data.native_eco, function(k,v) {
143-
$('div.well:not(.inactive_site)').find('.native_biomes').find('.biome_list').append(
144-
'<div class="biome_match checkbox">' +
145-
'<label class="biome-match"><input type="checkbox">' + k.replace(/_/g," ") + '</input></label>' +
146-
'<a class="edit_icon_link action-link" data-toggle="modal" data-target="#ecosystem_popup" href="#ecosystem_popup">' +
147-
'<i class="glyphicon glyphicon-list-alt" rel="tooltip" title="Edit"></i>' +
148-
'</a>' +
149-
'<a class="biome_pdf_link action-link"href="' +
150-
'/ecosystem_fact_sheets/' + v.code + '.pdf' + //pdf file name
151-
'" download><img class="download-pdf-icon" src="/assets/pdf_24x24.png"></a>' +
152-
'</div>'
155+
function biome_div(type) {
156+
return function make_element(k,v) {
157+
element = '<div class="biome_match checkbox">' +
158+
'<label class="biome-match"><input type="checkbox">' + k.replace(/_/g," ") + '</input></label>'
159+
if(v['in_synmap'][0]){
160+
element = element.concat('<span class="synmap-flag" style="color: red; font-size: 20px;">*</span>')
161+
$('#synmap-key').css("display","inline")
162+
}
163+
element = element.concat(
164+
'<a class="edit_icon_link action-link" data-toggle="modal" data-target="#ecosystem_popup" href="#ecosystem_popup">' +
165+
'<i class="glyphicon glyphicon-list-alt" rel="tooltip" title="Edit"></i>' +
166+
'</a>' +
167+
'<a class="biome_pdf_link action-link"href="' +
168+
'/ecosystem_fact_sheets/' + v.code + '.pdf' + //pdf file name
169+
'" download><img class="download-pdf-icon" src="/assets/pdf_24x24.png"></a>' +
170+
'</div>')
171+
$('div.well:not(.inactive_site)').find(type).find('.biome_list').append(
172+
element
153173
).parent().css("height", "auto");
154174
// Could add delegate option here to show / hide the EDIT icon on checking the checkbox
155-
});
175+
};
176+
};
177+
if ( data.native_eco != null ) {
178+
$.each( data.native_eco, biome_div('.native_biomes'));
156179
};
157-
158180
if ( data.agroecosystem_eco != null ) {
159-
$.each( data.agroecosystem_eco, function(k,v) {
160-
$('div.well:not(.inactive_site)').find('.agroecosystem_biomes').find('.biome_list').append(
161-
'<div class="biome_match checkbox">' +
162-
'<label class="biome-match"><input type="checkbox">' + k.replace(/_/g," ") + '</input></label>' +
163-
'<a class="edit_icon_link action-link" data-toggle="modal" href="#ecosystem_popup">' +
164-
'<i class="glyphicon glyphicon-list-alt inline-block" rel="tooltip" title="Edit" />' +
165-
'</a>' +
166-
'</div>'
167-
).parent().css("height", "auto");
168-
// Could add delegate option here to show / hide the EDIT icon on checking the checkbox
169-
});
181+
$.each( data.agroecosystem_eco, biome_div('.agroecosystem_biomes'));
170182
};
171183
});
172184
};
@@ -448,7 +460,7 @@ $(document).ready(function() {
448460
var biome_group = $(this);
449461
var ecosystem_to_include = get_selected_ecosystems_name_and_type( $(this) );
450462
var current_biomes_json = $.parseJSON( biome_group.find('.json_saved').text() );
451-
console.log("current_biomes_json: " + JSON.stringify(current_biomes_json));
463+
//console.log("current_biomes_json: " + JSON.stringify(current_biomes_json));
452464

453465
var loc = biome_group.find(".biome_site_header .site_latlng").text();
454466
var lat_lng_matcher = /\( *([\d\.-]+) *, *([\d\.-]+) *\)/;
@@ -467,7 +479,7 @@ $(document).ready(function() {
467479

468480
$.each( ecosystem_to_include, function(i,v) {
469481
var input_ecosystem_json = current_biomes_json[v[0] + "_eco"][v[1].replace(/ /g,"_")];
470-
console.log( input_ecosystem_json );
482+
//console.log( input_ecosystem_json );
471483
var biome_name_string = v[1].replace(/ /g,"_")
472484

473485
ghgvcR_input[biome_group_string]["ecosystems"][biome_name_string] = input_ecosystem_json;
@@ -513,12 +525,12 @@ $(document).ready(function() {
513525
mi_svg = mi_svg.replace(re, "glyph-mi")
514526
co2_svg = atob(data.plots.co2[0]);
515527
mi_svg = mi_svg.replace(re, "glyph-co2")
516-
528+
517529

518530
// Place SVGs on the map
519531
$("#mi_container").html(mi_svg);
520532
$("#co2_container").html(co2_svg);
521-
533+
522534
// make the returned data available so it can be exported to a csv
523535
window.json_data = data.results;
524536
// Add the message about the black dots
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
class ApplicationController < ActionController::Base
2+
console
23
protect_from_forgery
34
end

app/controllers/workflows_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def new
5252
# object returned is an array of hashes... Ex:
5353
# p @ecosystems[0] # will return a Hash
5454
# p @ecosystems[0]["category"] # => "native"
55-
@ecosystems = JSON.parse( File.open( "#{Rails.root}/public/data/default_ecosystems.json" , "r" ).read )
56-
@name_indexed_ecosystems = JSON.parse( File.open( "#{Rails.root}/public/data/name_indexed_ecosystems.json" , "r" ).read )
57-
@ecosystem = @ecosystems[0]
55+
#@ecosystems = JSON.parse( File.open( "#{Rails.root}/public/data/default_ecosystems.json" , "r" ).read )
56+
#@name_indexed_ecosystems = JSON.parse( File.open( "#{Rails.root}/public/data/name_indexed_ecosystems.json" , "r" ).read )
57+
#@ecosystem = @ecosystems[0]
5858

5959
respond_to do |format|
6060
format.html

0 commit comments

Comments
 (0)