Class: Topic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Topic
- Defined in:
- app/models/topic.rb
Overview
OpenLayers “layer” (WMS, etc.)
Class Method Summary collapse
-
.default_print_disclaimer ⇒ Object
print disclaimer.
-
.list(app, current_ability, zone, wms_host) ⇒ Object
Structure for Topic selection.
- .query_header ⇒ Object
- .query_header_file ⇒ Object
-
.query_header_fname ⇒ Object
header template.
Instance Method Summary collapse
-
#category_enum ⇒ Object
Enum for RailsAdmin form.
-
#geolion_gdd(site) ⇒ Object
Enum for RailsAdmin form (causes exception in name search) def parent_enum Topic.all.collect {|p| [ p.name, p.id ] } end.
- #icon_fname ⇒ Object
- #info_header ⇒ Object
- #info_header_file ⇒ Object
-
#info_header_fname ⇒ Object
header template for each topic.
- #legend ⇒ Object
- #legend_file ⇒ Object
- #legend_file_auto ⇒ Object
-
#legend_fname ⇒ Object
Topic legend collection.
- #print_disclaimer ⇒ Object
- #query(ability, query_topic, search_geom, nearest = nil, user = nil, client_srid = nil) ⇒ Object
-
#query_layers(ability, active_layers) ⇒ Object
TODO: 0.5s.
- #roles ⇒ Object
Class Method Details
.default_print_disclaimer ⇒ Object
print disclaimer
161 162 163 |
# File 'app/models/topic.rb', line 161 def self.default_print_disclaimer File.open(File.join(Rails.root, 'app', 'views', 'topics', '_print_disclaimer.txt'), 'r') { |f| f.read } end |
.list(app, current_ability, zone, wms_host) ⇒ Object
Structure for Topic selection
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/topic.rb', line 39 def self.list(app, current_ability, zone, wms_host) topics = [] ActiveRecord::Base.silence do app.gbapplications_categories.includes(:category).each do |gbapplications_category| category = gbapplications_category.category unless category.nil? category_topics = category.topics.accessible_by(current_ability) category_topics = category_topics.includes(:organisation).includes(:bg_topic).includes(:overlay_topics) # optimize query performance category_topics = category_topics.select('topics.*,categories_topics.sort AS categories_topics_sort') topics += category_topics.collect do |topic| subtopics = category_topics.select{|t| t.parent_id == topic.id}.collect do |subtopic| { "subtopicname" => subtopic.name, "subtopictitle" => subtopic.sub_title, "categories_topics_sort" => subtopic['categories_topics_sort'].to_i } end categorysort = gbapplications_category.sort - 1000*gbapplications_category.gbapp_specific rescue nil tools = Tool.accessible_tools(topic, current_ability) keywords = topic.title.split + (topic.keywords || '').split(',').collect(&:strip) { "name" => topic.name, "title" => topic.title, "print_title" => topic.print_title, "icon" => "/images/custom/themekl-#{topic.name.downcase}.gif", "organisationtitle" => topic.organisation.try(:title), "organisationsort" => topic.organisation.try(:sort), "categorytitle" => category.title, "gbapp_specific" => gbapplications_category.gbapp_specific, "categorysort" => categorysort, "categories_topics_sort" => topic['categories_topics_sort'].to_i, "keywords" => keywords, "geoliongdd" => topic.geolion_gdd(zone), "parent_id" => topic.parent_id, "hassubtopics" => subtopics.size > 0, "subtopics" => subtopics, "missingpermission" => current_ability.cannot?(:show, topic), "tools" => tools, "ollayer_class" => topic.ollayer_class, #z.B. "WMS" "ollayer_type" => topic.ollayer_args, #z.B. { name: "NASA Global Mosaic", url: "http://wms.jpl.nasa.gov/wms.cgi", params: {layers: "modis,global_mosaic"} } "bg_topic" => topic.bg_topic.try(:name), "overlay_topics" => topic..collect(&:name), "wms_url" => "#{wms_host}/#{topic.name}", "background_layer" => topic.background_layer, "main_layer" => topic.main_layer, "overlay_layer" => topic., "minscale" => topic.minscale, "gb1_params" => topic.gb1_params #TODO: generalized param for custom viewers } end end end end { "success" => true, #"activeTopic" => {"topicname" => "av", "grouping" => "theme"}, #TODO: from session "gbtopics" => topics, "results" => topics.size } end |
.query_header ⇒ Object
142 143 144 |
# File 'app/models/topic.rb', line 142 def self.query_header @query_header ||= File.exist?(query_header_file) ? "topics/#{query_header_fname[1..-10]}" : nil end |
.query_header_file ⇒ Object
138 139 140 |
# File 'app/models/topic.rb', line 138 def self.query_header_file File.join(Rails.root, 'app', 'views', 'topics', query_header_fname) end |
.query_header_fname ⇒ Object
header template
134 135 136 |
# File 'app/models/topic.rb', line 134 def self.query_header_fname "_query_header.html.erb" end |
Instance Method Details
#category_enum ⇒ Object
Enum for RailsAdmin form
25 26 27 |
# File 'app/models/topic.rb', line 25 def category_enum Category.all.collect {|p| [ p.name, p.id ] } end |
#geolion_gdd(site) ⇒ Object
Enum for RailsAdmin form (causes exception in name search) def parent_enum
Topic.all.collect {|p| [ p.name, p.id ] }
end
34 35 36 |
# File 'app/models/topic.rb', line 34 def geolion_gdd(site) site == SITE_DEFAULT ? geolion_gdd_internet : geolion_gdd_intranet end |
#icon_fname ⇒ Object
104 105 106 |
# File 'app/models/topic.rb', line 104 def icon_fname "themekl-#{name.downcase}.gif" end |
#info_header ⇒ Object
155 156 157 |
# File 'app/models/topic.rb', line 155 def info_header @info_header ||= File.exist?(info_header_file) ? "topics/custom/#{info_header_fname[1..-10]}" : nil end |
#info_header_file ⇒ Object
151 152 153 |
# File 'app/models/topic.rb', line 151 def info_header_file File.join(Rails.root, 'app', 'views', 'topics', 'custom', info_header_fname) end |
#info_header_fname ⇒ Object
header template for each topic
147 148 149 |
# File 'app/models/topic.rb', line 147 def info_header_fname "_#{name.downcase}_info.html.erb" end |
#legend ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'app/models/topic.rb', line 121 def legend @legend ||= begin if File.exist?(legend_file) "topics/custom/#{legend_fname[1..-10]}" elsif File.exist?(legend_file_auto) "topics/custom/auto/#{legend_fname[1..-10]}" else nil end end end |
#legend_file ⇒ Object
113 114 115 |
# File 'app/models/topic.rb', line 113 def legend_file File.join(Rails.root, 'app', 'views', 'topics', 'custom', legend_fname) end |
#legend_file_auto ⇒ Object
117 118 119 |
# File 'app/models/topic.rb', line 117 def legend_file_auto File.join(Rails.root, 'app', 'views', 'topics', 'custom', 'auto', legend_fname) end |
#legend_fname ⇒ Object
Topic legend collection
109 110 111 |
# File 'app/models/topic.rb', line 109 def legend_fname "_#{name.downcase}_legend.html.erb" end |
#print_disclaimer ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/models/topic.rb', line 165 def print_disclaimer @disclaimer ||= begin fname = File.join(Rails.root, 'app', 'views', 'topics', 'custom', "_#{name.downcase}_print_disclaimer.txt") if File.exist?(fname) # use custom topic disclaimer if there exists a corresponding text file File.open(fname, 'r') { |f| f.read } else Topic.default_print_disclaimer end end end |
#query(ability, query_topic, search_geom, nearest = nil, user = nil, client_srid = nil) ⇒ Object
182 183 184 185 186 187 188 189 190 191 |
# File 'app/models/topic.rb', line 182 def query(ability, query_topic, search_geom, nearest=nil, user=nil, client_srid=nil) active_layers = query_topic['layers'].split(',') qlayers = query_layers(ability, active_layers) results = [] qlayers.each do |layer| result = layer.query(ability, query_topic, search_geom, nearest, user, client_srid) results << result unless result.nil? end results end |
#query_layers(ability, active_layers) ⇒ Object
TODO: 0.5s
193 194 195 196 197 198 199 |
# File 'app/models/topic.rb', line 193 def query_layers(ability, active_layers) #TODO: 0.5s ActiveRecord::Base.silence do layers.accessible_by(ability).where('topics_layers.queryable').order('topics_layers.leg_sort DESC').find_all do |layer| active_layers.include?(layer.name) end end end |
#roles ⇒ Object
177 178 179 180 |
# File 'app/models/topic.rb', line 177 def roles perms = Permission.where(:resource_type => 'Topic', :resource => name).includes(:role) perms.collect(&:role) end |