root/Explorator/trunk/app/controllers/explorator_controller.rb @ 128

Revision 128, 4.4 KB (checked in by samuraraujo, 5 years ago)
Line 
1require "date"
2require "set"
3#This controller handles all users request that performs a changing in the domain model.
4#Author: Samur Araujo
5#Date: 25 jun 2008.
6
7#module where the SemanticExpression class is defined.
8require 'query_builder'
9#module where the query class is defined.
10require 'query_factory'
11
12class ExploratorController < ApplicationController 
13  require_dependency "resource_set"
14  require_dependency "explorator_application"
15  # attr_accessor :resourceset
16  #default rails method. returns the view index.rhtml.
17  def index       
18end
19 
20def resourcefilter
21   @resourceset =  Application.get(params[:uri]) 
22   render  :partial => 'subject_view',:layout=>false;
23end 
24  #  prints the filter screen
25  def filter   
26    @setid=params[:uri]
27    render :partial => 'filter',:layout=>false;
28  end
29  # This create method  a ResourceSet based on the Semantic Expression passed
30  # by the parameter 'exp';
31  # The exp value must be a valid SemanticExpression class instance.
32  #Request sample:
33  #/explorator/create?exp=SemanticExpression.new.union(:s,Namespace.lookup(:rdf,:type),Namespace.lookup(:rdfs,:Class))
34  def create   
35    puts params[:exp]
36    #creates a new set.
37    #the expression must be passed by the uri
38    set = EXPLORATOR::Set.new('http://www.tecweb.inf.puc-rio.br/resourceset/id/' + UUID.random_create.to_s)       
39    set.init(params[:exp])
40
41    #the object @resourceset is a global object that will be used by render
42    @resourceset = set     
43    view = params['view']
44    view = 'subject_view' if  params['view'] == nil || params['view'] == 'null'
45    #render the _window.rhtml view
46    render :partial => view,:layout=>false;
47  end
48  # The  update method updates a specfic ResourceSet instance identified by the parameter id.
49  # The new value will be defined by the expression passed by the parameter exp.
50  # The exp value must be a valid SemanticExpression class instance and the ResourceSet instance
51  # must has been defined before.
52  def update     
53       puts params[:exp]
54    #reevaluate the expression and return the set
55    resource = session[:application].get(params[:uri])
56 
57    resource.expression = params[:exp] 
58   
59    #the object @resourceset is a global object that will be used by render   
60    @resourceset =  session[:application].get(params[:uri]) 
61   
62    #render the _window.rhtml view
63    render :partial => 'subject_view', :layout=>false
64  end
65  #The execute method  evaluate a ruby expression.
66  #this method is used to invoke another method of Explorator.
67  #Basically, the UI call this method passing as the expression a
68  # call to the method refresh or remove.
69  def execute
70    #eval an expression   
71    puts params[:exp]
72    eval (params[:exp])
73  end
74 
75  #The reload method is used to return a specific range of resources from a ResourceSet
76  #This method is used by the UI when the user is accessing the paginatition indexes.
77  #The UI pass 2 parameters, the ResourceSet id and an offset value.
78  def reload 
79    #return a specific set of resource considering an offset.
80    @resourceset= session[:application].get(params[:uri]).setWithOffset( params[:offset])   
81    #render the _window.rhtml view
82    render :partial => params[:view]  , :layout=>false
83  end
84  #This method execute a ruby code over all array elements.
85  def map
86   
87  end
88  #The remove method removes a determined ResourceSet from the SetsPool or a specific resource from a ResourceSet
89  #This method is called by the execute method, being passing as parameter by the user interface.
90  def remove(uri)       
91    #for remove only one resource in the context
92    session[:application].remove(uri)   
93    render :text => '', :layout=>false
94  end
95  #The refresh method return a determined ResourceSet from the SetsPool
96  #This method is called by the Execute method, being passed as a parameter by the interface.
97  def refresh(uri,view=:subject_view, filter='')   
98    @resourceset= session[:application].get(uri).setWithOffset(0)   
99     @filter=filter
100    #render the _window.rhtml view
101    render :partial => view.to_s , :layout=>false
102  end
103 
104  def addfilter     
105    @resourceset= session[:application].get(params[:uri])
106    @resourceset.addFilter("filter('select{|i| i.to_i" + params[:op] +  params[:value]+ "}')")
107    render :partial => "subject_view" , :layout=>false
108  end
109  def sum
110    @resourceset= session[:application].get(params[:uri])
111    @resourceset.sum() 
112      render :partial => "subject_view" , :layout=>false
113  end
114 
115end
Note: See TracBrowser for help on using the browser.