incubator-alois-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fla...@apache.org
Subject svn commit: r1031127 [7/22] - in /incubator/alois/trunk: ./ bin/ debian/ doc/ etc/ etc/alois/ etc/alois/apache2/ etc/alois/environments/ etc/alois/prisma/ etc/cron.d/ etc/default/ etc/logrotate.d/ prisma/ prisma/bin/ prisma/conf/ prisma/conf/prisma/ pr...
Date Thu, 04 Nov 2010 18:27:42 GMT
Added: incubator/alois/trunk/rails/README
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/README?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/README (added)
+++ incubator/alois/trunk/rails/README Thu Nov  4 18:27:22 2010
@@ -0,0 +1,180 @@
+== Welcome to Rails
+
+Rails is a web-application and persistence framework that includes everything
+needed to create database-backed web-applications according to the
+Model-View-Control pattern of separation. This pattern splits the view (also
+called the presentation) into "dumb" templates that are primarily responsible
+for inserting pre-built data in between HTML tags. The model contains the
+"smart" domain objects (such as Account, Product, Person, Post) that holds all
+the business logic and knows how to persist themselves to a database. The
+controller handles the incoming requests (such as Save New Account, Update
+Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in 
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails.  You can read more about Action Pack in 
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting started
+
+1. Start the web server: <tt>ruby script/server</tt> (run with --help for options)
+2. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
+3. Follow the guidelines to start developing your application
+
+
+== Web servers
+
+Rails uses the built-in web server in Ruby called WEBrick by default, so you don't
+have to install or configure anything to play around. 
+
+If you have lighttpd installed, though, it'll be used instead when running script/server.
+It's considerably faster than WEBrick and suited for production use, but requires additional
+installation and currently only works well on OS X/Unix (Windows users are encouraged
+to start with WEBrick). We recommend version 1.4.11 and higher. You can download it from
+http://www.lighttpd.net.
+
+If you want something that's halfway between WEBrick and lighttpd, we heartily recommend
+Mongrel. It's a Ruby-based web server with a C-component (so it requires compilation) that
+also works very well with Windows. See more at http://mongrel.rubyforge.org/.
+
+But of course its also possible to run Rails with the premiere open source web server Apache.
+To get decent performance, though, you'll need to install FastCGI. For Apache 1.3, you want
+to use mod_fastcgi. For Apache 2.0+, you want to use mod_fcgid.
+
+See http://wiki.rubyonrails.com/rails/pages/FastCGI for more information on FastCGI.
+
+== Example for Apache conf
+
+  <VirtualHost *:80>
+    ServerName rails
+    DocumentRoot /path/application/public/
+    ErrorLog /path/application/log/server.log
+  
+    <Directory /path/application/public/>
+      Options ExecCGI FollowSymLinks
+      AllowOverride all
+      Allow from all
+      Order allow,deny
+    </Directory>
+  </VirtualHost>
+
+NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
+should be on and ".cgi" should respond. All requests from 127.0.0.1 go
+through CGI, so no Apache restart is necessary for changes. All other requests
+go through FCGI (or mod_ruby), which requires a restart to show changes.
+
+
+== Debugging Rails
+
+Have "tail -f" commands running on both the server.log, production.log, and
+test.log files. Rails will automatically display debugging and runtime
+information to these files. Debugging info will also be shown in the browser
+on requests from 127.0.0.1.
+
+
+== Breakpoints
+
+Breakpoint support is available through the script/breakpointer client. This
+means that you can break out of execution at any point in the code, investigate
+and change the model, AND then resume execution! Example:
+
+  class WeblogController < ActionController::Base
+    def index
+      @posts = Post.find_all
+      breakpoint "Breaking out from the list"
+    end
+  end
+  
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the breakpointer window. Here you can do things like:
+
+Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
+
+  >> @posts.inspect
+  => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>, 
+       #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+  >> @posts.first.title = "hello from a breakpoint"
+  => "hello from a breakpoint"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+  >> f = @posts.first 
+  => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+  >> f.
+  Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you press CTRL-D
+
+
+== Console
+
+You can interact with the domain model by starting the console through script/console. 
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+
+== Description of contents
+
+app
+  Holds all the code that's specific to this particular application.
+
+app/controllers
+  Holds controllers that should be named like weblog_controller.rb for
+  automated URL mapping. All controllers should descend from
+  ActionController::Base.
+
+app/models
+  Holds models that should be named like post.rb.
+  Most models will descend from ActiveRecord::Base.
+  
+app/views
+  Holds the template files for the view that should be named like
+  weblog/index.rhtml for the WeblogController#index action. All views use eRuby
+  syntax. This directory can also be used to keep stylesheets, images, and so on
+  that can be symlinked to public.
+  
+app/helpers
+  Holds view helpers that should be named like weblog_helper.rb.
+
+app/apis
+  Holds API classes for web services.
+
+config
+  Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+components
+  Self-contained mini-applications that can bundle together controllers, models, and views.
+
+db
+  Contains the database schema in schema.rb.  db/migrate contains all
+  the sequence of Migrations for your schema.
+
+lib
+  Application specific libraries. Basically, any kind of custom code that doesn't
+  belong under controllers, models, or helpers. This directory is in the load path.
+    
+public
+  The directory available for the web server. Contains subdirectories for images, stylesheets,
+  and javascripts. Also contains the dispatchers and the default HTML files.
+
+script
+  Helper scripts for automation and generation.
+
+test
+  Unit and functional tests along with fixtures.
+
+vendor
+  External libraries that the application depends on. Also includes the plugins subdirectory.
+  This directory is in the load path.

Added: incubator/alois/trunk/rails/Rakefile
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/Rakefile?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/Rakefile (added)
+++ incubator/alois/trunk/rails/Rakefile Thu Nov  4 18:27:22 2010
@@ -0,0 +1,12 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+require "libisi"
+init_libisi(:ui => "console")
+
+require(File.join(File.dirname(__FILE__), 'config', 'boot'))
+
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+require 'tasks/rails'

Added: incubator/alois/trunk/rails/app/controllers/alarms_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/alarms_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/alarms_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/alarms_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,98 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class AlarmsController < ApplicationController
+  include ApplicationHelper
+  
+  def index
+    status
+    render :action => 'status'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def status
+    @alarms = Alarm.paginate :page => params[:page], :order => "alarm_level, created_at DESC", :per_page => 10,
+      :conditions => Alarm::ACTIVE_YELLOW_RED_CONDITION
+    @infos = Alarm.paginate :page => params[:page_info], :per_page => 10, :order => "id DESC",
+      :conditions => Alarm::ACTIVE_WHITE_CONDITION
+    @ack_alarms = Alarm.paginate :page => params[:page_ack], :limit => 10, :per_page => 10, :order => "id DESC",
+      :conditions => Alarm::ACKNOWLEDGE_CONDITION
+  end
+
+  def list
+    status
+    render :action => 'status'
+  end
+
+  def listing    
+    @alarms = Alarm.paginate :page => params[:page], :order => "id DESC"
+    render :action => 'list'
+  end
+
+  def show
+    @alarm = Alarm.find(params[:id])
+  end
+
+  def new
+    @alarm = Alarm.new
+  end
+
+  def create
+    @alarm = Alarm.new(params[:alarm])
+    if @alarm.save
+      flash[:notice] = 'Alarm was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @alarm = Alarm.find(params[:id])
+  end
+
+  def update
+    @alarm = Alarm.find(params[:id])
+    params[:alarm] = {} unless params[:alarm]
+    params[:alarm][:updated_by] = user
+    if @alarm.update_attributes(params[:alarm])
+      flash[:notice] = 'Alarm was successfully updated.'
+      redirect_to :action => 'show', :id => @alarm
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    raise "Not supported"
+    Alarm.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+
+  def survey_component
+    @alarm_pages, @alarms = paginate :alarms, :per_page => 10, :order => "id DESC"    
+    render :partial => "survey_component"
+  end
+
+  # ACL: admin
+  def send_to_email
+    raise "No address given." unless params[:addresses]
+    @alarm = Alarm.find(params[:id])
+    AlarmMailer.deliver_simple(params[:addresses], @alarm)
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/alois_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/alois_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/alois_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/alois_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,21 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class AloisController < ActionController::Base
+
+  def index
+    redirect_to :controller => 'prisma', :action => 'overview'
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/application_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/application_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/application_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/application_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,76 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Filters added to this controller will be run for all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+class ApplicationController < ActionController::Base
+  include ApplicationHelper
+  helper :alarms
+#  around_filter :catch_exceptions
+    
+  private
+  def catch_exceptions
+    yield
+  rescue => exception
+    render_text "<pre>#{$!}</pre>",:layout => true  
+  end
+
+  public  
+
+  def local_request?
+    false
+  end
+
+  def rescue_action_in_public(exception)
+    @exception = exception
+    @exception_name = exception.class.to_s.underscore
+    if (@template.pick_template_extension("exception/#{@exception_name}") rescue nil)
+      render :partial => "exception/#{@exception_name}", :layout => true
+    else
+      render :partial => "exception/generic", :layout => true
+    end
+  end
+
+
+  if $selected_theme.respond_to?(:helper) then 
+    helper :application, $selected_theme.helper 
+  end
+  
+  if $selected_theme and $selected_theme.respond_to?(:layout) and $selected_theme.layout
+    layout  $selected_theme.layout
+  end
+
+  def render(options = nil, &block)
+    if params[:layout] == "false"
+      options ||= {}
+      options[:layout] ||= false
+    end
+    super
+  end
+  
+  def auto_complete_for_condition_value    
+    render :inline => "<%= content_tag(:ul, Time.suggest(params[:condition][:value]).map { |org| content_tag(:li, h(org)) }) %>"
+  end
+
+  FLASH_COLORS = {:info => "green",
+    :warning => "orange",
+    :error => "red"}
+
+  def flash_text
+    (flash || {}).map {|key,val|
+      "<p style='color: #{FLASH_COLORS[key] || "orange"}'>#{val}</p>"
+    }.join
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/bookmarks_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/bookmarks_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/bookmarks_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/bookmarks_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,74 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class BookmarksController < ApplicationController
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @bookmarks = Bookmark.paginate :page => params[:page]
+  end
+
+  def show
+    @bookmark = Bookmark.find(params[:id])
+  end
+
+  def go
+    @bookmark = Bookmark.find(params[:id])
+    redirect_to @bookmark.url
+  end
+
+  def new    
+    unless params[:bookmark]
+      @bookmark = Bookmark.new
+    else
+      @bookmark = Bookmark.new(params[:bookmark])
+    end
+  end
+
+  def create
+    @bookmark = Bookmark.new(params[:bookmark])
+    if @bookmark.save
+      flash[:notice] = 'Bookmark was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @bookmark = Bookmark.find(params[:id])
+  end
+
+  def update
+    @bookmark = Bookmark.find(params[:id])
+    if @bookmark.update_attributes(params[:bookmark])
+      flash[:notice] = 'Bookmark was successfully updated.'
+      redirect_to :action => 'show', :id => @bookmark
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    Bookmark.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/charts_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/charts_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/charts_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/charts_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,141 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class ChartsController < ApplicationController
+  include ApplicationHelper
+  include SurveyHelper
+  before_filter :handle_cancel, :only => [ :new, :create, :update ]
+  before_filter :init
+  
+  private
+  def init
+    initialize_parameters
+  end
+
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+  
+  public
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+#  verify :method => :post, :only => [ :destroy, :create, :update, :render_chart ],
+#         :redirect_to => { :action => :list }
+
+  def list
+    @charts = Chart.find :all
+  end
+
+  def show
+    @chart = Chart.find(params[:id])
+  end
+
+  def render_chart
+    @chart = Chart.find(params[:id])
+    redirect_to :controller => "survey", :action => "chart", 
+      :chart_id => @chart.id, :state_id => @state_id, :table => current_datasource.table.table_name
+#    @chart.datasource = current_datasource
+#    if @chart.datasource
+#      @chart.render
+#    end
+  end
+
+  def render_chart_inline
+    render_chart
+    render :partial => "render_chart_inline"
+  end
+
+  def chart_image
+    @chart = Chart.find(params[:id]) if params[:id]
+
+    if @chart.mode == :view_only
+      raise "Preview not allowed for view_only chart" if params[:preview]
+      raise "Recreate data not allowed for view_only chart" if params[:recreate_data]
+    else
+      @chart.mode = :preview if params[:preview]
+      @chart.datasource = current_datasource
+      @chart.render(:recreate_data => params[:recreate_data]) if @chart.datasource
+    end
+
+    headers['Cache-Control'] = 'no-cache, must-revalidate'
+    send_file( @chart.png_file_name,
+	      :disposition => 'inline',
+	      :type => 'image/png', 
+	      :filename => @chart.image_name)
+  end
+
+
+  def show_inline
+    render :layout => false
+  end
+
+  def new
+    initialize_parameters
+    if @chart
+      @chart = @chart.full_clone
+      @chart.mode = nil
+      @chart.datasource = current_datasource
+    else
+      @chart = Chart.new
+    end
+    
+    @chart.attributes = params[:chart] if params[:chart]
+    save_session
+  end
+
+  def edit_inline
+    render :partial => "form"
+  end
+
+  def edit
+    @chart = Chart.find(params[:id])    
+  end
+
+  def create
+    @chart = Chart.new(params[:chart])
+    @chart.datasource = current_datasource
+    
+    if @chart.save
+      flash[:notice] = 'Chart was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def update
+    @chart = Chart.find(params[:id])    
+    if @chart.update_attributes(params[:chart])
+      flash[:notice] = 'Chart was successfully updated.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    Chart.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+  def auto_complete_for_chart_time_range
+    render :inline => "<%= content_tag(:ul, Time.suggest(params[:chart][:time_range]).map { |org| content_tag(:li, h(org)) }) %>"
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/exception_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/exception_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/exception_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/exception_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,21 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class ExceptionController < ApplicationController
+
+  def record_not_found
+
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/filters_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/filters_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/filters_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/filters_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,190 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class FiltersController < ApplicationController
+  include ApplicationHelper
+  before_filter :handle_cancel, :only => [ :new, :create, :update ]
+  
+  private
+  def filter_class
+    # otherwise rails filter class would be returned
+    View.instance_eval("Filter")
+  end
+
+  def init
+    initialize_parameters
+    
+    @table_class = Prisma::Database.get_class_from_tablename(@table_name) if defined?(Prisma::Database)
+    @table_class = View.get_class_from_tablename(@table_name) unless @table_class
+    @conditions = @current_filter.conditions if @current_filter
+
+    if params[:id] and params[:id].to_s != @current_filter.id.to_s
+      @current_filter = filter_class.find(params[:id])
+    end
+  end
+
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+  
+  public
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+#  verify :method => :post, :only => [ :destroy, :create, :update, :update_condition ],
+#         :redirect_to => { :action => :list }
+
+  def list
+    init
+    @filters = filter_class.find(:all,:order => "name")
+  end
+
+  def show
+    init
+  end
+
+  def show_inline
+    init
+    render :layout => false
+  end
+
+  def new
+    init
+    @current_filter = filter_class.new(:name => "new") if (@current_filter.nil? or !params[:use_current])
+    @current_filter = filter_class.from_zip(params[:filter_zip]) if params[:filter_zip]
+    save_session
+  end
+
+  def edit_inline
+    init
+    render :partial => "form"
+  end
+
+  def edit
+    init
+    @conditions = @current_filter.conditions()
+    save_session
+  end
+
+  def create
+    init
+    if @current_filter
+      @current_filter.update_attributes(params[:current_filter])
+    else
+      @current_filter = filter_class.new(params[:current_filter])
+    end
+    
+    if @current_filter.save
+#redo      flash[:notice] = 'filter_class was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def add_condition
+    init
+    @current_filter = filter_class.new unless @current_filter
+    @current_filter.conditions = @current_filter.conditions << 
+      Condition.create(params[:column], params[:operator], params[:value])
+
+    if @current_filter.valid?      
+      reset_paging
+      save_session
+    else
+      @current_filter.conditions = @current_filter.conditions[0..-2]
+      flash[:warning] = "Session not saved. New filter not valid."
+    end
+    render :partial => "form"
+  end
+  
+  def remove_condition
+    init
+    @conditions[params[:condition_id].to_i..params[:condition_id].to_i] = []
+    @current_filter.conditions = @conditions
+    reset_paging
+    save_session
+    render :partial => "form"
+  end
+
+  def update_condition
+    init
+    c = @conditions[params[:condition_id].to_i]
+    c.update_from_params(params[:condition])
+    @conditions[params[:condition_id].to_i] = c
+    @current_filter.conditions = @conditions
+
+    if @current_filter.valid?
+      reset_paging
+      save_session
+    else
+      flash[:warning] = "Session not saved. New filter not valid."
+    end
+
+    render :partial => "form"    
+  end
+
+  def clear_current_filter
+    init
+    @current_filter = filter_class.new
+    reset_paging
+    save_session
+    render :partial => "form_with_functions"
+  end
+
+  def update
+    init
+    if @current_filter.update_attributes(params[:current_filter])
+      flash[:notice] = 'filter_class was successfully updated.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    init
+    filter_class.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+
+  def add_inline
+    init
+    @current_filter = filter_class.create_from_params(params)
+    @current_filter.save
+    redirect_to :action => 'list_inline'
+  end
+
+  def destroy_inline
+    init
+    filter_class.find(params[:id]).destroy
+    redirect_to :action => 'list_inline'
+  end
+
+  def list_possible_filters    
+    initialize_parameters
+    @filters = filter_class.find(:all,:order => "name").select {|f|
+      f.valid_for_table?(current_datasource)
+    }
+    render :partial => "possible_filters"
+  rescue
+    render :text => $!.to_s
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/help_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/help_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/help_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/help_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,28 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class HelpController < ApplicationController
+
+  def index
+  end
+
+  def inline 
+      render :layout => false
+  end
+
+  def hidden
+    render :layout => false
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/ip_ranges_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/ip_ranges_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/ip_ranges_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/ip_ranges_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,101 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class IpRangesController < ApplicationController
+
+  # GET /ip_ranges
+  # GET /ip_ranges.xml
+  def index
+    @ip_ranges = IpRange.find(:all)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @ip_ranges }
+    end
+  end
+
+  # GET /ip_ranges/1
+  # GET /ip_ranges/1.xml
+  def show
+    @ip_range = IpRange.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @ip_range }
+    end
+  end
+
+  # GET /ip_ranges/new
+  # GET /ip_ranges/new.xml
+  def new
+    @ip_range = IpRange.new
+
+    respond_to do |format|
+      format.html # new.html.erb
+      format.xml  { render :xml => @ip_range }
+    end
+  end
+
+  # GET /ip_ranges/1/edit
+  # POST /ip_ranges/1/edit
+  def edit
+    @ip_range = IpRange.find(params[:id])
+  end
+
+  # POST /ip_ranges
+  # POST /ip_ranges.xml
+  def create
+    @ip_range = IpRange.new(params[:ip_range])
+
+    respond_to do |format|
+      if @ip_range.save
+        flash[:notice] = 'IpRange was successfully created.'
+        format.html { redirect_to(@ip_range) }
+        format.xml  { render :xml => @ip_range, :status => :created, :location => @ip_range }
+      else
+        format.html { render :action => "new" }
+        format.xml  { render :xml => @ip_range.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # PUT /ip_ranges/1
+  # PUT /ip_ranges/1.xml
+  def update
+    @ip_range = IpRange.find(params[:id])
+
+    respond_to do |format|
+      if @ip_range.update_attributes(params[:ip_range])
+        flash[:notice] = 'IpRange was successfully updated.'
+        format.html { redirect_to(@ip_range) }
+        format.xml  { head :ok }
+      else
+        format.html { render :action => "edit" }
+        format.xml  { render :xml => @ip_range.errors, :status => :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /ip_ranges/1
+  # DELETE /ip_ranges/1.xml
+  def destroy
+    @ip_range = IpRange.find(params[:id])
+    @ip_range.destroy
+
+    respond_to do |format|
+      format.html { redirect_to(ip_ranges_url) }
+      format.xml  { head :ok }
+    end
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/prisma_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/prisma_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/prisma_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/prisma_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,255 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class PrismaController < ApplicationController
+  
+  MUNIN_DB_PATH = "/var/lib/munin/localdomain" unless defined?(MUNIN_DB_PATH)
+  STAT_NAMES = ['pumpy_count','pumpy_out','pumpy_queue','pumpy_in','alois_in','alarms_today', 'reports_today'] unless defined?(STAT_NAMES)
+
+  def PrismaController.init
+    alois_connection = Connection.from_name("alois")
+    prisma_connection = Connection.from_name("prisma")
+    pumpy_connection = Connection.from_name("pumpy")
+
+    dobby = (prisma_connection and prisma_connection.spec[:host]) or "localhost"
+    dobby = "localhost.localdomain" if dobby == "localhost"
+
+    reporter = (alois_connection and alois_connection.spec[:host]) or "localhost"
+    reporter = "localhost.localdomain" if reporter == "localhost"
+
+    sink = (pumpy_connection and pumpy_connection.spec[:host]) or "localhost"
+    sink = "localhost.localdomain" if sink == "localhost"
+=begin
+    config = read_config
+    dobby = config["alois"]["host"]
+    dobby = "localhost.localdomain" if dobby == "localhost"
+    reporter = config["reporter"]["host"]
+    reporter = "localhost.localdomain" if reporter == "localhost"
+    raise "Please define attribute 'host' for the reporter host in alois.conf." if reporter.nil? or reporter.strip == ""
+    sink = config["pumpy"]["host"]
+    sink = "localhost.localdomain" if sink == "localhost"
+=end
+    
+    if RAILS_ENV != "production"
+      pref = "http://localhost/"
+    else
+      pref = "/"
+    end
+    
+    statistic_items = [
+      {:name => "sink_flows", :link_prefix => "#{pref}munin/localdomain/#{reporter}-alois_sinkflows", :desc => "Sink Flows"},
+      {:name => "sink_queues", :link_prefix => "#{pref}munin/localdomain/#{reporter}-alois_sinkdb", :desc => "Sink Queues"},
+      {:name => "prismas", :link_prefix => "#{pref}munin/localdomain/#{reporter}-alois_aloisdb", :desc => "Prismas"}    ]
+    return [dobby,reporter,sink,statistic_items]
+  end
+
+  def init
+    @dobby,@reporter,@sink,@statistic_items = PrismaController.init
+  end
+
+  def PrismaController.statistic_image(name,interval)
+    dobby,reporter,sink,statistic_items = init
+    statistic = statistic_items.select{|s| s[:name] == name}[0]
+    throw "Statistic with name '#{name}' not found." unless statistic
+    interval = interval
+    throw "No interval defined." unless interval
+    return "<a href=\"#{statistic[:link_prefix]}.html\"><img src=\"#{statistic[:link_prefix]}-#{interval}.png\" alt=\"#{statistic[:desc]} #{interval}\" />"
+  end
+
+  def index
+    redirect_to :action => "overview"
+  end
+
+  def statistics
+    init
+  end
+  
+  def statistic
+    init
+  end
+
+  def overview
+    init()
+    render :template => "prisma/overview-#{params[:installation_schema] or $installation_schema}"
+  end
+
+  def databases
+    @connections = Connection.connections.values
+  end
+
+  def kill_query
+    @connection = Connection.connections[params[:connection_name]]
+    throw "Connection with name #{params[:connection_name]} not found." unless @connection
+    @connection.kill(params[:id].to_i)
+    sleep 1
+    flash[:info] = "Killed query '#{params[:id]}'"    
+    redirect_to :action => "databases"
+  rescue
+    flash[:error] = "Query with id '#{params[:id]}' not killed: #{$!}"
+    redirect_to :action => "databases"
+  end
+
+#  def guess_host(host)
+#    files = Pathname.glob("#{MUNIN_DB_PATH}/#{host}*.rrd")
+#    files = files.sort { |x,y| -(File.new(x).mtime <=> File.new(y).mtime)}
+#    for file in files
+#      if Pathname.new(file).split()[1].to_s =~ /^([^\-]*)\-.*$/
+#        return $1
+#      end
+#    end
+#    return nil
+#  end
+#require 'pathname'
+#  MUNIN_DB_PATH = "/var/lib/munin/localdomain"
+
+  def read_rrd(host, stat, value, last = false)
+    return 0 if RAILS_ENV != "production"
+    host = "*" unless host
+    files = Pathname.glob("#{MUNIN_DB_PATH}/#{host}-#{stat}-#{value}*.rrd")
+    files = files.sort { |x,y| -(File.new(x).mtime <=> File.new(y).mtime)}
+    
+    for file in files
+      begin
+        if last then
+	  open("|rrdtool last #{file}"){|f|
+	    for line in f
+	      return line.strip.to_f
+	    end
+	  }
+        else
+	  open("|rrdtool fetch #{file} AVERAGE -s -300 -e -300") {|f|
+	    for line in f
+	      if line =~ /^(\d*): (.*)$/
+		return $2.to_f
+	      end
+	    end
+	  }
+        end
+      rescue
+      end
+    end
+
+    throw "Could not read rrd #{host}/#{stat}/#{value}."
+  end 
+
+  def measure(type)
+    begin
+      title = "Msg/s"
+      result = "??"
+      case type
+      when "pumpy_in"
+        link = "/munin/localdomain/#{@sink}-alois_sink.html"
+        result = read_rrd(@sink, "alois_sink", "log_input_count")
+      
+      when "alois_in"
+        link = "/munin/localdomain/#{@reporter}-alois_aloisdb.html"
+        result = 0
+        for klass in Prisma::Database.get_classes(:meta) << Message
+          result = result + read_rrd(@reporter, "alois_aloisdb", "#{klass.table_name}")
+        end
+      
+      when "pumpy_queue"
+        link = "/munin/localdomain/#{@reporter}-alois_sinkdb.html"
+        title = "% Full"
+        result = RawsState.get_percentage()
+        
+      when "pumpy_count"
+        link = "/munin/localdomain/#{@reporter}-alois_sinkflows.html"
+
+        title = "Count"
+        result = 0
+        for klass in Prisma::Database.get_classes(:raw) 
+          result = result + read_rrd(@reporter, 'alois_sinkflows', "#{klass.table_name}_incoming")
+        end
+
+      when "pumpy_out"
+        link = "/munin/localdomain/#{@reporter}-alois_sinkflows.html"
+        
+        result = 0
+        for klass in Prisma::Database.get_classes(:raw) 
+          result = result + read_rrd(@reporter, "alois_sinkflows", "#{klass.table_name}_outgoing")
+        end
+
+      when "reports_today"
+	link = url_for(:controller => "reports")
+	result = Report.count(:conditions => ["date = ?", "today".to_time])
+	title = "Reports today"
+	
+      when "alarms_today"
+	link = url_for(:controller => "alarms", :action => 'status')
+	result = Alarm.count(:conditions => ["created_at >= ?", "today".to_time.strftime("%F")])
+	title = "Alarms today"
+	
+      when "yellow_alarms"
+	link = url_for(:controller => "alarms", :action => 'status')
+	result = Alarm.count(:conditions => Alarm::ACTIVE_YELLOW_CONDITION)
+	result = "<span style='background-color:yellow'>#{result}</span>" if result > 0
+	title = "Alarms of level: #{Alarm::YELLOW_LEVELS.join(",")}"
+
+      when "red_alarms"
+	link = url_for(:controller => "alarms", :action => 'status')
+	result = Alarm.count(:conditions => Alarm::ACTIVE_RED_CONDITION)
+	result = "<span style='background-color:red'>#{result}</span>" if result > 0
+	title = "Alarms of level: #{Alarm::RED_LEVELS.join(",")}"
+
+
+#      when "prisma_archiv"
+#        link = "/munin/localdomain/#{@reporter}-df.html"
+#	result = read_rrd(@reporter, "df", "/var/")
+
+        
+      else
+        throw "unknown type"
+      end
+      
+      result = (result.to_f * 100).round.to_f / 100 if result.class.name == "Float"
+    rescue
+      result = "EE"
+      if RAILS_ENV == "development"
+	result += $!.message
+      end
+    end
+
+    if link
+      return "<a class='paint_link' href='#{link}' title='#{title}'>#{result}</a>" 
+    else
+      return "#{result}"
+    end
+  end
+  
+  def measure_inline
+    init
+    val = measure(params[:type])
+    render :text => val, :layout => false
+  end
+
+  def status
+  end
+
+  def load_default_working_items
+    @text = Prisma.load_default_working_items.map {|item|
+      if item.class.name == "String"
+	item
+      else
+	if item.respond_to?(:name)
+	  "#{item.class.name} '#{item.name}' imported"
+	else
+	  "#{item} imported"
+	end
+      end
+    }.join("\n") 
+    @text = "No items to import." if @text == ""
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/report_templates_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/report_templates_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/report_templates_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/report_templates_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,146 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class ReportTemplatesController < ApplicationController
+  include ApplicationHelper
+  before_filter :handle_cancel, :only => [ :new, :create, :update ]
+  before_filter :initialize_parameters
+
+  private
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+
+  public
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @report_templates = ReportTemplate.paginate :page => params[:page]
+  end
+
+  def show
+    @report_template = ReportTemplate.find(params[:id])
+    @report_template.delete_cache if params[:delete_cache]
+
+    if params[:render] or @report_template.cache_exist?
+      @preview = true
+
+      @datasource, @conditions = parse_datasource_parameters
+
+      @options = {
+	:url => url_for(:controller => "charts", 
+			:action => "chart_image") + "?"      }      
+      
+      @options[:datasource] = @datasource
+      @options[:conditions] = @conditions
+
+      case params[:commit]
+      when "Save as Report"
+	@report_template.delete_cache
+	@report = Report.generate(@report_template,user, @options)
+	redirect_to :controller => "reports", :action => "show", :id => @report
+      when "Preview with real data"
+#	@report_template.mode = :real
+	@report_template.delete_cache
+	@report_template.render(@options)
+      when "Preview with fake data"
+	@report_template.delete_cache
+	@report_template.mode = :preview
+	cols = @datasource.table.columns.map{|c| c.name}
+	cols += ["data"] # for chart preview always a data col is needed
+	raise "No cols in view." if cols.length == 0
+	@datasource = RandomDatasource.new(cols)
+	@options[:datasource] = @datasource
+
+	@report_template.render(@options)
+      when nil
+	@report_template.mode = :preview	
+      else
+	raise "Unknown preview mode '#{params[:preview]}'."
+      end
+      
+    end
+    @report_template.mode = :preview if @preview
+  end
+
+  def new
+    @report_template = (load_current_object or ReportTemplate.new)
+  end
+
+  def create
+    @report_template = ReportTemplate.new(params[:report_template])
+    if @report_template.save
+      flash[:notice] = 'ReportTemplate was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @report_template = ReportTemplate.find(params[:id])
+  end
+
+  def update
+    @report_template = ReportTemplate.find(params[:id])
+    if @report_template.update_attributes(params[:report_template])
+      flash[:notice] = 'ReportTemplate was successfully updated.'
+      redirect_to :action => 'show', :id => @report_template
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def add_chart
+    @report_template = ReportTemplate.find(params[:id])
+    @chart = Chart.find(params[:chart])
+    @report_template.charts << @chart
+    redirect_to :action => "show", :id => @report_template
+  end
+  
+  def remove_chart
+    @report_template = ReportTemplate.find(params[:id])
+    @chart = Chart.find(params[:chart])
+    @report_template.charts.delete(@chart)
+    redirect_to :action => "show", :id => @report_template
+  end
+
+  def add_table
+    @report_template = ReportTemplate.find(params[:id])
+    @table = Table.find(params[:table])
+    @report_template.tables << @table
+    redirect_to :action => "show", :id => @report_template
+  end
+  
+  def remove_table
+    @report_template = ReportTemplate.find(params[:id])
+    @table = Table.find(params[:table])
+    @report_template.tables.delete(@table)
+    redirect_to :action => "show", :id => @report_template
+  end
+
+  def destroy
+    ReportTemplate.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/reports_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/reports_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/reports_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/reports_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,117 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class ReportsController < ApplicationController
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @reports = Report.paginate :page => params[:page], :order => "id DESC"
+  end
+
+  def show
+    @image_url = url_for(:controller => "charts", 
+	:action => "chart_image") + "?"
+    @report = Report.find(params[:id])
+    @chart_options = {
+	:url => url_for(:controller => "charts", 
+			:action => "chart_image") + "?"}
+#    begin
+#      raise "View not found." unless @report.original_report_template.view
+#      table = @report.original_report_template.view.table.table_name
+#      @chart_options[:link] = url_for(:controller => "survey",
+#				      :action => "chart_click",
+#				      :table => table) + "?"
+#    rescue
+#      flash[:warning] = "Could not create chart link: '#{$!}'"
+#    end
+    
+    begin
+      @report_text = @report.text(@chart_options) 
+    rescue
+      @report_text = "<span class='error'>'#{$!}'</span>"
+    end
+  end
+
+  def send_to_email
+    @report = Report.find(params[:id])
+    @email_types = ["normal","simple"]
+  end
+
+  def deliver_to_email
+    raise "No address given." unless params[:addresses]
+    raise "No type given" unless params[:type]
+    @report = Report.find(params[:id])
+    ReportMailer.send("deliver_#{params[:type]}", params[:addresses], @report)
+  end
+
+
+  def email_preview
+    @report = Report.find(params[:id])
+    m = ReportMailer.send("create_#{params[:type]}",nil,@report, {:preview => true})
+    render :text => "<html><body>#{BaseMailer.preview_html(m)}</body></html>"
+  end
+
+  def new
+    raise "not implemented"
+    @report = Report.new
+  end
+
+  def create
+    raise "not implemented"
+    @report = Report.new(params[:report])
+    if @report.save
+      flash[:notice] = 'Report was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    raise "Cannot edit a report."
+    @report = Report.find(params[:id])
+  end
+
+  def update
+    raise "not implemented"
+    @report = Report.find(params[:id])
+    if @report.update_attributes(params[:report])
+      flash[:notice] = 'Report was successfully updated.'
+      redirect_to :action => 'show', :id => @report
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    Report.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+
+  def get_data
+    @report = Report.find(params[:id])
+    obj = @report.objects[params[:number].to_i]
+    send_data(obj.to_csv,
+	      :type => 'text/csv; charset=iso-8859-1; header=present',
+	      :filename => safe_filename("#{@report.name}_#{@report.id}_#{obj.class.name}_#{obj.name}","csv",@report.date))
+
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/sentinels_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/sentinels_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/sentinels_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/sentinels_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,104 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class SentinelsController < ApplicationController
+  before_filter :handle_cancel, :only => [ :create, :update ]
+
+  private
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+
+  public
+  def index
+    list
+    render :action => 'list'
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @sentinels = Sentinel.find(:all, :order => "action desc,alarm_level,name")
+  end
+
+  def show
+    @sentinel = Sentinel.find(params[:id])
+  end
+
+  def new
+    @sentinel = (load_current_object or Sentinel.new)
+  end
+
+  def create
+    @sentinel = Sentinel.new(params[:sentinel])
+    begin
+      if @sentinel.save
+        flash[:notice] = 'Sentinel was successfully created.'
+	@sentinel.errors.each {|attribute,text|
+	  flash[:warning] = text
+	}
+        redirect_to :action => 'list'
+      else
+        render :action => 'new'
+      end
+    end
+  end
+
+  def manually_execute
+    @sentinel = Sentinel.find(params[:id])
+    alarm,report = @sentinel.process
+    if alarm
+      flash[:notice] = 'Sentinel produced this alarm.'
+      redirect_to :controller => "alarms", :action => "show", :id => alarm
+    else
+      if report
+	flash[:notice] = 'Sentinel produced this report.'
+	redirect_to :controller => "reports", :action => "show", :id => report
+      else
+	flash[:notice] = 'Sentinel did not produce an alarm or a report.'
+	redirect_to :action => "show", :id => @sentinel
+      end
+    end    
+  end
+
+  def edit
+    @sentinel = Sentinel.find(params[:id])
+  end
+
+  def update
+    @sentinel = Sentinel.find(params[:id])
+    if @sentinel.update_attributes(params[:sentinel])
+      flash[:notice] = 'Sentinel was successfully updated.'
+      @sentinel.errors.each {|attribute,text|
+	flash[:warning] = text
+      }
+      redirect_to :action => 'show', :id => @sentinel
+    else
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    Sentinel.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+
+  def auto_complete_for_sentinel_time_range
+    render :inline => "<%= content_tag(:ul, Time.suggest(params[:sentinel][:time_range]).map { |org| content_tag(:li, h(org)) }) %>"
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/surveillance_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/surveillance_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/surveillance_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/surveillance_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,22 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class SurveillanceController < ApplicationController
+
+  def index
+  end
+  
+end
+  
+  

Added: incubator/alois/trunk/rails/app/controllers/survey_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/survey_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/survey_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/survey_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,501 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class SurveyController < ApplicationController
+  include ApplicationHelper
+  include SurveyHelper
+  before_filter :handle_cancel, :only => [ :create, :update ]
+  before_filter :init
+
+  def init
+    initialize_parameters
+  end
+  
+  private
+
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+
+  public
+  def index
+    redirect_to :action => 'list', :transport => params[:transport], :msg_type => params[:msg_type], :application => params[:application], :table_postfix => params[:table_postfix]
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+    :redirect_to => { :action => :list }
+
+  def get_desc(i)
+    return nil
+    conditions = @conditions
+    conditions = [[nil,nil,nil,nil]] if @conditions.length ==0
+    value = conditions[i][2]
+    value = YAML.dump(value) unless value.class.name == "String"
+    ret = [
+      ["Column name or name of the rule.","Column/Name",
+        nil,nil,nil,conditions[i][0],nil],
+      ["Operator for the rule.","Operator",
+        nil,nil,nil,conditions[i][1],nil],
+      ["Value to compare for the rule.","Value",
+        nil,nil,nil,value,nil],
+      ["Percentage of items matched this rule.","%",
+        get_condition(i), nil, "ALL", nil, "del_condition","d"],
+      ["All values matched by that rule, and are in this sample.","In %",
+        get_condition_string(true), nil, get_condition(i), nil,nil,nil],
+      ["All values matched by that rule, that are not in this sample.","Not In %",
+        get_condition(i), get_condition_string(true) , get_condition(i), nil,'negate_all_but','>'],
+      ["How many records more would be in the sample if this rule where deleted.","Banish",
+        get_condition_string(true,i),get_condition_string(true), nil, nil,'banished', '>'],
+      ["Disable/Enable the rule.","",
+        nil, nil, nil, if conditions[i][3] then "on" else "off" end, 'toggle', '>']
+    ]
+  end
+
+  def report
+    conditions = get_condition_string
+    #flash[:notice] = "conditions: #{conditions}"
+    #    @pages, @records = paginate current_table_class,
+    #      :per_page => 100,
+    #      :conditions => conditions,
+    #      :joins => @join,
+    #      :select => params[:select],
+    #      :count => params[:count],
+    #      :order => params[:order]
+
+    #    @pages = Paginator.new self, params[:count].to_i, params[:page]
+    #    sql = @current_filter.get_sql
+    #    # this should be done by activerecord
+    #    sql = "SELECT * FROM (#{sql}) AS survey_table " +
+    #      " LIMIT #{@pages.current.offset},#{@pages.items_per_page}"
+    #    @records = current_table_class.find_by_sql(sql)
+  end
+
+  def list_inline
+    begin
+      do_list
+      render :partial => 'table'
+    rescue
+      render :text => "Message:<br><pre>#{$!.message}\n</pre>Trace:<br><pre>#{$!.backtrace.join("\n")}</pre>", :layout => false
+    end
+  end
+
+  private
+
+  def report_table_methods
+    return nil unless params[:show_originals]
+    ["original_text"]
+  end
+  def report_table(options = {})
+    if params[:type] == "chart"
+      data = @chart.get_data
+      table = Ruport::Data::Table.new(:column_names => data[0].keys.map {|k| k == "data" ? @chart.data_column : k})
+      data.each {|row|
+	table << data[0].keys.map {|k| row[k]}
+      }
+      @data = table
+    else
+      conditions = get_condition_string()
+      @data = current_table.report_table(:all,
+					 :conditions => get_condition_string,
+					 :methods => report_table_methods,
+					 :order => @order)
+    end
+  end
+
+  public
+
+  def text
+    #:max_col_width: Ordinal array of column widths. Set automatically but can be overridden. 
+    #:alignment: Defaults to left justify text and right justify numbers. Centers all fields when set to :center. 
+    #:table_width: Will truncate rows at this limit. 
+    #:show_table_headers: Defaults to true 
+    #:show_group_headers: Defaults to true 
+    #:ignore_table_width: When set to true, outputs full table without truncating it. Useful for file output.     
+    txt = report_table.as(:text, :ignore_table_width => true)
+    send_data(txt,
+	      :type => 'text/plain; charset=iso-8859-1; header=present',
+	      :filename => safe_filename(current_datasource.name,"txt"))
+  end
+
+  def csv
+    #:style Used for grouping (:inline,:justified,:raw) 
+    #:format_options A hash of FasterCSV options 
+    #:show_table_headers True by default 
+    #:show_group_headers True by default
+    csv = report_table.as(:csv)   
+    send_data(csv,
+	      :type => 'text/csv; charset=iso-8859-1; header=present',
+	      :filename => safe_filename(current_datasource.name,"csv"))
+  end
+
+  def pdf
+    # General:
+    #  * paper_size  #=> "LETTER"
+    #  * paper_orientation #=> :portrait
+    #
+    # Text:
+    #  * text_format (sets options to be passed to add_text by default)
+    #
+    # Table:
+    #  * table_format (a hash that can take any of the options available
+    #      to PDF::SimpleTable)
+    #  * table_format[:maximum_width] #=> 500
+    #
+    # Grouping:
+    #  * style (:inline,:justified,:separated,:offset)
+    pdf = report_table.as(:pdf)
+    send_data(pdf,
+	      :type => 'application/pdf',
+	      :filename => safe_filename(current_datasource.name,"pdf"))
+  end
+
+
+  def list
+    return redirect_to( :action => "list", :state_id => @state_id) unless params[:state_id]
+    do_list
+  end
+  
+  def add_condition
+   # leave this for backwards compatibility
+    @current_filter.conditions = @current_filter.conditions << 
+      Condition.create(params[:column], params[:operator], params[:value]) if
+      params[:column]
+    @current_filter.conditions = @current_filter.conditions << 
+      Condition.create(params[:column2], params[:operator2], params[:value2]) if 
+      params[:column2]
+
+    params[:columns].each_with_index {|col, i|
+      @current_filter.conditions = @current_filter.conditions << 
+	Condition.create(params[:columns][i], params[:operators][i], params[:values][i])
+    } if params[:columns] and params[:operators] and params[:values]
+    
+    reset_paging
+    save_session
+    redirect_to :action => 'list', :state_id => @state_id # unless params[:state_id]
+  end
+
+  def create_view
+    conditions = get_condition_string() ? " WHERE " + get_condition_string : ""
+    sql = "SELECT * FROM #{current_table.table_name} #{conditions}"
+    view = View.create(:sql_declaration => sql, :id_source_table => current_table.table_name)
+    view.save
+
+    redirect_to :controller => "views", :action => "edit", :id => view
+  end
+
+  def create_view_from_query
+    @record = current_table.find(params[:id])
+    names = []
+    cols =  params[:select_columns].map { |c|
+      c =~ /(.*)\.\`(.*)\`/
+      if names.index($2) == nil
+	ret = "#{c}"     
+      else
+	ret = "#{c} AS #{$1}_#{$2}"     
+      end
+      names.push($2)      
+      ret
+    }.join(", ")
+    view = View.create(:sql_declaration => "SELECT #{cols} FROM #{@record.join_query}", :id_source_table => current_table.table_name)
+    view.save
+
+    redirect_to :controller => "views", :action => "edit", :id => view
+  end
+  
+  def do_list    
+    throw "Table not found." unless current_table
+    conditions = get_condition_string
+
+    @raw_descriptions = get_desc(-1)
+    @descriptions = []
+
+    origin = current_table.table_name
+    origin = "( #{current_table.sql_declaration} ) AS #{origin}" if current_table.respond_to?(:sql_declaration)
+
+    @query_string = "SELECT * FROM #{origin}"
+    @query_string = @query_string + " WHERE #{get_condition_string}" if conditions
+
+    begin
+      @records = current_table.paginate(:page => @page_number.to_i,
+					:per_page => @paging_size.to_i,
+					:total_entries => if count_fast then count_fast else 100000 end,
+					:conditions => conditions,
+					:order => @order,
+					:limit  =>  @paging_size.to_i,
+					:offset =>  @page_offset)
+      @query_string = (current_table.last_executed_find or @query_string) if current_table.respond_to?(:last_executed_find)
+    rescue
+      @records = nil
+      flash[:error] = "Error executing query: #{$!}"
+    end
+				    
+
+#    @pages = Paginator.new self, 
+#      if count_fast then count_fast else 100000 end,
+#      @paging_size.to_i,
+#      @page_number.to_i
+#    @records = current_table.find :all, 
+
+  end
+
+  def count_text
+    render :partial => 'count_text'
+  end
+
+  def show
+    if params[:id]
+      @record = current_table.find(params[:id])
+    else
+      # show table or view description
+      if @table_class.class == View
+	redirect_to :controller => "views", :action => "show", :id => @table_class.id
+      else
+	redirect_to :controller => "tablelist"
+      end
+    end
+  end
+
+  def original_inline
+    @record = current_table.find(params[:id])
+    render :partial => "original"
+  end
+
+  def add_filter
+    if params[:survey] and params[:survey][:filter_id] 
+      @filters << Filter.find(params[:survey][:filter_id])
+      @filters = @filters.uniq
+      save_session
+    end
+    render :partial => "edit_named_filters"
+  end
+
+  def remove_filter
+    @filters.delete(Filter.find(params[:filter_id].to_i))
+    @filters = @filters.uniq
+    save_session
+    render :partial => "edit_named_filters"
+  end
+
+  def chart
+    return redirect_to( :action => "chart", :state_id => @state_id) unless params[:state_id]
+    save_session
+    @query_string = @chart.query
+    @chart.delete_data if params[:recreate_data]
+    render :action => "list"
+  end
+
+  def chart_inline
+    begin
+      @chart.delete_data if params[:recreate_data]
+      render :partial => 'chart'
+    rescue
+      render :text => "Message:<br><pre>#{$!.message}\n</pre>Trace:<br><pre>#{$!.backtrace.join("\n")}</pre>", :layout => false
+    end
+  end
+
+#  def chart_image    
+#    @chart.render(params[:recreate_data])
+#    headers['Cache-Control'] = 'no-cache, must-revalidate'
+#    send_file( @chart.png_file_name,
+#	      :disposition => 'inline', 
+#	      :type => 'image/png', 
+#	      :filename => @chart.image_id + ".png")
+#  end
+
+  def chart_map
+    @chart.render(:recreate_data => params[:recreate_data])   
+    @chart_image_tag = @chart.image_tag({:url => url_for(:controller => "charts", :action => "chart_image") + "?"})
+    @chart_image_map = @chart.image_map({:link => url_for(:action => "chart_click", :state_id => state_id) + "&"})
+    
+    render :partial => "chart_map"
+  end
+
+  def chart_data
+    data = @chart.get_data
+    table = Ruport::Data::Table.new(:column_names => data[0].keys.map {|k| k == "data" ? @chart.data_column : k})
+    data.each {|row|
+      table << data[0].keys.map {|k| row[k]}
+    }
+    if params[:type] == "csv"
+      render :text => "<pre>#{table.to_csv}</pre>"
+    else
+      render :text => "<pre>#{table}</pre>"
+    end
+  end
+
+  def normalize_parameter(column_param, value_param, remove_value_if_not_found = false)
+    column = params.delete(column_param)
+    if column.nil? or column == ""
+      params.delete(value_param) if remove_value_if_not_found
+      return nil 
+    end
+
+    value = params.delete(value_param)    
+    if value =~ Regexp.new("^" + Regexp.quote("#{column}=") + "(.*)")
+      value = $1
+    end
+
+    if value == Chart::NIL_VALUE then
+      value = nil
+    end
+    
+    if value.nil?
+      operator = "IS NULL"
+    else
+      if value.length > 0 and value[-1,1] == "%" 
+	operator = "LIKE"
+      else
+	operator = "="
+      end
+    end
+
+    if current_table and current_table.columns_hash[column] and 
+	current_table.columns_hash[column].type == :date and
+	value =~ /^\d+\.?\d*$/
+      value = Chart.map_to_date(value)
+    end
+
+    if current_table and current_table.columns_hash[column] and 
+	current_table.columns_hash[column].type == :time and
+	value =~ /^\d+\.?\d*$/
+      value = Chart.map_to_time(value)
+    end
+
+    params[:columns] ||= []
+    params[:operators] ||= []
+    params[:values] ||= []
+
+    params[:columns].push(column)
+    params[:operators].push(operator)
+    params[:values].push(value)
+  end
+
+  def chart_click
+    normalize_parameter(:column, :category)
+    normalize_parameter(:column1, :category)
+    normalize_parameter(:category_column, :category, true)
+    normalize_parameter(:column2, :series)
+    normalize_parameter(:serie_column, :series, true)
+    normalize_parameter(:range_column, :range)
+    
+    params[:action] = "add_condition"   
+
+    clone_session
+    params[:state_id] = state_id    
+    redirect_to params.update(:action => "add_condition")
+  end
+
+  def auto_refresh_inline
+    begin
+      if params[:auto_refresh]
+	if params[:auto_refresh].to_i < 1
+	  params[:auto_refresh] = nil 
+	  flash[:error] = "Auto refresh value must be an integer above 1."
+	end
+      end
+      render :partial => 'auto_refresh'
+    rescue
+      render :text => "Message:<br><pre>#{$!.message}\n</pre>Trace:<br><pre>#{$!.backtrace.join("\n")}</pre>", :layout => false
+    end   
+  end
+  def auto_refresh_info
+    @chart.delete_data if @chart
+    render :partial => "auto_refresh_info"
+  end
+
+  def create_date(param)
+    param[:year] = Time.now.year if param[:year] == ""
+    if param[:month] == "" and  param[:day] != "" then
+      param[:month] = Time.now.month
+    end
+    if param[:month] != "" and param[:day] == "" then
+      param[:day] = 1
+    end
+    return Date.civil(param[:year].to_i,param[:month].to_i,param[:day].to_i) if
+      param[:year] != "" and param[:month] != "" and param[:day] != ""
+  end
+
+  def del_condition
+    @conditions[params[:id].to_i..params[:id].to_i] = []
+    @current_filter.set_conditions(@conditions)
+    reset_paging
+    save_session
+    list
+    render :action => 'list'
+  end
+
+  def toggle
+    @conditions[params[:id].to_i][3] = !(@conditions[params[:id].to_i][3])
+    @current_filter.set_conditions(@conditions)
+    list
+    render :action => 'list'
+  end
+
+  def only_condition
+    @conditions = [@conditions[params[:id].to_i]]
+    @current_filter.set_conditions(@conditions)
+    list
+    render :action => 'list'
+  end
+
+  def negative_set
+    @negative_set = true
+    list
+    render :action => 'list'
+  end
+
+  def banished
+    @banished_set = true
+    @negative_set = true
+    @global_rule_number = number = params[:id].to_i
+    list
+    render :action => 'list'
+  end
+
+  def negate_all_but
+    @negative_set = true
+    @global_rule_number = number = params[:id].to_i
+    list
+    render :action => 'list'
+
+#    @conditions = Marshal.load(params[:conditions]) unless @conditions
+#    number = params[:id].to_i
+#    for i in 0...@conditions.length
+#      if i!=number then
+#        case @conditions[i][1]
+#        when "IS NULL"
+#          @conditions[i][1] = "NOT IS NULL"
+#        when "NOT IS NULL"
+#          @conditions[i][1] = "IS NULL"
+#        when "LIKE"
+#          @conditions[i][1] = "NOT LIKE"
+#        when "NOT LIKE"
+#          @conditions[i][1] = "LIKE"
+#        when "="
+#          @conditions[i][1] = "!="
+#        when "!="
+#          @conditions[i][1] = "="
+#        else
+#          throw "Unknown operator #{@conditions[i][1]}"
+#        end
+#      end
+#    end
+#    list
+#    render :action => 'list'
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/tablelist_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/tablelist_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/tablelist_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/tablelist_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,61 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class TablelistController < ApplicationController
+  include ApplicationHelper
+
+  def index
+  end
+
+  # Return the record count for a table
+  def count
+    begin
+      klass = Prisma::Database.get_class_from_tablename(params[:table_name])
+      throw "Class for table #{params[:table]} not found." unless klass
+      @count = klass.approx_count
+    rescue
+      @count = "N/A <!-- #{$!.message} -->"
+    end
+
+    # Render without layout as it is used inline
+    render(:layout => false)
+  end
+
+  def schema
+    initialize_parameters
+    @global_source_class = LogMeta #SourceDbMeta
+    @record = current_table.find(params[:id]) if params[:id]
+
+    p = @record
+    @child_path = [p]
+    while !p.nil? and (p.class.name != @global_source_class.name)
+      (p = p.parent)
+      @child_path.push(p)
+    end
+#    throw @child_path.map{|n| n.class.name}
+
+    @parent_path = []
+    while !p.nil?
+      @parent_path.push(p)
+      p = p.parent
+    end
+
+    if @parent_path.length == 0
+      @parent_path = @child_path
+      @child_path = []
+    else
+      @child_path.reverse!
+    end
+  end
+end

Added: incubator/alois/trunk/rails/app/controllers/tables_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/tables_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/tables_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/tables_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,103 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class TablesController < ApplicationController
+  before_filter :initialize_parameters
+
+  # GET /tables
+  # GET /tables.xml
+  def index
+    @tables = Table.find(:all)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.xml  { render :xml => @tables }
+    end
+  end
+
+  def list
+    redirect_to :action => :index
+  end
+
+  # GET /tables/1
+  # GET /tables/1.xml
+  def show
+    @table = Table.find(params[:id])
+
+    respond_to do |format|
+      format.html # show.html.erb
+      format.xml  { render :xml => @table }
+    end
+  end
+
+  # GET /tables/new
+  # GET /tables/new.xml
+  def new
+    @table = Table.new
+  end
+
+  # GET /tables/1/edit
+  def edit
+    @table = Table.find(params[:id])
+  end
+
+  # POST /tables
+  # POST /tables.xml
+  def create
+    @table = Table.new(params[:table])
+    
+    if @table.save
+      flash[:notice] = 'Table was successfully created.'
+      redirect_to :action => 'list'
+    else
+      render :action => 'new'
+    end
+  end
+
+  # PUT /tables/1
+  # PUT /tables/1.xml
+  def update
+    @table = Table.find(params[:id])    
+    if @table.update_attributes(params[:table])
+      flash[:notice] = 'Table was successfully updated.'
+      redirect_to :action => 'show', :id => @table
+    else
+      render :action => 'edit'
+    end
+  end
+
+  # DELETE /tables/1
+  # DELETE /tables/1.xml
+  def destroy
+    @table = Table.find(params[:id])
+    @table.destroy
+
+    respond_to do |format|
+      format.html { redirect_to :action => "list" }
+      format.xml  { head :ok }
+    end
+  end
+
+  def render_table
+    @table = Table.find(params[:id])
+    @datasource, @conditions = parse_datasource_parameters
+    @table.datasource = @datasource
+    @table.conditions = @conditions
+        
+    @table.remove_cache
+    @count = @table.count
+    @data =(@table.as(params[:type].to_sym, :ignore_table_width => true) or "NO DATA")
+  end
+
+end

Added: incubator/alois/trunk/rails/app/controllers/views_controller.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/controllers/views_controller.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/controllers/views_controller.rb (added)
+++ incubator/alois/trunk/rails/app/controllers/views_controller.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,94 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+class ViewsController < ApplicationController
+  include ApplicationHelper
+  before_filter :handle_cancel, :only => [ :new, :create, :update ]
+
+  private
+  def handle_cancel
+    if params[:commit] == "Cancel"
+      redirect_to :action => :list
+    end
+  end
+
+  public
+  def index
+    redirect_to :action => :list
+  end
+
+  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
+  verify :method => :post, :only => [ :destroy, :create, :update ],
+         :redirect_to => { :action => :list }
+
+  def list
+    @views = View.find(:all).select {|view| view.exclusive_for_group.nil? or view.exclusive_for_group == "" or view.exclusive_for_group == group}
+  end
+
+  def show
+    @view = View.find(params[:id])
+  end
+
+  def show_inline
+    @view = View.find(params[:id])
+    render :layout => false
+  end
+
+  def new
+    @view = View.new
+    @view = View.from_zip(params[:view_zip]) if params[:view_zip]
+  end
+
+  def create
+    begin
+      @view = View.new(params[:view])
+      if @view.save
+	flash[:notice] = 'View was successfully created.'
+	redirect_to :action => 'list'
+      else
+	p @view.errors
+	render :action => 'new'
+      end
+    rescue
+      p $!.message
+      flash[:error] = $!.message
+      render :action => 'new'
+    end
+  end
+
+  def edit
+    @view = View.find(params[:id])
+  end
+
+  def update
+    begin
+      @view = View.find(params[:id])
+      if @view.update_attributes(params[:view])
+	flash[:notice] = 'View was successfully updated.'
+	redirect_to :action => 'list', :id => @view
+      else
+	render :action => 'edit'
+      end
+    rescue
+      flash[:error] = $!.message
+      render :action => 'edit'
+    end
+  end
+
+  def destroy
+    View.find(params[:id]).destroy
+    redirect_to :action => 'list'
+  end
+
+end

Added: incubator/alois/trunk/rails/app/helpers/alarms_helper.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/helpers/alarms_helper.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/helpers/alarms_helper.rb (added)
+++ incubator/alois/trunk/rails/app/helpers/alarms_helper.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,33 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module AlarmsHelper
+
+  def status_traffic_light(options = {})
+    color = Alarm.status_color
+    img = case color
+	  when "red"
+	    "traffic_light_red_dan_ge_01.png"
+	  when "orange","yellow"
+	    "traffic_light_yellow_dan_01.png"
+	  when "green"
+	    "traffic_light_green_dan__01.png"
+	  else
+	    "traffic_light_dan_gerhar_01.png"
+	  end
+    
+    return "<a href='#{url_for(:controller => "alarms", :action => 'status')}' title='Current alarm level is: #{color}'>#{image_tag img, options}</a>" 
+
+  end
+end

Added: incubator/alois/trunk/rails/app/helpers/alois_helper.rb
URL: http://svn.apache.org/viewvc/incubator/alois/trunk/rails/app/helpers/alois_helper.rb?rev=1031127&view=auto
==============================================================================
--- incubator/alois/trunk/rails/app/helpers/alois_helper.rb (added)
+++ incubator/alois/trunk/rails/app/helpers/alois_helper.rb Thu Nov  4 18:27:22 2010
@@ -0,0 +1,63 @@
+# Copyright 2010 The Apache Software Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module AloisHelper
+
+  def alois_menu
+    common_menu
+  end
+
+  def navigation_bar
+    
+
+    @navigation=[]
+
+    @navigation.push({ :title => 'Home', :url => url_for( :controller => 'prisma', :action => 'overview')})
+
+    @navigation.push({ :title => 'Statistics', :url => url_for( :controller => 'prisma', :action => 'statistics')})
+
+    sub_entries=[]
+    for view in View.find(:all, :order => 'name')
+      sub_entries.push({ :title => view.name , :url => url_for( :controller => 'survey', :action => 'list', :table => view.view_name ) })
+    end
+
+    @navigation.push({ :title => 'Views', :url => url_for( :controller => 'views'), :submenu => sub_entries })
+
+    sub_entries=[]
+    for klass in Prisma::Database.get_classes(:meta).sort{ |x,y| ((x.name <=> y.name) == 0) ? x.description <=> y.description : x.name <=> y.name }
+      sub_entries.push({ :title => klass.description, :url => url_for( :controller => 'survey', :action => 'list', :table => klass.table_name ) })
+    end
+    @navigation.push({ :title => 'Tables', :url => url_for( :controller => 'tablelist'), :submenu => sub_entries })
+
+    sub_entries=[]
+    for filter in Filter.find(:all)
+      sub_entries.push({ :title => filter.name, :url => url_for( :controller => 'filters', :action => 'show', :id => filter ) })
+    end
+    @navigation.push({ :title => 'Filters', :url => url_for( :controller => 'filters' ), :submenu => sub_entries })
+
+    sub_entries=[]
+    for sentinel in Sentinel.find(:all)
+      sub_entries.push({ :title => sentinel.name, :url => url_for( :controller => 'sentinels', :action => 'show', :id => sentinel ) })
+    end
+    @navigation.push({ :title => 'Sentinels', :url => url_for( :controller => 'sentinels' ), :submenu => sub_entries })
+    return @navigation
+  end
+
+
+  # Output helper
+  def title(title)
+    return "<h1>#{h(title)}</h1>"
+  end
+
+end



Mime
View raw message