Skip to content
This repository was archived by the owner on Apr 7, 2022. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 4 additions & 59 deletions widgetastic_manageiq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
FileInput as BaseFileInput,
Table as VanillaTable, TableColumn as VanillaTableColumn, TableRow as VanillaTableRow,
Widget, View, Select, TextInput, Text, Checkbox, ParametrizedView, ClickableMixin,
ConditionalSwitchableView, do_not_read_this_widget)
ConditionalSwitchableView, do_not_read_this_widget, DynamicTableMixin)
from widgetastic.xpath import quote
from widgetastic_patternfly import (
Accordion as PFAccordion, BootstrapSwitch, BootstrapTreeview, BootstrapSelect,
Expand All @@ -33,11 +33,6 @@
from cfme.exceptions import ItemNotFound


class DynamicTableAddError(Exception):
"""Raised when an attempt to add or save a row to a `widgetastic_manageiq.DynamicTable` fails"""
pass


# TODO: replace below calls with direct calls later
ManageIQTree = BootstrapTreeview

Expand Down Expand Up @@ -3467,62 +3462,12 @@ def read(self):
return self.all_shortcuts


class DynamicTable(VanillaTable):
"""Extend the widget.Table class to implement row_add for dynamic tables with an 'Actions'
column.
In these tables, the top or bottom row can be clicked to add a new row, and when it is
clicked the row is replaced (top or bottom) with a row containing fillable widgets.

When the row is saved, it is moved to the bottom of the table. This behavior is specifc to
some MIQ dynamic tables.

Args:
action_row: index of the action row, generally 0 or -1, defaults to 0
class DynamicTable(VanillaTable, DynamicTableMixin):
"""Miq implementation of Dynamic Table where user can add/remove rows

See Widgetastic.widget.Table for more arguments
See Widgetastic.widget.Table and Widgetastic.widget.DynamicTableMixin for more arguments
"""

def __init__(self, *args, **kwargs):
self.action_row = kwargs.pop('action_row', 0) # pull this off and pass the rest up
super(DynamicTable, self).__init__(*args, **kwargs)

def row_add(self):
"""Use the action-cell column widget to add a row

Clicks on the row directly, not the action button

Returns:
int positive row index of the action row where the new widgets should be displayed
"""
# convert action_row into a positive index
if self.action_row >= 0:
pos_action_index = self.action_row
else:
pos_action_index = self._process_negative_index(nindex=self.action_row)

try:
self[pos_action_index].click()
except IndexError: # self.action_row must have been None
raise DynamicTableAddError('DynamicTable action_row index "{}" not found in table'
.format(self.action_row))
return pos_action_index

def row_save(self, row=None):
"""Save the row, assuming attributized columns includes 'actions'

Implements behavior of AnalysisProfile type tables, where the row is moved to the bottom
on save

Returns:
int row index of the last row in the table
"""
try:
self[row or self.action_row].actions.click()
except IndexError: # self.action_row must have been None
raise DynamicTableAddError('DynamicTable action_row index "{}" not found in table'
.format(self.action_row))
return self._process_negative_index(nindex=-1) # use process_negative_index to get last row


class FolderManager(Widget):
""" Represents the folder manager in Edit Report Menus screen
Expand Down