Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from yast/routing_cwm
add initial object proposal for dialog routes and gateway cwm widget
- Loading branch information
Showing
15 changed files
with
603 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require "ipaddr" | ||
|
||
require "cwm/popup" | ||
require "y2network/route" | ||
require "y2network/widgets/destination" | ||
require "y2network/widgets/devices" | ||
require "y2network/widgets/gateway" | ||
require "y2network/widgets/route_options" | ||
|
||
Yast.import "Label" | ||
|
||
module Y2Network | ||
module Dialogs | ||
# Dialog to create or edit route. | ||
class Route < CWM::Popup | ||
# @param route is now term from table, but it should be object for single route | ||
def initialize(route, available_devices) | ||
log.info "route dialog with route: #{route.inspect} " \ | ||
"and devices #{available_devices.inspect}" | ||
params = route.params | ||
@route_id = params[0] | ||
# TODO: netmask | ||
@route = ::Y2Network::Route.new( | ||
to: (params[1] || "-") == "-" ? :default : IPAddr.new(params[1]), | ||
interface: (params[4].nil? || params[4].empty?) ? :any : params[4], | ||
gateway: (params[2] || "-") == "-" ? nil : IPAddr.new(params[2]), | ||
options: params[5] || "" | ||
) | ||
|
||
@available_devices = available_devices | ||
end | ||
|
||
def run | ||
res = super | ||
log.info "route dialog result #{res.inspect}" | ||
return nil if res != :ok | ||
|
||
Yast::Term.new( | ||
:item, | ||
@route_id, | ||
@route.to == :default ? "-" : @route.to.to_s, | ||
@route.gateway.nil? ? "-" : @route.gateway.to_s, | ||
"-", # TODO: netmask | ||
@route.interface == :any ? "" : @route.interface, | ||
@route.options | ||
) | ||
end | ||
|
||
def contents | ||
MinWidth( | ||
60, | ||
VBox( | ||
HBox( | ||
HWeight(100, Widgets::Destination.new(@route)) | ||
), | ||
HBox( | ||
HWeight(70, Widgets::Gateway.new(@route)), | ||
HSpacing(1), | ||
HWeight(30, Widgets::Devices.new(@route, @available_devices)) | ||
), | ||
Widgets::RouteOptions.new(@route) | ||
) | ||
) | ||
end | ||
end | ||
|
||
def next_button | ||
Yast::Label.OKButton | ||
end | ||
|
||
def back_button | ||
Yast::Label.CancelButton | ||
end | ||
|
||
def abort_button | ||
"" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Yast.import "IP" | ||
Yast.import "Popup" | ||
|
||
require "ipaddr" | ||
|
||
require "cwm/common_widgets" | ||
|
||
module Y2Network | ||
module Widgets | ||
class Destination < CWM::InputField | ||
# @param route [Y2Network::Route] route to modify by widget | ||
def initialize(route) | ||
textdomain "network" | ||
|
||
@route = route | ||
end | ||
|
||
def label | ||
_("&Destination") | ||
end | ||
|
||
def help | ||
# TODO: original also does not have help, so write new one | ||
"" | ||
end | ||
|
||
def opt | ||
[:hstretch] | ||
end | ||
|
||
def init | ||
Yast::UI.ChangeWidget(Id(widget_id), :ValidChars, Yast::IP.ValidChars + "-/") | ||
val = @route.to | ||
self.value = val == :default ? "-" : (val.to_s + "/" + val.prefix.to_s) | ||
end | ||
|
||
def validate | ||
return true if valid_destination? | ||
|
||
Yast::Popup.Error(_("Destination is invalid.")) | ||
focus | ||
false | ||
end | ||
|
||
def store | ||
@route.to = value == "-" ? :default : IPAddr.new(value) | ||
end | ||
|
||
private | ||
|
||
# Validates user's input obtained from destination field | ||
def valid_destination? | ||
destination = value | ||
return true if destination == "-" | ||
|
||
ip = destination[/^[^\/]+/] | ||
Yast::IP.Check(ip) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.