Class: YuiRestClient::Widgets::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/yui_rest_client/widgets/table.rb

Overview

Class representing a table in the UI. It can be YTable

Instance Method Summary collapse

Methods inherited from Base

#action, #collect_all, #debug_label, #enabled?, #exists?, #initialize, #property

Methods included from YuiRestClient::Waitable

#wait_until, #wait_while

Constructor Details

This class inherits a constructor from YuiRestClient::Widgets::Base

Instance Method Details

#empty?Boolean

Returns whether the table contains any row or not

Examples:

Check if table with id “test_id” is empty

{
  "class": "YTable",
  "columns": 4,
  "header": [
    "header1",
    "header2",
    "header3",
    "header4"
  ],
  "id": "test_id",
  "items": null,
  "items_count": 0
}
app.table(id: 'test_id').empty?

Returns:

  • (Boolean)

    true if table is empty, otherwise false



25
26
27
# File 'lib/yui_rest_client/widgets/table.rb', line 25

def empty?
  property(:items).nil?
end

#headerArray

Returns the list of column names.

Examples:

Get header column names from the table with id “test_id”

app.table(id: 'test_id').header

Returns:

  • (Array)

    array of [String] objects containing names of the columns



75
76
77
# File 'lib/yui_rest_client/widgets/table.rb', line 75

def header
  property(:header)
end

#itemsArray

Returns the list of items available to select from the table.

Examples:

Get items from the table with id “test_id”

{
  "class": "YTable",
  "columns": 4,
  "header": [
    "header1",
    "header2",
    "header3",
    "header4"
  ],
  "id": "test_id",
  "items": [
      {
          "labels": [
              "test.item.1",
              "",
              "",
              ""
          ],
          "selected": true
      },
      {
          "labels": [
              "test.item.2",
              "",
              "",
              ""
          ]
      }
  ],
  "items_count": 2
}
app.table(id: 'test_id').items
# [test.item.1, "", "", ""]
# [test.item.2, "", "", ""]

Returns:

  • (Array)

    array of [Array] objects containing values for each column



67
68
69
# File 'lib/yui_rest_client/widgets/table.rb', line 67

def items
  property(:items).map { |x| x[:labels] }
end

#select(value: nil, column: nil, row: nil) ⇒ Table

Sends action to select a row in a table. Row can be selected either by cell value in the column (first column will be used by default), or by row number directly. If both are provided, value will be used. NOTE: row number corresponds to the position of the item in the list of column values which might differ to the display order.

Examples:

Select row with value “test.item.2” for column “header1” in table with id ‘test_id’

app.table(id: 'test_id').select(value: 'test.item.2', column: 'header1')

Select row number 3 in table with id ‘test_id’

app.table(id: 'test_id').select(row: 3)

Parameters:

  • value (String) (defaults to: nil)

    value to select in the table.

  • column (String) (defaults to: nil)

    column name where value is present

  • row (Numeric) (defaults to: nil)

    row number to select in the table.

Returns:

  • (Table)

    in case action is successful



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/yui_rest_client/widgets/table.rb', line 92

def select(value: nil, column: nil, row: nil)
  params = { action: Actions::SELECT }
  if !value.nil?
    params.merge!(value: value)
    params.merge!(column: get_index(column)) unless column.nil?
  elsif !row.nil?
    params.merge!(row: row)
  end
  action(params)
  self
end

#selected_itemsArray

Returns the list of items currently selected from the table.

Examples:

Get items from the table with id “test_id”

{
  "class": "YTable",
  "columns": 4,
  "header": [
    "header1",
    "header2",
    "header3",
    "header4"
  ],
  "id": "test_id",
  "items": [
      {
          "labels": [
              "test.item.1",
              "",
              "",
              ""
          ],
          "selected": true
      },
      {
          "labels": [
              "test.item.2",
              "",
              "",
              ""
          ],
          "selected": true
      }
  ],
  "items_count": 2
}
app.table(id: 'test_id').selected_items
# [test.item.1, "", "", ""]
# [test.item.2, "", "", ""]

Returns:

  • (Array)

    array of [Array] objects containing values for each column



143
144
145
# File 'lib/yui_rest_client/widgets/table.rb', line 143

def selected_items
  property(:items).map { |x| x[:labels] if x[:selected] }.compact
end