Class: EasyDatasController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- EasyDatasController
- Defined in:
- lib/controllers/easy_datas_controller.rb
Instance Method Summary collapse
-
#access_to_data ⇒ Object
Information about access to publicated data.
- #authenticate_user ⇒ Object
- #custom_attributes ⇒ Object
- #custom_rdf ⇒ Object
- #custom_settings ⇒ Object
-
#faq ⇒ Object
FAQ.
-
#info_easy_data ⇒ Object
Show information about data publications.
-
#linked_data ⇒ Object
Generate Linked Data Graph.
- #load_classes ⇒ Object
- #load_linked_data_graph ⇒ Object
- #load_properties ⇒ Object
- #login ⇒ Object
- #logout ⇒ Object
- #model_attributes ⇒ Object
- #model_attributes_edit ⇒ Object
- #model_attributes_info ⇒ Object
-
#models ⇒ Object
Access to list of model of Data Model.
- #refresh_information ⇒ Object
- #settings ⇒ Object
- #show ⇒ Object
- #show_all ⇒ Object
- #view_settings ⇒ Object
Instance Method Details
#access_to_data ⇒ Object
Information about access to publicated data
101 102 |
# File 'lib/controllers/easy_datas_controller.rb', line 101 def access_to_data end |
#authenticate_user ⇒ Object
315 316 |
# File 'lib/controllers/easy_datas_controller.rb', line 315 def authenticate_user end |
#custom_attributes ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/controllers/easy_datas_controller.rb', line 227 def custom_attributes rdf = ModelRdf.new @model = params[:model] params["rdf_type_attributes"].each do |att,value| rdf.update_attributes_model(params[:model],att,'namespace',value) if value != "" if params["attributes_property"] && !params["attributes_property"][att].nil? rdf.update_attributes_model(params[:model],att,'property',params["attributes_property"][att]) end rdf.update_attributes_model(params[:model],att,'privacy',params[:privacy][att]) end params["rdf_type_associations"].each do |assoc,value| if value != "" rdf.update_associations_model(params[:model],assoc,'namespace',value) end if params["associations_property"] && params["associations_property"][assoc] rdf.update_associations_model(params[:model],assoc,'property',params["associations_property"][assoc]) end rdf.update_associations_model(params[:model],assoc,'privacy',params[:privacy][assoc]) end rdf.update_model(params[:model],"privacy",params[:privacy][params[:model]]) if params[:privacy][params[:model]] if params[:property] rdf.update_model(params[:model],"namespace",params[:namespace][params[:model]]) rdf.update_model(params[:model],"property",params[:property][params[:model]]) end rdf.save @model_attributes = rdf.get_attributes_model(@model) render :partial => "model_attributes",:layout => nil end |
#custom_rdf ⇒ Object
126 127 128 129 |
# File 'lib/controllers/easy_datas_controller.rb', line 126 def custom_rdf @models = DataModels.load_models @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) end |
#custom_settings ⇒ Object
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/controllers/easy_datas_controller.rb', line 279 def custom_settings @settings = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) if !params["project"]["project"].empty? && params["project"]["project"]!=@settings["project"]["name"] @settings["project"]["name"] = params["project"]["project"] end if !params["project"]["logo"].empty? && params["project"]["logo"]!=@settings["project"]["logo"] @settings["project"]["logo"] = params["project"]["logo"] end if !params["project"]["description"].empty? && params["project"]["description"]!=@settings["project"]["description"] @settings["project"]["description"] = params["project"]["description"] end if !params["project"]["email"].empty? && params["project"]["email"]!=@settings["project"]["contact_email"] @settings["project"]["contact_email"] = params["project"]["email"] end if !params["user_admin"]["user"].empty? && !params["user_admin"]["pass"].empty? (@settings["user_admin"]["user"] = params["user_admin"]["user"]) if @settings["user_admin"]["user"]!=params["user_admin"]["user"] (@settings["user_admin"]["pass"] = params["user_admin"]["pass"]) if @settings["user_admin"]["pass"]!=params["user_admin"]["pass"] end (@settings["access"]["ip"] = params["access"]["ip"]) if params["access"]["ip"]!=@settings["access"]["ip"] && params["access"]["ip"]!= "" save_settings(@settings) render :template => "easy_datas/view_settings",:layout => false end |
#faq ⇒ Object
FAQ
109 110 |
# File 'lib/controllers/easy_datas_controller.rb', line 109 def faq end |
#info_easy_data ⇒ Object
Show information about data publications
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/controllers/easy_datas_controller.rb', line 84 def info_easy_data rdf = ModelRdf.new models = rdf.get_not_hidden_models @list = [] @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) models.each do |mod| @list << "#{mod.gsub("::","_")}" end respond_to do |format| format.html format.xml end end |
#linked_data ⇒ Object
Generate Linked Data Graph
105 106 |
# File 'lib/controllers/easy_datas_controller.rb', line 105 def linked_data end |
#load_classes ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/controllers/easy_datas_controller.rb', line 183 def load_classes unless params[:id] == "" namespace = "EasyData::RDF::#{params[:id].upcase}" rdf = ModelRdf.new @namespace = params[:id] @model_attributes = rdf.get_attributes_model(params[:model]) classes = (eval namespace).classes_form render :inline => "<span>Class:</span><%= select 'property',attribute,properties,{:prompt => 'Select a class...'} -%><span class='rdf_info'>(Current value: <%= current_value%>)</span><br />", :locals => {:properties => classes, :attribute => params[:model], :current_value => @model_attributes[:property]} else render :inline => "" end end |
#load_linked_data_graph ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/controllers/easy_datas_controller.rb', line 204 def load_linked_data_graph if params[:model] @model = params[:model] @associations = ModelRdf.new.get_associations_model(@model) @host = "http://"+request.env["HTTP_HOST"] render :partial => "linked_data_model" else rdf = ModelRdf.new models = [] DataModels.load_models.each do |mod| unless rdf.hidden?(mod) models << mod end end @list = [] models.each do |mod| @list << "#{mod.gsub("::","_")}" end render :partial => "linked_datas",:layout => nil end end |
#load_properties ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/controllers/easy_datas_controller.rb', line 161 def load_properties unless params[:id] == "" namespace = "EasyData::RDF::#{params[:id].upcase}" rdf = ModelRdf.new @namespace = params[:id] @model_attributes = rdf.get_attributes_model(params[:model]) properties = (eval namespace).properties_form render :inline => "<span>Property:</span><%= select type+'_property',attribute,properties,{:prompt => 'Select a property...'} -%><span class='rdf_info'>(Current value: <%= current_value%>)</span>", :locals => {:properties => properties, :type => params[:type], :attribute => params[:attribute], :current_value => @model_attributes[params[:type]][params[:attribute]][:property]} else render :inline => "" end end |
#login ⇒ Object
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/controllers/easy_datas_controller.rb', line 318 def login @admin = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) if @admin["user_admin"]["user"] == params[:nick] && @admin["user_admin"]["password"] == params[:pass] @current_user = params[:nick] session[:easy_data_session] = params[:nick] redirect_to :action => "custom_rdf" else redirect_to :authenticate_user end end |
#logout ⇒ Object
330 331 332 333 334 |
# File 'lib/controllers/easy_datas_controller.rb', line 330 def logout @current_user = nil session[:easy_data_session]=nil if !session[:easy_data_session].nil? redirect_to :action => "authenticate_user" end |
#model_attributes ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/controllers/easy_datas_controller.rb', line 131 def model_attributes rdf = ModelRdf.new @model_attributes = rdf.get_attributes_model(params[:model]) @model = params[:model] render :partial => "model_attributes",:layout => nil end |
#model_attributes_edit ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/controllers/easy_datas_controller.rb', line 140 def model_attributes_edit rdf = ModelRdf.new @model_attributes = rdf.get_attributes_model(params[:model]) @model = params[:model] @namespaces = EasyData::RDF::Namespaces.list_form render :partial => "model_attributes_edit",:layout => nil end |
#model_attributes_info ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/controllers/easy_datas_controller.rb', line 152 def model_attributes_info rdf = ModelRdf.new @model_attributes = rdf.get_attributes_model(params[:model]) @model = params[:model] render :partial => "model_attributes_info",:layout => nil end |
#models ⇒ Object
Access to list of model of Data Model
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/controllers/easy_datas_controller.rb', line 113 def models @xml = Builder::XmlMarkup.new rdf = ModelRdf.new @list = rdf.get_not_hidden_models @host="http://"+request.env["SERVER_NAME"] respond_to do |format| format.html format.xml # render :template => "/rdf/request.xml.builder" end end |
#refresh_information ⇒ Object
310 311 312 313 |
# File 'lib/controllers/easy_datas_controller.rb', line 310 def refresh_information EasyData.refresh_information redirect_to :action => "custom_rdf" end |
#settings ⇒ Object
273 274 275 276 277 |
# File 'lib/controllers/easy_datas_controller.rb', line 273 def settings @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) @images = Dir["#{RAILS_ROOT}/public/images/*"].map{|img| [img.gsub("#{RAILS_ROOT}/public/images/",""),img.gsub("#{RAILS_ROOT}/public/images/","")]} render :partial => "settings",:layout => nil end |
#show ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/controllers/easy_datas_controller.rb', line 11 def show if params[:id].nil? && params[:model] == params[:model].pluralize #Because, the model's name is the sames in pluralize format, example: News redirect_to :action => "show_all",:locals => {:model => params[:model]} end begin model = eval params[:model].to_s conditions = parser_params(params) rdf = ModelRdf.new @model_info = rdf.get_attributes_model params[:model] no_valid = lambda{|c| c.nil?||c.empty?} @reply = model.find :all, :conditions => {:id => params[:id]} unless @reply.nil? @host="http://"+request.env["HTTP_HOST"]+request.env["SCRIPT_NAME"] @rdf_model = rdf.get_model_rdf(@reply,params[:model],@host) end @xml = Builder::XmlMarkup.new if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated render :nothing => true, :status => 400 else respond_to do |format| format.html format.xml # render :template => "/rdf/request.xml.builder" end end rescue render :nothing => true, :status => 404 end end |
#show_all ⇒ Object
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 |
# File 'lib/controllers/easy_datas_controller.rb', line 50 def show_all begin model = eval params[:model].to_s rdf = ModelRdf.new @model_info = rdf.get_attributes_model params[:model] no_valid = lambda{|c| c.nil?||c.empty?} @reply = model.find :all || nil @host="http://"+request.env["HTTP_HOST"]+request.env["SCRIPT_NAME"] @rdf_model = rdf.get_model_rdf(@reply,params[:model],@host) @xml = Builder::XmlMarkup.new if no_valid.call(@rdf_model[:header]) || @reply.nil? # If the URI not available or data no publicated render :nothing => true, :status => 404 else respond_to do |format| format.html format.xml # render :template => "/rdf/request.xml.builder" end end rescue render :nothing => true, :status => 404 end end |
#view_settings ⇒ Object
268 269 270 271 |
# File 'lib/controllers/easy_datas_controller.rb', line 268 def view_settings @settings ||= YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/setting.yaml")) render :template => "easy_datas/view_settings", :layout => false end |