Skip to content

Commit

Permalink
Merge 67c97a6 into 29d565a
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 10, 2018
2 parents 29d565a + 67c97a6 commit 36ee948
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 196 deletions.
7 changes: 7 additions & 0 deletions package/yast2-dns-server.changes
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Tue Aug 7 12:14:35 UTC 2018 - dgonzalez@suse.com

- Use CWM::ServiceWidget to manage the service status
(part of fate#319428).
- 4.1.0

-------------------------------------------------------------------
Wed Jul 25 18:20:26 UTC 2018 - knut.anderssen@suse.com

Expand Down
12 changes: 7 additions & 5 deletions package/yast2-dns-server.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-dns-server
Version: 4.0.4
Version: 4.1.0
Release: 0
Url: https://github.com/yast/yast-dns-server

Expand All @@ -33,8 +33,8 @@ BuildRequires: yast2-perl-bindings
BuildRequires: yast2-testsuite
BuildRequires: rubygem(rspec)

# SuSEFirewall2 replaced by firewalld
BuildRequires: yast2 >= 4.0.39
# Yast2::ServiceWidget
BuildRequires: yast2 >= 4.1.0
Requires: /usr/bin/host
Requires: perl-gettext
# Exporter Data::Dumper
Expand All @@ -55,8 +55,8 @@ Requires: sed
# FATE #303386: Network setup tools
Requires: yast2-sysconfig

# SuSEFirewall2 replaced by firewalld
Requires: yast2 >= 4.0.39
# Yast2::ServiceWidget
Requires: yast2 >= 4.1.0

BuildArch: noarch

Expand All @@ -82,6 +82,8 @@ This package contains the YaST2 component for DNS server configuration.
%defattr(-,root,root)
%dir %{yast_yncludedir}/dns-server
%{yast_yncludedir}/dns-server/*
%dir %{yast_libdir}/dns-server
%{yast_libdir}/dns-server/*.rb
%{yast_clientdir}/dns-server.rb
%{yast_clientdir}/dns-server_*.rb
%{yast_moduledir}/*
Expand Down
1 change: 0 additions & 1 deletion src/.gitignore
@@ -1,3 +1,2 @@
.dep
*.ybc
dns-server
6 changes: 5 additions & 1 deletion src/Makefile.am
Expand Up @@ -30,6 +30,10 @@ ynclude_DATA = \
include/dns-server/cmdline.rb \
include/dns-server/helps.rb

ylibdir = @ylibdir@/dns-server
ylib_DATA = \
lib/dns-server/service_widget_helpers.rb

scrconf_DATA = \
scrconf/dns_zone.scr \
scrconf/cfg_named.scr \
Expand All @@ -49,6 +53,6 @@ schemafiles_DATA = \
desktop_DATA = \
desktop/dns-server.desktop

EXTRA_DIST = $(module_DATA) $(module1_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(agent_SCRIPTS) $(schemafiles_DATA) $(desktop_DATA)
EXTRA_DIST = $(module_DATA) $(module1_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(agent_SCRIPTS) $(schemafiles_DATA) $(desktop_DATA) $(ylib_DATA)

include $(top_srcdir)/Makefile.am.common
41 changes: 15 additions & 26 deletions src/include/dns-server/dialog-installwizard.rb
Expand Up @@ -9,8 +9,13 @@
#
# Representation of the configuration of dns-server.
# Input and output routines.

require "dns-server/service_widget_helpers"

module Yast
module DnsServerDialogInstallwizardInclude
include Y2DnsServer::ServiceWidgetHelpers

def initialize_dns_server_dialog_installwizard(include_target)
textdomain "dns-server"

Expand All @@ -23,6 +28,14 @@ def initialize_dns_server_dialog_installwizard(include_target)
Yast.import "CWMFirewallInterfaces"
end

# Writes settings and save the service
#
# @return [Boolean] true if service is saved successfully; false otherwise
def write_dns_settings
service_widget.store
service.save
end

def runInstallWizardForwardersDialog
caption =
# Dialog caption (before a colon)
Expand Down Expand Up @@ -184,22 +197,7 @@ def runInstallWizardFinishDialog
VBox(
firewall_layout,
ldap_support,
# Label for Radiobuttons - DNS starting
Left(Label(_("Start-up Behavior"))),
Left(
RadioButtonGroup(
Id("dns_server_type"),
VBox(
# Radiobutton label - DNS starting
Left(
RadioButton(Id(:on), _("O&n: Start Now and When Booting"))
),
# Radiobutton label - DNS starting
Left(RadioButton(Id(:off), _("O&ff: Only Start Manually"))),
VSpacing(1)
)
)
)
service_widget.contents,
),
RichText(Id("installation_overview"), rich_text),
VSpacing(2),
Expand All @@ -222,13 +220,6 @@ def runInstallWizardFinishDialog
SetDNSSErverIcon()
Wizard.SetNextButton(:next, Label.FinishButton)

auto_start = DnsServer.GetStartService
UI.ChangeWidget(
Id("dns_server_type"),
:CurrentButton,
auto_start ? :on : :off
)

use_ldap = false
# only expert allows to store data in ldap
if DnsServer.ExpertUI
Expand Down Expand Up @@ -270,10 +261,8 @@ def runInstallWizardFinishDialog
end

if ret == :next || ret == :expert
DnsServer.SetModified
write_dns_settings

auto_start2 = UI.QueryWidget(Id("dns_server_type"), :CurrentButton) == :on
DnsServer.SetStartService(auto_start2)
CWMFirewallInterfaces.OpenFirewallStore(firewall_widget, "", event)
end

Expand Down
148 changes: 77 additions & 71 deletions src/include/dns-server/dialog-main.rb
Expand Up @@ -5,12 +5,17 @@
# Summary: Data for configuration of dns-server, input and output functions.
# Authors: Jiri Srain <jsrain@suse.cz>

require "ui/service_status"
require "yast/logger"
require "yast2/popup"
require "dns-server/service_widget_helpers"

module Yast
# Representation of the configuration of dns-server.
# Input and output routines.
module DnsServerDialogMainInclude
include Yast::Logger
include Y2DnsServer::ServiceWidgetHelpers

def initialize_dns_server_dialog_main(include_target)
textdomain "dns-server"

Expand Down Expand Up @@ -259,20 +264,9 @@ def initialize_dns_server_dialog_main(include_target)
@functions = { :abort => fun_ref(method(:confirmAbort), "boolean ()") }
end

def InitStartUp(_key)
status_widget.refresh
nil
end
def handle_apply(_key, event)
SaveAndRestart(event) if event["ID"] == "apply"

def HandleStartUp(_key, event)
event_id = event["ID"]
if event_id == "apply"
SaveAndRestart()
else
if status_widget.handle_input(event_id) == :enabled_flag
DnsServer.SetStartService(status_widget.enabled_flag?)
end
end
nil
end

Expand Down Expand Up @@ -895,7 +889,7 @@ def CheckOptionValue(option, value)
_("Really set this\noption without any value?\n")
)
return false
end
end
# it is a YES or NO type
elsif OptionsIsYesNoType(option)
# it has not a yes/no value
Expand All @@ -913,7 +907,7 @@ def CheckOptionValue(option, value)
)
return false
end
end
end
# it must be a number
elsif OptionsIsNumberType(option)
# if has not a number value
Expand Down Expand Up @@ -1876,38 +1870,72 @@ def HandleExpertZonesPage(key, event)
end

# Write settings dialog
# @return `abort if aborted and `next otherwise
#
# @return [Symbol] :next whether configuration is saved successfully
# :back if user decided to change settings
# :abort otherwise
def WriteDialog
Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))
ret = DnsServer.Write
if ret
service.reload if service.running? && status_widget.reload_flag?
:next
else
if Popup.YesNo(_("Saving the configuration failed. Change the settings?"))
:back
else
:abort
end
end
log.info("Running write dialog")

Wizard.RestoreHelp(write_help_text)

return :next if write_settings
return :back if back_to_change_setting?
:abort
end

# Writes settings and restores the dialog without exiting
def SaveAndRestart
# Writes settings without exiting
def SaveAndRestart(event)
return nil unless validate_and_save_widgets(event)

Wizard.CreateDialog
Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))
ret = DnsServer.Write
if ret
service.reload if service.running? && status_widget.reload_flag?
else
Report.Error(_("Saving the configuration failed"))
end
Builtins.sleep(1000)
UI.CloseDialog
Wizard.RestoreHelp(write_help_text)
Report.Error(_("Saving the configuration failed")) unless write_settings
Wizard.CloseDialog

service_widget.refresh

nil
end

# Writes DNS server settings and save the service
#
# @note currently, the DnsServer is a Perl module, reason why the write of
# settings is being performed in two steps.
#
# @return [Boolean] true if settings are saved successfully; false otherwise
def write_settings
DnsServer.Write && service.save
end

# Shows a popup asking to user if wants to change settings
#
# @return [Boolean] true if user decides to go back to change settings; false otherwise
def back_to_change_setting?
change_settings_message = _("Saving the configuration failed. Change the settings?")
Yast2::Popup.show(change_settings_message, headline: :warning, buttons: :yes_no) == :yes
end

# Validates and saves CWM widgets
#
# @param [Hash] event map that triggered saving
def validate_and_save_widgets(event)
return false unless CWM.validate_current_widgets(event)

CWM.save_current_widgets(event)

true
end

# Returns the common help text during settings are being written
#
# @return [String] common help text, if any; empty string otherwise
def write_help_text
@HELPS.fetch("write") { "" }
rescue
""
end

# Ask for exit without saving
# @return event that should be handled, nil if user canceled the exit
def confirmAbort
Expand Down Expand Up @@ -1961,12 +1989,12 @@ def tabs
"start_up" => {
# FIXME: new startup
"contents" => VBox(
status_widget.widget,
service_widget.contents,
VSpacing(),
"firewall",
VStretch(),
Right(
PushButton(Id("apply"), _("Apply Changes"))
"apply"
)
),
# Dialog Label - DNS - expert settings
Expand All @@ -1981,7 +2009,7 @@ def tabs
# FIXME: new startup
"widget_names" => DnsServer.ExpertUI ?
# expert mode
["start_up", "firewall"] :
["start_up", "firewall", "apply"] :
# simple mode
["start_up", "firewall", "set_icon"]
},
Expand Down Expand Up @@ -2078,18 +2106,12 @@ def tabs
# Returns a hash describing the UI widgets
def new_widgets
@new_widgets ||= {
"start_up" => {
"widget" => :custom,
"custom_widget" => VBox(),
"init" => fun_ref(
method(:InitStartUp),
"void (string)"
),
"handle" => fun_ref(
method(:HandleStartUp),
"symbol (string, map)"
),
"help" => status_widget.help
"start_up" => service_widget.cwm_definition,
"apply" => {
"widget" => :push_button,
"label" => _("Apply Changes"),
"handle" => fun_ref(method(:handle_apply), "symbol (string, map)"),
"help" => ""
},
"firewall" => CWMFirewallInterfaces.CreateOpenFirewallWidget(
{ "services" => ["dns"], "display_details" => true }
Expand Down Expand Up @@ -2224,21 +2246,5 @@ def new_widgets
}
}
end

# Returns the status widget for service
#
# @return [::UI::ServiceStatus] status widget
#
# @see #service
def status_widget
@status_widget ||= ::UI::ServiceStatus.new(service)
end

# Returns the 'named' systemd service
#
# @return [SystemdService] 'named' systemd service instance
def service
@service ||= SystemdService.find("named")
end
end
end

0 comments on commit 36ee948

Please sign in to comment.