geoblacklight 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +19 -0
  3. data/.gitmodules +5 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE.txt +13 -0
  6. data/README.md +103 -0
  7. data/Rakefile +44 -0
  8. data/app/assets/images/blacklight/logo.png +0 -0
  9. data/app/assets/images/geoblacklight/src_berkeley.png +0 -0
  10. data/app/assets/images/geoblacklight/src_cambridge.png +0 -0
  11. data/app/assets/images/geoblacklight/src_harvard.png +0 -0
  12. data/app/assets/images/geoblacklight/src_maryland.png +0 -0
  13. data/app/assets/images/geoblacklight/src_massgis.png +0 -0
  14. data/app/assets/images/geoblacklight/src_mit.png +0 -0
  15. data/app/assets/images/geoblacklight/src_princeton.png +0 -0
  16. data/app/assets/images/geoblacklight/src_stanford.png +0 -0
  17. data/app/assets/images/geoblacklight/src_tufts.png +0 -0
  18. data/app/assets/images/geoblacklight/src_un.png +0 -0
  19. data/app/assets/images/geoblacklight/type_arc.png +0 -0
  20. data/app/assets/images/geoblacklight/type_dot.png +0 -0
  21. data/app/assets/images/geoblacklight/type_library.png +0 -0
  22. data/app/assets/images/geoblacklight/type_map.png +0 -0
  23. data/app/assets/images/geoblacklight/type_polygon.png +0 -0
  24. data/app/assets/images/geoblacklight/type_raster.png +0 -0
  25. data/app/assets/javascripts/geoblacklight/application.js +2 -0
  26. data/app/assets/javascripts/geoblacklight/geoblacklight.js +4 -0
  27. data/app/assets/javascripts/geoblacklight/modules/map-home.js +25 -0
  28. data/app/assets/javascripts/geoblacklight/modules/map-results.js +72 -0
  29. data/app/assets/javascripts/geoblacklight/modules/map-view.js +211 -0
  30. data/app/controllers/download_controller.rb +107 -0
  31. data/app/controllers/wms_controller.rb +81 -0
  32. data/app/helpers/geoblacklight_helper.rb +91 -0
  33. data/app/views/catalog/_document_list.html.erb +12 -0
  34. data/app/views/catalog/_home_text.html.erb +40 -0
  35. data/app/views/catalog/_index_header_default.html.erb +59 -0
  36. data/app/views/catalog/_show_default.html.erb +68 -0
  37. data/app/views/catalog/_show_sidebar.html.erb +76 -0
  38. data/geoblacklight.gemspec +36 -0
  39. data/lib/generators/geoblacklight/install_generator.rb +46 -0
  40. data/lib/generators/geoblacklight/templates/catalog_controller.rb +217 -0
  41. data/lib/generators/geoblacklight/templates/geoblacklight.css.scss +79 -0
  42. data/lib/generators/geoblacklight/templates/geoblacklight.js +1 -0
  43. data/lib/geoblacklight.rb +5 -0
  44. data/lib/geoblacklight/config.rb +0 -0
  45. data/lib/geoblacklight/engine.rb +15 -0
  46. data/lib/geoblacklight/fixtures_indexer.rb +34 -0
  47. data/lib/geoblacklight/version.rb +3 -0
  48. data/lib/tasks/geoblacklight.rake +13 -0
  49. data/spec/fixtures/geoblacklight_schema/transformed.json +53 -0
  50. data/spec/spec_helper.rb +37 -0
  51. data/spec/test_app_templates/lib/generators/test_app_generator.rb +23 -0
  52. metadata +299 -0
@@ -0,0 +1,107 @@
1
+ require 'nokogiri'
2
+ require 'httparty'
3
+ require 'net/http'
4
+
5
+ class Layer
6
+ include HTTParty
7
+ format :json
8
+
9
+ def self.getInfo(params)
10
+ url = params['URL']
11
+ params['BBOX'] = formatLatLng(params['BBOX'])
12
+ puts params
13
+ get(url, :query => params.except('URL'))
14
+ end
15
+ end
16
+
17
+ class DownloadController < ApplicationController
18
+ def file
19
+
20
+ send_file "tmp/data/#{params['q']}", :type=>"application/zip", :x_sendfile=>true
21
+
22
+ end
23
+
24
+ def shapefile
25
+
26
+ puts session['session_id']
27
+ uuid = params['layer_slug_s']
28
+ layername = params['layer_id_s']
29
+ wfsurl = params['solr_wfs_url']
30
+
31
+ params = {:service => 'wfs', :version => '2.0.0', :request => 'GetFeature', :srsName => 'EPSG:4326', :outputformat => 'SHAPE-ZIP', :typeName => layername}
32
+
33
+ # token = SecureRandom.base64(8).tr('+/=lIO0', 'abc123')
34
+ error = ''
35
+
36
+ if !Dir.exists?('tmp/data')
37
+ Dir.mkdir('tmp/data')
38
+ end
39
+ if (!File.file?("tmp/data/#{uuid}-shapefile.zip"))
40
+ File.open("tmp/data/#{uuid}-shapefile.zip", 'wb') do |f|
41
+ puts "#{uuid}-shapefile.zip created"
42
+ dl = HTTParty.get(wfsurl, :query => params)
43
+ if dl.headers['content-type'] == 'application/zip'
44
+ f.write dl.parsed_response
45
+ else
46
+ error = dl.parsed_response
47
+ end
48
+ end
49
+ else
50
+ puts "#{uuid}-shapefile.zip already exists"
51
+ end
52
+ respond_to do |format|
53
+ if error.length > 0
54
+ puts 'error!'
55
+ format.json { render :json => {:error => error}}
56
+ File.delete("tmp/data/#{uuid}-shapefile.zip")
57
+ puts "#{uuid}-shapefile.zip deleted"
58
+ else
59
+ format.json { render :json => {:data => "#{uuid}-shapefile.zip"}}
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ def kml
66
+ layername = params['layer_id_s']
67
+ puts layername
68
+ bbox = [params['solr_sw_pt_1_d'], params['solr_sw_pt_0_d'], params['solr_ne_pt_1_d'], params['solr_ne_pt_0_d']]
69
+ bbox = bbox.join(',')
70
+ wmsurl = params['solr_wms_url']
71
+ uuid = params['layer_slug_s']
72
+ puts bbox
73
+
74
+ params = {:service => 'wms', :version => '1.1.0', :request => 'GetMap', :srsName => 'EPSG:900913', :format => 'application/vnd.google-earth.kmz', :layers => layername, :bbox => bbox, :width => 2000, :height => 2000}
75
+
76
+ error = ''
77
+
78
+ if !Dir.exists?('tmp/data')
79
+ Dir.mkdir('tmp/data')
80
+ end
81
+ if (!File.file?("tmp/data/#{uuid}.kmz"))
82
+ File.open("tmp/data/#{uuid}.kmz", 'wb') do |f|
83
+ puts "#{uuid}.kmz created"
84
+ dl = HTTParty.get(wmsurl, :query => params)
85
+ puts dl.headers.inspect
86
+ puts dl.request.inspect
87
+ if dl.headers['content-type'] == 'application/vnd.google-earth.kmz'
88
+ f.write dl.parsed_response
89
+ else
90
+ error = dl.parsed_response
91
+ end
92
+ end
93
+ else
94
+ puts "#{uuid}.kmz already exists"
95
+ end
96
+ respond_to do |format|
97
+ if error.length > 0
98
+ puts 'error!'
99
+ format.json { render :json => {:error => error}}
100
+ File.delete("tmp/data/#{uuid}.kmz")
101
+ puts "#{uuid}.kmz deleted"
102
+ else
103
+ format.json { render :json => {:data => "#{uuid}.kmz"}}
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,81 @@
1
+ require 'nokogiri'
2
+
3
+ class Layer
4
+ include HTTParty
5
+ format :json
6
+
7
+ def self.getInfo(params)
8
+ url = params['URL']
9
+ params['BBOX'] = formatLatLng(params['BBOX'])
10
+ # puts 'hallo'
11
+ # params.delete "URL"
12
+ params.delete "action"
13
+ params.delete "controller"
14
+ puts params
15
+ get(url, :query => params.except('URL'))
16
+ end
17
+ end
18
+
19
+ # Refactor to a helper later on
20
+ def formatLatLng(val)
21
+ formated_val = []
22
+ val.split(',').each do |v|
23
+ vFloat = v.to_f
24
+ if vFloat > 180 || vFloat < -180
25
+ while vFloat > 180
26
+ vFloat -= 360
27
+ end
28
+ while vFloat < -180
29
+ vFloat += 360
30
+ end
31
+ formated_val.push(vFloat)
32
+ else
33
+ formated_val.push(v)
34
+ end
35
+ end
36
+ return formated_val.join(',')
37
+ end
38
+
39
+ class WmsController < ApplicationController
40
+ def handle
41
+ params["info_format"] = "text/html"
42
+ response = Layer.getInfo(params)
43
+ # puts response.inspect
44
+ puts response.body
45
+ puts response.request.inspect
46
+
47
+
48
+ page = Nokogiri::HTML(response.body)
49
+ table = {:values => []}
50
+ page.css('th').each_with_index do |th|
51
+ table[:values].push([th.text])
52
+ end
53
+ page.css('td').each_with_index do |td, i|
54
+ table[:values][i].push(td.text)
55
+ end
56
+
57
+ errorresponse = {}
58
+
59
+ if response.headers["content-type"].slice(0,8) == "text/xml"
60
+ puts response.body.to_s
61
+ errorresponse = Hash.from_xml(response.body).to_json
62
+ end
63
+
64
+ respond_to do |format|
65
+ if response.headers["content-type"].slice(0,9) == "text/html"
66
+ format.json { render :json => table}
67
+ else
68
+ format.json { render :json => errorresponse}
69
+ end
70
+ # if response.headers["content-type"] == "application/json"
71
+ # format.json { render :json => response }
72
+ # else
73
+ # if response.headers["content-type"] == "text/html"
74
+ # puts 'should be called'
75
+ # format.json { render :json => table}
76
+ # end
77
+ # # format.json { render :json => {"code" => "fail"}}
78
+ # end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,91 @@
1
+ module GeoblacklightHelper
2
+
3
+ def date_to_year(date)
4
+ Date.parse(date).to_formatted_s(:number).slice(0,4)
5
+ end
6
+
7
+ def sms_helper()
8
+ content_tag(:i, '', :class => 'fa fa-li fa-mobile') + t('blacklight.tools.sms')
9
+ end
10
+
11
+ def email_helper
12
+ content_tag(:i, '', :class => 'fa fa-li fa-envelope') + t('blacklight.tools.email')
13
+ end
14
+
15
+ def metadata_helper
16
+ content_tag(:i, '', :class => 'fa fa-li fa-download') + t('Metadata')
17
+ end
18
+
19
+ def abstract_truncator(abstract)
20
+ if (abstract)
21
+ if (abstract.length > 150)
22
+ html = abstract.slice(0,150) + content_tag(:span, ("..." + link_to("more", "#", :id =>"more-abstract", :data => {no_turbolink: true})).html_safe, :id => "abstract-trunc") + content_tag(:span, abstract.slice(150,abstract.length), :id => "abstract-full", :class => "hidden")
23
+ else
24
+ html = abstract
25
+ end
26
+ content_tag(:span, html.html_safe)
27
+ end
28
+ end
29
+
30
+ def snippit(text)
31
+ if (text)
32
+ if (text.length > 150)
33
+ text.slice(0,150) + '...'
34
+ else
35
+ text
36
+ end
37
+ else
38
+ ''
39
+ end
40
+ end
41
+
42
+ def layer_type_image(type)
43
+ case type
44
+ when "Polygon"
45
+ image_tag('geoblacklight/type_polygon.png', 'data-toggle' => 'tooltip', title: 'Polygon', :class => 'tooltip-icon')
46
+ when "Line"
47
+ image_tag('geoblacklight/type_arc.png', 'data-toggle' => 'tooltip', title: 'Line', :class => 'tooltip-icon')
48
+ when "Point"
49
+ image_tag('geoblacklight/type_dot.png', 'data-toggle' => 'tooltip', title: 'Point', :class => 'tooltip-icon')
50
+ when "Raster"
51
+ image_tag('geoblacklight/type_raster.png', 'data-toggle' => 'tooltip', title: 'Raster', :class => 'tooltip-icon')
52
+ when "Paper Map"
53
+ image_tag('geoblacklight/type_map.png', 'data-toggle' => 'tooltip', title: 'Paper Map', :class => 'tooltip-icon')
54
+ when "LibraryRecord"
55
+ content_tag(:i, '', class: 'fa fa-book fa-lg text-muted tooltip-icon', 'data-toggle' => 'tooltip', title: 'Library Record')
56
+ else
57
+ ""
58
+ end
59
+ end
60
+
61
+ def layer_institution_image(institution)
62
+ case institution
63
+ when /Stanford/
64
+ image_tag('geoblacklight/src_stanford.png', 'data-toggle' => 'tooltip', title: 'Stanford', :class => 'tooltip-icon')
65
+ when /Berkeley/
66
+ image_tag('geoblacklight/src_berkeley.png', 'data-toggle' => 'tooltip', title: 'UC Berkeley', :class => 'tooltip-icon')
67
+ when /Harvard/
68
+ image_tag('geoblacklight/src_harvard.png', 'data-toggle' => 'tooltip', title: 'Harvard', :class => 'tooltip-icon')
69
+ when /MIT/
70
+ image_tag('geoblacklight/src_mit.png', 'data-toggle' => 'tooltip', title: 'MIT', :class => 'tooltip-icon')
71
+ when /Tufts/
72
+ image_tag('geoblacklight/src_tufts.png', 'data-toggle' => 'tooltip', title: 'Tufts', :class => 'tooltip-icon')
73
+ when /MassGIS/
74
+ image_tag('geoblacklight/src_massgis.png', 'data-toggle' => 'tooltip', title: 'MassGIS', :class => 'tooltip-icon')
75
+ else
76
+ ""
77
+ end
78
+ end
79
+
80
+ def layer_access_image(access)
81
+ case access
82
+ when 'Restricted'
83
+ content_tag(:i, '', class: 'fa fa-lock fa-lg text-muted tooltip-icon', 'data-toggle' => 'tooltip', title: 'Restricted')
84
+ when 'Public'
85
+ content_tag(:i, '', class: 'fa fa-unlock fa-lg text-muted tooltip-icon', 'data-toggle' => 'tooltip', title: 'Public')
86
+ else
87
+ ""
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,12 @@
1
+ <%- # container for all documents in index view -%>
2
+ <%= javascript_tag "var solrDocs = #{documents.to_json};" %>
3
+ <%= javascript_tag "var bBoxs = new L.LayerGroup([]);" %>
4
+ <%= javascript_tag "var mapBbox = [];" %>
5
+
6
+ <div id="documents" class="docView col-md-6">
7
+ <%= render documents, :as => :document %>
8
+ </div>
9
+ <div id="geoblacklight-map-results">
10
+ <div id="map" class="listview-map col-md-6">
11
+ </div>
12
+ </div>
@@ -0,0 +1,40 @@
1
+ <div class="row">
2
+ <div class="col-md-6">
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading">
5
+ <h4><%= t('blacklight.welcome') %></h4>
6
+ </div>
7
+ <div class="panel-body">
8
+ <p>
9
+ Find GIS data!
10
+ </p>
11
+ <p>
12
+ Discover Maps!
13
+ </p>
14
+ </div>
15
+ </div>
16
+ </div>
17
+ <div class="col-md-6">
18
+ <div class="panel panel-default">
19
+ <div class="panel-heading">
20
+ <h4>Featured Datasets</h4>
21
+ </div>
22
+ <div class="panel-body">
23
+ <ul>
24
+ <li>
25
+ <a href="#">Amazing Data 1</a>
26
+ </li>
27
+ <li>
28
+ <a href="#">Amazing Data 2</a>
29
+ </li>
30
+ <li>
31
+ <a href="#">Amazing Data 3</a>
32
+ </li>
33
+ </ul>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ <div id='geoblacklight-map-home'>
39
+ <div id='map' class='mapview-map'></div>
40
+ </div>
@@ -0,0 +1,59 @@
1
+ <% # header bar for doc items in index view -%>
2
+ <div data-layer="<%= document['uuid'] %>" class="documentHeader row">
3
+
4
+ <%# main title container for doc partial view
5
+ How many bootstrap columns need to be reserved
6
+ for bookmarks control depends on size.
7
+ -%>
8
+ <h5 class="index_title col-sm-9 col-lg-10 text-span">
9
+ <% counter = document_counter_with_offset(document_counter) %>
10
+ <span class="document-counter">
11
+ <%= t('blacklight.search.documents.counter', :counter => counter) if counter %>
12
+ </span>
13
+ <%= link_to_document document, :label=>document_show_link_field(document), :counter => counter, :title => document['dc_title_s'] %>
14
+ &nbsp;
15
+ <%= layer_type_image(document['layer_geom_type_s']) %>
16
+ <%= layer_institution_image(document['dct_provenance_s']) %>
17
+ <%= layer_access_image(document['dc_rights_s']) %>
18
+ </h5>
19
+
20
+ <% # bookmark functions for items/docs -%>
21
+ <!-- <%= render_index_doc_actions document, :wrapping_class => "index-document-functions col-sm-3 col-lg-2" %> -->
22
+
23
+ <div class="row" data-layer="<%= document['uuid'] %>">
24
+ <div class="col-md-12">
25
+ <div class="" data-layer="<%= document['uuid'] %>-accordion">
26
+ <div data-layer="<%= document['uuid'] %>-collapse" class="panel-collapse collapse">
27
+ <div class="">
28
+ <small>
29
+ <ul class="list-unstyled">
30
+ <li>
31
+ <%= document['solr_year_i'] %>. <i><%= document['dc_creator_sm'].nil?? '' : document['dc_creator_sm'].join(', ') %></i>. <%= snippit(document['dc_description_s']) %>. <%= document['dc_publisher_s'] %>. Score: <%= document['score'] %>
32
+ </li>
33
+ </ul>
34
+ </small>
35
+ </div>
36
+ <br>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ </div>
41
+ <script>
42
+ $.fn.geoBlacklight_computeBbox(<%= document_counter %>);
43
+ $("*[data-layer=\"<%= document['uuid']%>\"]").click(function(){
44
+ $("*[data-layer=\"<%= document['uuid']%>-collapse\"]").collapse("toggle")
45
+ });
46
+
47
+ $("*[data-layer=\"<%= document['uuid']%>\"]").mouseover(function(){
48
+ if (bBoxs[<%= document_counter %>]){
49
+ // console.log(bBoxs[<%= document_counter %>]);
50
+ $.fn.geoBlacklight_addBbox(bBoxs[<%= document_counter %>]);
51
+ }
52
+ });
53
+
54
+ $("*[data-layer=\"<%= document['uuid']%>\"]").mouseout(function(){
55
+ $.fn.geoBlacklight_removeBbox(bBoxs[<%= document_counter %>]);
56
+ });
57
+ </script>
58
+ </div>
59
+
@@ -0,0 +1,68 @@
1
+ <div class="geoblacklight-view-panel">
2
+ <small>
3
+ <%= layer_type_image(document['layer_geom_type_s']) %>
4
+ <%= layer_institution_image(document['dct_provenance_s']) %>
5
+ <%= layer_access_image(document['dc_rights_s']) %>
6
+ </small>
7
+
8
+ <dl class="dl-horizontal">
9
+ <% unless document['dc_creator_sm'].nil? %>
10
+ <dt>Author</dt>
11
+ <dd><%= document['dc_creator_sm'].join(', ') %>&nbsp;</dd>
12
+ <% end %>
13
+ <% unless document['dc_publisher_s'].nil? %>
14
+ <dt>Publisher</dt>
15
+ <dd><%= document['dc_publisher_s'] %>&nbsp;</dd>
16
+ <% end %>
17
+ <dt>Year</dt>
18
+ <dd><%= document['solr_year_i'] %>&nbsp;</dd>
19
+ <dt>Abstract</dt>
20
+ <dd id=""><%= abstract_truncator(document['dc_description_s']) %>&nbsp;</dd>
21
+ <% unless document['dct_isPartOf_sm'].nil? %>
22
+ <dt>Collection</dt>
23
+ <dd><%= document['dct_isPartOf_sm'].sort.join(', ') %>&nbsp;</dd>
24
+ <% end %>
25
+ <% if document['dct_provenance_s'] == 'Stanford' and not document['dc_identifier_s'].nil? %>
26
+ <dt>Citation</dt>
27
+ <dd><%= link_to document['dc_identifier_s'], document['dc_identifier_s'] %>&nbsp;</dd>
28
+ <% end %>
29
+ <% unless document['dct_spatial_sm'].nil? %>
30
+ <dt>Places</dt>
31
+ <dd><%= document['dct_spatial_sm'].sort.join(', ') %>&nbsp;</dd>
32
+ <% end %>
33
+ <% unless document['dc_subject_sm'].nil? %>
34
+ <dt>Subjects</dt>
35
+ <dd><%= document['dc_subject_sm'].sort.join(', ') %>&nbsp;</dd>
36
+ <% end %>
37
+ <% unless document['dct_temporal_sm'].nil? %>
38
+ <dt>Years</dt>
39
+ <dd><%= document['dct_temporal_sm'].sort.join(', ') %>&nbsp;</dd>
40
+ <% end %>
41
+ </dl>
42
+ </div>
43
+
44
+ <div class='row'>
45
+ <div class="col-md-8">
46
+ <div id='geoblacklight-map-view'>
47
+ <div id='map' class='mapview-map'></div>
48
+ <div id='control'>
49
+ <div id='handle'></div>
50
+ <div id='bottom'></div>
51
+ </div>
52
+ </div>
53
+ </div>
54
+ <div id='table-container' class='col-md-4'><div id='attribute-table' ></div></div>
55
+ </div>
56
+ <% if @document['dct_provenance_s'] == 'Stanford' %>
57
+ <div class='geoblacklight-view-panel-footer'>
58
+ <br>
59
+ <br>
60
+ <hr/>
61
+ <p align="right">
62
+ <small>
63
+ <a href="<%= @document['dc_identifier_s'] %>.mods">Librarian View</a>
64
+ </small>
65
+ </p>
66
+ </div>
67
+ <% end %>
68
+ <%= javascript_tag "var solrDoc = #{@document.to_json};" %>