Skip to content

Commit

Permalink
Merge branch 'master' into cwm-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidner committed May 19, 2017
2 parents 8c0b603 + 7b3d8a7 commit e44e8a0
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 3 deletions.
55 changes: 55 additions & 0 deletions library/cwm/examples/object_api_table.rb
@@ -0,0 +1,55 @@
# Simple example to demonstrate object API Table for CWM

require_relative "example_helper"

require "cwm/table"

Yast.import "CWM"
Yast.import "Directory"
Yast.import "Wizard"

class NiceTable < CWM::Table
def header
[
Center("name"),
Right("surname"),
"icon"
]
end

def items
[
[1, "Joe", "Doe",
cell(icon(Yast::Directory.icondir + "/22x22/apps/yast-partitioning"))],
[2, "Billy", "Kid", nil],
[3, "Benny", nil, nil]
]
end

def init
self.value = 3
end
end

module Yast
class ExampleDialog
include Yast::I18n
include Yast::UIShortcuts
def run
textdomain "example"

table_widget = NiceTable.new

contents = HBox(
table_widget
)

Yast::Wizard.CreateDialog
CWM.show(contents, caption: _("Table Example"))
Yast.y2milestone("Selected item: #{table_widget.value.inspect}")
Yast::Wizard.CloseDialog
end
end
end

Yast::ExampleDialog.new.run
1 change: 1 addition & 0 deletions library/cwm/src/Makefile.am
Expand Up @@ -16,6 +16,7 @@ ylib_DATA = \
lib/cwm/custom_widget.rb \
lib/cwm/page.rb \
lib/cwm/pager.rb \
lib/cwm/table.rb \
lib/cwm/tabs.rb \
lib/cwm/tree.rb \
lib/cwm/tree_pager.rb \
Expand Down
121 changes: 121 additions & 0 deletions library/cwm/src/lib/cwm/table.rb
@@ -0,0 +1,121 @@
require "abstract_method"
require "cwm/custom_widget"

module CWM
# Represents Table widget
class Table < CustomWidget
# @method header
# return array of String or Yast::Term which is used as headers for table
# it can use e.g. align Left/Center/Right
# @note It has to be overwritten
# @return [Array<String|Yast::Term>]
#
# @example of header
# def header
# [
# _("First Name"),
# Right(_("Surname")
# ]
# end
abstract_method :header

# gets initial two dimensional array of Table content
# one element in the first dimension contain as first element id and then
# rest is data in table, which can be e.g. terms. Then it have to be enclosed in
# `cell` term.
# @see for more complex example see examples directory
# @note default value is empty array. It is useful when computation expensive content
# need to be set. In such case, it is better to keep empty items to quickly show table and
# then in #init call #change_items method, so it will be filled when all widgets are at place
# and just filling its content.
#
# @example for table with two columns
# def items
# [
# [:first_user, "Joe", "Doe"],
# [:best_user, "Chuck", "Norris"]
# ]
# end
def items
[]
end

# change list on fly with argument. Useful when content of widget is changed.
# @note items and change_items is consistent with ItemsSelection mixin, just format of
# items is different due to nature of Table content.
# @param items_list [Array<Array<Object>>] same format as {#items}
def change_items(items_list)
Yast::UI.ChangeWidget(Id(widget_id), :Items, format_items(items_list))
end

# gets id of selected item in table or array of ids if multiselection option is used
# @return [Array<Object>, Object] array if multiselection? return true
def value
val = Yast::UI.QueryWidget(Id(widget_id), :SelectedItems)
multiselection? ? val : val.first
end

# sets id of selected item(-s) in table
# @param id [Object, Array<Object>] selected id, if multiselection? is true
# it require array of ids to select
def value=(id)
Yast::UI.ChangeWidget(Id(widget_id), :SelectedItems, Array[id])
end

# Replaces content of single cell
# @param id [Object] id of row ( the first element in #items )
# @param column_number [Integer] index of cell in row. Index start with 0 for first cell.
# @param cell_content [String, Yast::Term, Object] Content of cell. Support same stuff as #items
# @note more efficient for bigger tables then changing everything with #change_items
def change_cell(id, column_number, cell_content)
Yast::UI.ChangeWidget(Id(widget_id), Cell(id, column_number), cell_content)
end

# Resulting table as YUI term.
# @note used mainly to pass it CWM.
def contents
opt_args = respond_to?(:opt, true) ? opt : []
Table(
Id(widget_id),
Opt(*opt_args),
Header(*header),
format_items(items)
)
end

protected

# helper to create icon term
# @param path [String] path to icon
def icon(path)
Yast::Term.new(:icon, path)
end

# helper to create icon term
# @param args content of cell, often used to combine icon and string
# @note Please see difference between `Cell` and `cell`. The first one is
# used in queries to pick exact cell, but later is used for content of cell.
# For reasons ask libyui authors.
#
# @example
# cell(icon("/tmp/cool_icon.png"), "Really cool!!!")
def cell(*args)
Yast::Term.new(:cell, *args)
end

# helper to say if table have multiselection
def multiselection?
return false unless respond_to?(:opt, true)

opt.include?(:multiSelection)
end

private

def format_items(items)
items.map do |item|
Item(Id(item.first), *item[1..-1])
end
end
end
end
1 change: 1 addition & 0 deletions library/cwm/test/Makefile.am
@@ -1,6 +1,7 @@
TESTS = \
abstract_widget_test.rb \
custom_widget_test.rb \
table_test.rb \
widgets_test.rb

TEST_EXTENSIONS = .rb
Expand Down
24 changes: 24 additions & 0 deletions library/cwm/test/table_test.rb
@@ -0,0 +1,24 @@
#! /usr/bin/env rspec --format doc

require_relative "test_helper"

require "cwm/rspec"
require "cwm/table"

describe CWM::Table do
class MyTable < CWM::Table
def header
["English", "Deutsch"]
end

def items
[
[:one, "one", "eins"],
[:two, "two", "zwei"]
]
end
end
subject { MyTable.new }

include_examples "CWM::CustomWidget"
end
4 changes: 2 additions & 2 deletions library/packages/src/lib/packages/update_messages_view.rb
Expand Up @@ -20,8 +20,8 @@ def initialize(messages)
#
# @return [String] Richtext representation of the list of messages
def richtext
text = "<h1>#{_("Packages notifications")}</h1>\n" \
"<p>#{_("You have notifications from the following packages:")}</p>"
text = "<h1>" + _("Packages notifications") + "</h1>\n<p>" \
+ _("You have notifications from the following packages:") + "</p>"
text << richtext_toc(@messages) if @messages.size > 1
text << @messages.map { |m| message_to_richtext(m) }.join("<hr>")
end
Expand Down
13 changes: 13 additions & 0 deletions package/yast2.changes
@@ -1,3 +1,16 @@
-------------------------------------------------------------------
Fri May 19 12:24:43 UTC 2017 - mvidner@suse.com

- Added CWM::Table (boo#1039901)
- 3.2.31

-------------------------------------------------------------------
Thu May 18 13:35:05 UTC 2017 - lslezak@suse.cz

- Translation fix: Ruby gettext cannot extract translatable texts
from interpolated strings (bsc#1038077)
- 3.2.30

-------------------------------------------------------------------
Tue May 16 12:04:40 UTC 2017 - mvidner@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 3.2.29
Version: 3.2.31
Release: 0
Summary: YaST2 - Main Package
License: GPL-2.0
Expand Down

0 comments on commit e44e8a0

Please sign in to comment.