mirror of
https://github.com/CodeforLeipzig/stadtratmonitor.git
synced 2025-04-20 07:11:33 +02:00
Rubocop autocorrect app directory
This commit is contained in:
parent
ec4aa64cfc
commit
c08ce6864c
10 changed files with 132 additions and 110 deletions
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
|
@ -12,11 +14,11 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def glossary
|
||||
render action: "glossary"
|
||||
render action: 'glossary'
|
||||
end
|
||||
|
||||
def impressum
|
||||
render action: "impressum"
|
||||
render action: 'impressum'
|
||||
end
|
||||
|
||||
helper_method :current_user, :signed_in?
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class GeoController < ApplicationController
|
||||
# frozen_string_literal: true
|
||||
|
||||
class GeoController < ApplicationController
|
||||
def index
|
||||
render action: "index"
|
||||
render action: 'index'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ImportController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, :only => [:new_papers_callback]
|
||||
skip_before_action :verify_authenticity_token, only: [:new_papers_callback]
|
||||
|
||||
def new_papers_callback
|
||||
require 'open-uri'
|
||||
api_key = Rails.application.config_for(:morph)["key"]
|
||||
api_key = Rails.application.config_for(:morph)['key']
|
||||
uri = URI.parse("https://api.morph.io/jrlover/city_council_leipzig_recent_papers/data.json?key=#{api_key}&query=select%20*%20from%20%27data%27")
|
||||
Paper.import_from_json(uri.read)
|
||||
render :nothing => true
|
||||
render nothing: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
SearchFacet = Struct.new("SearchFacet", :term, :count) do
|
||||
# frozen_string_literal: true
|
||||
|
||||
SearchFacet = Struct.new('SearchFacet', :term, :count) do
|
||||
def term_with_count
|
||||
"#{term} (#{count})"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class SearchController < ApplicationController
|
||||
def index
|
||||
@search_definition = PaperSearch.new(search_params)
|
||||
@search_definition.sort_by ||= "date"
|
||||
@search_definition.sort_by ||= 'date'
|
||||
|
||||
execute_search
|
||||
end
|
||||
|
@ -16,7 +17,7 @@ class SearchController < ApplicationController
|
|||
def show
|
||||
@search_definition = PaperSearch.find params[:id]
|
||||
execute_search
|
||||
render action: "index"
|
||||
render action: 'index'
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -24,35 +25,35 @@ class SearchController < ApplicationController
|
|||
def execute_search
|
||||
@response = Paper.search(@search_definition.to_definition)
|
||||
@papers = @response.page(params[:page]).results
|
||||
@sub = Hash.new
|
||||
@sub = {}
|
||||
@papers.each do |paper|
|
||||
unless paper.reference.nil? && paper.reference.contains("-")
|
||||
segments = paper.reference.split("-")
|
||||
id = ((paper.reference.start_with?("VI-") || paper.reference.start_with?("VII-")) && segments.count > 2 ?
|
||||
segments[2] : segments[1])
|
||||
escaped_chars = Regexp.escape('\\+-*:()[]{}&!?^|\/')
|
||||
sanitized_id = id.gsub(/([#{escaped_chars}])/, '\\\\\1')
|
||||
['AND', 'OR', 'NOT'].each do |reserved|
|
||||
escaped_reserved = reserved.split('').map { |c| "\\#{c}" }.join('')
|
||||
sanitized_id = sanitized_id.gsub('/\s*\b(#{reserved.upcase})\b\s*/',
|
||||
" #{escaped_reserved} ")
|
||||
end
|
||||
@sub_search_definition = Elasticsearch::DSL::Search.search do
|
||||
query do
|
||||
query_string do
|
||||
query "*" + sanitized_id + "*"
|
||||
fields ["reference"]
|
||||
end
|
||||
end
|
||||
next if paper.reference.nil? && paper.reference.contains('-')
|
||||
|
||||
sort do
|
||||
by :published_at, order: 'desc'
|
||||
by :reference, order: 'desc'
|
||||
segments = paper.reference.split('-')
|
||||
id = ((paper.reference.start_with?('VI-') || paper.reference.start_with?('VII-')) && segments.count > 2 ?
|
||||
segments[2] : segments[1])
|
||||
escaped_chars = Regexp.escape('\\+-*:()[]{}&!?^|\/')
|
||||
sanitized_id = id.gsub(/([#{escaped_chars}])/, '\\\\\1')
|
||||
%w[AND OR NOT].each do |reserved|
|
||||
escaped_reserved = reserved.split('').map { |c| "\\#{c}" }.join('')
|
||||
sanitized_id = sanitized_id.gsub('/\s*\b(#{reserved.upcase})\b\s*/',
|
||||
" #{escaped_reserved} ")
|
||||
end
|
||||
@sub_search_definition = Elasticsearch::DSL::Search.search do
|
||||
query do
|
||||
query_string do
|
||||
query '*' + sanitized_id + '*'
|
||||
fields ['reference']
|
||||
end
|
||||
end
|
||||
@sub_papers = Paper.search(@sub_search_definition)
|
||||
@sub[paper.reference] = @sub_papers
|
||||
|
||||
sort do
|
||||
by :published_at, order: 'desc'
|
||||
by :reference, order: 'desc'
|
||||
end
|
||||
end
|
||||
@sub_papers = Paper.search(@sub_search_definition)
|
||||
@sub[paper.reference] = @sub_papers
|
||||
end
|
||||
@paper_type_facets = extract_facets('paper_types')
|
||||
@originator_facets = extract_facets('originators')
|
||||
|
@ -63,9 +64,8 @@ class SearchController < ApplicationController
|
|||
end
|
||||
|
||||
def extract_facets(name)
|
||||
@response.
|
||||
response['aggregations'][name.to_s][name.to_s]['buckets'].
|
||||
map {|m| SearchFacet.new(m['key'], m['doc_count'])}
|
||||
@response
|
||||
.response['aggregations'][name.to_s][name.to_s]['buckets']
|
||||
.map { |m| SearchFacet.new(m['key'], m['doc_count']) }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue