Mailinglist Archive: yast-devel (246 mails)

< Previous Next >
[yast-devel] Re: [yast-commit] <web-client> master : custom-services client
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Mon, 17 Aug 2009 10:28:10 +0200
  • Message-id: <4A89149A.5090808@xxxxxxx>
On 08/17/2009 10:02 AM, Jiri Suchomel wrote:
ref: refs/heads/master
commit 89703cf8f4b2848c1bfbdb71de8df8414d0f5a96
Author: Jiri Suchomel <jsuchome@xxxxxxx>
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

I recommend using proxy_loader library. That handle properly all stuff
with loading proxy and also ensure same behavior for all plugins. It is
well documented with examplanation example.

+
+ # 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 %>
I think you don't want this, this is helper for AJAX stuff (loads all
necessary libs for working AJAX helpers) . Your library I think is
included already from template.
+
+<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>
+

We have YAHOO js lib? I think we remove it. At least it should be good
if we document what libraries is used in webyast and what should other
module use.

+<!-- 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] %>
unless is common in ruby
+<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>
I think we should not use hardcoded style, I think better is send mail
to robert and choose some class for this case.
+ <%
+ end
+ end %>
+</li>
+<% end %>
+</ul>
+
+</div>



--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language
and time
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages