ref: refs/heads/master
commit 1a8fdbddd0e0b8fee7b53a9c5a4f0fa02d83df84
Author: Michal Zugec
Date: Thu Sep 10 10:52:25 2009 +0200
editable form for network, send routing value to rest-api, clean code
---
.../network/app/controllers/network_controller.rb | 237 ++++++--------------
plugins/network/app/views/network/edit.html.erb | 2 +-
plugins/network/app/views/network/index.html.erb | 97 +++++++--
3 files changed, 144 insertions(+), 192 deletions(-)
diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb
index eb67a3d..07b6e35 100644
--- a/plugins/network/app/controllers/network_controller.rb
+++ b/plugins/network/app/controllers/network_controller.rb
@@ -5,26 +5,25 @@ class NetworkController < ApplicationController
before_filter :login_required
layout 'main'
include ProxyLoader
+
+ # Initialize GetText and Content-Type.
+ init_gettext "yast_webclient_network"
private
def network_permissions
- @network = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.networks')
- unless @network
+ @client = YaST::ServiceResource.proxy_for('org.opensuse.yast.modules.yapi.network')
+ unless @client
+ # FIXME: check the reason why proxy_for failed, i.e.
+ # - no server known
+ # - no permission to connect to server
+ # - server does not provide interface
+ # - server does not respond (timeout, etc.)
+ # - invalid session
flash[:notice] = _("Invalid session, please login again.")
redirect_to( logout_path ) and return
end
- @permissions = @network.permissions
- end
-
- # Initialize GetText and Content-Type.
- init_gettext "yast_webclient_network"
-
- public
- def initialize
- end
-
- # GET /network
- def index
+
+ @permissions = @client.permissions
@ifcs = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", :all
@iface = params[:interface] || @ifcs[0].id
@@ -40,13 +39,14 @@ class NetworkController < ApplicationController
rt = load_proxy "org.opensuse.yast.modules.yapi.network.routes", "default"
return false unless rt
- # FIXME mixed up by multiple load_proxy
- unless @permissions[:read]
- flash[:warning] = _("No permissions for network module")
- redirect_to root_path
- return false
- end
-
+# # FIXME mixed up by multiple load_proxy
+# unless @permissions[:read]
+# flash[:warning] = _("No permissions for network module")
+# redirect_to root_path
+# return false
+# end
+#
+
@conf_mode = ifc.bootproto
if @conf_mode == "static"
ipaddr = ifc.ipaddr
@@ -61,170 +61,63 @@ class NetworkController < ApplicationController
@searchdomains = dns.searches
@default_route = rt.via
- end
- # GET /users/new
- # GET /users/new.xml
- def new
- return unless network_permissions
-# @user = @client.new( :id => :nil,
-# :no_home=>nil,
-# :default_group=>nil,
-# :new_login_name=>nil,
-# :login_name=>nil,
-# :groups=>[],
-# :grp_string=>nil,
-# :home_directory=>nil,
-# :full_name=>nil,
-# :uid=>nil,
-# :sshkey=>nil,
-# :new_uid=>nil,
-# :login_shell=>"/bin/bash",
-# :password=>nil,
-# :type=>"local",
-# :id=>nil )
-# respond_to do |format|
-# format.html # new.html.erb
-# format.xml { render :xml => @user }
+# @network = YaST::ServiceResource.proxy_for('org.opensuse.yast.system.network')
+# unless @network
+# flash[:notice] = _("Invalid session, please login again.")
+# redirect_to( logout_path ) and return
# end
end
-
- # GET /users/1/edit
- def edit
- return unless network_permissions
-
- @network = @network.find(params[:id])
-# @user.type = ""
-# @user.id = @user.login_name
-# @user.grp_string = ""
-# counter = 0
-# @user.grp_string = ""
-# @user.groups.each do |group|
-# if counter == 0
-# @user.grp_string = group.id
-# else
-# @user.grp_string += ",#{group.id}"
-# end
-# counter += 1
-# end
+
+ public
+ def initialize
end
-
-
-
- # POST /users
- # POST /users.xml
- def create
- return unless client_permissions
- dummy = @client.new(params[:user])
- dummy.grp_string = params[:user][:grp_string] #do not know, why this will not be assigned in the constructor
-
- dummy.groups = []
- if dummy.grp_string != nil
- dummy.grp_string.split(",").each do |group|
- dummy.groups << { :id=>group.strip }
- end
- end
- @user = @client.new(:no_home=>params[:nohome],
- :default_group=>dummy.default_group,
- :new_login_name=>nil,
- :login_name=>dummy.login_name,
- :groups=>dummy.groups,
- :grp_string=>dummy.grp_string,
- :home_directory=>dummy.home_directory,
- :full_name=>dummy.full_name,
- :uid=>dummy.uid,
- :sshkey=>nil,
- :new_uid=>nil,
- :login_shell=>dummy.login_shell,
- :password=>dummy.password,
- :type=>"local")
-
- #Only UID greater than 1000 are allowed for local user
- response = true
- if @user.uid.to_i < 1000
- response = false
- else
- begin
- response = @user.save
- rescue ActiveResource::ClientError => e
- flash[:error] = YaST::ServiceResource.error(e)
- response = false
- end
+
+ # GET /network
+ def index
+ return unless network_permissions
+ @networks = []
+ begin
+ @networks = @client.find(:all)
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
end
+
respond_to do |format|
- if response
- flash[:notice] = _('User was successfully created.')
- format.html { redirect_to(users_url) }
- else
- if @user.uid.to_i < 1000
- #Only UID greater than 1000 are allowed for local user
- flash[:error] = _("UID: value >= 1000 is valid for local user only")
- end
- format.html { render :action => "new" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
- end
+ format.html # index.html.erb
+ format.xml { render :xml => @networks }
end
end
+ # GET /users/1/edit
+ def edit
+ end
+
+
# PUT /users/1
# PUT /users/1.xml
def update
- return unless network_permissions
- @user = @client.find(params[:id])
- @user.new_login_name = nil
- @user.new_uid = nil
- @user.id = @user.login_name
- @user.default_group = params["user"]["default_group"]
- @user.groups = []
- if params["user"]["grp_string"] != nil
- @user.grp_string = params["user"]["grp_string"]
- params["user"]["grp_string"].split(",").each do |group|
- @user.groups << { :id=>group.strip }
- end
- end
- if @user.login_name != params["user"]["login_name"]
- @user.new_login_name = params["user"]["login_name"]
- end
- @user.home_directory = params["user"]["home_directory"]
- @user.full_name = params["user"]["full_name"]
- if @user.uid != params["user"]["uid"]
- @user.new_uid = params["user"]["uid"]
- end
- @user.login_shell = params["user"]["login_shell"]
- @user.password = params["user"]["password"]
- @user.type = "local"
-
- respond_to do |format|
- response = true
- begin
- response = @user.save
- rescue ActiveResource::ClientError => e
- flash[:error] = YaST::ServiceResource.error(e)
- response = false
- end
- if response
- flash[:notice] = _('User was successfully updated.')
- format.html { redirect_to(users_url) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
- end
+ rt = load_proxy "org.opensuse.yast.modules.yapi.network.routes", "default"
+ unless rt
+ return false
end
- end
- # DELETE /users/1
- # DELETE /users/1.xml
- def destroy
- return unless network_permissions
- @user = @client.find(params[:id])
- @user.id = @user.login_name
- @user.type = "local"
- @user.destroy
-
- respond_to do |format|
- format.html { redirect_to(users_url) }
- format.xml { head :ok }
- end
+ rt.via = params["default_route"]
+# fill_proxy_with_time t,params
+
+ begin
+ rt.save
+ flash[:notice] = _('Settings have been written.')
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ logger.warn e
+ rescue Exception => e
+ flash[:error] = e.message
+ logger.warn e
+ end
+
+# redirect_to :action => :index
+# index
+ redirect_to :action => 'index'
end
end
diff --git a/plugins/network/app/views/network/edit.html.erb b/plugins/network/app/views/network/edit.html.erb
index 5fed60a..90fc23f 100644
--- a/plugins/network/app/views/network/edit.html.erb
+++ b/plugins/network/app/views/network/edit.html.erb
@@ -3,7 +3,7 @@
<% disabled = ! @permissions[:write] %>
-<% form_for(:network, @network, :url => { :action => "update" }, :html => { :method => :put } ) do |f| %>
+<% form_for(:network, @network, :url => { :action => "update" }, :xml => { :method => :put } ) do |f| %>
<%= f.error_messages %>
<div class="table">
diff --git a/plugins/network/app/views/network/index.html.erb b/plugins/network/app/views/network/index.html.erb
index 1bb268c..edef995 100644
--- a/plugins/network/app/views/network/index.html.erb
+++ b/plugins/network/app/views/network/index.html.erb
@@ -2,30 +2,89 @@
<div class='plugin-content'>
<h2><%=_("Network")%></h2>
-<!-- TODO translations -->
+<% disabled = ! @permissions[:write] %>
-<h3>Interface</h3>
-<% form_tag("/network", :method => "get") do |f| %>
+<% form_for(:network, @network, :url => { :action => "update" }, :html => { :method => :put } ) do |n| %>
+<%#= n.error_messages %>
+<!-- ~/svn/web-client/plugins/systemtime/app/views/systemtime/index.rhtml -->
+
+
+<!--
+TODO: we can't do form-in-form, use some AJAX trick instead
+//-->
+<%# form_tag("/network", :method => "get") do |f| %>
<!-- (collection, value, text, selected) -->
- <%= select_tag(:interface,
- options_from_collection_for_select(@ifcs, :id, :id, @iface)) %>
- <%= submit_tag("Select") %>
-<% end %>
+ <div class="table">
+ <table class="list" cellpadding="0" cellspacing="0">
+ <tr>
+ <th class="full" colspan="2"><%=_("Interface")%></th>
+ </tr>
+ <tr>
+ <td class="first" width="120"><%= select_tag(:interface,
+ options_from_collection_for_select(@ifcs, :id, :id, @iface)) %></td>
+ <td class="last"><%#= submit_tag("Select") %></td>
+ </tr>
+ </table>
+ </div>
+<%# end %>
-<h3>IP Address</h3>
+ <div class="table">
+ <table class="list" cellpadding="0" cellspacing="0">
+ <tr>
+ <th class="full" colspan="2"><%=_("IP Address")%></th>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Configuration Mode")%></strong></td>
+ <td class="last"><%=text_field_tag :conf_mode, @conf_mode, :disabled => disabled %></td>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("IP Address")%></strong></td>
+ <td class="last"><%=text_field_tag :ip, @ip, :disabled => disabled %></td>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Netmask")%></strong></td>
+ <td class="last"><%=text_field_tag :netmask, @netmask, :disabled => disabled %></td>
+ </tr>
+ </table>
+ </div>
-<p>Configuration Mode: <%=h @conf_mode %></p>
-<p>IP Address: <%=h @ip %></p>
-<p>Netmask: <%=h @netmask %></p>
+ <div class="table">
+ <table class="list" cellpadding="0" cellspacing="0">
+ <tr>
+ <th class="full" colspan="2"><%=_("DNS")%></th>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Hostname")%></strong></td>
+ <td class="last"><%=text_field_tag :name, @name, :disabled => disabled %></td>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Domain")%></strong></td>
+ <td class="last"><%=text_field_tag :domain, @domain, :disabled => disabled %></td>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Name Servers")%></strong></td>
+ <td class="last"><%=text_field_tag :nameservers, @nameservers.join(" "), :disabled => disabled %></td>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Search Domains")%></strong></td>
+ <td class="last"><%=text_field_tag :searchdomains, @searchdomains.join(" "), :disabled => disabled %></td>
+ </tr>
-<h3>DNS</h3>
-<p>Hostname: <%=h @name %></p>
-<p>Domain: <%=h @domain %></p>
-<p>Name Servers: <%=h @nameservers.join " " %></p>
-<p>Search Domains: <%=h @searchdomains.join " " %></p>
+ </table>
+ </div>
-<h3>Routing</h3>
-<p>Default Route: <%=h @default_route %></p>
+ <div class="table">
+ <table class="list" cellpadding="0" cellspacing="0">
+ <tr>
+ <th class="full" colspan="2"><%=_("Routing")%></th>
+ </tr>
+ <tr>
+ <td class="first" width="120"><strong><%=_("Default Route")%></strong></td>
+ <td class="last"><%=text_field_tag :default_route, @default_route, :disabled => disabled %></td>
+ </tr>
+ </table>
+ </div>
-<a href="/" class="button"><%=_("Back")%></a>
+<%= n.submit _("Update"), :disabled => disabled %><a href="/" class="button"><%=_("Back")%></a>
+<% end %>
</div>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org