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

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