-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
439 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# 2 space indentation | ||
[*.rb] | ||
indent_style = space | ||
indent_size = 2 |
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
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,94 @@ | ||
# Copyright (c) [2019] 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. | ||
|
||
module Y2ConfigurationManagement | ||
module Salt | ||
# A boolean condition operating on a value in the form, | ||
# used for widget visibility ($visibleIf). | ||
class FormCondition | ||
class ParseError < RuntimeError | ||
end | ||
|
||
# @param s [String] | ||
# @param context [FormElementLocator] for resolving relative expressions | ||
def self.parse(s, context:) | ||
if s.empty? | ||
nil | ||
# This matches checkVisibilityCondition in FormulaComponentGenerator.js | ||
# TODO: specify it better | ||
elsif s.include?("==") | ||
parts = s.split("==").map(&:strip) | ||
locator = parse_locator(parts[0].strip, context) | ||
value = parse_value(parts[1].strip) | ||
EqualCondition.new(locator: locator, value: value) | ||
elsif s.include?("!=") | ||
parts = s.split("!=").map(&:strip) | ||
locator = parse_locator(parts[0], context) | ||
value = parse_value(parts[1]) | ||
NotEqualCondition.new(locator: locator, value: value) | ||
else | ||
raise ParseError, "Expecting equality or inequality: #{s.inspect}" | ||
end | ||
end | ||
|
||
def self.parse_locator(s, context) | ||
if s.start_with? "." | ||
while s.start_with? "." | ||
s = s[1..-1] | ||
context = context.parent | ||
end | ||
else | ||
context = FormElementLocator.new([:root]) | ||
end | ||
s_parts = s.split("#").map(&:to_sym) | ||
context.join(* s_parts) | ||
end | ||
|
||
def self.parse_value(s) | ||
if (s[0] == "'" && s[-1] == "'") || (s[0] == "\"" && s[-1] == "\"") | ||
s[1..-2] | ||
else | ||
s | ||
end | ||
end | ||
end | ||
|
||
# A {FormCondition} checking if a widget is equal to a constant | ||
class EqualCondition < FormCondition | ||
def initialize(locator:, value:) | ||
@locator = locator | ||
@value = value | ||
end | ||
|
||
# @param data [FormData] | ||
def evaluate(data) | ||
left = data.get(@locator).to_s | ||
right = @value.to_s | ||
left == right | ||
end | ||
end | ||
|
||
# A {FormCondition} checking if a widget is not equal to a constant | ||
class NotEqualCondition < EqualCondition | ||
def evaluate(data) | ||
!super | ||
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
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
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
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
42 changes: 42 additions & 0 deletions
42
src/lib/y2configuration_management/widgets/salt_visibility_switcher.rb
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,42 @@ | ||
# Copyright (c) [2019] 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" | ||
|
||
module Y2ConfigurationManagement | ||
module Widgets | ||
# Salt-forms specific visibility switching | ||
module SaltVisibilitySwitcher | ||
# @return [FormCondition,nil] | ||
attr_reader :visible_if | ||
|
||
def initialize_salt_visibility_switcher(visible_if) | ||
@visible_if = visible_if | ||
end | ||
|
||
# Automatic invisibility: when the form controller asks us, | ||
# we evaluate a condition and update our visibility | ||
# @param data [FormData] | ||
def update_visibility(data) | ||
return unless @visible_if | ||
self.visible = @visible_if.evaluate(data) | ||
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
Oops, something went wrong.