Class: GeoController

Inherits:
ApplicationController show all
Defined in:
app/controllers/geo_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/geo_controller.rb', line 27

def create
  @features = []
  feature_collection = geo_model.geojson_decode(request.raw_post)
  if feature_collection.nil? || !geo_model.can_edit?(current_ability)
    head :bad_request
    return
  end

  feature_collection.each do |feature|
    if feature.feature_id.is_a? Integer
      new_feature = geo_model.find(feature.feature_id)
    end
    if new_feature.nil?
      new_feature = geo_model.new
    end

    logger.info "#{geo_model.table_name}.update_attributes_from_feature: #{feature.inspect}"
    if new_feature.update_attributes_from_geojson_feature(feature, current_user)
      @features << new_feature
    end
  end

  render :json => @features.to_geojson, :status => :created
end

#destroyObject



74
75
76
77
78
# File 'app/controllers/geo_controller.rb', line 74

def destroy
  @feature = geo_model.user_filter(current_ability).find(params[:id])
  @feature.destroy
  head :no_content
end

#geo_modelObject



5
6
7
# File 'app/controllers/geo_controller.rb', line 5

def geo_model
  throw NotImplementedError
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/geo_controller.rb', line 9

def index
  @features = geo_model.bbox_filter(params).user_filter(current_ability)
  respond_to do |format|
    # NOTE: return GeoJSON by default (OpenLayers.Protocol.HTTP PUT does not work with '.json' format selection)
    format.html {
      render :json => @features.json_filter.to_geojson
    }
    format.csv {
      send_csv_excel(@features.csv_filter)
    }
  end
end

#showObject



22
23
24
25
# File 'app/controllers/geo_controller.rb', line 22

def show
  @feature = geo_model.user_filter(current_ability).json_filter.find(params[:id])
  render :json => [@feature].to_geojson
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/geo_controller.rb', line 52

def update
  feature = geo_model.user_filter(current_ability).geojson_decode(request.raw_post)
  if feature.nil?
    head :bad_request
    return
  end

  if feature.feature_id.is_a? Integer
    @feature = geo_model.find(feature.feature_id)
  end
  if @feature.nil?
    head :not_found
    return
  end

  if @feature.update_attributes_from_geojson_feature(feature, current_user)
    render :json => @feature.to_geojson, :status => :created
  else
    head :unprocessable_entity
  end
end