Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8249 from izapolsk/restore_nonjs_paginator_for_ssui
Browse files Browse the repository at this point in the history
[WIPTEST] NonJS Paginator has been restored due to no support of JS api in SSUI
  • Loading branch information
mshriver committed Dec 6, 2018
2 parents 754b23f + 6fc3287 commit 6244ff2
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cfme/services/dashboard/ssui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from cfme.utils.wait import wait_for
from widgetastic_manageiq import (SSUIPrimarycard, SSUIAggregatecard,
SSUIlist, PaginationPane)
SSUIlist, SSUIPaginationPane)


class DashboardView(SSUIBaseLoggedInPage):
Expand All @@ -40,7 +40,7 @@ class MyServiceForm(SSUIBaseLoggedInPage):
class MyServicesView(MyServiceForm):
title = Text(locator='//li[@class="active"]')
results = Text(locator='//div[contains(@class, "toolbar-pf-results")]/*/h5')
paginator = PaginationPane()
paginator = SSUIPaginationPane()

@property
def in_myservices(self):
Expand Down
197 changes: 197 additions & 0 deletions widgetastic_manageiq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
from collections import namedtuple
from datetime import date, datetime, timedelta
from math import ceil
from tempfile import NamedTemporaryFile

import six
Expand Down Expand Up @@ -1693,6 +1694,202 @@ def reset_selection(self):
return False


class NonJSPaginationPane(View):
""" Represents Paginator Pane with the following controls.
The intention of this view is to use it as nested view on f.e. Infrastructure Providers page.
"""

ROOT = '//div[@id="paging_div"]'

check_all_items = Checkbox(id="masterToggle")
sort_by = BootstrapSelect(id="sort_choice")
items_on_page = BootstrapSelect(id="ppsetting")
paginator = Paginator()

@property
def is_displayed(self):
# there are cases when paging_div is shown but it is empty
return (
self.check_all_items.is_displayed
or self.paginator.is_displayed
and self.items_on_page.is_displayed
)

@property
def exists(self):
return self.is_displayed

def check_all(self):
self.check_all_items.fill(True)

def uncheck_all(self):
self.check_all()
self.check_all_items.fill(False)

def sort(self, value):
self.sort_by.select_by_visible_text(value)

@property
def sorted_by(self):
raise NotImplementedError("to implement it when needed")

@property
def items_per_page(self):
selected = self.items_on_page.selected_option
return int(re.sub(r"\s+items", "", selected))

def set_items_per_page(self, value):
"""Selects number of items to be displayed on page.
Args:
value: Ideally value is a positive int
"""
try:
int(value)
except ValueError:
raise ValueError("Value should be integer and not {}".format(value))

if self.browser.product_version >= "5.8.2":
items_text = str(value)
else:
items_text = "{} items".format(value)
self.items_on_page.select_by_visible_text(items_text)

def _parse_pages(self):
min_item, max_item, item_amt = self.paginator.page_info()

item_amt = int(item_amt)
max_item = int(max_item)
items_per_page = self.items_per_page

# obtaining amount of existing pages, there is 1 page by default
if item_amt == 0:
page_amt = 1
else:
# round up after dividing total item count by per-page
page_amt = int(ceil(float(item_amt) / float(items_per_page)))

# calculating current_page_number
if max_item <= items_per_page:
cur_page = 1
else:
# round up after dividing highest displayed item number by per-page
cur_page = int(ceil(float(max_item) / float(items_per_page)))

return cur_page, page_amt

@property
def cur_page(self):
return self._parse_pages()[0]

@property
def pages_amount(self):
return self._parse_pages()[1]

def next_page(self):
self.paginator.next_page()

def prev_page(self):
self.paginator.prev_page()

def first_page(self):
if self.cur_page != 1:
self.paginator.first_page()

def last_page(self):
if self.cur_page != self.pages_amount:
self.paginator.last_page()

def pages(self):
"""Generator to iterate over pages, yielding after moving to the next page"""
if self.exists:
# start iterating at the first page
if self.cur_page != 1:
self.logger.debug("Resetting paginator to first page")
self.first_page()

# Adding 1 to pages_amount to include the last page in loop
for page in range(1, self.pages_amount + 1):
yield self.cur_page
if self.cur_page == self.pages_amount:
# last or only page, stop looping
break
else:
self.logger.debug("Paginator advancing to next page")
self.next_page()
else:
return

@property
def items_amount(self):
return self.paginator.page_info()[2]

@property
def min_item(self):
return self.paginator.page_info()[0]

@property
def max_item(self):
return self.paginator.page_info()[1]

def find_row_on_pages(self, table, *args, **kwargs):
"""Find first row matching filters provided by kwargs on the given table widget
Args:
table: Table widget object
args: Filters to be passed to table.row()
kwargs: Filters to be passed to table.row()
"""
self.first_page()
for _ in self.pages():
try:
row = table.row(*args, **kwargs)
except IndexError:
continue
if not row:
continue
else:
return row
else:
raise NoSuchElementException(
"Row matching filter {} not found on table {}".format(kwargs, table)
)

def reset_selection(self):
if self.is_displayed:
self.check_all()
self.uncheck_all()
return True
return False


class SSUIPaginator(Paginator):
""" Represents Paginator control for SSUI."""

PAGINATOR_CTL = './/ul[@class="pagination"]'
CUR_PAGE_CTL = "./li[3]/span/.."
PAGE_BUTTON_CTL = "./li[contains(@class, {})]/span"


class SSUIPaginationPane(NonJSPaginationPane):
""" Represents Paginator Pane for SSUI."""

ROOT = '//div[@class="pagination-footer"]'

check_all_items = Checkbox(id="masterToggle")
sort_by = BootstrapSelect(id="sort_choice")
items_on_page = SSUIDropdown("items")
paginator = SSUIPaginator()

def set_items_per_page(self, value):
"""Selects number of items to be displayed on page.
Args:
value: value like 5 items or 10 items.
"""
self.items_on_page.item_select(value)


class Stepper(View):
""" A CFME Stepper Control
Expand Down

0 comments on commit 6244ff2

Please sign in to comment.