Mailinglist Archive: yast-commit (2080 mails)

< Previous Next >
[yast-commit] <web-client> network : use YaPI based API (org.opensuse.yast.modules.yapi.services)
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Mon, 24 Aug 2009 15:37:54 +0200
  • Message-id: <E1MnBbr-0003V4-1Q@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit bb00de7f6db94f639ade1d8923eda10ccaced50b
Author: Jiri Suchomel <jsuchome@xxxxxxx>
Date: Tue Aug 18 15:23:20 2009 +0200

use YaPI based API (org.opensuse.yast.modules.yapi.services)
---
.../app/controllers/config_ntp_controller.rb | 53 ---------
.../app/controllers/services_controller.rb | 95 +++++----------
plugins/services/app/models/config_ntp.rb | 6 -
plugins/services/app/models/service.rb | 5 -
.../services/app/views/config_ntp/show.html.erb | 32 -----
.../services/app/views/services/fancy_index.rhtml | 122 --------------------
plugins/services/app/views/services/index.rhtml | 38 +++---
7 files changed, 50 insertions(+), 301 deletions(-)

diff --git a/plugins/services/app/controllers/config_ntp_controller.rb
b/plugins/services/app/controllers/config_ntp_controller.rb
deleted file mode 100644
index 82de4a3..0000000
--- a/plugins/services/app/controllers/config_ntp_controller.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-class ConfigNtpController < ApplicationController
- before_filter :login_required
- layout 'main'
-
- # Initialize GetText and Content-Type.
- init_gettext "yast_webclient_services" # textdomain, options(:charset,
:content_type)
-
- def show
- @client =
YaST::ServiceResource.proxy_for('org.opensuse.yast.system.services')
- @permissions = @client.permissions
-
- @ntp = ConfigNtp.find(:one, :from => '/services/ntp/config.xml')
- logger.debug "ConfigNtp: #{@ntp.inspect}"
-
- if @ntp.enabled == true
- @is_enabled = "checked"
- else
- @is_enabled = ""
- end
- if @ntp.use_random_server == true
- @is_use_random_server = "checked"
- else
- @is_use_random_server = ""
- end
- end
-
- def create
- @ntp = ConfigNtp.find(:one, :from => '/services/ntp/config.xml')
- logger.debug "ConfigNtp: #{@ntp.inspect}"
- logger.debug "Changing to #{params.inspect}"
- @ntp.manual_server = params[:manual_server]
- if params[:enabled] == "true"
- @ntp.enabled = true
- else
- @ntp.enabled = false
- end
- if params[:use_random_server] == "true"
- @ntp.use_random_server = true
- else
- @ntp.use_random_server = false
- end
- @ntp.id = "ntp"
- response = @ntp.put(:config, {}, @ntp.to_xml)
- retNtp = Hash.from_xml(response.body)
- if retNtp["config_ntp"]["error_id"] != 0
- flash[:error] = retNtp["config_ntp"]["error_string"]
- else
- flash[:notice] = _("Settings have been written.")
- end
- redirect_to :action => :show
- end
-
-end
diff --git a/plugins/services/app/controllers/services_controller.rb
b/plugins/services/app/controllers/services_controller.rb
index 9932336..9d86f9d 100644
--- a/plugins/services/app/controllers/services_controller.rb
+++ b/plugins/services/app/controllers/services_controller.rb
@@ -1,81 +1,49 @@
-require 'service'
+require 'yast/service_resource'

class ServicesController < 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_services" # textdomain, options(:charset,
:content_type)

- def index
- proxy =
YaST::ServiceResource.proxy_for('org.opensuse.yast.system.services')
- @permissions = proxy.permissions
+ public

- @services = Service.find(:all, :from => '/services.xml')
- @table = []
- counter = 1
- max_column = 0
- table_counter = 1
- @services.each do | s |
- @services[counter-1].command_list = []
- commands = %w{status start stop restart force-reload bogus} # FIXME
s.commands is gone
- commands.each do | comm |
- cname = comm # FIXME comm.name is gone
- iname = cname
- case iname
- when "run"
- iname = "start"
- when "try-restart"
- iname = "restart"
- when "force-reload"
- iname = "reload"
- else
- iname = "empty"
- end
- c = {:name => cname, :icon => "/images/#{iname}.png" }
- @services[counter-1].command_list << c
- end
+ def initialize
+ end

- if s.link == "ntp"
- #add configuration module if there is a read permission
- c = {:name=>"configure", :icon=>"/images/configure.png" }
- @services[counter-1].command_list << c
- end
- if @services[counter-1].command_list.size > max_column
- max_column = @services[counter-1].command_list.size
- end
- if table_counter * 4 == counter #next table have to begin
- @table << max_column
- table_counter +=1
- max_column = 0
- end
- counter += 1
- end
- if max_column > 0
- @table << max_column #add last table
- end
- if params[:last_error] && params[:last_error] != 0
- @last_result = params[:last_error]
- else
- @last_result = 0
- end
- if params[:last_error_string]
- @last_result_string = params[:last_error_string]
- else
- @last_result_string = ""
+ # GET /services
+ # GET /services.xml
+ def index
+ return unless client_permissions
+ @services = []
+ begin
+ @services = @client.find(:all)
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
end

- if params[:fancy] == "1"
- render :fancy_index and return
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @services }
end
end

def execute
- @service = Service.find(params[:service_id])
- @service.id = @service.link
- command_id = "commands/" + params[:id]
- logger.debug "calling #{command_id} with service #{@service.inspect}"
- response = @service.put(command_id)
+ 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)
@@ -85,11 +53,12 @@ class ServicesController < ApplicationController
@result_string = ""
@result_string << ret["stdout"] if ret["stdout"]
@result_string << ret["stderr"] if ret["stderr"]
- @error_string = ret["exit"].to_s # TODO translate exit codes (use YaST?)
+ @error_string = ret["exit"].to_s
if ret["exit"] == 0
@error_string = _("success")
end
render(:partial =>'result')
end

+
end
diff --git a/plugins/services/app/models/config_ntp.rb
b/plugins/services/app/models/config_ntp.rb
deleted file mode 100644
index 9d24b74..0000000
--- a/plugins/services/app/models/config_ntp.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require 'yast/service_resource'
-
-class ConfigNtp< YaST::ServiceResource::Base
- self.collection_name = "services"
- self.element_name = "config_ntp"
-end
diff --git a/plugins/services/app/models/service.rb
b/plugins/services/app/models/service.rb
deleted file mode 100644
index 870ad2f..0000000
--- a/plugins/services/app/models/service.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'yast/service_resource'
-
-class Service < YaST::ServiceResource::Base
- attr_accessor :commandList
-end
diff --git a/plugins/services/app/views/config_ntp/show.html.erb
b/plugins/services/app/views/config_ntp/show.html.erb
deleted file mode 100644
index c2b28df..0000000
--- a/plugins/services/app/views/config_ntp/show.html.erb
+++ /dev/null
@@ -1,32 +0,0 @@
-<h1><%=_("NTP Server")%></h1>
-<br>
-
-<% form_tag 'config' do %>
- <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"><%=_("Settings")%></th>
- </tr>
- <tr>
- <td class="first" width="120"><strong><%=_("Enabled")%></strong></td>
- <td class="last"><input type="checkbox" name="enabled" value="true"
<%= @is_enabled %> <%= "disabled=\"disabled\"" if !@permissions[:write] %>></td>
- </tr>
- <tr class="bg">
- <td class="first"><strong><%=_("Use random server")%></strong></td>
- <td class="last"><input type="checkbox" name="use_random_server"
value="true" <%= @is_use_random_server %> <%= "disabled=\"disabled\"" if
!@permissions[:write] %>></td>
- </tr>
- <tr>
- <td class="first"><strong><%=_("Manual Servers")%></strong></td>
- <td class="last"><%= text_field_tag "manual_server",
@ntp.manual_server , :disabled=>!@permissions[:write]%></td>
- </tr>
- </table>
- <p><%= submit_tag _("Save"), :disabled=> !@permissions[:write] -%><%=
link_to _('Back'), {:controller => 'services'}, :class => "button" %></p>
- </div>
-<% end %>
-
-
-
-
-
diff --git a/plugins/services/app/views/services/fancy_index.rhtml
b/plugins/services/app/views/services/fancy_index.rhtml
deleted file mode 100644
index 8c6884c..0000000
--- a/plugins/services/app/views/services/fancy_index.rhtml
+++ /dev/null
@@ -1,122 +0,0 @@
-<%= 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 -->
-
-<h1><%=_("Services")%></h1>
-<br>
-
-<% if ! @permissions[:execute] %>
-<!-- TODO generalize this to all views -->
-<p>You do not have permission to execute the services. The links are
disabled.</p>
-<% end %>
-<% for table_counter in 0..@xxxxxxxxxxxx do %>
- <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" cellpadding="0" cellspacing="0">
- <tr>
- <% for column_counter in 0..3 do %>
- <% i = table_counter*4+column_counter %>
- <% if @services.size > i %>
- <% link = @services[i].link %>
- <% if column_counter == 0 %>
- <th class="first" width=17%><%=h link %></th>
- <% elsif column_counter == 3 %>
- <th class="last" width=17%><%=h link %></th>
- <% else %>
- <th width=17%><%=h link %></th>
- <% end %>
- <% else %>
- <% if column_counter == 3 %>
- <th class="last" width=17%></th>
- <% else %>
- <th width=17%></th>
- <% end %>
- <% end %>
- <% end %>
- </tr>
- <% for line_counter in 0..@table[table_counter]-1 do %>
- <tr>
- <% for column_counter in 0..3 do %>
- <% i = table_counter*4+column_counter %>
- <% if @services.size > i %>
- <% command_list = @services[i].command_list %>
- <% link = @services[i].link %>
- <% if line_counter < command_list.size %>
- <td>
- <% if command_list[line_counter][:name] ==
"configure" %>
- <%= link_to
image_tag("#{command_list[line_counter][:icon]}", :alt => "icon"),
- :id=>"config",
- :action =>link %>
- <strong><%= link_to
"#{command_list[line_counter][:name]}", :id=>"config",
- :action =>link %></strong>
- <% else %>
- <% if @permissions[:execute] %>
- <%= link_to_remote
image_tag("#{command_list[line_counter][:icon]}", :alt => "icon"),
- :update => "resultdlg",
- :url=>{ :id=>
command_list[line_counter][:name],
- :action =>
"execute",
- :service_id=> link
},
- :loading =>
"Element.show('progress');",
- :complete =>
"Element.hide('progress'); showResultDialog();" %>
- <strong><%= link_to_remote
"#{command_list[line_counter][:name]}",
- :update => "resultdlg",
- :url=>{ :id=>
command_list[line_counter][:name],
- :action =>
"execute",
- :service_id=> link
},
- :loading =>
"Element.show('progress');",
- :complete =>
"Element.hide('progress'); showResultDialog();"
- %></strong>
- <% else %>
- <%=
image_tag("#{command_list[line_counter][:icon]}", :alt => "icon") %>
- <strong><span style="color:
#BDBDBD"><%="#{command_list[line_counter][:name]}" -%></span></strong>
- <% end %>
- <% end %>
- </td>
- <% else %>
- <td> </td>
- <% end %>
- <% else %>
- <% if column_counter == 3 %>
- <td class="last" width=17%></td>
- <% else %>
- <td width=17%></td>
- <% end %>
- <% end %>
- <% end %>
- </tr>
- <% end %>
- </table>
- </div>
-<% end %>
diff --git a/plugins/services/app/views/services/index.rhtml
b/plugins/services/app/views/services/index.rhtml
index c3d63d8..ff71692 100644
--- a/plugins/services/app/views/services/index.rhtml
+++ b/plugins/services/app/views/services/index.rhtml
@@ -27,7 +27,6 @@
YAHOO.util.Event.addListener(window, "load", initResultDialog);
</script>

-
<!-- begin: dialog box -->
<div id="resultdlg">
</div>
@@ -40,30 +39,29 @@
<br>

<% if ! @permissions[:execute] %>
-<!-- TODO generalize this to all views -->
-<p>You do not have permission to execute the services. The links are
disabled.</p>
+<p><%=_("You do not have permission to execute the services. The links are
disabled.")%></p>
<% end %>

<ul>
-<% @services.each do |svc| %>
-<li><b><%=h svc.link %></b>
- <% svc.command_list.each do |cmd|
- if cmd[:name] == "configure" %>
- <%= link_to cmd[:name], :id=>"config", :action =>svc.link %>
- <% else
- if @permissions[:execute] %>
- <%= link_to_remote cmd[:name],
+<% @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[:name],
+ :url=>{ :id=> cmd,
:action => "execute",
- :service_id=> svc.link },
- :loading => "Element.show('progress');",
- :complete => "Element.hide('progress');
showResultDialog();"
- %>
- <% else %>
- <span style="color: #BDBDBD"><%="#{cmd[:name]}" -%></span>
- <% end
- end
+ :service_id=> service.name
+ }
+# :loading => "Element.show('progress')"
+# :complete => "Element.hide('progress');
showResultDialog();"
+ %>
+ <%
+ else %>
+ <span style="color: #BDBDBD"><%="#{cmd}" -%></span>
+ <%
+ end
end %>
</li>
<% end %>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages