-
Notifications
You must be signed in to change notification settings - Fork 8
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 #81 from yast/features/interfaces-list
Add a list of interfaces
- Loading branch information
Showing
13 changed files
with
800 additions
and
58 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,63 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "cwm/popup" | ||
require "y2firewall/widgets/zone_options" | ||
|
||
module Y2Firewall | ||
module Dialogs | ||
# This dialog allows the user to select which zone should be an interface assigned to. | ||
class ChangeZone < ::CWM::Popup | ||
# @!attribute [r] interface | ||
# @return [Y2Firewall::Firewalld::Interface] Interface to act on | ||
attr_reader :interface | ||
|
||
# Constructor | ||
# | ||
# @param interface [Y2Firewall::Firewalld::Interface] Interface to act on | ||
def initialize(interface) | ||
textdomain "firewall" | ||
@interface = interface | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def title | ||
_("Change Zone") | ||
end | ||
|
||
# @macro seeCustomWidget | ||
def contents | ||
VBox(zone_options) | ||
end | ||
|
||
private | ||
|
||
# Returns a combobox to select the zone | ||
# | ||
# @note The widget is 'memoized'. | ||
# | ||
# @return [Y2Firewall::Widgets::ZoneOptions] | ||
def zone_options | ||
@zone_options ||= Y2Firewall::Widgets::ZoneOptions.new(interface) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "cwm/ui_state" | ||
|
||
module Y2Firewall | ||
# Singleton class to keep the position of the user in the UI and other similar | ||
# information that needs to be rememberd across UI redraws to give the user a | ||
# sense of continuity. | ||
class UIState < CWM::UIState | ||
# Method to be called when the user decides to visit a given page by | ||
# clicking in one node of the general tree. | ||
# | ||
# It remembers the decision so the user is taken back to a sensible point of | ||
# the tree (very often the last he decided to visit) after redrawing. | ||
# | ||
# @param [CWM::Page] page associated to the tree node | ||
def go_to_tree_node(page) | ||
super | ||
self.candidate_nodes = | ||
if page.respond_to?(:zone) | ||
zone_page_candidates(page) | ||
else | ||
[page.label] | ||
end | ||
end | ||
|
||
protected | ||
|
||
# @see CWM::UIState#textdomain_name | ||
def textdomain_name | ||
"firewall" | ||
end | ||
|
||
# List of candidate nodes to go back after opening a zone view in the tree | ||
def zone_page_candidates(page) | ||
zone = page.zone | ||
|
||
[zone.name] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "cwm" | ||
require "y2firewall/dialogs/change_zone" | ||
require "y2firewall/ui_state" | ||
|
||
module Y2Firewall | ||
module Widgets | ||
# This button opens a dialog to change the zone for a given interface | ||
class ChangeZoneButton < CWM::PushButton | ||
# @!attribute [r] interface | ||
# @return [Y2Firewall::Firewalld::Interface] Interface to act on | ||
attr_accessor :interface | ||
|
||
# Constructor | ||
# | ||
# @param interface [Y2Firewall::Firewalld::Interface] Interface to act on | ||
def initialize(interface) | ||
textdomain "firewall" | ||
@interface = interface | ||
end | ||
|
||
# @see seeAbstractWidget | ||
def label | ||
_("Change Zone") | ||
end | ||
|
||
# @see seeAbstractWidget | ||
def handle | ||
return nil unless interface | ||
result = Dialogs::ChangeZone.run(interface) | ||
result == :ok ? :redraw : nil | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# encoding: utf-8 | ||
|
||
# Copyright (c) [2018] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "cwm" | ||
require "cwm/table" | ||
require "y2firewall/ui_state" | ||
|
||
module Y2Firewall | ||
module Widgets | ||
# A table with all {Y2Firewall::Firewalld::Interface}s. | ||
class InterfacesTable < ::CWM::Table | ||
DEFAULT_ZONE_NAME = "default".freeze | ||
|
||
# @!attribute [r] interfaces | ||
# @return [Array<Y2Firewall::Firewalld::Interface>] Interfaces | ||
attr_reader :interfaces | ||
|
||
# Constructor | ||
# | ||
# @param interfaces [Array<Y2Firewall::Firewalld::Interfaces>] Interfaces to list | ||
# @param change_zone_button [Y2Firewall::Widgets::ChangeZoneButton] Button to change assigned | ||
# zone | ||
def initialize(interfaces, change_zone_button) | ||
textdomain "firewall" | ||
@interfaces = interfaces | ||
@change_zone_button = change_zone_button | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def opt | ||
[:notify, :immediate] | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def init | ||
interface = Y2Firewall::UIState.instance.row_id | ||
if interface && interfaces.map(&:id).include?(interface) | ||
self.value = interface | ||
end | ||
change_zone_button.interface = selected_interface | ||
end | ||
|
||
# @see CWM::Table#header | ||
def header | ||
[ | ||
_("Device"), | ||
_("Zone"), | ||
_("Name") | ||
] | ||
end | ||
|
||
# @see CWM::Table#items | ||
def items | ||
interfaces.map do |iface| | ||
[ | ||
iface.id, | ||
iface.name, | ||
iface.zone ? iface.zone.name : DEFAULT_ZONE_NAME, | ||
iface.device_name | ||
] | ||
end | ||
end | ||
|
||
# @macro seeAbstractWidget | ||
def handle(event) | ||
return nil unless event["EventReason"] == "SelectionChanged" | ||
UIState.instance.select_row(value) | ||
change_zone_button.interface = selected_interface | ||
nil | ||
end | ||
|
||
def selected_interface | ||
interfaces.find { |i| i.id == value } | ||
end | ||
|
||
private | ||
|
||
# @return [Y2Firewalld::Widgets::ChangeZoneButton] Button to change the assigned zone | ||
attr_reader :change_zone_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
Oops, something went wrong.