diff --git a/.DS_Store b/.DS_Store
index 861ce21..797e7a7 100644
Binary files a/.DS_Store and b/.DS_Store differ
diff --git a/Gemfile b/Gemfile
index b7d7aab..b5edc6e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,10 +1,16 @@
source 'https://rubygems.org'
+group :development, :test do
+ gem 'sqlite3'
+end
+group :production do
+ gem 'pg', '~> 0.18'
+end
+gem 'jquery-rails'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.2'
# Use sqlite3 as the database for Active Record
-gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
@@ -41,7 +47,6 @@ gem 'cancan' # or cancancan
gem 'draper'
gem 'pundit'
-
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
diff --git a/Gemfile.lock b/Gemfile.lock
index 1ef8616..50aa96c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -24,15 +24,15 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
- activeadmin (1.1.0)
+ activeadmin (1.3.0)
arbre (>= 1.1.1)
coffee-rails
formtastic (~> 3.1)
formtastic_i18n
- inherited_resources (~> 1.7)
- jquery-rails
- kaminari (>= 0.15, < 2.0)
- railties (>= 4.2, < 5.2)
+ inherited_resources (>= 1.7.0)
+ jquery-rails (>= 4.2.0)
+ kaminari (>= 0.15)
+ railties (>= 4.2, < 5.3)
ransack (~> 1.3)
sass (~> 3.1)
sprockets (< 4.1)
@@ -58,10 +58,11 @@ GEM
activesupport (>= 3.0.0)
arel (7.1.4)
bcrypt (3.1.11)
- binding_of_caller (0.7.2)
+ bcrypt (3.1.11-x86-mingw32)
+ binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
builder (3.2.3)
- byebug (9.1.0)
+ byebug (10.0.2)
cancan (1.6.10)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
@@ -71,12 +72,12 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.0.5)
- crass (1.0.2)
+ crass (1.0.4)
debug_inspector (0.0.3)
- devise (4.3.0)
+ devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
- railties (>= 4.1.0, < 5.2)
+ railties (>= 4.1.0, < 6.0)
responders
warden (~> 1.2.3)
draper (3.0.1)
@@ -87,7 +88,8 @@ GEM
request_store (~> 1.0)
erubis (2.7.0)
execjs (2.7.0)
- ffi (1.9.18)
+ ffi (1.9.23)
+ ffi (1.9.23-x86-mingw32)
formtastic (3.1.5)
actionpack (>= 3.2.13)
formtastic_i18n (0.6.0)
@@ -96,20 +98,20 @@ GEM
haml (5.0.4)
temple (>= 0.8.0)
tilt
- has_scope (0.7.1)
- actionpack (>= 4.1, < 5.2)
- activesupport (>= 4.1, < 5.2)
- i18n (0.9.1)
+ has_scope (0.7.2)
+ actionpack (>= 4.1)
+ activesupport (>= 4.1)
+ i18n (0.9.5)
concurrent-ruby (~> 1.0)
- inherited_resources (1.7.2)
- actionpack (>= 3.2, < 5.2.x)
+ inherited_resources (1.8.0)
+ actionpack (>= 4.2, <= 5.2)
has_scope (~> 0.6)
- railties (>= 3.2, < 5.2.x)
+ railties (>= 4.2, <= 5.2)
responders
jbuilder (2.7.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
- jquery-rails (4.3.1)
+ jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
@@ -126,25 +128,28 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
- loofah (2.1.1)
+ loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mini_mime (>= 0.1.1)
method_source (0.9.0)
- mini_mime (0.1.4)
+ mini_mime (1.0.0)
mini_portile2 (2.3.0)
- minitest (5.10.3)
- multi_json (1.12.1)
- nio4r (2.1.0)
- nokogiri (1.8.1)
+ minitest (5.11.3)
+ multi_json (1.13.1)
+ nio4r (2.3.0)
+ nokogiri (1.8.2)
+ mini_portile2 (~> 2.3.0)
+ nokogiri (1.8.2-x86-mingw32)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
- polyamorous (1.3.1)
+ pg (0.21.0)
+ polyamorous (1.3.3)
activerecord (>= 3.0)
pundit (1.1.0)
activesupport (>= 3.0.0)
- rack (2.0.3)
+ rack (2.0.5)
rack-cors (0.3.1)
rack-test (0.6.3)
rack (>= 1.0)
@@ -163,35 +168,36 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
- rails-html-sanitizer (1.0.3)
- loofah (~> 2.0)
+ rails-html-sanitizer (1.0.4)
+ loofah (~> 2.2, >= 2.2.2)
railties (5.0.2)
actionpack (= 5.0.2)
activesupport (= 5.0.2)
method_source
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
- rake (12.2.1)
- ransack (1.8.4)
+ rake (12.3.1)
+ ransack (1.8.8)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
i18n
- polyamorous (~> 1.3)
- rb-fsevent (0.10.2)
+ polyamorous (~> 1.3.2)
+ rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
rdoc (4.3.0)
- request_store (1.3.2)
+ request_store (1.4.1)
+ rack (>= 1.4)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
- sass (3.5.1)
+ sass (3.5.6)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
- sass-rails (5.0.6)
+ sass-rails (5.0.7)
railties (>= 4.0.0, < 6)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
@@ -200,9 +206,9 @@ GEM
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
- simple_form (3.5.0)
- actionpack (> 4, < 5.2)
- activemodel (> 4, < 5.2)
+ simple_form (4.0.0)
+ actionpack (> 4)
+ activemodel (> 4)
spring (2.0.2)
activesupport (>= 4.2)
sprockets (3.7.1)
@@ -213,16 +219,17 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
+ sqlite3 (1.3.13-x86-mingw32)
temple (0.8.0)
thor (0.20.0)
thread_safe (0.3.6)
tilt (2.0.8)
- turbolinks (5.0.1)
- turbolinks-source (~> 5)
- turbolinks-source (5.0.3)
- tzinfo (1.2.4)
+ turbolinks (5.1.1)
+ turbolinks-source (~> 5.1)
+ turbolinks-source (5.1.0)
+ tzinfo (1.2.5)
thread_safe (~> 0.1)
- uglifier (3.2.0)
+ uglifier (4.1.10)
execjs (>= 0.3.0, < 3)
warden (1.2.7)
rack (>= 1.0)
@@ -233,10 +240,11 @@ GEM
sprockets-rails (>= 2.0, < 4.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
- websocket-extensions (0.1.2)
+ websocket-extensions (0.1.3)
PLATFORMS
ruby
+ x86-mingw32
DEPENDENCIES
activeadmin
@@ -248,6 +256,7 @@ DEPENDENCIES
haml
jbuilder (~> 2.0)
jquery-rails
+ pg (~> 0.18)
pundit
rack-cors (~> 0.3.1)
rails (= 5.0.2)
@@ -261,4 +270,4 @@ DEPENDENCIES
web-console (~> 2.0)
BUNDLED WITH
- 1.16.0
+ 1.16.1
diff --git a/README.md b/README.md
index 792b0dd..820cdaf 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,54 @@
# LFC_Features
+### Local Food Connection Application
+LFC is a Grinnell farm directory service. It contains basic information of farms that are connected to Local Food Connection Organization. The goal of the app is to allow user to easily search for Grinnell's sustainable food system.
+
+You can obtain the source with the following command:
+```shell
+git clone https://github.com/CSC322-Grinnell/LFC_Features.git
+```
+
+## Authors and Contributors
+
+### Current Builds
+
+- [Sara Marku](https://github.com/saramarku)
+- [Linh Pham](https://github.com/linhpha)
+- [Pratik Karki](https://github.com/karkipra)
+- [Elise Brod](https://github.com/brodelis)
+- [James Msekela]()
+
+### Previous Builds
+
+- Matt Murphy
+- Thu Nguyen
+- Minh Tran
+- Alexandar Hrusanov
+- Nick Roberson
+
+
+### Project Structure
+
+
+### How to build
+
+
+
+### Things to do
+
+
+## License
+```
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+```
diff --git a/app/admin/farm.rb b/app/admin/farm.rb
index d7dfc50..a0cce77 100644
--- a/app/admin/farm.rb
+++ b/app/admin/farm.rb
@@ -1,17 +1,4 @@
ActiveAdmin.register Farm do
- # See permitted parameters documentation:
- # https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
- #
- # permit_params :list, :of, :attributes, :on, :model
- #
- # or
- #
- # permit_params do
- # permitted = [:permitted, :attributes]
- # permitted << :other if params[:action] == 'create' && current_user.admin?
- # permitted
- # end
-
controller do
before_filter :authorize_index, only: :index
def authorize_index
@@ -26,13 +13,9 @@ def authorize_index
end
# scope_to :current_farm, unless: proc{ :current_farm }
-
- permit_params do
- permitted = [:name, :address, :phone, :email, :url, :facebook, :instagram,
- :password, :password_confirmation, :twitter]
- permitted << :approved if current_farm.admin?
- permitted
- end
+ ## Add strong parameters for admin to be able to edit these fields
+ permit_params :name, :address, :phone, :email, :url, :facebook, :instagram, :password, :password_confirmation, :primary_operation, :growth_promoter, :antibiotic, :why_farm, :fav_activity, :twitter, :approved,
+ operation_ids: [], selling_method_ids: [], growing_method_ids: [], market_ids: []
index do
selectable_column
@@ -69,15 +52,13 @@ def authorize_index
f.input :twitter
f.input :other_media
- @ops = ['Fruit', 'Vegetables', 'Dairy', 'Pork', 'Chicken', 'Turkey', 'Lamb', 'Duck', 'Agitourism', 'Hay', 'Row Crop']
- @grow = ['Certified Natural Grown', 'USDA Certified Organic', '100% Grass Fed', 'Grass Finished', 'Non-GMO', 'Regenerative Organic Certified', 'Integrated Pest Management', 'Pasture Raised', 'Corn Fed', 'Conventional']
- @sell = ['CSA', 'Farmers Market', 'Wholesale', 'Grocery Stores', 'Grinnell Area Local Food Source', 'On-Farm', 'Iowa Food Coop', 'Institutions', 'Restaurants']
- @market = ['Grinnell-Thursday', 'Grinnell-Saturday', "Des Moines Downtown-Saturday", "Cedar Rapids Downtown-Select Saturdays", "Iowa City-Saturday", "Tama-Toledo", "Brooklyn"]
- f.input :operations, as: :check_boxes, collection: @ops
- f.input :growing_methods, as: :check_boxes, collection: @grow
+
+ f.input :operations, as: :check_boxes, collection: Operation.all
+ f.input :primary_operation, as: :check_boxes, collection: PrimaryOperation.all
+ f.input :growing_methods, as: :check_boxes, collection: GrowingMethod.all
f.input :link_to_cert
- f.input :selling_methods, as: :check_boxes, collection: @sell
- f.input :markets, as: :check_boxes, collection: @market
+ f.input :selling_methods, as: :check_boxes, collection: SellingMethod.all
+ f.input :markets, as: :check_boxes, collection: Market.all
f.input :growth_promoter, as: :boolean, checked_value: true, unchecked_value: false
f.input :antibiotic, as: :boolean, checked_value: true, unchecked_value: false
diff --git a/app/assets/icons/24apple.png b/app/assets/icons/24apple.png
new file mode 100644
index 0000000..a4b7099
Binary files /dev/null and b/app/assets/icons/24apple.png differ
diff --git a/app/assets/icons/24broccoli.png b/app/assets/icons/24broccoli.png
new file mode 100644
index 0000000..cb057ef
Binary files /dev/null and b/app/assets/icons/24broccoli.png differ
diff --git a/app/assets/icons/24chicken.png b/app/assets/icons/24chicken.png
new file mode 100644
index 0000000..d462e90
Binary files /dev/null and b/app/assets/icons/24chicken.png differ
diff --git a/app/assets/icons/24cow.png b/app/assets/icons/24cow.png
new file mode 100644
index 0000000..f13173f
Binary files /dev/null and b/app/assets/icons/24cow.png differ
diff --git a/app/assets/icons/24dairy.png b/app/assets/icons/24dairy.png
new file mode 100644
index 0000000..6927072
Binary files /dev/null and b/app/assets/icons/24dairy.png differ
diff --git a/app/assets/icons/24pig.png b/app/assets/icons/24pig.png
new file mode 100644
index 0000000..7c81a0e
Binary files /dev/null and b/app/assets/icons/24pig.png differ
diff --git a/app/assets/icons/24sheep.png b/app/assets/icons/24sheep.png
new file mode 100644
index 0000000..1bdce28
Binary files /dev/null and b/app/assets/icons/24sheep.png differ
diff --git a/app/assets/icons/64cow.png b/app/assets/icons/64cow.png
new file mode 100644
index 0000000..c448c32
Binary files /dev/null and b/app/assets/icons/64cow.png differ
diff --git a/app/assets/icons/agricultural.png b/app/assets/icons/agricultural.png
new file mode 100644
index 0000000..a151cff
Binary files /dev/null and b/app/assets/icons/agricultural.png differ
diff --git a/app/assets/icons/carrot.png b/app/assets/icons/carrot.png
new file mode 100644
index 0000000..6b1b1d2
Binary files /dev/null and b/app/assets/icons/carrot.png differ
diff --git a/app/assets/icons/dairy_free.png b/app/assets/icons/dairy_free.png
new file mode 100644
index 0000000..43c9bde
Binary files /dev/null and b/app/assets/icons/dairy_free.png differ
diff --git a/app/assets/icons/farm2.jpg b/app/assets/icons/farm2.jpg
new file mode 100644
index 0000000..c5f19f2
Binary files /dev/null and b/app/assets/icons/farm2.jpg differ
diff --git a/app/assets/icons/gluten_free.png b/app/assets/icons/gluten_free.png
new file mode 100644
index 0000000..558d955
Binary files /dev/null and b/app/assets/icons/gluten_free.png differ
diff --git a/app/assets/icons/kosher.png b/app/assets/icons/kosher.png
new file mode 100644
index 0000000..30b07b7
Binary files /dev/null and b/app/assets/icons/kosher.png differ
diff --git a/app/assets/icons/peanut_free.jpg b/app/assets/icons/peanut_free.jpg
new file mode 100644
index 0000000..ca38b82
Binary files /dev/null and b/app/assets/icons/peanut_free.jpg differ
diff --git a/app/assets/icons/steak-512.png b/app/assets/icons/steak-512.png
new file mode 100644
index 0000000..c5182d0
Binary files /dev/null and b/app/assets/icons/steak-512.png differ
diff --git a/app/assets/icons/tree_nut_free.jpg b/app/assets/icons/tree_nut_free.jpg
new file mode 100644
index 0000000..5eda7af
Binary files /dev/null and b/app/assets/icons/tree_nut_free.jpg differ
diff --git a/app/assets/icons/vegetarian.jpg b/app/assets/icons/vegetarian.jpg
new file mode 100644
index 0000000..e78c81c
Binary files /dev/null and b/app/assets/icons/vegetarian.jpg differ
diff --git a/app/assets/images/logo.png b/app/assets/images/logo.png
new file mode 100644
index 0000000..640bc00
Binary files /dev/null and b/app/assets/images/logo.png differ
diff --git a/app/assets/javascripts/active_admin.js.coffee b/app/assets/javascripts/active_admin.js.coffee
new file mode 100644
index 0000000..3752dce
--- /dev/null
+++ b/app/assets/javascripts/active_admin.js.coffee
@@ -0,0 +1 @@
+#= require active_admin/base
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index e07c5a8..a8670ea 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -1,16 +1,631 @@
-// This is a manifest file that'll be compiled into application.js, which will include all the files
-// listed below.
-//
-// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
-// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
-//
-// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
-// compiled file.
-//
-// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
-// about supported directives.
-//
+// To enable jquery for rails
//= require jquery
-//= require jquery_ujs
-//= require turbolinks
-//= require_tree .
+var map;
+var geocoder;
+var farms = {};
+var recipes = {};
+/***********
+ * API_KEYS *
+ ***********/
+var edemam_app_id = "0649d198";
+var edemam_app_key = "77bd12dd099e7f2c02338006ef659724";
+var lfc_key = "YAS0sY2rbi";
+$(document).ready(function() {
+ $(".dropdown-menu li a").click(function() {
+ $("#category_button").text($(this).text());
+ });
+});
+/********
+ * INIT *
+ ********/
+$(window).load(function() {
+ init();
+});
+/**
+Set up on_click for search farm and search recipe
+**/
+function init() {
+ // set up recipe search
+ document.getElementById("search_recipes").onclick = function() {
+ // Get checked values for dietary choises
+ var checkedDietaryOptionsList = [];
+ $('input[name=recipeCheckboxList]:checked').each(function() {
+ checkedDietaryOptionsList.push($(this).val());
+ });
+ var text = $('#recipe_search_text').val();
+ text = text.split(' ').join('%20')
+ if (text != "") {
+ callFood2Fork(text, checkedDietaryOptionsList);
+ }
+ };
+ // set up farm search
+ document.getElementById("search_farm").onclick = function() {
+ // Delete old markers on map
+ DeleteMarkers();
+ // Get checked values for operations
+ var checkedOperations = [];
+ $('input[name=checkboxList]:checked').each(function() {
+ if ($(this).val() == "meat")
+ checkedOperations.push("lamb", "beef", "chicken", "pork");
+ else if ($(this).val() == "agritourism")
+ checkedOperations.push("agritourism", "hay", "row crop");
+ else
+ checkedOperations.push($(this).val());
+ });
+ // Get farm by filtered operation
+ callIndexApi2(checkedOperations);
+ // Get searech option
+ var text = $('#search_farm_text').val();
+ var search_by = $('#category_button').text();
+ // Search by Address
+ if (search_by == "Address") {
+ // Set up map positions
+ if (text != "") {
+ geocoder.geocode({
+ 'address': text
+ }, function(results, status) {
+ if (status == 'OK') {
+ map.setCenter(results[0].geometry.location);
+ map.setZoom(17);
+ //map.panTo(curmarker.position);
+ var marker = new google.maps.Marker({
+ map: map,
+ position: results[0].geometry.location
+ });
+ } else {
+ alert('Geocode was not successful for the following reason: ' + status);
+ }
+ });
+
+ }
+ // Search by Farm's Name
+ } else if (search_by == "Farm's Name") {
+ var farms = [];
+ var call_url = "/farms/farm_json";
+ // Get all farms
+ $.ajax({
+ type: "GET",
+ url: call_url,
+ headers: {
+ 'X-Auth-Token': lfc_key
+ },
+ dataType: 'json',
+ contentType: 'application/json',
+ crossDomain: true,
+ async: false,
+ success: function(result) {
+ if (result != null || result.length > 0) {
+ farms = handleAddressCall(result, text);
+ handleIndexCall3(farms);
+ // text += "Iowa, 50112"; // this is temporary
+ } else {
+ alert("Your search query returned no results . . . ")
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ console.log("Status: " + textStatus);
+ console.log("Error: " + errorThrown);
+ }
+ });
+ if (text != "") {
+ geocoder.geocode({
+ 'address': text
+ }, function(results, status) {
+ if (status == 'OK') {
+ map.setCenter(results[0].geometry.location);
+ map.setZoom(17);
+ //map.panTo(curmarker.position); ??
+ var marker = new google.maps.Marker({
+ map: map,
+ position: results[0].geometry.location
+ });
+ } else {
+ alert('Geocode was not successful for the following reason: ' + status);
+ }
+ });
+ }
+ } else {
+ document.getElementById("search_farm_text").text = "Please enter your query";
+ }
+ }
+}
+/*************
+ * INIT MAP *
+ * ***********/
+function initMap() {
+ // set location set to grinnell as center of map
+ var grinnell = {
+ lat: 41.7434,
+ lng: -92.7232
+ };
+ // init map
+ map = new google.maps.Map(document.getElementById('map'), {
+ zoom: 13.7,
+ center: grinnell
+ });
+ // init geocoder
+ geocoder = new google.maps.Geocoder();
+ // call index function for API to load all farms
+ callIndexApi();
+}
+/****************************************
+ * GEOCODING AND ADDING MARKERS FUNCTIONS
+ * **************************************/
+function geocodeAddressAndAddMarker(farm) {
+ var address = farm.address + ", Iowa, 50112"
+ geocoder.geocode({
+ 'address': address
+ }, function(results, status) {
+ // if OK/200 status, add marker to map, else throw alert.
+ if (status === 'OK') {
+ addMarker(farm, results);
+ } else {
+ alert('Geocode was not successful for the following reason: ' + status);
+ }
+ });
+}
+var markers = []
+
+function addMarker(farm, results) {
+ if (farm.operations.length == 0) {
+ operation_icon = '/assets/64cow.png';
+ } else {
+ var primary_operation = farm.operations[0].food;
+ if (primary_operation == "cow" || primary_operation == "pork" || primary_operation == "chicken" ||
+ primary_operation == "turkey" || primary_operation == "lamb" || primary_operation == "duck") {
+ operation_icon = '/assets/steak-512.png';
+ } else if (primary_operation == "fruit") {
+ console.log("HERE");
+ operation_icon = '/assets/24apple.png';
+ } else if (primary_operation == "vegetables") {
+ operation_icon = '/assets/24broccoli.png';
+ } else if (primary_operation == "dairy") {
+ operation_icon = '/assets/24dairy.png';
+ } else if (primary_operation == "agritourism" || primary_operation == "hay" || primary_operation == "row crop") {
+ operation_icon = '/assets/agricultural.png';
+ } else if (primary_operation == "") {}
+ }
+ var iconCow = '/assets/64cow.png'
+ var iconPig = '/assets/24pig.png'
+ // create marker object
+ var marker = new google.maps.Marker({
+ map: map,
+ animation: google.maps.Animation.BOUNCE,
+ position: results[0].geometry.location,
+ title: farm.name,
+ icon: operation_icon
+ });
+ // data string for display tooltip
+ var data = farm.name;
+ // info window for tooltip, contains data
+ var infowindow = new google.maps.InfoWindow({
+ content: data
+ });
+ // add listener to map for marker to display info window
+ google.maps.event.addListener(marker, 'click', function() {
+ // open info window
+ infowindow.open(map, marker);
+ });
+ markers.push(marker);
+}
+/***********************
+ * DELETE MARKERS ON MAP *
+ * *********************/
+function DeleteMarkers() {
+ //Loop through all the markers and remove
+ for (var i = 0; i < markers.length; i++) {
+ markers[i].setMap(null);
+ }
+ markers = [];
+};
+/***********************
+ * FARM API FUNCTIONS *
+ * *********************/
+function callIndexApi() {
+ document.getElementById("farmList").innerHTML = "";
+ var call_url = "/farms/farm_json";
+ $.ajax({
+ type: "GET",
+ url: call_url,
+ headers: {
+ 'X-Auth-Token': lfc_key
+ },
+ dataType: 'json',
+ contentType: 'application/json',
+ crossDomain: true,
+ async: false,
+ success: function(result) {
+ if (result != null || result.length > 0) {
+ handleIndexCall(result);
+ } else {
+ alert("Your search query returned no results . . . ")
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ console.log("Status: " + textStatus);
+ console.log("Error: " + errorThrown);
+ }
+ });
+}
+
+function handleIndexCall(result) {
+ // set to new map
+ farms = {};
+ for (var i = 0; i < result.length; i++) {
+ // create id
+ var id = "farm_" + result[i].id;
+ // add to map
+ farms[id] = result[i];
+ // append card
+ $('#farmList').append('
' +
+ '' + result[i].name + '
' +
+ '' + result[i].address + '
' +
+ 'CSA, Wholesale, and Farmers Market
' +
+ '' + result[i].url + ' | ' +
+ '' + result[i].phone + '' +
+ ''
+ );
+ // on click to show modal
+ $('#' + id).on('click', function() {
+ var new_id = this.getAttribute('id');
+ console.log("new id" + new_id);
+ // alter html in modal
+ setAndShowFarmModal(farms[new_id]);
+ });
+ // add marker at proper placec
+ geocodeAddressAndAddMarker(result[i]);
+ }
+}
+
+function handleAddressCall(result, addressSearch) {
+ farms = [];
+ for (var i = 0; i < result.length; i++) {
+ // create id
+ var name = result[i].name;
+ var id = "farm_" + result[i].id;
+ // add to map
+ //farms[id] = result[i];
+ console.log("name is " + name);
+ if ((name.toLowerCase()).includes(addressSearch.toLowerCase())) {
+ console.log("name is " + name);
+ // return result[i].address;
+ farms.push(result[i]);
+ }
+ }
+ console.log("Address call to farms");
+ console.log(farms);
+ return farms;
+}
+/*************************
+ * RECIPE API FUNCTIONS *
+ * ***********************/
+function callFood2Fork(food_string, checkRecipeValues) {
+ // clear the html to get rid of old recipes
+ $("#recipe_grid").html("");
+ // set new url to access
+ // var call_url = "https://api.edamam.com/search?q=${food_string}&app_id=${edemam_app_id}&app_key=${edemam_app_key}"
+ var call_url = "https://api.edamam.com/search?q=" + food_string + "&app_id=" + edemam_app_id + "&app_key=" + edemam_app_key;
+ var health_query = "";
+ console.log(checkRecipeValues);
+ for (var i = 0; i < checkRecipeValues.length; i++) {
+ console.log(checkRecipeValues[i]);
+ if (i != checkRecipeValues.length - 1) {
+ health_query += checkRecipeValues[i] + ',%20';
+ }
+ }
+ if (checkRecipeValues.length > 0) {
+ call_url += "&healthLabels=" + health_query;
+ }
+ // make call
+ $.ajax({
+ type: "GET",
+ url: call_url,
+ headers: {
+ "more": true,
+ },
+ dataType: 'json',
+ crossDomain: true,
+ success: function(result) {
+ if (result != null && result.hits.length > 0) {
+ console.log(result);
+ handleRecipeAPICall(result.hits);
+ } else {
+ alert("Your search query returned no results . . . ")
+ }
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ console.log("Status: " + textStatus);
+ console.log("Error: " + errorThrown);
+ }
+ });
+}
+
+function handleRecipeAPICall(recipe_list) {
+ // reset recipe list
+ recipes = {};
+ // iterate through
+ for (var i = 0; i < recipe_list.length; i++) {
+ // get current recipe and id
+ var current_recipe = recipe_list[i].recipe;
+ var id = "recipe_" + (i + 1);
+ // put in recipe list
+ recipes[id] = current_recipe;
+ // add html
+ $('#recipe_grid').append(
+ '