Provide partial-completed progress bar for DataTable status columns.

Current progress bar for a status column is always 100%.
We need to provide a way for the DataTable to show incompleted status.
For some long operations, this is not so user friendly.

Closes-Bug: 1811046

Change-Id: Idf1ff00e5989ff347419faad2218becbe6d4415e
Signed-off-by: Yan Chen <yan.chen@intel.com>
This commit is contained in:
Yan Chen 2018-12-19 21:01:22 +08:00
parent 0a5d6db65b
commit cc2a9c0503
2 changed files with 63 additions and 0 deletions

View File

@ -85,8 +85,12 @@ horizon.datatables = {
.addClass('progress progress-striped active')
.appendTo($container);
// Incomplete progress bar addition
$width = $new_row.find('[percent]:first').attr('percent') || "100%";
$(document.createElement('div'))
.addClass('progress-bar')
.css("width", $width)
.appendTo($progress);
// if action/confirm is required, show progress-bar with "?"

View File

@ -88,6 +88,15 @@ TEST_DATA_7 = (
'not wrapped optional'),
)
TEST_DATA_8 = (
FakeObject('1', 'object_1', 'value_1',
'started', 'optional_1', 'excluded_1'),
FakeObject('2', 'object_1', 'value_1',
'half', 'optional_1', 'excluded_1'),
FakeObject('3', 'object_1', 'value_1',
'finished', 'optional_1', 'excluded_1'),
)
class MyLinkAction(tables.LinkAction):
name = "login"
@ -125,6 +134,14 @@ class MyRowSelectable(tables.Row):
return datum.value != 'DELETED'
class MyRowSortable(tables.Row):
ajax = True
@classmethod
def get_data(cls, request, obj_id):
return TEST_DATA_8[0]
class MyRow(tables.Row):
ajax = True
@ -302,6 +319,23 @@ class MyTable(tables.DataTable):
MyBatchActionWithHelpText)
class MyProgressTable(MyTable):
tooltip_dict = {'started': {'percent': '10%'},
'half': {'percent': '50%'},
'finished': {'percent': '100%'}}
status = tables.Column('status', truncate=35,
status=True,
cell_attributes_getter=tooltip_dict.get)
class Meta(object):
name = "my_table"
verbose_name = "My Table"
status_columns = ["status"]
columns = ('id', 'name', 'value', 'optional', 'status')
row_class = MyRowSortable
column_class = MyColumn
class TableWithColumnsPolicy(tables.DataTable):
name = tables.Column('name')
restricted = tables.Column('restricted',
@ -715,6 +749,31 @@ class DataTableTests(test.TestCase):
self.assertNotContains(resp_optional, '<ul>')
self.assertNotContains(resp_optional, '</ul>')
def test_progress_bar_rendering(self):
self.table = MyProgressTable(self.request, TEST_DATA_8)
row = self.table.get_rows()[0]
status_cell0 = row.cells['status']
row = self.table.get_rows()[1]
status_cell1 = row.cells['status']
row = self.table.get_rows()[2]
status_cell2 = row.cells['status']
# Check if is cell is rendered correctly.
status_cell0_rendered = status_cell0.render()
resp = http.HttpResponse(status_cell0_rendered)
self.assertContains(resp, 'warning', 1)
self.assertContains(resp, 'percent="10%"', 1)
status_cell1_rendered = status_cell1.render()
resp = http.HttpResponse(status_cell1_rendered)
self.assertContains(resp, 'warning', 1)
self.assertContains(resp, 'percent="50%"', 1)
status_cell2_rendered = status_cell2.render()
resp = http.HttpResponse(status_cell2_rendered)
self.assertContains(resp, 'warning', 1)
self.assertContains(resp, 'percent="100%"', 1)
def test_inline_edit_mod_checkbox_with_label(self):
class TempTable(MyTable):
name = tables.Column(get_name,