Class: GazetteersController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GazetteersController
- Includes:
- DataControllerConfiguration::ProjectDataControllerConfiguration, Lib::Vendor::RgeoShapefileHelper
- Defined in:
- app/controllers/gazetteers_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #autocomplete ⇒ Object
- #citation_params ⇒ Object private
-
#create ⇒ Object
POST /gazetteers.json.
-
#destroy ⇒ Object
DELETE /gazetteers/1 DELETE /gazetteers/1.json.
-
#download ⇒ Object
GET /gazetteers/download.
-
#edit ⇒ Object
GET /gazetteers/1/edit.
- #gazetteer_params ⇒ Object private
-
#import ⇒ Object
POST /gazetteers/import.json.
-
#index ⇒ Object
GET /gazetteers GET /gazetteers.json.
-
#list ⇒ Object
GET /gazetteers/list.
-
#new ⇒ Object
GET /gazetteers/new.
-
#preview ⇒ Object
Using POST instead of GET to support long WKT strings POST /gazetteers/preview.json.
- #projects_param ⇒ Object private
- #search ⇒ Object
-
#select_options ⇒ Object
GET /gazetteers/select_options.json.
- #set_gazetteer ⇒ Object private
- #shape_params ⇒ Object private
-
#shapefile_fields ⇒ Object
GET /gazetteers/shapefile_fields.json.
- #shapefile_params ⇒ Object private
-
#shapefile_text_field_values ⇒ Object
GET /gazetteers/shapefile_text_field_values.json.
-
#show ⇒ Object
GET /gazetteers/1 or /gazetteers/1.json.
-
#update ⇒ Object
PATCH/PUT /gazetteers/1 PATCH/PUT /gazetteers/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#autocomplete ⇒ Object
105 106 107 108 109 110 |
# File 'app/controllers/gazetteers_controller.rb', line 105 def autocomplete @gazetteers = ::Queries::Gazetteer::Autocomplete.new( params.require(:term), project_id: sessions_current_project_id, ).autocomplete end |
#citation_params ⇒ Object (private)
225 226 227 228 229 |
# File 'app/controllers/gazetteers_controller.rb', line 225 def citation_params params.require(:citation_options).permit( :cite_gzs, citation: [:source_id, :pages, :is_original] ) end |
#create ⇒ Object
POST /gazetteers.json
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/gazetteers_controller.rb', line 56 def create @gazetteer = Gazetteer.new(gazetteer_params) @gazetteer.build_gi_from_shapes( shape_params['shapes'], params.require('geometry_operation_is_union') ) if @gazetteer.errors.include?(:base) render json: @gazetteer.errors, status: :unprocessable_entity return end begin Gazetteer .save_and_clone_to_projects(@gazetteer, projects_param['projects']) render :show, status: :created, location: @gazetteer rescue ActiveRecord::RecordInvalid => e render json: { errors: e. }, status: :unprocessable_entity end end |
#destroy ⇒ Object
DELETE /gazetteers/1 DELETE /gazetteers/1.json
93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/gazetteers_controller.rb', line 93 def destroy @gazetteer.destroy! respond_to do |format| format.html { redirect_to gazetteers_url, notice: 'Gazetteer was successfully destroyed.' } format.json { head :no_content } end end |
#download ⇒ Object
GET /gazetteers/download
122 123 124 125 126 127 128 |
# File 'app/controllers/gazetteers_controller.rb', line 122 def download send_data Export::CSV.generate_csv( Gazetteer.where(project_id: sessions_current_project_id) ), type: 'text', filename: "gazetteers_#{DateTime.now}.tsv" end |
#edit ⇒ Object
GET /gazetteers/1/edit
40 41 42 43 44 45 46 |
# File 'app/controllers/gazetteers_controller.rb', line 40 def edit respond_to do |format| format.html { redirect_to new_gazetteer_task_path gazetteer_id: @gazetteer.id } end end |
#gazetteer_params ⇒ Object (private)
203 204 205 206 |
# File 'app/controllers/gazetteers_controller.rb', line 203 def gazetteer_params params.require(:gazetteer).permit(:name, :parent_id, :iso_3166_a2, :iso_3166_a3) end |
#import ⇒ Object
POST /gazetteers/import.json
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'app/controllers/gazetteers_controller.rb', line 131 def import begin addShapefileImportJobToQueue( shapefile_params, citation_params, projects_param['projects'], sessions_current_project_id, sessions_current_user_id ) rescue TaxonWorks::Error => e render json: { errors: e. }, status: :unprocessable_entity return end head :no_content end |
#index ⇒ Object
GET /gazetteers GET /gazetteers.json
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/gazetteers_controller.rb', line 10 def index respond_to do |format| format.html do @recent_objects = Gazetteer .recent_from_project_id(sessions_current_project_id) .order(updated_at: :desc) .limit(10) render '/shared/data/all/index' end format.json do @gazetteers = ::Queries::Gazetteer::Filter.new(params).all .includes(:geographic_item) .page(params[:page]) .per(params[:per]) end end end |
#list ⇒ Object
GET /gazetteers/list
49 50 51 52 53 |
# File 'app/controllers/gazetteers_controller.rb', line 49 def list @gazetteers = Gazetteer .with_project_id(sessions_current_project_id) .page(params[:page]).per(params[:per]) end |
#new ⇒ Object
GET /gazetteers/new
33 34 35 36 37 |
# File 'app/controllers/gazetteers_controller.rb', line 33 def new respond_to do |format| format.html { redirect_to new_gazetteer_task_path } end end |
#preview ⇒ Object
Using POST instead of GET to support long WKT strings POST /gazetteers/preview.json
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/controllers/gazetteers_controller.rb', line 148 def preview begin s = Gazetteer.combine_shapes_to_rgeo( shape_params['shapes'], params.require('geometry_operation_is_union') ) rescue TaxonWorks::Error => e render json: { base: [e.] }, status: :unprocessable_entity return end f = RGeo::GeoJSON::Feature.new(s) @shape = RGeo::GeoJSON.encode(f) end |
#projects_param ⇒ Object (private)
208 209 210 |
# File 'app/controllers/gazetteers_controller.rb', line 208 def projects_param params.permit(projects: []) end |
#search ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'app/controllers/gazetteers_controller.rb', line 112 def search if params[:id].blank? redirect_to(gazetteer_path, alert: 'You must select an item from the list with a click or tab press before clicking show.') else redirect_to gazetteer_path(params[:id]) end end |
#select_options ⇒ Object
GET /gazetteers/select_options.json
190 191 192 193 194 195 |
# File 'app/controllers/gazetteers_controller.rb', line 190 def @gazetteers = Gazetteer.select_optimized( sessions_current_user_id, sessions_current_project_id, params.permit(:target)[:target] ) end |
#set_gazetteer ⇒ Object (private)
199 200 201 |
# File 'app/controllers/gazetteers_controller.rb', line 199 def set_gazetteer @gazetteer = Gazetteer.find(params[:id]) end |
#shape_params ⇒ Object (private)
212 213 214 215 216 |
# File 'app/controllers/gazetteers_controller.rb', line 212 def shape_params params.require(:gazetteer).permit( shapes: { geojson: [], wkt: [], points: [], ga_combine: [], gz_combine: [] } ) end |
#shapefile_fields ⇒ Object
GET /gazetteers/shapefile_fields.json
163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/gazetteers_controller.rb', line 163 def shapefile_fields begin @shapefile_fields = fields_from_shapefile( params[:shp_doc_id], params[:dbf_doc_id], sessions_current_project_id ) rescue TaxonWorks::Error => e render json: { errors: e }, status: :unprocessable_entity return end end |
#shapefile_params ⇒ Object (private)
218 219 220 221 222 223 |
# File 'app/controllers/gazetteers_controller.rb', line 218 def shapefile_params params.require(:shapefile).permit( :shp_doc_id, :shx_doc_id, :dbf_doc_id, :prj_doc_id, :cpg_doc_id, :name_field, :iso_a2_field, :iso_a3_field ) end |
#shapefile_text_field_values ⇒ Object
GET /gazetteers/shapefile_text_field_values.json
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'app/controllers/gazetteers_controller.rb', line 176 def shapefile_text_field_values begin text_data_hash = validate_and_fetch_shapefile_text_field_values( shapefile_params, sessions_current_project_id ) rescue TaxonWorks::Error => e render json: { errors: e }, status: :unprocessable_entity return end render json: text_data_hash end |
#show ⇒ Object
GET /gazetteers/1 or /gazetteers/1.json
29 30 |
# File 'app/controllers/gazetteers_controller.rb', line 29 def show end |
#update ⇒ Object
PATCH/PUT /gazetteers/1 PATCH/PUT /gazetteers/1.json
79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/gazetteers_controller.rb', line 79 def update respond_to do |format| if @gazetteer.update(gazetteer_params) format.html { redirect_to gazetteer_url(@gazetteer) } format.json { render :show, status: :ok } else format.html { render :edit, status: :unprocessable_entity } format.json { render json: @gazetteer.errors, status: :unprocessable_entity } end end end |