Rally:使用TreeStoreBuilder和rallygridboard自定义数据

时间:2016-12-14 01:10:45

标签: rally

我正在尝试创建一个显示自定义数据的Rally页面,并允许我将数据导出到Excel。我正在努力,因为我可以在一个拉力网格中显示数据(这允许我计算自定义字段并显示它们),或者我可以在拉力网格中显示数据(这允许我导出数据),但我不似乎能够做到这两点。

任何人对我能做些什么都有任何想法?

我想要显示的自定义数据是用户素材的功能主要倡议名称fwiw。

Rally's examples中的代码显示了如何在网格中显示自定义数据。我不会在此处粘贴完整代码以节省空间,但这里是他们示例中的相关代码段:

        launch: function() {
                Ext.create('Rally.data.wsapi.Store', {
                    model: 'userstory',
                    autoLoad: true,
                    listeners: {
                        load: this._onDataLoaded,
                        scope: this
                    },
                    fetch: ['FormattedID', 'Name', 'ScheduleState', 'Tasks', 'Defects']
                });
            },

            _onDataLoaded: function(store, data) {
                var records = _.map(data, function(record) {
                    //Perform custom actions with the data here
                    //Calculations, etc.
                    return Ext.apply({
                        TaskCount: record.get('Tasks').Count
                    }, record.getData());
                });

           this.add({
                    xtype: 'rallygrid',
                    showPagingToolbar: false,
                    showRowActionsColumn: false,
                    editable: false,
                    store: Ext.create('Rally.data.custom.Store', {
                        data: records
                    }),

...

这适用于拉力网,但是拉力网似乎不支持导出到csv。

当我将拉力赛网格切换为拉力赛板时,同样的方法(使用_onDataLoaded)不起作用。我在这行的_onDataLoaded中收到错误:     var feature = record.get('Feature'); 我得到的错误是:“record.get不是函数”

这是我的完整代码。请注意,这是编码以获取我实际想要的数据(这是用户故事的东西),而不是任务(这只是Rally示例文件)。

<!DOCTYPE html>
<html>
<head>
<title>Exportable Grid Board Example</title>

<script type="text/javascript" src="/apps/2.1/sdk.js"></script>

<script type="text/javascript">
    var recordCount = 0;

    Rally.onReady(function() {
        Ext.define('Rally.example.ExportableGridBoard', {
            extend: 'Rally.app.App',
            componentCls: 'app',

            launch: function() {
                Ext.create('Rally.data.wsapi.TreeStoreBuilder').build({
                    models: ['portfolioitem/feature','userstory'],
                    autoLoad: true,
                    enableHierarchy: true,
                    listeners: {
                        load: this._onDataLoaded,
                        scope: this
                    }
                }).then({
                    success: this._onStoreBuilt,
                    scope: this
                });
            },

            _onDataLoaded: function (store, data) {
                var records = _.map(data, function (record) {
                    //Perform custom actions with the data here
                    //Calculations, etc.

                    //console.log(record);
                    recordCount++;

                    var feature = record.get('Feature');

                    var featureName;
                    var initiative;
                    var initiativeName;

                    if (feature == null) {
                        featureName = '';
                        initiative = '';
                        initiativeName = '';
                    }
                    else {
                        featureName = feature.FormattedID + ' ' + feature.Name;
                        initiative = feature.Parent;

                        if (initiative == null) {
                            initiativeName = '';
                        }
                        else {
                            initiativeName = initiative.FormattedID + ' ' + initiative.Name;
                        }

                    }

                    return Ext.apply({
                            featureName: featureName,
                            initiativeName: initiativeName
                        }, record.getData());
                })
            },//_onDataLoaded


            _onStoreBuilt: function(store) {

                //this._onDataLoaded(store, store.data);

                //console.log('num records: '+ recordCount);//seems to always be 0

                var modelNames = ['userstory'],
                    context = this.getContext();

                this.add({
                    xtype: 'rallygridboard',
                    context: context,
                    modelNames: modelNames,
                    toggleState: 'grid',
                    stateful: false,
                    plugins: [
                        {
                            ptype: 'rallygridboardactionsmenu',
                            menuItems: [
                                {
                                    text: 'Export...',
                                    handler: function() {
                                        window.location = Rally.ui.gridboard.Export.buildCsvExportUrl(
                                            this.down('rallygridboard').getGridOrBoard());
                                    },
                                    scope: this
                                }
                            ],
                            buttonConfig: {
                                iconCls: 'icon-export'
                            }
                        }
                    ],
                    gridConfig: {
                        store: store,
                        columnCfgs: [
                            'Name',
                            'ScheduleState',
                            //'c_AffinityEstimate',
                            'PlanEstimate',
                            'Project',
                            'Feature',
                            'Feature.Parent',
                            'featureName',
                            'initiativeName'
                        ]
                    },
                    height: this.getHeight()
                });
            }
        });


        Rally.launchApp('Rally.example.ExportableGridBoard', {
          name: 'Exportable Grid Board Example'
        });
    });
</script>

<style type="text/css">

</style>
</head>
<body></body>
</html>

1 个答案:

答案 0 :(得分:0)

仅支持从WSAPI查询填充所有数据的网格导出数据。为了导出您的自定义数据,您必须手动编写一些代码以在客户端上生成CSV字符串,然后使用数据URI触发下载。

我试图找到一个应用程序执行此操作的示例但是空了。以下是对该方法的描述:

https://developer.zendesk.com/blog/app-tricks-generate-csv-files-for-download-with-handlebars-and-data-uris

您只需遍历故事中的每条记录,然后构建分离的字符串,您就可以链接到结果,也可以将window.location设置为结果。