Class: Tasks::Gis::ReportController

Inherits:
ApplicationController
  • Object
show all
Includes:
TaskControllerConfiguration
Defined in:
app/controllers/tasks/gis/report_controller.rb

Instance Method Summary (collapse)

Methods included from TaskControllerConfiguration

#set_is_task_controller

Instance Method Details

- (Object) gather_area_data_x(shape_in, include_)

this will be a feature or feature collection



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/tasks/gis/report_controller.rb', line 120

def gather_area_data_x(shape_in, include_) # this will be a feature or feature collection
  if shape_in.blank?
    #   case finding
    #     when 'collection_object'
    @list_collection_objects = CollectionObject.where('false')
    #     else
    #   end
  else
    feature   = RGeo::GeoJSON.decode(shape_in, :json_parser => :json)
    # isolate the WKT
    geometry  = feature.geometry
    this_type = geometry.geometry_type.to_s.downcase
    geometry  = geometry.as_text
    radius    = feature['radius']
    # case finding
    #   when 'collection_object'
    case this_type
      when 'point'
        @list_collection_objects = CollectionObject
                                     .joins(:geographic_items)
                                     .where(project_id: $project_id)
                                     .where(GeographicItem.within_radius_of_wkt_sql(geometry, radius))
                                     .page(params[:page])
      when 'polygon'
        @list_collection_objects = CollectionObject
                                     .joins(:geographic_items)
                                     .where(project_id: $project_id)
                                     .where(GeographicItem.contained_by_wkt_sql(geometry))
                                     .page(params[:page])
      else
    end
    # else
    # end
  end
end

- (Object) gather_data_x(geographic_area_id, include_page)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/tasks/gis/report_controller.rb', line 94

def gather_data_x(geographic_area_id, include_page)
  return if geographic_area_id.blank?
  @geographic_area = GeographicArea.joins(:geographic_items).find(geographic_area_id)
  total_records    = CollectionObject.count
  limit            = include_page ? 25 : total_records
  # params[:page] = 2
  if @geographic_area.has_shape?
    @all_collection_objects_count = CollectionObject.where(project_id: $project_id)
                                      .in_geographic_item(@geographic_area.default_geographic_item, total_records).count
    if include_page
      @list_collection_objects = CollectionObject.where(project_id: $project_id)
                                   .in_geographic_item(@geographic_area.default_geographic_item, limit)
                                   .order(:id)
                                   .page(params[:page])
    else
      @list_collection_objects = CollectionObject.where(project_id: $project_id)
                                   .in_geographic_item(@geographic_area.default_geographic_item, limit)
                                   .order(:id)
    end
  else
    @all_collection_objects_count = 0
    @list_collection_objects      = CollectionObject.where('false')
  end
  @list_collection_objects
end

- (Object) location_report_list



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/tasks/gis/report_controller.rb', line 11

def location_report_list
  geographic_area_id = params[:geographic_area_id]
  current_headers    = params[:hd]
  shape_in           = params['drawn_area_shape']
  finding            = params['selection_object']

  case params[:commit]
    when 'Show'
      # remove all the headers which are NOT checked
      %w(ce co bc).each { |column|
        group = current_headers[column.to_sym]
        group.keys.each { |type|
          headers = group[type.to_sym]
          entry   = current_headers[column.to_sym][type.to_sym]
          unless headers.empty?
            headers.keys.each { |header|
              if headers[header].empty?
                # we must be in 'get' processing
              else
                check = headers[header][:checked]
                # we are in 'post'
                if check == '1'
                  entry[header] = nil # leave the key in place
                else
                  entry.delete(header) # remove the key:value pair
                end
              end
            }
          end
        } unless group.nil?
      } unless current_headers.nil?
      # selected_headers               ||= {ce: {in: {}, im: {}}, # make sure all columns and types are present,
      #                                     co: {in: {}, im: {}}, # even if empty
      #                                     bc: {in: {}, im: {}}}
      @selected_column_names         = current_headers
      session['co_selected_headers'] = current_headers
      # get first 25 records
      @list_collection_objects       = GeographicItem.gather_selected_data(geographic_area_id, shape_in, finding, true, params[:page])
    when 'download'
      # fixme: repair this: it aborts use of Redis, and forces load of all data
      test_redis_not = false
      table_data     = nil
      unless test_redis_not
        # TODO: This needs to be cleaned up and consolidated
        # check Redis mem-store for a valid result
        if test_redis
          table_name = sessions_current_user.email + '-c_o_table_data'
          table_data = JSON.parse(@c_o_table_store.get(table_name))
          # remove the selected data from Redis mem-store
          @c_o_table_store.set(table_name, '')
        else
          table_data = nil
        end

        table_data = nil
      end

      @list_collection_objects = GeographicItem.gather_selected_data(geographic_area_id, shape_in, finding, false)
      report_file              = CollectionObject.generate_report_download(@list_collection_objects, current_headers, table_data)
      send_data(report_file, type: 'text', filename: "collection_objects_report_#{DateTime.now.to_s}.csv")
    else
  end
  current_headers
end

- (Object) new

before_action :disable_turbolinks, only: [:new, :generate_choices]



6
7
8
9
# File 'app/controllers/tasks/gis/report_controller.rb', line 6

def new
  @list_collection_objects = [] # CollectionObject.where('false')
  session.delete('co_selected_headers')
end

- (Object) repaint



156
157
158
159
160
161
# File 'app/controllers/tasks/gis/report_controller.rb', line 156

def repaint
  session.delete('co_selected_headers')
  location_report_list
  # remove the list from the session so that they are not included in the links generated by pagination
  render 'location_report_list'
end

- (Object) test_redis



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/tasks/gis/report_controller.rb', line 76

def test_redis
  retval           = true
  @c_o_table_store = Redis.new

  begin
    @c_o_table_store.ping
  rescue Exception => e
    @c_o_table_store = nil
    retval           = false
    e.inspect
    e.message
    # puts "#{e.inspect}"
    # e.inspect
  end

  retval
end