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.
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
- #legend ⇒ Object
- #legend_file ⇒ Object
- #legend_file_auto ⇒ Object
-
#legend_fname ⇒ Object
Topic legend collection.
- #print_disclaimer ⇒ Object
- #query(ability, query_topic, searchbbox) ⇒ Object
-
#query_layers(ability, active_layers) ⇒ Object
TODO: 0.5s.
- #roles ⇒ Object
Class Method Details
.default_print_disclaimer ⇒ Object
print disclaimer
142 143 144 |
# File 'app/models/topic.rb', line 142 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 |
# File 'app/models/topic.rb', line 39 def self.list(app, current_ability, zone, wms_host) topics = [] app.gbapplications_categories.includes(:category).each do |gbapplications_category| category = gbapplications_category.category unless category.nil? category_topics = category.topics.accessible_by(current_ability).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 } end end end { "success" => true, #"activeTopic" => {"topicname" => "av", "grouping" => "theme"}, #TODO: from session "gbtopics" => topics, "results" => topics.size } 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
99 100 101 |
# File 'app/models/topic.rb', line 99 def icon_fname "themekl-#{name.downcase}.gif" end |
#info_header ⇒ Object
136 137 138 |
# File 'app/models/topic.rb', line 136 def info_header @info_header ||= File.exist?(info_header_file) ? "topics/custom/#{info_header_fname[1..-10]}" : nil end |
#info_header_file ⇒ Object
132 133 134 |
# File 'app/models/topic.rb', line 132 def info_header_file File.join(Rails.root, 'app', 'views', 'topics', 'custom', info_header_fname) end |
#info_header_fname ⇒ Object
128 129 130 |
# File 'app/models/topic.rb', line 128 def info_header_fname "_#{name.downcase}_info.html.erb" end |
#legend ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/topic.rb', line 116 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
108 109 110 |
# File 'app/models/topic.rb', line 108 def legend_file File.join(Rails.root, 'app', 'views', 'topics', 'custom', legend_fname) end |
#legend_file_auto ⇒ Object
112 113 114 |
# File 'app/models/topic.rb', line 112 def legend_file_auto File.join(Rails.root, 'app', 'views', 'topics', 'custom', 'auto', legend_fname) end |
#legend_fname ⇒ Object
Topic legend collection
104 105 106 |
# File 'app/models/topic.rb', line 104 def legend_fname "_#{name.downcase}_legend.html.erb" end |
#print_disclaimer ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/models/topic.rb', line 146 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, searchbbox) ⇒ Object
163 164 165 166 167 168 169 170 171 172 |
# File 'app/models/topic.rb', line 163 def query(ability, query_topic, searchbbox) active_layers = query_topic['layers'].split(',') qlayers = query_layers(ability, active_layers) results = [] qlayers.each do |layer| result = layer.query(ability, query_topic, searchbbox) results << result unless result.nil? end results end |
#query_layers(ability, active_layers) ⇒ Object
TODO: 0.5s
174 175 176 177 178 |
# File 'app/models/topic.rb', line 174 def query_layers(ability, active_layers) #TODO: 0.5s 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 |
#roles ⇒ Object
158 159 160 161 |
# File 'app/models/topic.rb', line 158 def roles perms = Permission.where(:resource_type => 'Topic', :resource => name).includes(:role) perms.collect(&:role) end |