ref: refs/heads/master
commit dac459299cf0f7557ed6927cde2e26f3255aa94b
Author: Jiri Suchomel
Date: Mon Aug 17 10:02:18 2009 +0200
custom-services client
---
plugins/custom_services/README | 7 ++
plugins/custom_services/Rakefile | 10 +++
.../app/controllers/custom_services_controller.rb | 67 ++++++++++++++++++
.../app/views/custom_services/_result.rhtml | 20 ++++++
.../app/views/custom_services/index.rhtml | 70 +++++++++++++++++++
plugins/custom_services/config/rails_parent.rb | 15 ++++
plugins/custom_services/init.rb | 12 +++
plugins/custom_services/install.rb | 1 +
.../yast2-webclient-custom-services.changes | 4 +
.../package/yast2-webclient-custom-services.spec | 73 ++++++++++++++++++++
plugins/custom_services/shortcuts.yml | 8 ++
.../tasks/custom_services_tasks.rake | 6 ++
.../custom_services/test/custom_services_test.rb | 8 ++
.../functional/custom_services_controller_test.rb | 45 ++++++++++++
plugins/custom_services/test/test_helper.rb | 19 +++++
plugins/custom_services/uninstall.rb | 1 +
16 files changed, 366 insertions(+), 0 deletions(-)
diff --git a/plugins/custom_services/README b/plugins/custom_services/README
new file mode 100644
index 0000000..afbf229
--- /dev/null
+++ b/plugins/custom_services/README
@@ -0,0 +1,7 @@
+Services
+=========
+
+Plugin for hanling custom vendor service.
+
+
+Copyright (c) 2009 Novell, released under the MIT license
diff --git a/plugins/custom_services/Rakefile b/plugins/custom_services/Rakefile
new file mode 100644
index 0000000..ca63e76
--- /dev/null
+++ b/plugins/custom_services/Rakefile
@@ -0,0 +1,10 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+require File.join(File.dirname(__FILE__), 'config', 'rails_parent')
+require File.join(RailsParent.parent, 'config', 'boot')
+require 'tasks/rails'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
diff --git a/plugins/custom_services/app/controllers/custom_services_controller.rb b/plugins/custom_services/app/controllers/custom_services_controller.rb
new file mode 100644
index 0000000..518bccd
--- /dev/null
+++ b/plugins/custom_services/app/controllers/custom_services_controller.rb
@@ -0,0 +1,67 @@
+require 'yast/service_resource'
+
+class CustomServicesController < ApplicationController
+ before_filter :login_required
+ layout 'main'
+
+ private
+ def client_permissions
+ @client = YaST::ServiceResource.proxy_for('org.opensuse.yast.modules.yapi.services')
+ unless @client
+ flash[:notice] = _("Invalid session, please login again.")
+ redirect_to( logout_path ) and return
+ end
+ @permissions = @client.permissions
+ end
+
+ # Initialize GetText and Content-Type.
+ init_gettext "yast_webclient_custom_service" # textdomain, options(:charset, :content_type)
+
+ public
+
+ def initialize
+ end
+
+ # GET /services
+ # GET /services.xml
+ def index
+ return unless client_permissions
+ @services = []
+logger.debug "-------------------------------- index"
+
+ begin
+ @services = @client.find(:all)
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ end
+logger.debug @services.inspect
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @services }
+ end
+ end
+
+ def execute
+ return unless client_permissions
+ @service = @client.find(params[:service_id])
+
+ response = @client.put(params[:service_id], :execute => params[:id])
+
+ # we get a hash with exit, stderr, stdout
+ ret = Hash.from_xml(response.body)
+ ret = ret["hash"]
+ logger.debug "returns #{ret.inspect}"
+
+ @result_string = ""
+ @result_string << ret["stdout"] if ret["stdout"]
+ @result_string << ret["stderr"] if ret["stderr"]
+ @error_string = ret["exit"].to_s
+ if ret["exit"] == 0
+ @error_string = _("success")
+ end
+ render(:partial =>'result')
+ end
+
+
+end
diff --git a/plugins/custom_services/app/views/custom_services/_result.rhtml b/plugins/custom_services/app/views/custom_services/_result.rhtml
new file mode 100644
index 0000000..3af3d5f
--- /dev/null
+++ b/plugins/custom_services/app/views/custom_services/_result.rhtml
@@ -0,0 +1,20 @@
+ <div class="box">
+ <div class="table">
+ <img src="images/bg-th-left.gif" width="8" height="7" alt="" class="left" />
+ <img src="images/bg-th-right.gif" width="7" height="7" alt="" class="right" />
+ <table class="listing form" cellpadding="0" cellspacing="0">
+ <tr>
+ <th class="full" colspan="2"><%=_("Service Call Result")%></th>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Result")%></strong></td>
+ <td class="last"><%=h @error_string %></td>
+ </tr>
+ <tr class="bg">
+ <td class="first"><strong><%=_("Description")%></strong></td>
+ <td class="last"><%=h @result_string %></td>
+ </tr>
+ </table>
+ <p><a href="services" class="button"><%=_("Back")%></a></p>
+ </div>
+ </div>
\ No newline at end of file
diff --git a/plugins/custom_services/app/views/custom_services/index.rhtml b/plugins/custom_services/app/views/custom_services/index.rhtml
new file mode 100644
index 0000000..7498013
--- /dev/null
+++ b/plugins/custom_services/app/views/custom_services/index.rhtml
@@ -0,0 +1,70 @@
+<%= javascript_include_tag :defaults %>
+
+<script language="javascript">
+
+ YAHOO.namespace('yuiresult');
+
+ function initResultDialog() {
+ var handleCancel = function() {
+ this.cancel();
+ }
+
+ YAHOO.yuiresult.resultDialog = new YAHOO.widget.Dialog("resultdlg", {
+ width: "625px",
+ modal: true,
+ visible: false,
+ fixedcenter: true,
+ constraintoviewport: true,
+ draggable: true });
+
+ YAHOO.yuiresult.resultDialog.render();
+ }
+
+ function showResultDialog() {
+ YAHOO.yuiresult.resultDialog.show();
+ }
+
+ YAHOO.util.Event.addListener(window, "load", initResultDialog);
+</script>
+
+<!-- begin: dialog box -->
+<div id="resultdlg">
+</div>
+<!-- end: dialog box -->
+
+<div class='plugin-icon'><img src='/icons/yast-online_update.png'/></div>
+<div class='plugin-content'>
+
+<h2><%=_("The full name of vendor service here")%></h2>
+<br>
+
+<% if ! @permissions[:execute] %>
+<p><%=_("You do not have permission to execute the service. The links are disabled.")%></p>
+<% end %>
+
+<ul>
+<% @services.each do |service| %>
+<li><b><%=h service.name %></b>
+ <% [ "start", "stop" ].each do |cmd|
+ if @permissions[:execute] %>
+ <%=
+ link_to_remote cmd,
+ :update => "resultdlg",
+ :url=>{ :id=> cmd,
+ :action => "execute",
+ :service_id=> service.name
+ }
+# :loading => "Element.show('progress')"
+# :complete => "Element.hide('progress'); showResultDialog();"
+ %>
+ <%
+ else %>
+ <span style="color: #BDBDBD"><%="#{cmd}" -%></span>
+ <%
+ end
+ end %>
+</li>
+<% end %>
+</ul>
+
+</div>
diff --git a/plugins/custom_services/config/rails_parent.rb b/plugins/custom_services/config/rails_parent.rb
new file mode 100644
index 0000000..59e7892
--- /dev/null
+++ b/plugins/custom_services/config/rails_parent.rb
@@ -0,0 +1,15 @@
+class RailsParent
+
+ def RailsParent.parent
+ parent = ENV["RAILS_PARENT"]
+ unless parent
+ parent = File.expand_path(File.join('..','..','..', 'webclient'), File.dirname(__FILE__))
+ unless File.directory?( parent || "" )
+ $stderr.puts "Nope: #{parent}\nPlease set RAILS_PARENT environment"
+ exit 1
+ end
+ end
+ parent
+ end
+
+end
diff --git a/plugins/custom_services/init.rb b/plugins/custom_services/init.rb
new file mode 100644
index 0000000..e5b1498
--- /dev/null
+++ b/plugins/custom_services/init.rb
@@ -0,0 +1,12 @@
+# Include hook code here
+# always reload all files in development mode
+if ENV['RAILS_ENV'] == 'development'
+ # get all subdirectories in app/
+ dirs = Dir[File.join(directory, 'app', '*')].reject{|x| not File.directory?(x)}
+
+ dirs.each do |dir|
+ $LOAD_PATH << dir
+ ActiveSupport::Dependencies.load_paths << dir
+ ActiveSupport::Dependencies.load_once_paths.delete(dir)
+ end
+end
diff --git a/plugins/custom_services/install.rb b/plugins/custom_services/install.rb
new file mode 100644
index 0000000..f7732d3
--- /dev/null
+++ b/plugins/custom_services/install.rb
@@ -0,0 +1 @@
+# Install hook code here
diff --git a/plugins/custom_services/package/yast2-webclient-custom-services.changes b/plugins/custom_services/package/yast2-webclient-custom-services.changes
new file mode 100644
index 0000000..5cdd97b
--- /dev/null
+++ b/plugins/custom_services/package/yast2-webclient-custom-services.changes
@@ -0,0 +1,4 @@
+-------------------------------------------------------------------
+Mon Aug 17 08:38:57 CEST 2009 - jsuchome@suse.cz
+
+- initial version
diff --git a/plugins/custom_services/package/yast2-webclient-custom-services.spec b/plugins/custom_services/package/yast2-webclient-custom-services.spec
new file mode 100644
index 0000000..ea9e996
--- /dev/null
+++ b/plugins/custom_services/package/yast2-webclient-custom-services.spec
@@ -0,0 +1,73 @@
+#
+# spec file for package yast2-webclient-custom-services (Version 0.1)
+#
+# Copyright (c) 2008 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# This file and all modifications and additions to the pristine
+# package are under the same license as the package itself.
+#
+# Please submit bugfixes or comments via http://bugs.opensuse.org/
+#
+
+
+Name: yast2-webclient-custom-services
+PreReq: yast2-webclient
+Provides: yast2-webclient:/srv/www/yast/app/controllers/custom_services_controller.rb
+License: GPL
+Group: Productivity/Networking/Web/Utilities
+Autoreqprov: on
+Version: 0.0.1
+Release: 0
+Summary: YaST2 - Webclient - Custom Service
+Source: www.tar.bz2
+BuildRoot: %{_tmppath}/%{name}-%{version}-build
+BuildArch: noarch
+
+#
+%define pkg_user yast
+%define plugin_name custom_services
+#
+
+
+%description
+YaST2 - Webclient - UI for YaST-webservice in order to handle custom service.
+Authors:
+--------
+ Stefan Schubert
+
+%prep
+%setup -q -n www
+
+%build
+export RAILS_PARENT=/srv/www/yast
+(rake makemo)
+
+%install
+
+#
+# Install all web and frontend parts.
+#
+mkdir -p $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+cp -a * $RPM_BUILD_ROOT/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+%dir /srv/www/%{pkg_user}
+%dir /srv/www/%{pkg_user}/vendor
+%dir /srv/www/%{pkg_user}/vendor/plugins
+%dir /srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/README
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/Rakefile
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/init.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/install.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/uninstall.rb
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/app
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/locale
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/po
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/shortcuts.yml
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/tasks
+#/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/test
+/srv/www/%{pkg_user}/vendor/plugins/%{plugin_name}/config
diff --git a/plugins/custom_services/shortcuts.yml b/plugins/custom_services/shortcuts.yml
new file mode 100644
index 0000000..d9fb55a
--- /dev/null
+++ b/plugins/custom_services/shortcuts.yml
@@ -0,0 +1,8 @@
+main:
+# FIXME: use the correct icon
+ icon: '/icons/yast-online_update.png'
+ url: /custom_services
+ groups: [ Services ]
+ tags: [ init, script, service ]
+ title: Custom Service
+ description: Manage the custom service
diff --git a/plugins/custom_services/tasks/custom_services_tasks.rake b/plugins/custom_services/tasks/custom_services_tasks.rake
new file mode 100644
index 0000000..1568c54
--- /dev/null
+++ b/plugins/custom_services/tasks/custom_services_tasks.rake
@@ -0,0 +1,6 @@
+begin
+ require 'tasks/webservice'
+rescue LoadError => e
+ $stderr.puts "Install rubygem-yast2-webservice-tasks.rpm"
+end
+
diff --git a/plugins/custom_services/test/custom_services_test.rb b/plugins/custom_services/test/custom_services_test.rb
new file mode 100644
index 0000000..fe7b428
--- /dev/null
+++ b/plugins/custom_services/test/custom_services_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class CustomServicesTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/plugins/custom_services/test/functional/custom_services_controller_test.rb b/plugins/custom_services/test/functional/custom_services_controller_test.rb
new file mode 100644
index 0000000..f3dd307
--- /dev/null
+++ b/plugins/custom_services/test/functional/custom_services_controller_test.rb
@@ -0,0 +1,45 @@
+require 'test_helper'
+
+class ServicesControllerTest < ActionController::TestCase
+ def test_should_get_index
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:services)
+ end
+
+ def test_should_get_new
+ get :new
+ assert_response :success
+ end
+
+ def test_should_create_service
+ assert_difference('Service.count') do
+ post :create, :service => { }
+ end
+
+ assert_redirected_to service_path(assigns(:service))
+ end
+
+ def test_should_show_service
+ get :show, :id => services(:one).id
+ assert_response :success
+ end
+
+ def test_should_get_edit
+ get :edit, :id => services(:one).id
+ assert_response :success
+ end
+
+ def test_should_update_service
+ put :update, :id => services(:one).id, :service => { }
+ assert_redirected_to service_path(assigns(:service))
+ end
+
+ def test_should_destroy_service
+ assert_difference('Service.count', -1) do
+ delete :destroy, :id => services(:one).id
+ end
+
+ assert_redirected_to services_path
+ end
+end
diff --git a/plugins/custom_services/test/test_helper.rb b/plugins/custom_services/test/test_helper.rb
new file mode 100644
index 0000000..5d083a8
--- /dev/null
+++ b/plugins/custom_services/test/test_helper.rb
@@ -0,0 +1,19 @@
+rails_parent = ENV["RAILS_PARENT"]
+unless rails_parent
+ default_parent = "../../webclient"
+ if File.directory?(default_parent)
+ $stderr.puts "Taking #{default_parent} for RAILS_PARENT"
+ rails_parent = default_parent
+ else
+ $stderr.puts "Please set RAILS_PARENT environment"
+ exit
+ end
+end
+# first config rails
+require File.expand_path(rails_parent + "/config/environment")
+# then enable testing, this will get the routing right
+ENV["RAILS_ENV"] = "test"
+
+require 'rubygems'
+require 'active_support'
+require 'active_support/test_case'
diff --git a/plugins/custom_services/uninstall.rb b/plugins/custom_services/uninstall.rb
new file mode 100644
index 0000000..9738333
--- /dev/null
+++ b/plugins/custom_services/uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org