def testCreateHotlistTableData_EndPagination(self):
     self.setUpCreateHotlistTableDataTestMR(hotlist=self.test_hotlist,
                                            path='/123?num=2&start=2')
     table_data, _ = hotlist_helpers.CreateHotlistTableData(
         self.mr, self.hotlist_items_list, profiler.Profiler(),
         self.services)
     self.assertEqual(len(table_data), 1)
Ejemplo n.º 2
0
    def GetTableViewData(self, mr):
        """EZT template values to render a Table View of issues.

    Args:
      mr: commonly used info parsed from the request.

    Returns:
      Dictionary of page data for rendering of the Table View.
    """
        table_data, table_related_dict = hotlist_helpers.CreateHotlistTableData(
            mr, mr.hotlist.items, self.services)
        columns = mr.col_spec.split()
        ordered_columns = [
            template_helpers.EZTItem(col_index=i, name=col)
            for i, col in enumerate(columns)
        ]
        table_view_data = {
            'table_data':
            table_data,
            'panels':
            [template_helpers.EZTItem(ordered_columns=ordered_columns)],
            'cursor':
            mr.cursor or mr.preview,
            'preview':
            mr.preview,
            'default_colspec':
            features_constants.DEFAULT_COL_SPEC,
            'default_results_per_page':
            10,
            'preview_on_hover': (settings.enable_quick_edit
                                 and mr.auth.user_pb.preview_on_hover),
            # token must be generated using url with userid to accommodate
            # multiple urls for one hotlist
            'edit_hotlist_token':
            xsrf.GenerateToken(
                mr.auth.user_id,
                hotlist_helpers.GetURLOfHotlist(mr.cnxn,
                                                mr.hotlist,
                                                self.services.user,
                                                url_for_token=True) + '.do'),
            'add_local_ids':
            '',
            'placeholder':
            _INITIAL_ADD_ISSUES_MESSAGE,
            'add_issues_selected':
            ezt.boolean(False),
            'col_spec':
            ''
        }
        table_view_data.update(table_related_dict)

        return table_view_data
Ejemplo n.º 3
0
    def testCreateHotlistTableData(self):
        self.setUpCreateHotlistTableDataTestMR(hotlist=self.test_hotlist)
        table_data, table_related_dict = hotlist_helpers.CreateHotlistTableData(
            self.mr, self.hotlist_items_list, self.services)
        self.assertEqual(len(table_data), 3)
        start_index = 100001
        for row in table_data:
            self.assertEqual(row.project_name, 'ProjectName')
            self.assertEqual(row.issue_id, start_index)
            start_index += 1
        self.assertEqual(len(table_related_dict['column_values']), 3)

        # test none of the shown columns show up in unshown_columns
        self.assertTrue(
            set(self.mr.col_spec.split()).isdisjoint(
                table_related_dict['unshown_columns']))
        self.assertEqual(table_related_dict['is_cross_project'], False)
        self.assertEqual(len(table_related_dict['pagination'].visible_results),
                         3)
Ejemplo n.º 4
0
    def HandleRequest(self, mr):
        changed_ranks = self._GetNewRankings(mr)

        if changed_ranks:
            relations_to_change = dict(
                (issue_id, rank) for issue_id, rank in changed_ranks)

            self.services.features.UpdateHotlistItemsFields(
                mr.cnxn, mr.hotlist_id, new_ranks=relations_to_change)

            hotlist_items = self.services.features.GetHotlist(
                mr.cnxn, mr.hotlist_id).items

            # Note: Cannot use mr.hotlist because hotlist_issues
            # of mr.hotlist is not updated

            sorting.InvalidateArtValuesKeys(
                mr.cnxn,
                [hotlist_item.issue_id for hotlist_item in hotlist_items])
            (table_data, _) = hotlist_helpers.CreateHotlistTableData(
                mr, hotlist_items, self.profiler, self.services)

            json_table_data = [{
                'cells': [{
                    'type':
                    cell.type,
                    'values': [{
                        'item': value.item,
                        'isDerived': value.is_derived,
                    } for value in cell.values],
                    'colIndex':
                    cell.col_index,
                    'align':
                    cell.align,
                    'noWrap':
                    cell.NOWRAP,
                    'nonColLabels': [{
                        'value': label.value,
                        'isDerived': label.is_derived,
                    } for label in cell.non_column_labels],
                } for cell in table_row.cells],
                'issueRef':
                table_row.issue_ref,
                'idx':
                table_row.idx,
                'projectName':
                table_row.project_name,
                'projectURL':
                table_row.project_url,
                'localID':
                table_row.local_id,
                'issueID':
                table_row.issue_id,
                'isStarred':
                table_row.starred,
                'issueCleanURL':
                table_row.issue_clean_url,
                'issueContextURL':
                table_row.issue_ctx_url,
            } for table_row in table_data]

            for row, json_row in zip([table_row for table_row in table_data],
                                     json_table_data):
                if (row.group and row.group.cells):
                    json_row.update({
                        'group': {
                            'rowsInGroup':
                            row.group.rows_in_group,
                            'cells': [
                                {
                                    'groupName':
                                    cell.group_name,
                                    'values': [
                                        {
                                            # TODO(jojwang): check if this gives error when there
                                            # is no value.item
                                            'item':
                                            value.item
                                            if value.item else 'None',
                                        } for value in cell.values
                                    ],
                                } for cell in row.group.cells
                            ],
                        }
                    })
                else:
                    json_row['group'] = 'no'

            return {'table_data': json_table_data}
        else:
            return {'table_data': ''}